coupon-select.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template id="coupon-select">
  2. <div>
  3. <el-dialog title="选择优惠券" :visible.sync="dialogVisible" width="1100px" @close="dialogClose" append-to-body>
  4. <div v-loading='loading'>
  5. <div class="check_box flex flex-y-center" style="margin-bottom: 20px;">
  6. <el-form>
  7. <el-form-item label="优惠券名称" prop="title">
  8. <el-input v-model="keyword" placeholder='请输入优惠券名称' size="small" style="width: 50%;"></el-input>
  9. <el-button type="primary" size="small" @click="query">查询</el-button>
  10. <el-button type="danger" @click="resetQuery" size="small" v-if="show_clear_search_btn">清除条件</el-button>
  11. </el-form-item>
  12. </el-form>
  13. </div>
  14. <el-table :data="tableData" ref="multipleTable" key='coupon' :row-key="getRowKeys" border style="width: 100%" @selection-change="handleSelectionChange">
  15. <el-table-column type="selection" :reserve-selection="true" width="60" align='center'></el-table-column>
  16. <el-table-column prop="id" label="序号" width="80" align='center'></el-table-column>
  17. <el-table-column prop="name" label="优惠券名称" width="180" align='center'></el-table-column>
  18. <el-table-column prop="total_count" label="数量" width="80" align='center'></el-table-column>
  19. <el-table-column prop="min_price" label="最低消费金额" width="120" align='center'></el-table-column>
  20. <el-table-column prop="type_text" label="类型" width="120" align='center'>平台优惠券</el-table-column>
  21. <el-table-column prop="discount_method" label="优惠方式" align='center'>
  22. <template slot-scope="scope">
  23. <div v-if="scope.row.type == 1">{{ scope.row.discount }}折</div>
  24. <div v-else>优惠{{ scope.row.sub_price }}元</div>
  25. </template>
  26. </el-table-column>
  27. <el-table-column prop="effective_time" label="有效时间" align='center'>
  28. <template slot-scope="scope">
  29. <span v-if="scope.row.expire_type == 1">
  30. 领取{{scope.row.expire_day}}天后过期
  31. </span>
  32. <span v-else-if="scope.row.expire_type == 2">
  33. {{scope.row.begin_at|dateTimeFormat('Y-m-d H:i:s')}}至{{scope.row.end_at|dateTimeFormat('Y-m-d H:i:s')}}
  34. </span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column prop="address" label="是否过期" width="100" align='center'>
  38. <template slot-scope="scope">
  39. <div v-if="scope.row.is_failure != 0">已过期</div>
  40. <div v-else>未过期</div>
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="address" label="发放数量" align='center'>
  44. <template slot-scope="scope">
  45. <el-input-number v-model="scope.row.num" size="small" :min="1" :max="scope.row.total_count == -1?99999999999:Number(scope.row.total_count)"></el-input-number>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <div class="check_pagination flex">
  50. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  51. </div>
  52. </div>
  53. <span slot="footer" class="dialog-footer">
  54. <el-button type="primary" @click="chooseSure" size="small">确 定</el-button>
  55. <el-button @click="dialogVisible = false" size="small">取 消</el-button>
  56. </span>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. Vue.component('coupon-select', {
  62. template: '#coupon-select',
  63. props: {
  64. coupon_arr: {
  65. type: Array,
  66. default: function() {
  67. return [];
  68. }
  69. },
  70. couponLoading: {
  71. type: Boolean,
  72. default: false
  73. },
  74. },
  75. data() {
  76. return {
  77. loading: false,
  78. dialogVisible: false,
  79. form: {},
  80. staging_arr: [],
  81. tableData: [],
  82. keyword: null,
  83. page: 1,
  84. pageCount: 0,
  85. }
  86. },
  87. watch: {
  88. couponLoading: function(newVal) {
  89. if (newVal) {
  90. this.dialogVisible = true;
  91. if (this.$refs.multipleTable) {
  92. this.$refs.multipleTable.clearSelection(); // 清空选择
  93. }
  94. this.getCoupon();
  95. }
  96. },
  97. // index: function(newVal) {
  98. // if (newVal != -1) {
  99. // this.dialogVisible = true;
  100. // this.getCoupon();
  101. // }
  102. // },
  103. },
  104. computed: {
  105. show_clear_search_btn: function() {
  106. return this.keyword != null;
  107. },
  108. },
  109. methods: {
  110. query() {
  111. this.page = 1;
  112. this.getCoupon();
  113. },
  114. resetQuery() { // 清空查询条件
  115. this.keyword = null;
  116. this.page = 1;
  117. this.getCoupon();
  118. },
  119. pagination(currentPage) {
  120. let self = this;
  121. self.page = currentPage;
  122. self.getCoupon();
  123. },
  124. getCoupon() {
  125. this.loading2 = true;
  126. request({
  127. params: {
  128. r: 'coupon/default/select-coupon',
  129. },
  130. data: {
  131. page: this.page,
  132. limit: 10,
  133. keyword: this.keyword,
  134. },
  135. method: 'post',
  136. }).then(e => {
  137. this.loading2 = false;
  138. if (e.data.code == 0) {
  139. this.tableData = e.data.data.list;
  140. let coupon_arr_length = this.coupon_arr.length;
  141. this.tableData.forEach(item => {
  142. this.$set(item, 'num', 1);
  143. if (coupon_arr_length > 0) {
  144. this.coupon_arr.forEach(row => {
  145. if (item.id == row.relevant_id) {
  146. // 已选的优惠券被勾选
  147. this.$refs.multipleTable.toggleRowSelection(item);
  148. this.$set(item, 'num', row.num);
  149. }
  150. });
  151. }
  152. })
  153. this.pageCount = e.data.data.page_count;
  154. } else {
  155. this.$message.error(e.data.msg);
  156. }
  157. })
  158. },
  159. getRowKeys(rows) {
  160. return rows.id
  161. },
  162. handleSelectionChange(val) { //优惠券选择事件
  163. this.staging_arr = val;
  164. },
  165. chooseSure() { //确定选择券
  166. this.dialogVisible = false;
  167. let self = this;
  168. let new_arr = [];
  169. this.staging_arr.forEach(function(item) {
  170. let is_push = true;
  171. if (self.coupon_arr) {
  172. for (let index in self.coupon_arr) {
  173. let row = self.coupon_arr[index];
  174. if (item.id == row.relevant_id) {
  175. is_push = false;
  176. self.$set(row, 'num', item.num);
  177. return false; // 终止本次循环
  178. }
  179. }
  180. }
  181. if (is_push) {
  182. new_arr.push({
  183. relevant_id: item.id,
  184. num: item.num,
  185. name: item.name,
  186. total_count: item.total_count,
  187. from_type: item.from_type,
  188. discount_method: item.type == 1 ? item.discount + '折' : '优惠' + item.sub_price + '元',
  189. status: item.status,
  190. });
  191. }
  192. });
  193. self.coupon_arr.push(...new_arr);
  194. this.$emit('submit', self.coupon_arr);
  195. },
  196. dialogClose() {
  197. this.$emit('close')
  198. },
  199. }
  200. })
  201. </script>