coupon-select.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template id="coupon-select">
  2. <div>
  3. <el-dialog title="选择优惠券" :visible.sync="dialogVisible" width="1100px" @close="dialogClose">
  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="type_text" label="类型" width="100" align='center'></el-table-column>
  18. <el-table-column prop="name" label="优惠券名称" width="180" align='center'></el-table-column>
  19. <el-table-column prop="total_count" label="数量" width="80" align='center'></el-table-column>
  20. <el-table-column prop="min_price" 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>
  50. <span slot="footer" class="dialog-footer">
  51. <el-button type="primary" @click="chooseSure" size="small">确 定</el-button>
  52. <el-button @click="dialogVisible = false" size="small">取 消</el-button>
  53. </span>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script>
  58. Vue.component('coupon-select', {
  59. template: '#coupon-select',
  60. props: {
  61. coupon_arr: {
  62. type: Array,
  63. default: function() {
  64. return [];
  65. }
  66. },
  67. couponLoading:{
  68. type:Boolean,
  69. default:false
  70. },
  71. },
  72. data() {
  73. return {
  74. loading: false,
  75. dialogVisible: false,
  76. form: {},
  77. staging_arr:[],
  78. tableData:[],
  79. keyword:null,
  80. page:1,
  81. pageCount:0,
  82. }
  83. },
  84. watch: {
  85. couponLoading: function(newVal) {
  86. if (newVal) {
  87. this.dialogVisible = true;
  88. if (this.coupon_arr.length == 0 && this.$refs.multipleTable) {
  89. this.$refs.multipleTable.clearSelection();// 清空选择
  90. }
  91. this.getCoupon();
  92. }
  93. },
  94. },
  95. computed: {
  96. show_clear_search_btn: function() {
  97. return this.keyword != null;
  98. },
  99. },
  100. methods: {
  101. query() {
  102. this.page = 1;
  103. this.getCoupon();
  104. },
  105. resetQuery() {// 清空查询条件
  106. this.keyword = null;
  107. this.page = 1;
  108. this.getCoupon();
  109. },
  110. pagination(currentPage) {
  111. let self = this;
  112. self.page = currentPage;
  113. self.getCoupon();
  114. },
  115. getCoupon() {
  116. this.loading2 = true;
  117. request({
  118. params: {
  119. r: 'store/client/coupon/select-coupon',
  120. },
  121. data: {
  122. page: this.page,
  123. limit: 10,
  124. keyword: this.keyword,
  125. },
  126. method: 'post',
  127. }).then(e => {
  128. this.loading2 = false;
  129. if (e.data.code == 0) {
  130. this.tableData = e.data.data;
  131. let coupon_arr_length = this.coupon_arr.length;
  132. this.tableData.forEach(item => {
  133. this.$set(item, 'num', 1);
  134. if (coupon_arr_length > 0) {
  135. this.coupon_arr.forEach(row => {
  136. if (item.id == row.relevant_id) {
  137. // 已选的优惠券被勾选
  138. this.$refs.multipleTable.toggleRowSelection(item);
  139. this.$set(item, 'num', row.num);
  140. }
  141. });
  142. }
  143. })
  144. this.pageCount = e.data.data.page_count;
  145. } else {
  146. this.$message.error(e.data.msg);
  147. }
  148. })
  149. },
  150. getRowKeys(rows) {
  151. return rows.id
  152. },
  153. handleSelectionChange(val) { //优惠券选择事件
  154. this.staging_arr = val;
  155. },
  156. chooseSure() { //确定选择券
  157. this.dialogVisible = false;
  158. let self = this;
  159. let new_arr = [];
  160. this.staging_arr.forEach(function (item) {
  161. let is_push = true;
  162. if (self.coupon_arr) {
  163. for (let index in self.coupon_arr) {
  164. let row = self.coupon_arr[index];
  165. if (item.id == row.relevant_id) {
  166. is_push = false;
  167. self.$set(row, 'num', item.num);
  168. return false;// 终止本次循环
  169. }
  170. }
  171. }
  172. if (is_push) {
  173. new_arr.push({
  174. coupon_id: item.id,
  175. num: item.num,
  176. from_type: item.from_type,
  177. type_text: item.type_text,
  178. name: item.name,
  179. total_count: item.total_count,
  180. discount_method: item.type == 1 ? item.discount + '折' : '优惠' + item.sub_price + '元',
  181. status: item.status,
  182. });
  183. }
  184. });
  185. self.coupon_arr.push(...new_arr);
  186. this.$emit('submit',self.coupon_arr);
  187. },
  188. dialogClose() {
  189. this.$emit('close')
  190. },
  191. }
  192. })
  193. </script>