index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div>
  3. <template v-if="AddSet">
  4. <div class="search">
  5. <Search :SearchForm="SetMealSearchForm" @query="initData" @reset="reset"></Search>
  6. </div>
  7. <div class="addSetMeal">
  8. <a-button type="primary" @click="visibleSetMeal = true">新增套餐计划</a-button>
  9. </div>
  10. <div class="table">
  11. <a-table row-key="id" :data="tableData" :columns="columnsSetMeal" :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 ? '上架' : '下架' }}</a-tag>
  15. </template>
  16. <template #Controls="{ record }">
  17. <a-space>
  18. <a-button type="text" @click="SetUpPackage(record)" v-if="record.isRecharge == 1"> 设置套餐</a-button>
  19. <a-button type="text" @click="unmount(record)">{{ record.status == 1 ? '下架' : '上架' }}</a-button>
  20. </a-space>
  21. </template>
  22. <template #isRechargeName="{ record }">
  23. {{ filterDict(SetMealList, record.isRecharge) }}
  24. </template>
  25. <template #defaultTrafficName="{ record }">
  26. {{ record.defaultTraffic.label }}
  27. </template>
  28. </a-table>
  29. </div>
  30. </template>
  31. <a-modal v-model:visible="visibleSetMeal" width="600px" @cancel="handelCancel" title="新增套餐计划">
  32. <div class="Form">
  33. <a-form ref="formRef" :rules="rules" :model="Form">
  34. <a-form-item label="套餐计划名称" field="label" validate-trigger="blur">
  35. <a-input placeholder="请输入套餐计划名称" v-model="Form.label"></a-input>
  36. </a-form-item>
  37. <a-form-item label="选择所属客户" field="userId" validate-trigger="blur">
  38. <a-select :style="{ width: '320px' }" v-model="Form.userId" placeholder="请选择所属客户">
  39. <a-option v-for="(item, index) in userList" :value="item.id">{{ item.name }}</a-option>
  40. </a-select>
  41. </a-form-item>
  42. <a-form-item label="运营商" field="source" validate-trigger="blur">
  43. <a-select :style="{ width: '320px' }" v-model="Form.source" placeholder="请选择运营商">
  44. <a-option v-for="(item, index) in sourceList" :value="item.value">{{ item.label }}</a-option>
  45. </a-select>
  46. </a-form-item>
  47. <a-form-item label="套餐计划类型" field="isRecharge">
  48. <a-radio-group v-model="Form.isRecharge" :options="SetMealList" />
  49. </a-form-item>
  50. <div class="title" v-if="Form.isRecharge==1">此类型下,一个套餐计划代表一个充值二维码请在下载粘贴二维码时仔细核对</div>
  51. <div class="title" v-if="Form.isRecharge==2">非充值类型套餐计划,则无需用户充值,导卡成功充值后用户可直接使用流量</div>
  52. <a-form-item label="默认绑定资费" >
  53. <a-select v-model="Form.defaultTrafficId">
  54. <a-option v-for="item in tariffListData" :value="item.id" :key="item.id">{{ item.label
  55. }}</a-option>
  56. </a-select>
  57. </a-form-item>
  58. <!-- <div class="title">
  59. 终端用户充值类该字段必填,非充值类该字段非必填
  60. </div> -->
  61. </a-form>
  62. </div>
  63. <template #footer>
  64. <a-button @click="handelCancel">取消</a-button>
  65. <a-button type="primary" @click="handleSubmit">确定</a-button>
  66. </template>
  67. </a-modal>
  68. <!-- 新增套餐计划 -->
  69. <AddSetMeal v-if="!AddSet" :list="list" @break="AddSet = true" />
  70. </div>
  71. </template>
  72. <script setup>
  73. import { ref, onMounted, toRefs, watch } from 'vue';
  74. import Search from '@/components/Search/index.vue'
  75. import { SetMealSearchForm, columnsSetMeal } from '../config.js'
  76. import { getMessUserList, } from '@/api/customer.js';
  77. import { PackageSchedule, addTariffSchedule, PackageTakedown, tariffList } from '@/api/path/tariffManagement.api.js'
  78. import QrcodeVue from 'qrcode.vue'
  79. import { Getdictionary, tableFunction, filterDict } from '@/mixins/index.js'
  80. import { Message, Modal } from '@arco-design/web-vue';
  81. import AddSetMeal from './addSetMeal.vue'
  82. const formRef = ref(null);
  83. const rules = {
  84. userId: [
  85. { required: true, message: '请选择所属客户', trigger: 'blur' },
  86. ],
  87. label: [
  88. { required: true, message: '请输入套餐计划名称', trigger: 'blur' },
  89. ],
  90. source: [
  91. { required: true, message: '请选择运营商', trigger: 'blur' },
  92. ],
  93. };
  94. const state = ref({
  95. pagination: {
  96. total: 0,
  97. pageSize: 10,
  98. current: 1,
  99. },
  100. visibleSetMeal: false,
  101. Form: {
  102. userId: null,
  103. label: null,
  104. isRecharge: '1',
  105. defaultTrafficId: null,
  106. source: null
  107. },
  108. userList: [],
  109. SetMealList: [],
  110. tariffListData: [],
  111. sourceList:[],
  112. AddSet: true,
  113. list: {}
  114. })
  115. const { pagination, visibleSetMeal, userList, Form, AddSet, SetMealList, tariffListData, sourceList, list } = toRefs(state.value)
  116. const { tableData, evChangePage, initData, reset } = tableFunction(pagination.value, PackageSchedule)
  117. const fetchCustomerList = async (item) => {
  118. const response = await getMessUserList({
  119. current: 1,
  120. pageSize: 99999,
  121. });
  122. if (response.code === 200 && response.data) {
  123. userList.value = response.data.records
  124. }
  125. };
  126. const handleSubmit = ({ values, errors }) => {
  127. formRef.value.validate(async (values, errors) => {
  128. if (!errors) {
  129. if (Form.value.isRecharge == 1 && Form.value.defaultTrafficId == null) return Message.error('请选择充值绑定资费')
  130. Form.value.isRecharge = Number(Form.value.isRecharge)
  131. const response = await addTariffSchedule(Form.value)
  132. if (response.code === 200) {
  133. Message.success('添加成功')
  134. visibleSetMeal.value = false
  135. initData()
  136. } else {
  137. console.log(response)
  138. }
  139. }
  140. })
  141. }
  142. const unmount = async (record) => {
  143. Modal.info({
  144. title: `确定要${record.status == 1 ? '下架' : '上架'}吗?`,
  145. content: '',
  146. onOk: async () => {
  147. let res = await PackageTakedown({ id: record.id, status: record.status == 1 ? 2 : 1, label: record.label, userId: record.userId })
  148. if (res.code === 200) {
  149. Message.success(`${record.status == 1 ? '下架' : '上架'}成功`)
  150. initData()
  151. }
  152. }
  153. });
  154. }
  155. const SetUpPackage = (item) => {
  156. list.value.id = item.id
  157. list.value.source = item.source
  158. list.value.userId = item.userId
  159. AddSet.value = false
  160. }
  161. const handelCancel = () => {
  162. Object.keys(Form.value).forEach(res => {
  163. Form.value[res] = null
  164. })
  165. visibleSetMeal.value = false
  166. Form.value.isRecharge = "1"
  167. }
  168. watch(() => Form.value.userId, val => {
  169. getTarrife(val)
  170. }, { deep: true })
  171. watch(() => Form.value.source, val => {
  172. getTarrife(Form.value.userId, val)
  173. }, { deep: true })
  174. // 资费
  175. const getTarrife = async (item, sourceId) => {
  176. let res = await tariffList({ current: 1, size: 99999, userId: item, source: sourceId })
  177. tariffListData.value = []
  178. Form.value.defaultTrafficId = null
  179. if (res.code === 200) {
  180. tariffListData.value = (res.data.records || []).map(item => {
  181. return {
  182. ...item,
  183. value: item.id,
  184. label: item.label + '---' + item.userName
  185. }
  186. })
  187. }
  188. }
  189. onMounted(async () => {
  190. let dict = await Getdictionary(['setMeal', 'source'])
  191. SetMealList.value = dict[0]
  192. sourceList.value = dict[1]
  193. initData()
  194. fetchCustomerList()
  195. getTarrife()
  196. })
  197. </script>
  198. <style lang="less" scoped>
  199. .search,
  200. .table {
  201. margin-top: 1rem;
  202. }
  203. .code {
  204. justify-content: center;
  205. display: flex;
  206. }
  207. .title {
  208. font-size: 14px;
  209. color: #ccc;
  210. margin-left: 120px;
  211. margin-top: -15px;
  212. margin-bottom: 10px;
  213. }
  214. </style>