add.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <script setup>
  2. import { ref, onMounted, toRefs, toRef, watch } from 'vue';
  3. import { Message } from "@arco-design/web-vue";
  4. import {
  5. addTrafficPool,
  6. updateTrafficPool,
  7. updateCardList
  8. } from "@/api/path/flowPool.api"
  9. import { tariffList } from "@/api/path/tariffManagement.api"
  10. import { Getdictionary } from '@/mixins/index.js'
  11. import { useI18n } from 'vue-i18n'
  12. const { t } = useI18n()
  13. const props = defineProps({
  14. modelValue: {
  15. type: Boolean,
  16. default: false
  17. },
  18. status: {
  19. type: [String, Number],
  20. default: ''
  21. },
  22. typeCurrent: {
  23. type: [String, Number],
  24. default: ''
  25. },
  26. record: {
  27. type: [Array, Object],
  28. default: () => {
  29. }
  30. }
  31. })
  32. const modelValue = toRef(props, 'modelValue')
  33. const status = toRef(props, 'status')
  34. const typeCurrent = toRef(props, 'typeCurrent')
  35. const record = toRef(props, 'record')
  36. const emit = defineEmits(['update:modelValue', 'submit'])
  37. const rules = {
  38. label: [{ required: true, trigger: 'change', }],
  39. source: [{ required: true, trigger: 'change', }],
  40. status: [{ required: true, trigger: 'change', }],
  41. simTariffId: [{ required: true, trigger: 'change', }],
  42. expireTime: [{ required: true, trigger: 'change', }],
  43. size: [{ required: true, trigger: 'change', }],
  44. sizeType: [{ required: true, trigger: 'change', }],
  45. };
  46. const state = ref({
  47. typeList: [],
  48. tariffIdList: [],
  49. formState: {
  50. "label": "",
  51. "trafficPoolType": status.value,
  52. "source": "",
  53. "status": "",
  54. "simTariffId": null,
  55. "expireTime": "",
  56. // "iccids": [],
  57. "size": null,
  58. "sizeType": ""
  59. },
  60. card: [],
  61. formRef: null,
  62. sourceList: [],
  63. trafficList: [],
  64. SelectAll: false
  65. })
  66. const { typeList, tariffIdList, formState, card, formRef, sourceList, trafficList, SelectAll } = toRefs(state.value)
  67. // 提交
  68. const handleSubmit = ({ values, errors }) => {
  69. formRef.value.validate(async (errors) => {
  70. if (!errors) {
  71. values.size = Number(values.size)
  72. if (status.value == 1) {
  73. delete formState.value.sizeType
  74. delete formState.value.size
  75. }
  76. if (formState.value.id) {
  77. const { code, data } = await updateTrafficPool(formState.value)
  78. if (code == 200) {
  79. Message.success({
  80. content: t('setting.editSuccess'),
  81. duration: 2000,
  82. })
  83. resetForm()
  84. emit('submit', true)
  85. }
  86. } else {
  87. const { code, data } = await addTrafficPool(formState.value)
  88. if (code == 200) {
  89. Message.success({
  90. content: t('setting.addSuccess'),
  91. duration: 2000,
  92. })
  93. resetForm()
  94. emit('submit', true)
  95. }
  96. }
  97. }
  98. });
  99. }
  100. // 获取资费列表选择id
  101. const handleTariff = async () => {
  102. const { code, data } = await tariffList({
  103. "current": 1,
  104. "size": 10
  105. })
  106. if (code == 200) {
  107. tariffIdList.value = (data.records || []).map(item => {
  108. return {
  109. ...item,
  110. value: item.id,
  111. label: item.label + '---' + item.userName
  112. }
  113. })
  114. }
  115. }
  116. // 取消
  117. const resetForm = () => {
  118. emit('update:modelValue', false)
  119. formState.value = {
  120. "label": "",
  121. "trafficPoolType": "2",
  122. "source": "",
  123. "status": "",
  124. "simTariffId": null,
  125. "expireTime": "",
  126. // "iccids": [],
  127. "size": null,
  128. "sizeType": ""
  129. }
  130. }
  131. // 获取字典
  132. const handleDictValue = async () => {
  133. sourceList.value = await Getdictionary('source')
  134. trafficList.value = await Getdictionary('trafficPacketStatus')
  135. typeList.value = await Getdictionary('trafficPoolType')
  136. }
  137. // const selectChange = (val) => {
  138. // updateCardList({ id: val }).then(res => {
  139. // if (res.code === 200) {
  140. // formState.value.iccids = []
  141. // card.value = res.data
  142. // }
  143. // })
  144. // }
  145. watch(() => record.value, val => {
  146. const datas = JSON.parse(JSON.stringify(val))
  147. if (props.typeCurrent == 2) {
  148. formState.value = datas
  149. // formState.value.iccids = []
  150. // updateCardList({ id: val.simTariffId }).then(res => {
  151. // if (res.code === 200) {
  152. // val.iccids.forEach(res => {
  153. // formState.value.iccids.push(res.iccid)
  154. // })
  155. // card.value = res.data
  156. // }
  157. // })
  158. }
  159. }, { deep: true })
  160. watch(() => modelValue.value, val => {
  161. if (val) {
  162. handleDictValue()
  163. handleTariff()
  164. }
  165. })
  166. // const changeAll = (e)=>{
  167. // SelectAll.value = e
  168. // if (e) {
  169. // formState.value.iccids = card.value.map(res => res.iccid)
  170. // } else {
  171. // formState.value.iccids = []
  172. // }
  173. // }
  174. </script>
  175. <template>
  176. <a-modal :render-to-body="false"
  177. :title="typeCurrent == 1 ? $t('form.Add') : typeCurrent == 2 ? $t('form.Edit') : $t('flowPool.Detail')"
  178. v-model:visible="modelValue" @cancel="resetForm" centered :maskClosable="false" :footer="null" width="55%">
  179. <a-tabs v-model:active-key="activeKey">
  180. <a-tab-pane key="1" :title="$t('flowPool.infoTabs')">
  181. <a-form ref="formRef" :rules="rules" :model="formState" @submit="handleSubmit" style="width: 620px;">
  182. <a-form-item :label="$t('flowPool.label')" field="label">
  183. <a-input v-model="formState.label"
  184. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.label')" />
  185. </a-form-item>
  186. <a-form-item :label="$t('flowPool.source')" field="source">
  187. <a-select v-model="formState.source"
  188. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.source')">
  189. <a-option v-for=" item in sourceList" :key="item.id" :value="item.value">{{
  190. item.label
  191. }}
  192. </a-option>
  193. </a-select>
  194. </a-form-item>
  195. <a-form-item :label="$t('flowPool.trafficPoolStatus')" field="status">
  196. <a-select v-model="formState.status"
  197. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.trafficPoolStatus')">
  198. <a-option v-for=" item in trafficList" :key="item.id" :value="item.value">{{
  199. item.label
  200. }}
  201. </a-option>
  202. </a-select>
  203. </a-form-item>
  204. <a-form-item :label="$t('flowPool.simRariff')" field="simTariffId">
  205. <a-select v-model="formState.simTariffId" @change="selectChange"
  206. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.simRariff')">
  207. <a-option v-for=" item in tariffIdList" :key="item.id" :value="item.value">{{
  208. item.label
  209. }}
  210. </a-option>
  211. </a-select>
  212. </a-form-item>
  213. <!-- <a-form-item :label="$t('flowPool.ICCIDlabel')" v-if="formState?.simTariffId !== null">
  214. <a-select v-model="formState.iccids" multiple :placeholder="$t('flowPool.ICCIDName')" :max-tag-count="10">
  215. <a-option v-for=" item in card" :key="item.iccid" :value="item.iccid">{{item.iccid}}
  216. </a-option>
  217. <template #header>
  218. <div style="padding: 6px 12px;">
  219. <a-checkbox v-model="SelectAll" @change="changeAll">全选</a-checkbox>
  220. </div>
  221. </template>
  222. </a-select>
  223. </a-form-item> -->
  224. <a-form-item :label="$t('flowPool.expireTime')" field="expireTime">
  225. <a-date-picker v-model="formState.expireTime" show-time :time-picker-props="{ defaultValue: '09:09:06' }"
  226. format="YYYY-MM-DD HH:mm:ss" />
  227. </a-form-item>
  228. <a-form-item :label="$t('flowPool.poolSize')" field="size" v-if="status == 2">
  229. <a-input v-model="formState.size" :placeholder="$t('flowPool.poolSize')" />
  230. <a-select v-model="formState.sizeType" style="width: 80px; margin-left: 8px;">
  231. <a-option value="KB">KB</a-option>
  232. <a-option value="MB">MB</a-option>
  233. <a-option value="GB">GB</a-option>
  234. </a-select>
  235. </a-form-item>
  236. <a-form-item>
  237. <a-button type="primary" html-type="submit" style="margin-right: 10px;">{{
  238. $t('form.Confirm')
  239. }}
  240. </a-button>
  241. <a-button @click="resetForm">{{ $t('form.Cancel') }}</a-button>
  242. </a-form-item>
  243. </a-form>
  244. </a-tab-pane>
  245. </a-tabs>
  246. </a-modal>
  247. </template>
  248. <style scoped lang="less"></style>