AwardsList.vue 8.8 KB

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