selectQwUser.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <!-- 现有表单内容保持不变 -->
  5. <el-form-item label="企微主体" prop="corpId">
  6. <el-select v-model="queryParams.corpId" placeholder="企微主体" size="small" @change="updateCorpId()">
  7. <el-option
  8. v-for="dict in myQwCompanyList"
  9. :key="dict.dictValue"
  10. :label="dict.dictLabel"
  11. :value="dict.dictValue"
  12. />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="企微账号" prop="qwUserId">
  16. <el-input
  17. v-model="queryParams.qwUserId"
  18. placeholder="请输入企微账号"
  19. clearable
  20. size="small"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. <el-form-item label="企微昵称" prop="qwUserName">
  25. <el-input
  26. v-model="queryParams.qwUserName"
  27. placeholder="请输入企微昵称"
  28. clearable
  29. size="small"
  30. @keyup.enter.native="handleQuery"
  31. />
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-table
  39. height="500"
  40. border
  41. v-loading="loading"
  42. :data="customerList"
  43. ref="customerList"
  44. @selection-change="handleSelectionChange"
  45. >
  46. <!-- 添加多选列 -->
  47. <el-table-column type="selection" width="55" align="center" />
  48. <el-table-column label="企微昵称" align="center" prop="qwUserName" />
  49. <el-table-column label="企微账号" align="center" prop="qwUserId" />
  50. <el-table-column label="企微所属部门" align="center" prop="departmentName" />
  51. <el-table-column label="状态" align="center" prop="status" >
  52. <template slot-scope="scope">
  53. <dict-tag :options="qwStatusOptions" :value="scope.row.status"/>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="企微主体" align="center" prop="corpName" />
  57. </el-table>
  58. <div style="margin-top: 10px; text-align: right;">
  59. <el-button type="primary" @click="handleBatchBind">确定</el-button>
  60. <el-button @click="cancelSelect">取消选择</el-button>
  61. </div>
  62. <pagination
  63. v-show="total>0"
  64. :total="total"
  65. :page.sync="queryParams.pageNum"
  66. :limit.sync="queryParams.pageSize"
  67. @pagination="getList"
  68. />
  69. </div>
  70. </template>
  71. <script>
  72. import { userList, getMyQwCompanyList } from '@/api/qw/user'
  73. export default {
  74. name: "miniCustomer",
  75. components: {},
  76. props: {
  77. qwOpenCompanyId: {
  78. type: [String, Number],
  79. default: null
  80. }
  81. },
  82. data() {
  83. return {
  84. // 遮罩层
  85. loading: true,
  86. myQwCompanyList:[],
  87. qwStatusOptions:[],
  88. // 显示搜索条件
  89. showSearch: true,
  90. // 总条数
  91. total: 0,
  92. // 员工表格数据
  93. customerList: [],
  94. // 弹出层标题
  95. title: "",
  96. // 是否显示弹出层
  97. open: false,
  98. // 查询参数
  99. queryParams: {
  100. pageNum: 1,
  101. pageSize: 10,
  102. qwUserId: null,
  103. corpId: null,
  104. qwUserName: null,
  105. },
  106. // 表单参数
  107. form: {},
  108. // 表单校验
  109. rules: {},
  110. // 多选数据
  111. selectedUsers: [],
  112. // 已选中的用户ID列表(用于初始化选中状态)
  113. preSelectedUserIds: []
  114. };
  115. },
  116. created() {
  117. this.getDicts("sys_qw_user_status").then(response => {
  118. this.qwStatusOptions = response.data;
  119. });
  120. getMyQwCompanyList(this.qwOpenCompanyId).then(response => {
  121. this.myQwCompanyList = response.data;
  122. if(this.myQwCompanyList!=null){
  123. this.queryParams.corpId=this.myQwCompanyList[0].dictValue
  124. this.getList();
  125. }
  126. });
  127. },
  128. watch: {
  129. qwOpenCompanyId: {
  130. handler(newVal) {
  131. if (newVal != null) {
  132. getMyQwCompanyList(newVal).then(response => {
  133. this.myQwCompanyList = response.data;
  134. if(this.myQwCompanyList!=null){
  135. this.queryParams.corpId=this.myQwCompanyList[0].dictValue
  136. this.getList();
  137. }
  138. });
  139. }
  140. },
  141. immediate: false
  142. }
  143. },
  144. methods: {
  145. updateCorpId(){
  146. this.getList();
  147. },
  148. /** 查询客户列表 */
  149. getList() {
  150. this.loading = true;
  151. userList(this.queryParams).then(response => {
  152. this.customerList = response.rows;
  153. this.total = response.total;
  154. this.loading = false;
  155. // 在数据加载完成后设置已选中项
  156. this.$nextTick(() => {
  157. this.setPreSelectedItems();
  158. });
  159. });
  160. },
  161. // 设置预选中的项
  162. setPreSelectedItems() {
  163. if (this.preSelectedUserIds.length > 0 && this.customerList.length > 0) {
  164. // 找到需要预选中的行
  165. const selectedRows = this.customerList.filter(row =>
  166. this.preSelectedUserIds.includes(row.id)
  167. );
  168. // 设置选中状态
  169. this.$nextTick(() => {
  170. selectedRows.forEach(row => {
  171. this.$refs.customerList.toggleRowSelection(row, true);
  172. });
  173. });
  174. }
  175. },
  176. // 多选处理
  177. handleSelectionChange(selection) {
  178. this.selectedUsers = selection;
  179. },
  180. // 批量绑定选择
  181. handleBatchBind() {
  182. if (this.selectedUsers.length === 0) {
  183. this.$message.warning("请至少选择一个用户");
  184. return;
  185. }
  186. // 发送所有选中的用户数据
  187. this.selectedUsers.forEach(user => {
  188. this.$emit("bindQwUser", user);
  189. });
  190. // 清空选择
  191. this.clearSelection();
  192. this.$emit('close'); // 通知父组件关闭对话框
  193. },
  194. // 添加一个新的方法用于清除选择
  195. clearSelection() {
  196. this.selectedUsers = [];
  197. this.preSelectedUserIds = [];
  198. if (this.$refs.customerList) {
  199. this.$refs.customerList.clearSelection();
  200. }
  201. },
  202. // 设置已选中的用户(由父组件调用)
  203. setSelectedUsers(users) {
  204. this.preSelectedUserIds = users.map(user => user.id);
  205. this.selectedUsers = [...users];
  206. // 如果数据已经加载,直接设置选中状态
  207. if (this.customerList.length > 0) {
  208. this.setPreSelectedItems();
  209. }
  210. },
  211. // 取消选择
  212. cancelSelect() {
  213. this.$refs.customerList.clearSelection();
  214. this.selectedUsers = [];
  215. },
  216. // 取消按钮
  217. cancel() {
  218. this.open = false;
  219. this.reset();
  220. this.clearSelection(); // 清除选择
  221. },
  222. /** 搜索按钮操作 */
  223. handleQuery() {
  224. this.queryParams.pageNum = 1;
  225. this.getList();
  226. },
  227. /** 重置按钮操作 */
  228. resetQuery() {
  229. this.resetForm("queryForm");
  230. this.queryParams.corpId= this.myQwCompanyList[0].dictValue;
  231. this.handleQuery();
  232. },
  233. }
  234. };
  235. </script>
  236. <style>
  237. .el-tag + .el-tag {
  238. margin-left: 10px;
  239. }
  240. .button-new-tag {
  241. margin-left: 10px;
  242. height: 32px;
  243. line-height: 30px;
  244. padding-top: 0;
  245. padding-bottom: 0;
  246. }
  247. .input-new-tag {
  248. width: 90px;
  249. margin-left: 10px;
  250. vertical-align: bottom;
  251. }
  252. .el-dialog__wrapper{
  253. z-index: 100000;
  254. }
  255. </style>