redPacket.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div>
  3. <!-- 公司列表弹窗 -->
  4. <!-- <el-dialog title="设置红包" :visible.sync="companyDialogVisible" width="800px" append-to-body>-->
  5. <el-table :data="companyList" border>
  6. <el-table-column type="index" label="序号" width="60" align="center" />
  7. <el-table-column label="公司名称" prop="companyName" align="center" />
  8. <el-table-column label="操作" align="center" width="120">
  9. <template slot-scope="scope">
  10. <el-button
  11. size="mini"
  12. type="text"
  13. @click="handleInputAmount(scope.row)"
  14. v-hasPermi="['course:period:setCourseRedPacket']"
  15. >设置红包</el-button>
  16. </template>
  17. </el-table-column>
  18. </el-table>
  19. <!-- <div slot="footer" class="dialog-footer">-->
  20. <!-- </div>-->
  21. <!-- </el-dialog>-->
  22. <!-- 课程红包设置弹窗 -->
  23. <el-dialog title="设置红包金额" :visible.sync="courseDialogVisible" width="1200px" append-to-body>
  24. <el-table :data="redPacketList" border>
  25. <el-table-column type="index" label="序号" width="60" align="center" />
  26. <el-table-column label="课程" prop="courseName" align="center" />
  27. <el-table-column label="小节" prop="videoName" align="center" />
  28. <el-table-column label="营期日期" prop="dayDate" align="center"/>
  29. <el-table-column label="红包金额(0.0-0.3元)" width="200px" align="center">
  30. <template slot-scope="scope">
  31. <el-input-number
  32. v-model="scope.row.amount"
  33. :min="0.0"
  34. :max="0.3"
  35. :precision="2"
  36. :step="0.01"
  37. size="small"
  38. style="width: 150px"
  39. >
  40. <template slot="append">元</template>
  41. </el-input-number>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. <div slot="footer" class="dialog-footer">
  46. <el-button @click="courseDialogVisible = false">取 消</el-button>
  47. <el-button type="primary" @click="handleSave">保 存</el-button>
  48. </div>
  49. </el-dialog>
  50. </div>
  51. </template>
  52. <script>
  53. import { getPeriodCompanyList, batchSaveRedPacket, getPeriodRedPacketList } from "@/api/course/userCoursePeriod";
  54. import redPacket from "@/views/course/userCoursePeriod/redPacket.vue";
  55. export default {
  56. name: "RedPacket",
  57. computed: {
  58. // redPacket() {
  59. // return redPacket
  60. // }
  61. },
  62. props: {
  63. visible: {
  64. type: Boolean,
  65. default: false
  66. },
  67. activeTab: {
  68. type: String,
  69. default: ''
  70. },
  71. periodId: {
  72. type: [String, Number],
  73. default: ''
  74. },
  75. // videoId: {
  76. // type: [String, Number],
  77. // default: ''
  78. // }
  79. },
  80. data() {
  81. return {
  82. // companyDialogVisible: false,
  83. // activeTab: '',
  84. courseDialogVisible: false,
  85. companyList: [],
  86. redPacketList: [],
  87. currentCompany: null
  88. };
  89. },
  90. created() {
  91. if(this.activeTab == "company"){
  92. this.getCompanyList();
  93. }
  94. },
  95. watch: {
  96. activeTab(val) {
  97. this.activeTab = val;
  98. if (val == "company") {
  99. this.getCompanyList();
  100. }
  101. },
  102. companyDialogVisible(val) {
  103. if (!val) {
  104. this.$emit('update:visible', false);
  105. }
  106. }
  107. },
  108. methods: {
  109. // 获取公司列表
  110. getCompanyList() {
  111. getPeriodCompanyList({
  112. periodId: this.periodId
  113. }).then(response => {
  114. this.companyList = response.data || [];
  115. });
  116. },
  117. // 点击录入金额
  118. handleInputAmount(row) {
  119. this.currentCompany = row;
  120. this.courseDialogVisible = true;
  121. this.getCourseList();
  122. },
  123. // 获取课程列表
  124. getCourseList() {
  125. getPeriodRedPacketList({
  126. periodId: this.periodId,
  127. companyId: this.currentCompany.companyId
  128. }).then(response => {
  129. console.log("-----------",JSON.stringify(response.data))
  130. this.redPacketList = (response.data || []).map(item => ({
  131. ...item,
  132. // amount: item.amount || 0.1
  133. amount:item.amount ?? 0.1
  134. }));
  135. });
  136. },
  137. // 保存红包金额
  138. handleSave() {
  139. // 筛选出有金额的项目
  140. const validAmountItems = this.redPacketList.filter(item => item.amount >= 0);
  141. if (validAmountItems.length === 0) {
  142. this.$message.warning('请至少设置一个红包金额');
  143. return;
  144. }
  145. // 验证金额范围
  146. const invalidItems = validAmountItems.filter(item => item.amount < 0.0 || item.amount > 0.3);
  147. if (invalidItems.length > 0) {
  148. this.$message.error('红包金额需要在0.0元至0.3元之间');
  149. return;
  150. }
  151. const saveData = validAmountItems.map(item => ({
  152. companyId: this.currentCompany.companyId,
  153. redPacketMoney: item.amount,
  154. videoId: item.videoId,
  155. periodId: this.periodId,
  156. dataType: 2
  157. }));
  158. batchSaveRedPacket(saveData).then(response => {
  159. if (response.code === 200) {
  160. this.$message.success('保存成功');
  161. this.courseDialogVisible = false;
  162. this.$emit('success');
  163. } else {
  164. this.$message.error(response.msg || "保存失败");
  165. }
  166. }).catch(error => {
  167. this.$message.error("保存失败:" + error.message);
  168. });
  169. }
  170. }
  171. };
  172. </script>
  173. <style scoped>
  174. .el-input-number {
  175. width: 100%;
  176. }
  177. </style>