meal.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <a-modal width="55%" v-model:visible="modelValue" @ok="handleOk" @cancel="handleCancel" title="套餐">
  3. <div class="add"><a-button type="primary" @click="addMeal" v-if="role.getRole == 1">添加套餐</a-button></div>
  4. <div class="item_warp">
  5. <a-table :columns="columns" :data="wanberFloter" style="margin-top: 20px" :pagination="false"
  6. :scroll="{ y: 'auto' }">
  7. <template #period="{ record, rowIndex }">
  8. <a-input v-model="record.period" :disabled="role.getRole !== 1" />
  9. </template>
  10. <template #price="{ record, rowIndex }">
  11. <a-input v-model="record.price" />
  12. </template>
  13. <template #currency="{ record, rowIndex }">
  14. <a-select v-model="record.currency" :style="{ width: '300px' }" placeholder="请选择币种"
  15. :disabled="role.getRole !== 1">
  16. <a-option v-for="res of Pricing" :value="res.value" :label="res.label" />
  17. </a-select>
  18. </template>
  19. <template #label="{ record, rowIndex }">
  20. <a-input v-model="record.label" v-if="role.getRole !== 1" />
  21. </template>
  22. <template #setting="{ record }">
  23. <a class="a-link" href="javascript:;" style="margin-right: 1rem" @click="addUpate(record)">{{
  24. record.id == '' ? '添加' : '修改' }}</a>
  25. <a-popconfirm :content="$t('form.Delete')" :ok-text="$t('form.Confirm')"
  26. :cancel-text="$t('form.Cancel')" @ok="deletaMeal(record.id)">
  27. <a class="a-link" href="javascript:;" v-if="role.getRole == 1">{{
  28. $t('form.Delete')
  29. }}</a>
  30. </a-popconfirm>
  31. </template>
  32. </a-table>
  33. </div>
  34. </a-modal>
  35. </template>
  36. <script setup>
  37. import { ref, onMounted, toRefs, toRef, watch } from 'vue';
  38. import { Getdictionary } from '@/mixins/index.js'
  39. import { useSystemStore } from '@/store/modules/systemStore'
  40. import { Message } from '@arco-design/web-vue'
  41. import { addTariffPackage, CheckTariffPackages, UpdateTariffTtems, DeleteTariffItems } from '@/api/path/tariffManagement.api'
  42. const props = defineProps({
  43. modelValue: {
  44. type: Boolean,
  45. default: false
  46. },
  47. traffIds: {
  48. type: [String, Number],
  49. default: undefined
  50. }
  51. })
  52. const role = useSystemStore()
  53. const modelValue = toRef(props, 'modelValue')
  54. const traffIds = toRef(props, 'traffIds')
  55. const indexSet = ref(0)
  56. const emit = defineEmits(['update:modelValue', 'submit'])
  57. const columns = [{
  58. title: '套餐期限(月)',
  59. dataIndex: 'period',
  60. slotName: 'period',
  61. ellipsis: true,
  62. align: 'center',
  63. }, {
  64. title: '套餐价格',
  65. dataIndex: 'price',
  66. slotName: 'price',
  67. ellipsis: true,
  68. align: 'center',
  69. }, {
  70. title: '币种',
  71. dataIndex: 'currency',
  72. slotName: 'currency',
  73. ellipsis: true,
  74. align: 'center',
  75. }, {
  76. title: '套餐名称',
  77. slotName: 'label',
  78. ellipsis: true,
  79. align: 'center',
  80. }, {
  81. title: '操作',
  82. slotName: 'setting',
  83. ellipsis: true,
  84. align: 'center',
  85. }];
  86. const state = ref({
  87. wanberFloter: [
  88. { id: '', period: '', price: '', currency: '', label: '' }
  89. ],
  90. formRef: null,
  91. Pricing: []
  92. })
  93. const { wanberFloter, formRef, Pricing } = toRefs(state.value)
  94. // 添加套餐
  95. const handleOk = () => {
  96. emit('update:modelValue', false)
  97. emit('submit', true)
  98. handleCancel()
  99. }
  100. // 确定或者修改
  101. const addUpate = async (item) => {
  102. item.period = Number(item.period)
  103. let res;
  104. if (item.id == '') {
  105. res = await addTariffPackage({ TrafficId: traffIds.value, price: item.price, currency: item.currency, period: item.period, label: item.label })
  106. } else {
  107. res = await UpdateTariffTtems(item)
  108. }
  109. if (res.code === 200) {
  110. Message.success(res.message)
  111. await getList()
  112. }
  113. }
  114. const handleCancel = () => {
  115. emit('update:modelValue', false)
  116. wanberFloter.value = [
  117. { id: '', period: '', price: '', currency: '', label: '' }
  118. ]
  119. traffIds.value = undefined
  120. }
  121. const addMeal = () => {
  122. wanberFloter.value.push({ id: '', period: '', price: '', currency: '', label: '' })
  123. }
  124. // 删除
  125. const deletaMeal = async (ids) => {
  126. let res = await DeleteTariffItems({ id: ids })
  127. if (res.code === 200) {
  128. Message.success("删除成功")
  129. await getList()
  130. }
  131. }
  132. const handeDict = async () => {
  133. Pricing.value = await Getdictionary('currencyType')
  134. }
  135. const getList = () => {
  136. CheckTariffPackages({ tariffId: traffIds.value }).then(res => {
  137. if (res.code === 200) {
  138. indexSet.value = res.data.length
  139. wanberFloter.value = res.data
  140. }
  141. })
  142. }
  143. watch(() => modelValue.value, async (val, newVal) => {
  144. if (val) {
  145. await getList()
  146. }
  147. }, { deep: true })
  148. onMounted(() => {
  149. handeDict()
  150. })
  151. </script>
  152. <style scoped lang="less">
  153. .add {
  154. display: flex;
  155. justify-content: end;
  156. }
  157. .item_warp {
  158. margin-top: 20px;
  159. display: flex;
  160. flex-wrap: wrap;
  161. gap: 10px;
  162. justify-content: space-between;
  163. }
  164. </style>