AwardsList.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. 关联奖级:<el-select v-model="item.awardsLabel" style="width: 120px;">
  9. <el-option v-for="(item,index) in awardsLabelList" :label="item.dictLabel" :value="item.dictLabel" :key="index"/>
  10. </el-select>
  11. </div>
  12. <div v-if="ticketType == 'offline'">
  13. 奖级数量:
  14. <el-input-number
  15. v-model="item.quantity"
  16. controls-position="right"
  17. @change="handleChangeAll($event, item)"
  18. :min="0"
  19. size="small"
  20. :disabled="item.isEdit"
  21. ></el-input-number>
  22. </div>
  23. <div v-else>奖级数量:{{ item.quantity }}</div>
  24. </div>
  25. <div class="prize-table">
  26. <el-table :data="item.prizeList" class="el-table">
  27. <el-table-column label="奖品图片">
  28. <template slot-scope="scope">
  29. <el-image
  30. style="width: 70px; height: 70px"
  31. :src="scope.row.picUrl"
  32. :preview-src-list="[scope.row.picUrl]"
  33. >
  34. </el-image>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="奖品名称" prop="title" >
  38. <template slot-scope="{ row }">
  39. <div v-if="row.prizeType == 'coin' && row.value >= 0">盲豆 x{{ row.value }}</div>
  40. <div v-else>{{ row.title }}</div>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="奖品类型">
  44. <template slot-scope="scope">
  45. <div v-if="scope.row.prizeType == 'goods'">商品</div>
  46. <div v-if="scope.row.prizeType == 'coupon'">券</div>
  47. <div v-if="scope.row.prizeType == 'coupon_pkg'">券包</div>
  48. <div v-if="scope.row.prizeType == 'coin'">盲豆</div>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="商品价格">
  52. <template slot-scope="scope">
  53. <div v-if="scope.row.prizeType == 'goods'">¥{{ $numberFormat(scope.row.value) }}</div>
  54. <span v-else>--</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="商品成本">
  58. <template slot-scope="scope">
  59. <div v-if="scope.row.prizeType == 'goods'">¥{{ $numberFormat(scope.row.cost) }}</div>
  60. <span v-else>--</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="奖品数量" prop="quantity" v-if="ticketType != 'offline'" align="center">
  64. <template slot-scope="scope">
  65. <div>
  66. <el-input-number
  67. v-model="scope.row.quantity"
  68. controls-position="right"
  69. @change="handleChange($event, index)"
  70. :min="1"
  71. size="small"
  72. ></el-input-number>
  73. </div>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="已兑数量" prop="cashedQty" align="center" v-if="boxId" />
  77. <el-table-column label="排序" prop="sortWeight" align="center">
  78. <template slot-scope="scope">
  79. <div>
  80. <el-input-number
  81. v-model="scope.row.sortWeight"
  82. controls-position="right"
  83. :min="0"
  84. size="small"
  85. ></el-input-number>
  86. </div>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="操作" align="center">
  90. <template slot-scope="scope">
  91. <el-button
  92. size="mini"
  93. type="text"
  94. @click="handleDel(scope.$index, item)"
  95. >删除</el-button
  96. >
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. </div>
  101. <div class="prize-btn">
  102. <el-dropdown @command="handleCommand($event, index)">
  103. <el-button type="primary" size="small">
  104. 添加奖品<i class="el-icon-arrow-down el-icon--right"></i>
  105. </el-button>
  106. <el-dropdown-menu slot="dropdown">
  107. <el-dropdown-item command="goods">商品</el-dropdown-item>
  108. <el-dropdown-item command="coupon">券</el-dropdown-item>
  109. <el-dropdown-item command="coupon_pkg">券包</el-dropdown-item>
  110. <el-dropdown-item command="coin">盲豆</el-dropdown-item>
  111. </el-dropdown-menu>
  112. </el-dropdown>
  113. </div>
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. export default {
  119. name: "AwardList",
  120. props: {
  121. value: {
  122. type: Array,
  123. default: () => []
  124. },
  125. id: {
  126. type: [String,Number],
  127. default: false,
  128. },
  129. },
  130. data() {
  131. return {
  132. boxId: this.$route.query.id,
  133. awardsLabelList: [],//关联奖级列表
  134. prizeIndex: 0, // 奖级下标
  135. // 奖级列表
  136. awardsList: [
  137. {
  138. name: "奖品一",
  139. sort: 1,
  140. quantity: 0,
  141. prizeList: [],
  142. },
  143. {
  144. name: "奖品二",
  145. sort: 2,
  146. quantity: 0,
  147. prizeList: [],
  148. },
  149. {
  150. name: "奖品三",
  151. sort: 3,
  152. quantity: 0,
  153. prizeList: [],
  154. },
  155. {
  156. name: "奖品四",
  157. sort: 4,
  158. quantity: 0,
  159. prizeList: [],
  160. },
  161. {
  162. name: "奖品五",
  163. sort: 5,
  164. quantity: 0,
  165. prizeList: [],
  166. },
  167. {
  168. name: "奖品六",
  169. sort: 6,
  170. quantity: 0,
  171. prizeList: [],
  172. },
  173. {
  174. name: "奖品七",
  175. sort: 7,
  176. quantity: 0,
  177. prizeList: [],
  178. },
  179. {
  180. name: "奖品八",
  181. sort: 8,
  182. quantity: 0,
  183. prizeList: [],
  184. },
  185. {
  186. name: "奖品九",
  187. sort: 9,
  188. quantity: 0,
  189. prizeList: [],
  190. },
  191. {
  192. name: "奖品十",
  193. sort: 10,
  194. quantity: 0,
  195. prizeList: [],
  196. },
  197. {
  198. name: "奖品十一",
  199. sort: 11,
  200. quantity: 0,
  201. prizeList: [],
  202. },
  203. {
  204. name: "奖品十二",
  205. sort: 12,
  206. quantity: 0,
  207. prizeList: [],
  208. },
  209. ],
  210. ticketType: '',
  211. };
  212. },
  213. created() {
  214. this.getAwardsLabelList()
  215. },
  216. methods: {
  217. //获取关联奖级
  218. getAwardsLabelList(){
  219. this.getDicts('awards_label').then(res=>{
  220. this.awardsLabelList = res.data
  221. })
  222. },
  223. // 添加奖品
  224. add(type, item) {
  225. if(type == 1) {
  226. this.awardsList[this.prizeIndex].prizeList = this.awardsList[this.prizeIndex].prizeList.concat(item);
  227. } else if (type == 2) {
  228. this.awardsList[this.prizeIndex].prizeList.push(item);
  229. } else if (type == 3) {
  230. this.awardsList = item
  231. }
  232. this.$emit('input', this.awardsList)
  233. this.$emit('close')
  234. if (this.ticketType != 'offline' && this.id == 0) {
  235. this.getQuantity();
  236. }
  237. },
  238. changetype(e) {
  239. this.ticketType = e
  240. },
  241. // 选择奖品种类
  242. handleCommand(e, index) {
  243. this.prizeIndex = index;
  244. this.$emit('handleCommand', e)
  245. },
  246. // 改变奖级数量
  247. handleChangeAll(e, item) {
  248. this.$set(item, "quantity", e);
  249. this.$forceUpdate();
  250. if (this.ticketType != 'offline' && this.id == 0) {
  251. this.getQuantity();
  252. }
  253. },
  254. // 改变奖品数量
  255. handleChange(e, index) {
  256. this.prizeIndex = index;
  257. this.$forceUpdate();
  258. if (this.ticketType != 'offline' && this.id == 0) {
  259. this.getQuantity();
  260. }
  261. },
  262. // 奖级商品删除
  263. handleDel(index, item) {
  264. this.prizeIndex = item.sort - 1;
  265. let list = item.prizeList;
  266. list.splice(index, 1);
  267. this.$set(item, "prizeList", list);
  268. if (this.ticketType != 'offline' && this.id == 0) {
  269. this.getQuantity();
  270. }
  271. },
  272. // 计算奖级数量
  273. getQuantity() {
  274. let num = 0;
  275. this.awardsList[this.prizeIndex].prizeList.forEach((item) => {
  276. num += item.quantity;
  277. });
  278. this.awardsList[this.prizeIndex].quantity = num;
  279. },
  280. },
  281. };
  282. </script>
  283. <style lang="scss" scoped>
  284. .prize {
  285. width: 100%;
  286. margin-bottom: 50px;
  287. background: #f9f9f9;
  288. border: 1px solid #bbbbbb;
  289. font-size: 14px;
  290. &-top {
  291. padding: 10px 20px;
  292. margin-bottom: 10px;
  293. display: flex;
  294. align-content: center;
  295. justify-content: space-around;
  296. border-bottom: 1px solid #bbbbbb;
  297. div {
  298. line-height: 36px;
  299. }
  300. }
  301. &-btn {
  302. border-top: 1px solid #bbbbbb;
  303. padding: 10px;
  304. }
  305. }
  306. </style>