AwardsList.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div>
  3. <div class="prize" v-for="(item, index) in awardsList" :key="index">
  4. <div class="prize-top">
  5. <div>奖级名称:{{ item.name }}</div>
  6. <div>奖级:{{ item.sort }}</div>
  7. <div>
  8. 奖级数量:
  9. <el-input-number
  10. v-model="item.quantity"
  11. controls-position="right"
  12. @change="handleChangeAll($event, item)"
  13. :min="0"
  14. size="small"
  15. :disabled="item.isEdit"
  16. ></el-input-number>
  17. </div>
  18. </div>
  19. <div class="prize-table">
  20. <el-table :data="item.prizeList" class="el-table">
  21. <el-table-column label="奖品图片">
  22. <template slot-scope="scope">
  23. <el-image
  24. style="width: 70px; height: 70px"
  25. :src="scope.row.picUrl"
  26. :preview-src-list="[scope.row.picUrl]"
  27. >
  28. </el-image>
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="奖品名称" prop="title" />
  32. <el-table-column label="奖品类型">
  33. <template slot-scope="scope">
  34. <div v-if="scope.row.prizeType == 'goods'">商品</div>
  35. <div v-if="scope.row.prizeType == 'coupon'">券</div>
  36. <div v-if="scope.row.prizeType == 'coupon_pkg'">券包</div>
  37. <div v-if="scope.row.prizeType == 'coin'">盲豆</div>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="排序" prop="sortWeight">
  41. <template slot-scope="scope">
  42. <div>
  43. <el-input-number
  44. v-model="scope.row.sortWeight"
  45. controls-position="right"
  46. :min="0"
  47. size="small"
  48. ></el-input-number>
  49. </div>
  50. </template>
  51. </el-table-column>
  52. <!-- <el-table-column label="奖品数量" prop="storeName">
  53. <template slot-scope="scope">
  54. <div>
  55. <el-input-number
  56. v-model="scope.row.quantity"
  57. controls-position="right"
  58. @change="handleChange($event, index)"
  59. :min="1"
  60. size="small"
  61. ></el-input-number>
  62. </div>
  63. </template>
  64. </el-table-column> -->
  65. <el-table-column label="操作" align="center">
  66. <template slot-scope="scope">
  67. <el-button
  68. size="mini"
  69. type="text"
  70. @click="handleDel(scope.$index, item)"
  71. >删除</el-button
  72. >
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. </div>
  77. <div class="prize-btn">
  78. <el-dropdown @command="handleCommand($event, index)">
  79. <el-button type="primary" size="small">
  80. 添加奖品<i class="el-icon-arrow-down el-icon--right"></i>
  81. </el-button>
  82. <el-dropdown-menu slot="dropdown">
  83. <el-dropdown-item command="goods">商品</el-dropdown-item>
  84. <el-dropdown-item command="coupon">券</el-dropdown-item>
  85. <el-dropdown-item command="coupon_pkg">券包</el-dropdown-item>
  86. <el-dropdown-item command="coin">盲豆</el-dropdown-item>
  87. </el-dropdown-menu>
  88. </el-dropdown>
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. export default {
  95. name: "AwardList",
  96. props: {
  97. value: {
  98. type: Array,
  99. default: () => []
  100. },
  101. },
  102. data() {
  103. return {
  104. prizeIndex: null, // 奖级下标
  105. // 奖级列表
  106. awardsList: [
  107. {
  108. name: "奖品一",
  109. sort: 1,
  110. quantity: 0,
  111. prizeList: [],
  112. },
  113. {
  114. name: "奖品二",
  115. sort: 2,
  116. quantity: 0,
  117. prizeList: [],
  118. },
  119. {
  120. name: "奖品三",
  121. sort: 3,
  122. quantity: 0,
  123. prizeList: [],
  124. },
  125. {
  126. name: "奖品四",
  127. sort: 4,
  128. quantity: 0,
  129. prizeList: [],
  130. },
  131. {
  132. name: "奖品五",
  133. sort: 5,
  134. quantity: 0,
  135. prizeList: [],
  136. },
  137. {
  138. name: "奖品六",
  139. sort: 6,
  140. quantity: 0,
  141. prizeList: [],
  142. },
  143. {
  144. name: "奖品七",
  145. sort: 7,
  146. quantity: 0,
  147. prizeList: [],
  148. },
  149. {
  150. name: "奖品八",
  151. sort: 8,
  152. quantity: 0,
  153. prizeList: [],
  154. },
  155. {
  156. name: "奖品九",
  157. sort: 9,
  158. quantity: 0,
  159. prizeList: [],
  160. },
  161. {
  162. name: "奖品十",
  163. sort: 10,
  164. quantity: 0,
  165. prizeList: [],
  166. },
  167. ],
  168. };
  169. },
  170. methods: {
  171. // 添加奖品
  172. add(type, item) {
  173. if(type == 1) {
  174. this.awardsList[this.prizeIndex].prizeList = this.awardsList[this.prizeIndex].prizeList.concat(item);
  175. } else if (type == 2) {
  176. this.awardsList[this.prizeIndex].prizeList.push(item);
  177. } else if (type == 3) {
  178. this.awardsList = item
  179. }
  180. this.$emit('input', this.awardsList)
  181. this.$emit('close')
  182. },
  183. // 选择奖品种类
  184. handleCommand(e, index) {
  185. this.prizeIndex = index;
  186. this.$emit('handleCommand', e)
  187. },
  188. // 改变奖级数量
  189. handleChangeAll(e, item) {
  190. this.$set(item, "quantity", e);
  191. this.$forceUpdate();
  192. // this.getQuantity();
  193. },
  194. // 改变奖品数量
  195. handleChange(e, index) {
  196. this.prizeIndex = index;
  197. this.$forceUpdate();
  198. // this.getQuantity();
  199. },
  200. // 奖级商品删除
  201. handleDel(index, item) {
  202. this.prizeIndex = item.sort - 1;
  203. let list = item.prizeList;
  204. list.splice(index, 1);
  205. this.$set(item, "prizeList", list);
  206. // this.getQuantity();
  207. },
  208. // 计算奖级数量
  209. getQuantity() {
  210. let num = 0;
  211. this.awardsList[this.prizeIndex].prizeList.forEach((item) => {
  212. num += item.quantity;
  213. });
  214. this.awardsList[this.prizeIndex].quantity = num;
  215. },
  216. },
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. .prize {
  221. width: 1000px;
  222. margin-bottom: 50px;
  223. background: #f9f9f9;
  224. border: 1px solid #bbbbbb;
  225. font-size: 14px;
  226. &-top {
  227. padding: 10px 20px;
  228. margin-bottom: 10px;
  229. display: flex;
  230. align-content: center;
  231. justify-content: space-around;
  232. border-bottom: 1px solid #bbbbbb;
  233. div {
  234. line-height: 36px;
  235. }
  236. }
  237. &-btn {
  238. border-top: 1px solid #bbbbbb;
  239. padding: 10px;
  240. }
  241. }
  242. </style>