selectQwUser.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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,listUser, getUser, delUser, addUser, updateUser, exportUser, updateUserWeclome,getMyQwCompanyList,getMyQwUserList,relieveFastGptRoleById,staffListUser } from '@/api/qw/user'
  73. export default {
  74. name: "miniCustomer",
  75. components: {},
  76. data() {
  77. return {
  78. // 遮罩层
  79. loading: true,
  80. myQwCompanyList:[],
  81. qwStatusOptions:[],
  82. // 显示搜索条件
  83. showSearch: true,
  84. // 总条数
  85. total: 0,
  86. // 员工表格数据
  87. customerList: [],
  88. // 弹出层标题
  89. title: "",
  90. // 是否显示弹出层
  91. open: false,
  92. // 查询参数
  93. queryParams: {
  94. pageNum: 1,
  95. pageSize: 10,
  96. qwUserId: null,
  97. corpId: null,
  98. qwUserName: null,
  99. },
  100. // 表单参数
  101. form: {},
  102. // 表单校验
  103. rules: {},
  104. // 多选数据
  105. selectedUsers: [],
  106. // 已选中的用户ID列表(用于初始化选中状态)
  107. preSelectedUserIds: []
  108. };
  109. },
  110. created() {
  111. this.getDicts("sys_qw_user_status").then(response => {
  112. this.qwStatusOptions = response.data;
  113. });
  114. getMyQwCompanyList().then(response => {
  115. this.myQwCompanyList = response.data;
  116. if(this.myQwCompanyList!=null){
  117. this.queryParams.corpId=this.myQwCompanyList[0].dictValue
  118. this.getList();
  119. }
  120. });
  121. },
  122. methods: {
  123. updateCorpId(){
  124. this.getList();
  125. },
  126. /** 查询客户列表 */
  127. getList() {
  128. this.loading = true;
  129. userList(this.queryParams).then(response => {
  130. this.customerList = response.rows;
  131. this.total = response.total;
  132. this.loading = false;
  133. // 在数据加载完成后设置已选中项
  134. this.$nextTick(() => {
  135. this.setPreSelectedItems();
  136. });
  137. });
  138. },
  139. // 设置预选中的项
  140. setPreSelectedItems() {
  141. if (this.preSelectedUserIds.length > 0 && this.customerList.length > 0) {
  142. // 找到需要预选中的行
  143. const selectedRows = this.customerList.filter(row =>
  144. this.preSelectedUserIds.includes(row.id)
  145. );
  146. // 设置选中状态
  147. this.$nextTick(() => {
  148. selectedRows.forEach(row => {
  149. this.$refs.customerList.toggleRowSelection(row, true);
  150. });
  151. });
  152. }
  153. },
  154. // 多选处理
  155. handleSelectionChange(selection) {
  156. this.selectedUsers = selection;
  157. },
  158. // 批量绑定选择
  159. handleBatchBind() {
  160. if (this.selectedUsers.length === 0) {
  161. this.$message.warning("请至少选择一个用户");
  162. return;
  163. }
  164. // 发送所有选中的用户数据
  165. this.selectedUsers.forEach(user => {
  166. this.$emit("bindQwUser", user);
  167. });
  168. // 清空选择
  169. this.clearSelection();
  170. this.$emit('close'); // 通知父组件关闭对话框
  171. },
  172. // 添加一个新的方法用于清除选择
  173. clearSelection() {
  174. this.selectedUsers = [];
  175. this.preSelectedUserIds = [];
  176. if (this.$refs.customerList) {
  177. this.$refs.customerList.clearSelection();
  178. }
  179. },
  180. // 设置已选中的用户(由父组件调用)
  181. setSelectedUsers(users) {
  182. this.preSelectedUserIds = users.map(user => user.id);
  183. this.selectedUsers = [...users];
  184. // 如果数据已经加载,直接设置选中状态
  185. if (this.customerList.length > 0) {
  186. this.setPreSelectedItems();
  187. }
  188. },
  189. // 取消选择
  190. cancelSelect() {
  191. this.$refs.customerList.clearSelection();
  192. this.selectedUsers = [];
  193. },
  194. // 取消按钮
  195. cancel() {
  196. this.open = false;
  197. this.reset();
  198. this.clearSelection(); // 清除选择
  199. },
  200. /** 搜索按钮操作 */
  201. handleQuery() {
  202. this.queryParams.pageNum = 1;
  203. this.getList();
  204. },
  205. /** 重置按钮操作 */
  206. resetQuery() {
  207. this.resetForm("queryForm");
  208. this.queryParams.corpId= this.myQwCompanyList[0].dictValue;
  209. this.handleQuery();
  210. },
  211. }
  212. };
  213. </script>
  214. <style>
  215. .el-tag + .el-tag {
  216. margin-left: 10px;
  217. }
  218. .button-new-tag {
  219. margin-left: 10px;
  220. height: 32px;
  221. line-height: 30px;
  222. padding-top: 0;
  223. padding-bottom: 0;
  224. }
  225. .input-new-tag {
  226. width: 90px;
  227. margin-left: 10px;
  228. vertical-align: bottom;
  229. }
  230. .el-dialog__wrapper{
  231. z-index: 100000;
  232. }
  233. </style>