batchRedPacket.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <el-dialog
  3. title="批量设置红包"
  4. :visible.sync="dialogVisible"
  5. width="800px"
  6. append-to-body
  7. @close="handleClose"
  8. >
  9. <el-table
  10. v-loading="loading"
  11. :data="tableData"
  12. border
  13. style="width: 100%"
  14. >
  15. <el-table-column
  16. type="index"
  17. label="序号"
  18. width="80"
  19. align="center"
  20. />
  21. <el-table-column
  22. prop="periodName"
  23. label="营期"
  24. align="center"
  25. />
  26. <el-table-column
  27. label="金额"
  28. align="center"
  29. width="200"
  30. >
  31. <template slot-scope="scope">
  32. <el-input-number
  33. v-model="scope.row.amount"
  34. :min="0.1"
  35. :precision="2"
  36. :step="0.01"
  37. size="small"
  38. style="width: 150px"
  39. />
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <div slot="footer" class="dialog-footer">
  44. <el-button @click="handleClose">取 消</el-button>
  45. <el-button type="primary" @click="handleSave">保 存</el-button>
  46. </div>
  47. </el-dialog>
  48. </template>
  49. <script>
  50. import { batchSaveRedPacketByPeriod } from "@/api/course/userCoursePeriod";
  51. export default {
  52. name: 'BatchRedPacket',
  53. props: {
  54. visible: {
  55. type: Boolean,
  56. default: false
  57. },
  58. selectedData: {
  59. type: Array,
  60. default: () => []
  61. }
  62. },
  63. data() {
  64. return {
  65. loading: false,
  66. tableData: [],
  67. dialogVisible: false
  68. }
  69. },
  70. watch: {
  71. visible(val) {
  72. this.dialogVisible = val;
  73. if (val) {
  74. this.initTableData()
  75. }
  76. },
  77. dialogVisible(val) {
  78. if (!val) {
  79. // 当弹窗关闭时,通知父组件
  80. this.$emit('update:visible', false);
  81. }
  82. }
  83. },
  84. methods: {
  85. // 初始化表格数据
  86. initTableData() {
  87. this.tableData = this.selectedData.map(item => ({
  88. ...item,
  89. amount: 0.1
  90. }))
  91. },
  92. // 保存
  93. handleSave() {
  94. // 验证金额范围
  95. const invalidItems = this.tableData.filter(item => item.amount < 0.1);
  96. if (invalidItems.length > 0) {
  97. this.$message.error('红包金额需要大于等于0.1元');
  98. return;
  99. }
  100. this.$confirm(`是否确定?确定后营期下的所有公司红包金额都将设置成对应值`, '提示', {
  101. confirmButtonText: '确定',
  102. cancelButtonText: '取消',
  103. type: 'warning'
  104. }).then(() => {
  105. this.loading = true;
  106. const saveData = this.tableData.map(item => ({
  107. periodId: item.periodId,
  108. redPacketMoney: item.amount
  109. }));
  110. batchSaveRedPacketByPeriod(saveData).then(response => {
  111. if (response.code === 200) {
  112. this.$message.success('设置成功');
  113. this.$emit('success');
  114. this.handleClose();
  115. } else {
  116. this.$message.error(response.msg || '批量设置失败');
  117. }
  118. }).catch(error => {
  119. this.$message.error('批量设置失败:' + error.message);
  120. }).finally(() => {
  121. this.loading = false;
  122. });
  123. })
  124. },
  125. // 关闭
  126. handleClose() {
  127. this.dialogVisible = false;
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .el-input-number {
  134. width: 100%;
  135. }
  136. </style>