CusRoleList.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px"
  4. @submit.prevent="handleQuery">
  5. <el-form-item label="销售名称" prop="memberName">
  6. <el-input v-model="queryParams.memberName" placeholder="请输入销售名称" clearable size="small"
  7. @keydown.enter.native="handleQueryEnter" />
  8. </el-form-item>
  9. <el-form-item label="所属公司" prop="roleName">
  10. <el-input v-model="queryParams.roleName" placeholder="请输入所属公司" clearable size="small"
  11. @keydown.enter.native="handleQueryEnter" />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-table
  19. v-loading="loading"
  20. :data="roleList"
  21. ref="roleList"
  22. :row-key="row => String(row.id)"
  23. :class="{ 'cus-role-single': !multiple }"
  24. @select="singleSelectHandler"
  25. @select-all="allSelectHandler"
  26. >
  27. <el-table-column type="selection" width="55" align="center"/>
  28. <el-table-column label="销售id" align="center" prop="id" min-width="100"/>
  29. <el-table-column label="销售名称" align="center" prop="memberName" min-width="140" show-overflow-tooltip/>
  30. <el-table-column label="所属公司" align="center" prop="roleName" min-width="140" show-overflow-tooltip/>
  31. <el-table-column label="备注" align="center" prop="remark" min-width="160" show-overflow-tooltip/>
  32. </el-table>
  33. <div style="margin-top: 30px;display: flex;justify-content: center">
  34. <el-button type="warning" icon="el-icon-search" @click="confirmSelect">确定选择</el-button>
  35. </div>
  36. <pagination
  37. v-show="total > 0"
  38. :total="total"
  39. :page.sync="queryParams.pageNum"
  40. :limit.sync="queryParams.pageSize"
  41. @pagination="getList"
  42. />
  43. </div>
  44. </template>
  45. <script>
  46. import { listRole } from "@/api/app/user/userList";
  47. export default {
  48. name: "SelectedCustomer",
  49. props: {
  50. defaultPageNum: {
  51. type: Number,
  52. default: 1
  53. },
  54. defaultPageSize: {
  55. type: Number,
  56. default: 10
  57. },
  58. selected: {
  59. type: Array,
  60. default: () => [],
  61. },
  62. // 是否允许多选,false 时只能勾选一个
  63. multiple: {
  64. type: Boolean,
  65. default: true,
  66. },
  67. // 排除的销售id
  68. ignoreIds: {
  69. type: Array,
  70. default: () => [],
  71. },
  72. // 仅查询指定销售id
  73. ids: {
  74. type: Array,
  75. default: () => [],
  76. },
  77. // 所属公司id:有值时仅查该公司下销售
  78. companyId: {
  79. type: [Number, String],
  80. default: null,
  81. },
  82. },
  83. data() {
  84. return {
  85. // 遮罩层
  86. loading: true,
  87. // 总条数
  88. total: 0,
  89. // 客服成员表格数据
  90. roleList: [],
  91. // 查询参数
  92. queryParams: {
  93. pageNum: 1,
  94. pageSize: 10,
  95. memberName: null,
  96. roleName: null,
  97. companyId: null,
  98. },
  99. };
  100. },
  101. created() {
  102. this.queryParams.pageNum = this.defaultPageNum;
  103. this.queryParams.pageSize = this.defaultPageSize;
  104. this.queryParams.companyId = this.companyId || null;
  105. this.getList();
  106. },
  107. watch: {
  108. selected: {
  109. immediate: true,
  110. handler(nv) {
  111. this.setSelectionStatus();
  112. }
  113. },
  114. companyId: {
  115. handler(n) {
  116. this.reloadByCompany(n);
  117. }
  118. }
  119. },
  120. methods: {
  121. /**
  122. * 按公司刷新列表(搜索页切换所属公司后调用)
  123. */
  124. reloadByCompany(companyId) {
  125. this.queryParams.companyId = companyId || null;
  126. this.queryParams.pageNum = 1;
  127. this.getList();
  128. },
  129. /**
  130. * 查询客服成员列表
  131. */
  132. getList() {
  133. this.loading = true;
  134. let qp = { ...this.queryParams };
  135. if (this.companyId) {
  136. qp.companyId = this.companyId;
  137. } else if (!qp.companyId) {
  138. delete qp.companyId;
  139. }
  140. if (this.ignoreIds && this.ignoreIds.length) {
  141. qp['ignoreIds'] = this.ignoreIds;
  142. } else {
  143. delete qp.ignoreIds;
  144. }
  145. if (this.ids && this.ids.length) {
  146. qp['ids'] = this.ids;
  147. } else {
  148. delete qp.ids;
  149. }
  150. listRole(qp).then(response => {
  151. this.roleList = response.rows;
  152. this.total = response.total;
  153. this.loading = false;
  154. this.setSelectionStatus();
  155. });
  156. },
  157. // 取消按钮
  158. cancel() {
  159. this.reset();
  160. try {
  161. this.$emit("cancel", this.selected);
  162. } catch (e) {
  163. console.warn('暂未指定确认选择回调');
  164. }
  165. },
  166. setSelectionStatus() {
  167. if (this.roleList.length == 0) {
  168. return;
  169. }
  170. this.$nextTick(() => {
  171. this.roleList.forEach(row => {
  172. // 判断当前行ID是否在全局选中集合中
  173. const isSelected = this.selected.some(si => row.id == si.id);
  174. this.$refs.roleList.toggleRowSelection(row, isSelected);
  175. });
  176. });
  177. },
  178. /**
  179. * 表单重置
  180. */
  181. reset() {
  182. this.queryParams = {
  183. pageNum: this.defaultPageNum,
  184. pageSize: this.defaultPageSize,
  185. memberName: null,
  186. roleName: null,
  187. companyId: this.companyId || null,
  188. }
  189. this.resetForm("form");
  190. },
  191. /**
  192. * 确定选择
  193. */
  194. confirmSelect() {
  195. try {
  196. this.$emit("confirm", this.selected);
  197. } catch (e) {
  198. console.warn('暂未指定确认选择回调');
  199. }
  200. },
  201. /**
  202. * 搜索按钮操作
  203. */
  204. handleQuery() {
  205. this.queryParams.pageNum = 1;
  206. this.getList();
  207. },
  208. handleQueryEnter(event) {
  209. // 确保事件对象存在
  210. if (event && event.preventDefault) {
  211. event.preventDefault(); // 阻止默认提交行为
  212. }
  213. this.handleQuery();
  214. },
  215. /**
  216. * 重置按钮操作
  217. */
  218. resetQuery() {
  219. this.resetForm("queryForm");
  220. this.queryParams.companyId = this.companyId || null;
  221. this.handleQuery();
  222. }, /**
  223. * 单选
  224. * @param selection
  225. * @param row
  226. */
  227. singleSelectHandler(selection, row) {
  228. // 单选模式:只保留当前行
  229. if (!this.multiple) {
  230. const isSelected = selection.some(l => l.id == row.id)
  231. this.$refs.roleList.clearSelection()
  232. if (isSelected) {
  233. this.$nextTick(() => {
  234. this.$refs.roleList.toggleRowSelection(row, true)
  235. })
  236. }
  237. try {
  238. this.$emit('selectionChange', {
  239. mode: 0,
  240. row,
  241. selected: isSelected
  242. })
  243. } catch (e) {
  244. console.warn('当前组件暂未指定selection回调')
  245. }
  246. return
  247. }
  248. let pm = {
  249. mode: 0,//0-单行选,1-全选
  250. row,//操作的行
  251. }
  252. //列表中找不到当前行数据,则说明是取消选中
  253. if (!selection.some(l => l.id == row.id)) {
  254. pm['selected'] = false;//设置取消选中
  255. } else {
  256. pm['selected'] = true;//设置选中
  257. }
  258. try {
  259. this.$emit("selectionChange", pm);
  260. } catch (e) {
  261. console.warn('当前组件暂未指定selection回调');
  262. }
  263. },
  264. /**
  265. * 全选
  266. * @param selection
  267. */
  268. allSelectHandler(selection) {
  269. // 单选模式不允许全选
  270. if (!this.multiple) {
  271. this.$refs.roleList.clearSelection()
  272. return
  273. }
  274. let pm = {
  275. mode: 1,//0-单行选,1-全选
  276. rows: this.roleList,//操作的所有行
  277. selected: selection.length > 0 ? true : false,
  278. }
  279. try {
  280. this.$emit("selectionChange", pm);
  281. } catch (e) {
  282. console.warn('当前组件暂未指定selection回调');
  283. }
  284. },
  285. }
  286. };
  287. </script>
  288. <style scoped>
  289. /* 单选模式隐藏表头全选勾选框 */
  290. .cus-role-single ::v-deep .el-table__header-wrapper .el-checkbox {
  291. display: none;
  292. }
  293. </style>