add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <!--资费 弹框 -->
  3. <a-modal :title="typeIndex == 1 ? $t('form.Add') : $t('form.Edit')" v-model:visible="modelValue"
  4. @onCancel="resetForm" centered :maskClosable="false" :footer="null" width="700px" :closable="false">
  5. <a-form ref="formRef" :rules="rules" :model="formState" @submit="handleSubmit">
  6. <div class="formTitle">{{ $t('tariffManagement.BasicInformation') }}</div>
  7. <a-form-item :label="$t('tariffManagement.source')" field="source">
  8. <a-select v-model="formState.source">
  9. <a-option v-for=" item in sourceList" :key="item.id" :value="item.value">{{
  10. item.label
  11. }}
  12. </a-option>
  13. </a-select>
  14. </a-form-item>
  15. <template v-if="formState.source">
  16. <a-form-item :label="$t('tariffManagement.simDataPlanId')" field="simDataPlanId">
  17. <a-select v-model="formState.simDataPlanId" :disabled="typeIndex!==1">
  18. <a-option v-for=" (item, index) in planList" :key="item.id" :value="item.id">{{ $t('tariffManagement.DataPackage') }} {{
  19. item.productName
  20. }}
  21. </a-option>
  22. </a-select>
  23. </a-form-item>
  24. </template>
  25. <a-form-item :label="$t('tariffManagement.label')" field="label">
  26. <a-input v-model="formState.label" />
  27. </a-form-item>
  28. <a-form-item :label="$t('tariffManagement.userId')" field="userId">
  29. <a-select v-model="formState.userId">
  30. <a-option v-for=" item in userIdList" :key="item.id" :value="item.id">{{
  31. item.name
  32. }}
  33. </a-option>
  34. </a-select>
  35. </a-form-item>
  36. <a-form-item :label="$t('tariffManagement.billingMethod')" field="billingMethod">
  37. <a-select v-model="formState.billingMethod">
  38. <a-option v-for=" item in methodList" :key="item.id" :value="item.value">{{
  39. item.label
  40. }}
  41. </a-option>
  42. </a-select>
  43. </a-form-item>
  44. <a-form-item :label="$t('tariffManagement.currency')" field="currency">
  45. <a-select v-model="formState.currency">
  46. <a-option v-for=" item in currency" :key="item.id" :value="item.value">{{
  47. item.label
  48. }}
  49. </a-option>
  50. </a-select>
  51. </a-form-item>
  52. <div class="formTitle">{{ $t('tariffManagement.BillingInformation') }}</div>
  53. <a-form-item field="billingCycle" :label="$t('tariffManagement.billingCycle')" required>
  54. <a-radio-group v-model="formState.billingCycle" :options="billingCycleData">
  55. </a-radio-group>
  56. </a-form-item>
  57. <a-form-item field="" :label="$t('tariffManagement.pricing')" required>
  58. <a-input v-model="formState.pricing" v-if="formState.billingMethod == 2">
  59. <template #append>
  60. {{ formState.currency === '0' ? $t('setting.yuan') : $t('setting.USD') }}
  61. </template>
  62. </a-input>
  63. <a-input v-model="formState.trafficBilling" v-if="formState.billingMethod == 1"></a-input>
  64. <a-select v-model="formState.trafficBillingType" style="width: 80px; margin:0 8px;"
  65. v-if="formState.billingMethod == 1">
  66. <a-option value="MB">MB</a-option>
  67. </a-select>
  68. <a-input v-model="formState.trafficBillingAmount" v-if="formState.billingMethod == 1">
  69. <template #append>
  70. {{ formState.currency === '0' ? $t('setting.yuan') : $t('setting.USD') }}
  71. </template>
  72. </a-input>
  73. </a-form-item>
  74. <a-form-item field="endDate" :label="$t('tariffManagement.cycleBuy')">
  75. <a-date-picker v-model="formState.endDate" style="width: 100%;" />
  76. </a-form-item>
  77. <a-form-item :label="$t('tariffManagement.MRCName')" field="mrcAmount">
  78. <a-input v-model="formState.mrcAmount">
  79. <template #append>
  80. {{ formState.currency === '0' ? $t('setting.yuan') : $t('setting.USD')}}
  81. </template>
  82. </a-input>
  83. </a-form-item>
  84. <a-form-item :label="$t('tariffManagement.networkName')" field="networkAccessFee">
  85. <a-input v-model="formState.networkAccessFee">
  86. <template #append>
  87. {{ formState.currency === '0' ? $t('setting.yuan') : $t('setting.USD') }}
  88. </template>
  89. </a-input>
  90. </a-form-item>
  91. <a-form-item>
  92. <a-button type="primary" html-type="submit" style="margin-right: 10px;">{{
  93. $t('form.Confirm')
  94. }}
  95. </a-button>
  96. <a-button @click="resetForm">{{ $t('form.Cancel') }}</a-button>
  97. </a-form-item>
  98. </a-form>
  99. </a-modal>
  100. </template>
  101. <script setup>
  102. import { ref, onMounted, toRefs, toRef, watch } from 'vue';
  103. import { getDataPlanList } from "@/api/path/lotCard.api"
  104. import { getSTSInfoList } from '@/api/path/system.api'
  105. import { updateTariff, addTariff } from "@/api/path/tariffManagement.api"
  106. import { Getdictionary } from '@/mixins/index.js'
  107. import { Message } from '@arco-design/web-vue'
  108. import {useI18n} from 'vue-i18n'
  109. const {t} = useI18n();
  110. const props = defineProps({
  111. modelValue: {
  112. type: Boolean,
  113. default: false
  114. },
  115. typeIndex: {
  116. type: Number,
  117. default: null
  118. },
  119. FormDataList: {
  120. type: Object,
  121. default: () => { }
  122. }
  123. })
  124. const modelValue = toRef(props, 'modelValue')
  125. const typeIndex = toRef(props, 'typeIndex')
  126. const FormDataList = toRef(props, 'FormDataList')
  127. const emit = defineEmits(['update:modelValue', 'submit'])
  128. const state = ref({
  129. formState: {
  130. // 资费名称(必填)
  131. "label": "",
  132. // 流量包ID(必填)
  133. "simDataPlanId": null,
  134. // 用户ID(必填)
  135. "userId": null,
  136. // 来源(必填)
  137. "source": "",
  138. // 计费周期(必填)
  139. "billingCycle": "",
  140. // 计费方式(必填)
  141. "billingMethod": "1",
  142. // 价格(必填)
  143. "pricing": "",
  144. // 币种(必填)
  145. "currency": "usb",
  146. // 流量资费计费
  147. "trafficBilling": '',
  148. // 流量资费计费类型
  149. "trafficBillingType": 'MB',
  150. // 流量资费计费金
  151. "trafficBillingAmount": '',
  152. // MRC金额
  153. "mrcAmount": '',
  154. // 网络接入费
  155. "networkAccessFee": '',
  156. "endDate":''
  157. },
  158. sourceList: [],
  159. userIdList: [],
  160. methodList: [],
  161. currency: [],
  162. billingCycleData: [],
  163. planList: [],
  164. formRef: null
  165. })
  166. const { formState, sourceList, userIdList, methodList, currency, billingCycleData, planList, formRef } = toRefs(state.value)
  167. const rules = {
  168. label: [{ required: true, trigger: 'change', }],
  169. simDataPlanId: [{ required: true, trigger: 'change', }],
  170. userId: [{ required: true, trigger: 'change', }],
  171. source: [{ required: true, trigger: 'change', }],
  172. billingCycle: [{ required: true, trigger: 'change', }],
  173. billingMethod: [{ required: true, trigger: 'change', }],
  174. currency: [{ required: true, trigger: 'change', }],
  175. trafficBilling: [{ required: true, trigger: 'change', }],
  176. trafficBillingType: [{ required: true, trigger: 'change', }],
  177. trafficBillingAmount: [{ required: true, trigger: 'change', }],
  178. mrcAmount: [{ required: true, trigger: 'change', }],
  179. networkAccessFee: [{ required: true, trigger: 'change', }],
  180. endDate: [{ required: true, trigger: 'change', }],
  181. };
  182. // 提交
  183. const handleSubmit = ({ values, errors }) => {
  184. formRef.value.validate(async (errors) => {
  185. if (!errors) {
  186. const formVal = JSON.parse(JSON.stringify(values))
  187. delete formVal.settlementCycleMap
  188. formVal.userId = Number(values.userId)
  189. formVal.simDataPlanId = String(values.simDataPlanId)
  190. formVal.simDataPlanId = String(values.simDataPlanId)
  191. formVal.pricing = Number(values.pricing)
  192. if (typeIndex.value === 2) {
  193. const { code, data } = await updateTariff(formVal)
  194. if (code == 200) {
  195. Message.success({
  196. content: t('setting.editSuccess'),
  197. duration: 2000,
  198. })
  199. emit('update:modelValue', false)
  200. emit('submit', true)
  201. resetForm()
  202. }
  203. } else {
  204. const { code, data } = await addTariff(formVal)
  205. if (code == 200) {
  206. Message.success({
  207. content: t('setting.addSuccess'),
  208. duration: 2000,
  209. })
  210. emit('update:modelValue', false)
  211. emit('submit', true)
  212. resetForm()
  213. }
  214. }
  215. }
  216. });
  217. }
  218. // 取消
  219. const resetForm = () => {
  220. emit('update:modelValue', false)
  221. Object.keys(formState.value).forEach(key => {
  222. formState.value[key] = ''
  223. })
  224. delete formState.value.id
  225. FormDataList.value = {}
  226. }
  227. const handleDataPlan = async () => {
  228. const param = {
  229. current: 1,
  230. size: 999,
  231. source: formState.value.source
  232. }
  233. getDataPlanList(param).then(res => {
  234. planList.value = res.data.records || []
  235. })
  236. }
  237. // 获取id数组
  238. const handleModelId = async () => {
  239. const param = {
  240. current: 1,
  241. size: 999,
  242. }
  243. getSTSInfoList(param).then(res => {
  244. userIdList.value = (res.data.records || [])
  245. })
  246. }
  247. const handleDictValue = async () => {
  248. sourceList.value = await Getdictionary('source')
  249. methodList.value = await Getdictionary('billingMethod')
  250. currency.value = await Getdictionary('currencyType')
  251. billingCycleData.value = await Getdictionary('Billingcycle')
  252. }
  253. watch(() => modelValue.value, val => {
  254. if (val) {
  255. handleDictValue()
  256. handleModelId()
  257. formState.value.billingMethod = '1'
  258. formState.value.trafficBillingType = 'MB'
  259. }
  260. })
  261. watch(() => formState.value.billingMethod, val => {
  262. if (val == 2) {
  263. formState.value.trafficBillingType = ''
  264. formState.value.trafficBilling = ''
  265. formState.value.trafficBillingAmount = ''
  266. }else{
  267. formState.value.pricing = ''
  268. }
  269. })
  270. watch(
  271. () => formState.value.source,
  272. (newValue, oldValue) => {
  273. if (newValue != oldValue) {
  274. handleDataPlan()
  275. }
  276. },
  277. { immediate: true,deep:true }
  278. );
  279. watch(() => FormDataList.value, val => {
  280. if (!val.id) return
  281. Object.keys(formState.value).forEach(key => {
  282. if (val[key]) {
  283. formState.value[key] = key === 'userId' ? Number(val[key]) : val[key];
  284. }
  285. })
  286. formState.value.id = val.id
  287. },{deep:true})
  288. </script>
  289. <style scoped></style>