meal.vue 4.8 KB

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