CompExtras.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="custom-list">
  3. <div style="text-align: right; margin-bottom: 10px;">
  4. <el-button type="primary" size="mini" plain icon="el-icon-plus" @click="addExtra">添加奖励</el-button>
  5. </div>
  6. <div class="extra-row" v-for="(item, index) in innerValue" :key="index">
  7. <div class="extra-line">
  8. <span class="label">完成:</span>
  9. <el-select v-model="item.tierIndex" placeholder="请选择阶梯" size="small" style="width: 200px"
  10. @change="handleChange">
  11. <el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value"
  12. :disabled="innerValue.some(t => t.tierIndex === opt.value && t !== item)">
  13. </el-option>
  14. </el-select>
  15. <i class="el-icon-delete delete-icon" @click="removeExtra(index)"></i>
  16. </div>
  17. <div class="extra-line" style="margin-top: 10px;">
  18. <span class="label">奖励:</span>
  19. <el-select v-model="item.rewardType" placeholder="类型" size="small"
  20. style="width: 200px; margin-right: 10px;" @change="handleChange">
  21. <el-option v-for="item in dicts.rewardType" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
  22. </el-select>
  23. <div class="dynamic-input">
  24. <el-input-number v-if="item.rewardType == 1" :min="0" v-model="item.rewardValue"
  25. controls-position="right" size="small" placeholder="输入金额"
  26. @change="handleChange"></el-input-number>
  27. <span v-if="item.rewardType == 1" style="margin-left:5px">元</span>
  28. <el-select v-else-if="item.rewardType == 2" v-model="item.rewardValue" placeholder="选择权益券"
  29. size="small" @change="handleChange">
  30. <el-option v-for="item in dicts.rightInfoId" :key="item.val" :label="item.name" :value="item.val"></el-option>
  31. </el-select>
  32. <el-select v-else-if="item.rewardType == 3" v-model="item.rewardValue" placeholder="选择抽奖活动"
  33. size="small" @change="handleChange">
  34. <el-option v-for="item in dicts.lotteryActivityId" :key="item.val" :label="item.name" :value="item.val"></el-option>
  35. </el-select>
  36. </div>
  37. </div>
  38. </div>
  39. <div v-if="innerValue.length === 0"
  40. style="color: #999; text-align: center; padding: 10px; background: #fafafa; border-radius: 4px;">
  41. 暂无额外奖励,点击右上角添加
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import {
  47. getDicts
  48. } from '@/api/system/menu';
  49. import {
  50. getDictListByType,
  51. } from '@/api/activity/index';
  52. export default {
  53. name: 'CompExtras',
  54. props: {
  55. value: {
  56. type: Array,
  57. default: () => []
  58. },
  59. options: {
  60. type: Array,
  61. default: () => []
  62. }
  63. },
  64. data() {
  65. return {
  66. innerValue: [],
  67. dicts: {
  68. rewardType: [],
  69. rightInfoId: [],
  70. lotteryActivityId: []
  71. }
  72. };
  73. },
  74. watch: {
  75. value: {
  76. handler(val) {
  77. this.innerValue = val ? JSON.parse(JSON.stringify(val)) : [];
  78. },
  79. immediate: true,
  80. deep: true
  81. }
  82. },
  83. created() {
  84. this.initData();
  85. },
  86. methods: {
  87. initData() {
  88. // 奖励方式
  89. getDicts('reward_groupFission_method').then((res) => {
  90. this.dicts.rewardType = res.data;
  91. });
  92. // 权益券
  93. getDictListByType({ type: 2 }).then((res) => {
  94. this.dicts.rightInfoId = res.data;
  95. });
  96. // 抽奖
  97. getDictListByType({ type: 3 }).then((res) => {
  98. this.dicts.lotteryActivityId = res.data;
  99. });
  100. },
  101. addExtra() {
  102. this.innerValue.push({
  103. tierIndex: undefined,
  104. rewardType: '1',
  105. rewardValue: undefined
  106. });
  107. this.handleChange();
  108. },
  109. removeExtra(index) {
  110. this.innerValue.splice(index, 1);
  111. this.handleChange();
  112. },
  113. handleChange() {
  114. this.$emit('input', this.innerValue);
  115. this.$emit('change', this.innerValue);
  116. }
  117. }
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .custom-list {
  122. width: 100%;
  123. max-width: 800px;
  124. .extra-row {
  125. color: #606266;
  126. padding: 15px;
  127. margin-bottom: 15px;
  128. border: 1px solid #e8e8e8;
  129. border-radius: 4px;
  130. background: #fff;
  131. position: relative;
  132. .extra-line {
  133. display: flex;
  134. align-items: center;
  135. }
  136. .label {
  137. width: 80px;
  138. text-align: right;
  139. padding-right: 10px;
  140. }
  141. .delete-icon {
  142. font-size: 16px;
  143. color: #f56c6c;
  144. cursor: pointer;
  145. position: absolute;
  146. top: 15px;
  147. right: 15px;
  148. }
  149. .dynamic-input {
  150. flex: 1;
  151. display: flex;
  152. }
  153. }
  154. }
  155. </style>