electron-coupon-select.php 8.4 KB

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