addSetMeal.vue 11 KB

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