AwardsList.vue 6.2 KB

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