user-select.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template id="user-select">
  2. <div>
  3. <el-dialog title="选择会员" :visible.sync="dialogVisible" width="500px" @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" label-width="150px">
  8. <el-input v-model="keyword" placeholder='请输入会员名称' size="small" style="width: 50%;"></el-input>
  9. </el-form-item>
  10. <el-form-item label="会员id" prop="user_id" label-width="150px">
  11. <el-input v-model="user_id" placeholder='请输入会员id' size="small" style="width: 50%;"></el-input>
  12. </el-form-item>
  13. <el-form-item label="会员手机号码" prop="mobile" label-width="150px">
  14. <el-input v-model="mobile" placeholder='请输入会员手机号码' size="small" style="width: 50%;"></el-input>
  15. <el-button type="primary" size="small" @click="query">查询</el-button>
  16. <el-button type="danger" @click="resetQuery" size="small" v-if="show_clear_search_btn">清除条件</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. <el-table :data="tableData" ref="multipleTable" key='user' :row-key="getRowKeys" border style="width: 100%" @selection-change="handleSelectionChange">
  21. <el-table-column type="selection" :reserve-selection="true" width="60" align='center'></el-table-column>
  22. <el-table-column prop="id" label="序号" width="80" align='center'></el-table-column>
  23. <el-table-column label="会员" width="180" >
  24. <template slot-scope="scope">
  25. <div class="user_img" v-if="scope.row.id>0">
  26. <el-image class="default-avatar" :src="scope.row.avatar_url">
  27. <div slot="error" class="image-slot">
  28. <com-image src="/resources/img/common/default-avatar.png"></com-image>
  29. </div>
  30. </el-image>
  31. </div>
  32. <div class="user_img" v-else>
  33. <el-image class="default-avatar" :src="scope.row.user_avatar_url">
  34. <div slot="error" class="image-slot">
  35. <com-image src="/resources/img/common/default-avatar.png"></com-image>
  36. </div>
  37. </el-image>
  38. </div>
  39. <div>
  40. <div style="color:#000;" v-if="scope.row.id>0">{{scope.row.nickname}}</div>
  41. <div style="color:#000;" v-else>{{scope.row.user_name}}</div>
  42. <div style="font-size: 13px;" v-if="scope.row.id>0">{{scope.row.mobile}}</div>
  43. </div>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <div class="check_pagination flex">
  48. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  49. </div>
  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. <style>
  59. /*头像样式 start*/
  60. .default-avatar{
  61. width: 50px;
  62. height: 50px;
  63. border-radius: 50%;
  64. }
  65. .user_img{
  66. position: relative;
  67. margin-right: 8px;
  68. height: 50px;
  69. width: 50px;
  70. }
  71. .el-table_1_column_3 .cell { /*-2 表示在第二行*/
  72. display: flex;
  73. }
  74. /*头像样式 end*/
  75. </style>
  76. <script>
  77. Vue.component('user-select', {
  78. template: '#user-select',
  79. props: {
  80. user_arr: {
  81. type: Array,
  82. default: function() {
  83. return [];
  84. }
  85. },
  86. userLoading:{
  87. type:Boolean,
  88. default:false
  89. },
  90. },
  91. data() {
  92. return {
  93. loading: false,
  94. dialogVisible: false,
  95. form: {},
  96. staging_arr:[],
  97. tableData:[],
  98. keyword:null,
  99. mobile:null,
  100. user_id:null,
  101. page:1,
  102. pageCount:0,
  103. }
  104. },
  105. watch: {
  106. userLoading: function(newVal) {
  107. if (newVal) {
  108. this.dialogVisible = true;
  109. if (this.user_arr.length == 0 && this.$refs.multipleTable) {
  110. this.$refs.multipleTable.clearSelection();// 清空选择
  111. }
  112. this.getuser();
  113. }
  114. },
  115. },
  116. computed: {
  117. show_clear_search_btn: function() {
  118. return this.mobile!=null||this.user_id!=null||this.keyword != null;
  119. },
  120. },
  121. methods: {
  122. query() {
  123. this.page = 1;
  124. this.getuser();
  125. },
  126. resetQuery() {// 清空查询条件
  127. this.keyword = null;
  128. this.user_id = null;
  129. this.mobile = null;
  130. this.page = 1;
  131. this.getuser();
  132. },
  133. pagination(currentPage) {
  134. let self = this;
  135. self.page = currentPage;
  136. self.getuser();
  137. },
  138. getuser() {
  139. this.loading2 = true;
  140. request({
  141. params: {
  142. r: 'issue-coupons/default/select-user',
  143. },
  144. data: {
  145. page: this.page,
  146. limit: 10,
  147. keyword: this.keyword,
  148. mobile: this.mobile,
  149. user_id: this.user_id,
  150. },
  151. method: 'post',
  152. }).then(e => {
  153. this.loading2 = false;
  154. if (e.data.code == 0) {
  155. this.tableData = e.data.data.list;
  156. let user_arr_length = this.user_arr.length;
  157. this.tableData.forEach(item => {
  158. this.$set(item, 'num', 1);
  159. if (user_arr_length > 0) {
  160. this.user_arr.forEach(row => {
  161. if (item.id == row.user_id) {
  162. // 已选的会员被勾选
  163. this.$refs.multipleTable.toggleRowSelection(item);
  164. this.$set(item, 'num', row.num);
  165. }
  166. });
  167. }
  168. })
  169. this.pageCount = e.data.data.page_count;
  170. } else {
  171. this.$message.error(e.data.msg);
  172. }
  173. })
  174. },
  175. getRowKeys(rows) {
  176. return rows.id
  177. },
  178. handleSelectionChange(val) { //会员选择事件
  179. this.staging_arr = val;
  180. },
  181. chooseSure() { //确定选择券
  182. this.dialogVisible = false;
  183. let self = this;
  184. let new_arr = [];
  185. this.staging_arr.forEach(function (item) {
  186. let is_push = true;
  187. if (self.user_arr) {
  188. for (let index in self.user_arr) {
  189. let row = self.user_arr[index];
  190. if (item.id == row.user_id) {
  191. is_push = false;
  192. self.$set(row, 'num', item.num);
  193. return false;// 终止本次循环
  194. }
  195. }
  196. }
  197. if (is_push) {
  198. new_arr.push({
  199. use_id: item.id,
  200. name: item.nickname?item.nickname:item.username,
  201. });
  202. }
  203. });
  204. //self.user_arr.push(...new_arr);
  205. this.$emit('submit',new_arr);
  206. },
  207. dialogClose() {
  208. this.$emit('close')
  209. },
  210. }
  211. })
  212. </script>