AwardsList.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. name: "奖品十一",
  169. sort: 11,
  170. quantity: 0,
  171. prizeList: [],
  172. },
  173. {
  174. name: "奖品十二",
  175. sort: 12,
  176. quantity: 0,
  177. prizeList: [],
  178. },
  179. ],
  180. };
  181. },
  182. methods: {
  183. // 添加奖品
  184. add(type, item) {
  185. if(type == 1) {
  186. this.awardsList[this.prizeIndex].prizeList = this.awardsList[this.prizeIndex].prizeList.concat(item);
  187. } else if (type == 2) {
  188. this.awardsList[this.prizeIndex].prizeList.push(item);
  189. } else if (type == 3) {
  190. this.awardsList = item
  191. }
  192. this.$emit('input', this.awardsList)
  193. this.$emit('close')
  194. },
  195. // 选择奖品种类
  196. handleCommand(e, index) {
  197. this.prizeIndex = index;
  198. this.$emit('handleCommand', e)
  199. },
  200. // 改变奖级数量
  201. handleChangeAll(e, item) {
  202. this.$set(item, "quantity", e);
  203. this.$forceUpdate();
  204. // this.getQuantity();
  205. },
  206. // 改变奖品数量
  207. handleChange(e, index) {
  208. this.prizeIndex = index;
  209. this.$forceUpdate();
  210. // this.getQuantity();
  211. },
  212. // 奖级商品删除
  213. handleDel(index, item) {
  214. this.prizeIndex = item.sort - 1;
  215. let list = item.prizeList;
  216. list.splice(index, 1);
  217. this.$set(item, "prizeList", list);
  218. // this.getQuantity();
  219. },
  220. // 计算奖级数量
  221. getQuantity() {
  222. let num = 0;
  223. this.awardsList[this.prizeIndex].prizeList.forEach((item) => {
  224. num += item.quantity;
  225. });
  226. this.awardsList[this.prizeIndex].quantity = num;
  227. },
  228. },
  229. };
  230. </script>
  231. <style lang="scss" scoped>
  232. .prize {
  233. width: 1000px;
  234. margin-bottom: 50px;
  235. background: #f9f9f9;
  236. border: 1px solid #bbbbbb;
  237. font-size: 14px;
  238. &-top {
  239. padding: 10px 20px;
  240. margin-bottom: 10px;
  241. display: flex;
  242. align-content: center;
  243. justify-content: space-around;
  244. border-bottom: 1px solid #bbbbbb;
  245. div {
  246. line-height: 36px;
  247. }
  248. }
  249. &-btn {
  250. border-top: 1px solid #bbbbbb;
  251. padding: 10px;
  252. }
  253. }
  254. </style>