add.vue 13 KB

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