add.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. })
  65. const { typeList, tariffIdList, formState, card, formRef, sourceList, trafficList } = toRefs(state.value)
  66. // 提交
  67. const handleSubmit = ({ values, errors }) => {
  68. formRef.value.validate(async (errors) => {
  69. if (!errors) {
  70. values.size = Number(values.size)
  71. if (status.value == 1) {
  72. delete formState.value.sizeType
  73. delete formState.value.size
  74. }
  75. if (formState.value.id) {
  76. const { code, data } = await updateTrafficPool(formState.value)
  77. if (code == 200) {
  78. Message.success({
  79. content: t('setting.editSuccess'),
  80. duration: 2000,
  81. })
  82. resetForm()
  83. emit('submit', true)
  84. }
  85. } else {
  86. const { code, data } = await addTrafficPool(formState.value)
  87. if (code == 200) {
  88. Message.success({
  89. content: t('setting.addSuccess'),
  90. duration: 2000,
  91. })
  92. resetForm()
  93. emit('submit', true)
  94. }
  95. }
  96. }
  97. });
  98. }
  99. // 获取资费列表选择id
  100. const handleTariff = async () => {
  101. const { code, data } = await tariffList({
  102. "current": 1,
  103. "size": 10
  104. })
  105. if (code == 200) {
  106. tariffIdList.value = (data.records || []).map(item => {
  107. return {
  108. ...item,
  109. value: item.id,
  110. label: item.label + '---' + item.userName
  111. }
  112. })
  113. }
  114. }
  115. // 取消
  116. const resetForm = () => {
  117. emit('update:modelValue', false)
  118. formState.value = {
  119. "label": "",
  120. "trafficPoolType": "2",
  121. "source": "",
  122. "status": "",
  123. "simTariffId": null,
  124. "expireTime": "",
  125. "iccids": [],
  126. "size": null,
  127. "sizeType": ""
  128. }
  129. }
  130. // 获取字典
  131. const handleDictValue = async () => {
  132. sourceList.value = await Getdictionary('source')
  133. trafficList.value = await Getdictionary('trafficPacketStatus')
  134. typeList.value = await Getdictionary('trafficPoolType')
  135. }
  136. const selectChange = (val) => {
  137. updateCardList({ id: val }).then(res => {
  138. if (res.code === 200) {
  139. formState.value.iccids = []
  140. card.value = res.data
  141. }
  142. })
  143. }
  144. watch(() => record.value, val => {
  145. const datas = JSON.parse(JSON.stringify(val))
  146. if (props.typeCurrent == 2) {
  147. formState.value = datas
  148. formState.value.iccids = []
  149. updateCardList({ id: val.simTariffId }).then(res => {
  150. if (res.code === 200) {
  151. val.iccids.forEach(res => {
  152. formState.value.iccids.push(res.iccid)
  153. })
  154. card.value = res.data
  155. }
  156. })
  157. console.log(formState.value.iccids);
  158. }
  159. }, { deep: true })
  160. watch(() => modelValue.value, val => {
  161. if (val) {
  162. handleDictValue()
  163. handleTariff()
  164. }
  165. })
  166. </script>
  167. <template>
  168. <a-modal :render-to-body="false"
  169. :title="typeCurrent == 1 ? $t('form.Add') : typeCurrent == 2 ? $t('form.Edit') : $t('flowPool.Detail')"
  170. v-model:visible="modelValue" @cancel="resetForm" centered :maskClosable="false" :footer="null" width="55%">
  171. <a-tabs v-model:active-key="activeKey">
  172. <a-tab-pane key="1" :title="$t('flowPool.infoTabs')">
  173. <a-form ref="formRef" :rules="rules" :model="formState" @submit="handleSubmit" style="width: 620px;">
  174. <a-form-item :label="$t('flowPool.label')" field="label">
  175. <a-input v-model="formState.label"
  176. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.label')" />
  177. </a-form-item>
  178. <a-form-item :label="$t('flowPool.source')" field="source">
  179. <a-select v-model="formState.source"
  180. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.source')">
  181. <a-option v-for=" item in sourceList" :key="item.id" :value="item.value">{{
  182. item.label
  183. }}
  184. </a-option>
  185. </a-select>
  186. </a-form-item>
  187. <a-form-item :label="$t('flowPool.trafficPoolStatus')" field="status">
  188. <a-select v-model="formState.status"
  189. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.trafficPoolStatus')">
  190. <a-option v-for=" item in trafficList" :key="item.id" :value="item.value">{{
  191. item.label
  192. }}
  193. </a-option>
  194. </a-select>
  195. </a-form-item>
  196. <a-form-item :label="$t('flowPool.simRariff')" field="simTariffId">
  197. <a-select v-model="formState.simTariffId" @change="selectChange"
  198. :placeholder="$t('form.datapoolForm.pleaseSelect') + $t('flowPool.simRariff')">
  199. <a-option v-for=" item in tariffIdList" :key="item.id" :value="item.value">{{
  200. item.label
  201. }}
  202. </a-option>
  203. </a-select>
  204. </a-form-item>
  205. <a-form-item :label="$t('flowPool.ICCIDlabel')" v-if="formState?.simTariffId !== null">
  206. <a-select v-model="formState.iccids" multiple :placeholder="$t('flowPool.ICCIDName')">
  207. <a-option v-for=" item in card" :key="item.iccid" :value="item.iccid">{{
  208. item.iccid
  209. }}
  210. </a-option>
  211. </a-select>
  212. </a-form-item>
  213. <a-form-item :label="$t('flowPool.expireTime')" field="expireTime">
  214. <a-date-picker v-model="formState.expireTime" show-time :time-picker-props="{ defaultValue: '09:09:06' }"
  215. format="YYYY-MM-DD HH:mm:ss" />
  216. </a-form-item>
  217. <a-form-item :label="$t('flowPool.poolSize')" field="size" v-if="status == 2">
  218. <a-input v-model="formState.size" :placeholder="$t('flowPool.poolSize')" />
  219. <a-select v-model="formState.sizeType" style="width: 80px; margin-left: 8px;">
  220. <a-option value="KB">KB</a-option>
  221. <a-option value="MB">MB</a-option>
  222. <a-option value="GB">GB</a-option>
  223. </a-select>
  224. </a-form-item>
  225. <a-form-item>
  226. <a-button type="primary" html-type="submit" style="margin-right: 10px;">{{
  227. $t('form.Confirm')
  228. }}
  229. </a-button>
  230. <a-button @click="resetForm">{{ $t('form.Cancel') }}</a-button>
  231. </a-form-item>
  232. </a-form>
  233. </a-tab-pane>
  234. </a-tabs>
  235. </a-modal>
  236. </template>
  237. <style scoped lang="less"></style>