com-coupon-select.php 8.8 KB

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