addSetMeal.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div>
  3. <div class="search">
  4. <Search :SearchForm="SetMealSearchForm" @query="initData" @reset="reset"></Search>
  5. </div>
  6. <div class="addSetMeal">
  7. <a-button type="primary" @click="visible = true">新增套餐</a-button>
  8. </div>
  9. <div class="table">
  10. <a-table row-key="id" :data="tableData" :columns="columnsTarrit" :pagination="pagination"
  11. :scroll="{ x: 'auto' }" @page-change="evChangePage">
  12. <template #status="{ record }">
  13. <a-tag :color="record.status == 1 ? '#7bc616' : '#86909c'">{{ record.status == 1 ? '上架' : '下架'
  14. }}</a-tag>
  15. </template>
  16. <template #options="{ record }">
  17. <a-space>
  18. <a-button type="text" @click="SetUpPackage(record)">修改</a-button>
  19. <a-button type="text" @click="unmount(record)">{{ record.status == 1 ? '下架' : '上架' }}</a-button>
  20. <a-popconfirm content="是否要删除该资费商品?" @ok="handelDeleteTariff(record)">
  21. <a-button type="text">删除</a-button>
  22. </a-popconfirm>
  23. </a-space>
  24. </template>
  25. </a-table>
  26. </div>
  27. <a-modal v-model:visible="visible" width="600px" @cancel="handelCancel" title="新增套餐计划">
  28. <div class="Form">
  29. <a-form ref="formRef" :rules="rules" :model="Form">
  30. <a-form-item label="套餐名称" field="label" validate-trigger="input">
  31. <a-input placeholder="请输入套餐名称" v-model="Form.label"></a-input>
  32. </a-form-item>
  33. <a-form-item label="充值类型" field="type" validate-trigger="input">
  34. <a-select v-model="Form.type" placeholder="请选择充值类型">
  35. <a-option v-for="item in puyType" :value="item.value" :key="item.value">{{ item.label
  36. }}</a-option>
  37. </a-select>
  38. </a-form-item>
  39. <a-form-item label="充值周期" field="period" validate-trigger="input">
  40. <a-input v-model="Form.period"></a-input>
  41. <a-select v-model="Form.timeUnit" style="width: 140px; margin:0 8px;">
  42. <a-option v-for="item in cyciy" :value="item.value" :key="item.value">{{ item.label
  43. }}</a-option>
  44. </a-select>
  45. </a-form-item>
  46. <a-form-item label="充值售价" field="price" validate-trigger="input">
  47. <a-input v-model="Form.price"></a-input>
  48. <a-select v-model="Form.currency" style="width: 140px; margin:0 8px;">
  49. <a-option v-for="item in Currency" :value="item.value" :key="item.value">{{ item.label
  50. }}</a-option>
  51. </a-select>
  52. </a-form-item>
  53. <a-form-item label="充值绑定资费" field="trafficId" validate-trigger="blur">
  54. <a-select v-model="Form.trafficId">
  55. <a-option v-for="item in tariffListData" :value="item.id" :key="item.id">{{ item.label
  56. }}</a-option>
  57. </a-select>
  58. </a-form-item>
  59. <a-form-item label="流量大小" field="Flow" validate-trigger="change" v-if="Form.type == 2">
  60. <a-input v-model="Form.flow"></a-input>
  61. <a-select v-model="Form.flowUnit" style="width: 140px; margin:0 8px;">
  62. <a-option value="KB">KB</a-option>
  63. <a-option value="MB">MB</a-option>
  64. <a-option value="GB">GB</a-option>
  65. </a-select>
  66. </a-form-item>
  67. </a-form>
  68. </div>
  69. <template #footer>
  70. <a-button @click="visible = false">取消</a-button>
  71. <a-button type="primary" @click="handleSubmit">确定</a-button>
  72. </template>
  73. </a-modal>
  74. </div>
  75. </template>
  76. <script setup>
  77. import { watch, defineProps, toRefs, ref, onMounted } from 'vue';
  78. import { CheckTariffPackages } from '@/api/path/tariffManagement.api'
  79. import { Getdictionary, tableFunction, filterDict } from '@/mixins/index.js'
  80. import Search from '@/components/Search/index.vue'
  81. import { columnsTarrit } from '../config'
  82. import { tariffList, addTariffPackage, UpdateTariffTtems, DeleteTariffItems } from "@/api/path/tariffManagement.api"
  83. import { Message, Modal } from '@arco-design/web-vue';
  84. const props = defineProps({
  85. id: [Array, String]
  86. })
  87. const state = ref({
  88. pagination: {
  89. total: 0,
  90. pageSize: 10,
  91. current: 1,
  92. simTerminalId: null
  93. },
  94. visible: false,
  95. puyType: [],
  96. cyciy: [],
  97. Currency: [],
  98. tariffListData: [],
  99. billingMethodList: [],
  100. Form: {
  101. label: '',
  102. type: "",
  103. period: "",
  104. timeUnit: "",
  105. price: "",
  106. currency: "",
  107. trafficId: "",
  108. flow: "1",
  109. flowUnit: "",
  110. id:"",
  111. },
  112. formRef: null,
  113. Type: true,
  114. })
  115. const { pagination, visible, puyType, Currency, cyciy, tariffListData, Form, formRef, billingMethodList, Type } = toRefs(state.value)
  116. const rules = {
  117. label: [{ required: true, message: '套餐名称不能为空' }],
  118. type: [{ required: true, message: '请选择充值类型' }],
  119. period: [{ required: true, message: '请填写充值周期' }, {
  120. validator: (value, cb) => {
  121. const pattern = /^[1-9]\d*$/
  122. if (!pattern.test(value)) {
  123. cb('请输入整数')
  124. } else {
  125. cb()
  126. }
  127. }
  128. }],
  129. price: [{ required: true, message: '请填写充值售价' }, {
  130. validator: (value, cb) => {
  131. const pattern = /^[1-9]\d*$/
  132. if (!pattern.test(value)) {
  133. cb('请输入合法的数字')
  134. } else {
  135. cb()
  136. }
  137. }
  138. }],
  139. trafficId: [{ required: true, message: '请选择充值绑定资费' }]
  140. }
  141. const processData = (data) => {
  142. return (data.records || []).map((item, index) => {
  143. return {
  144. ...item,
  145. price: item.price + '/' + item.currency,
  146. typeName: item.type == 1 ? '服务时长' : "购买流量",
  147. profitPrice: item.profitPrice + '/' + item.currency,
  148. billingMethod: filterDict(billingMethodList.value, item.billingMethod),
  149. costPrice:item.costPrice + '/' + item.trafficCurrency,
  150. oldPrice:item.oldPrice + '/' + item.trafficCurrency
  151. }
  152. })
  153. }
  154. const { tableData, evChangePage, initData, reset } = tableFunction(pagination.value, CheckTariffPackages, processData)
  155. const handleSubmit = () => {
  156. formRef.value.validate(async (errors) => {
  157. if (!errors) {
  158. const FormList = {
  159. ...Form.value,
  160. type: Number(Form.value.type),
  161. period: Number(Form.value.period),
  162. simTerminalId: props.id
  163. }
  164. if(Type.value){
  165. delete FormList.id
  166. }
  167. let res = Type.value ? await addTariffPackage(FormList) : await UpdateTariffTtems(FormList)
  168. if (res.code === 200) {
  169. initData()
  170. Message.success(Type.value ? '添加成功' : '修改成功')
  171. visible.value = false
  172. handelCancel()
  173. }
  174. }
  175. })
  176. }
  177. const handelCancel = () => {
  178. Form.value.label = ""
  179. Form.value.type = puyType.value[0]?.value
  180. Form.value.period = ""
  181. Form.value.timeUnit = cyciy.value[0]?.value
  182. Form.value.price = ""
  183. Form.value.currency = Currency.value[0]?.value
  184. Form.value.trafficId = null
  185. Type.value = true
  186. }
  187. const unmount = async (record) => {
  188. Modal.info({
  189. title: `确定要${record.status == 1 ? '下架' : '上架'}吗?`,
  190. content: '',
  191. onOk: async () => {
  192. const FormList = {
  193. ...record,
  194. type: Number(Form.value.type),
  195. period: Number(Form.value.period),
  196. simTerminalId: props.id
  197. }
  198. let res = await UpdateTariffTtems(FormList)
  199. if (res.code === 200) {
  200. Message.success(`${record.status == 1 ? '下架' : '上架'}成功`)
  201. initData()
  202. }
  203. }
  204. });
  205. }
  206. const handelDeleteTariff = async (record) => {
  207. let res = await DeleteTariffItems({ id: record.id })
  208. if (res.code === 200) {
  209. Message.success('删除成功')
  210. initData()
  211. }
  212. }
  213. const SetUpPackage = async (record) => {
  214. Object.keys(Form.value).forEach(key => {
  215. Form.value[key] = record[key]
  216. })
  217. Form.value.price = record.price.split('/')[0];
  218. Form.value.type = String(Form.value.type)
  219. visible.value = true
  220. Type.value = false
  221. }
  222. onMounted(async () => {
  223. let dict = await Getdictionary(['RechargeType', 'PuyCycle', 'currencyType', 'billingMethod'])
  224. puyType.value = dict[0]
  225. Form.value.type = puyType.value[0]?.value
  226. cyciy.value = dict[1]
  227. Form.value.timeUnit = cyciy.value[0]?.value
  228. Currency.value = dict[2]
  229. Form.value.currency = Currency.value[0]?.value
  230. billingMethodList.value = dict[3]
  231. let res = await tariffList({ current: 1, size: 99999 })
  232. if (res.code === 200) {
  233. tariffListData.value = res.data.records || res.data
  234. }
  235. pagination.value.simTerminalId = props.id
  236. initData()
  237. })
  238. </script>
  239. <style scoped lang='less'>
  240. .search,
  241. .table {
  242. margin-top: 20px;
  243. }
  244. </style>