selectQwUser.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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" :selectable="checkSelectable"/>
  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. // 检查是否可选择(状态不为1的用户才可选择)
  127. checkSelectable(row, index) {
  128. return row.status !== 1;
  129. },
  130. /** 查询客户列表 */
  131. getList() {
  132. this.loading = true;
  133. userList(this.queryParams).then(response => {
  134. this.customerList = response.rows;
  135. this.total = response.total;
  136. this.loading = false;
  137. // 在数据加载完成后设置已选中项
  138. this.$nextTick(() => {
  139. this.setPreSelectedItems();
  140. });
  141. });
  142. },
  143. // 设置预选中的项
  144. setPreSelectedItems() {
  145. if (this.preSelectedUserIds.length > 0 && this.customerList.length > 0) {
  146. // 找到需要预选中的行,排除状态为1的用户
  147. const selectedRows = this.customerList.filter(row =>
  148. this.preSelectedUserIds.includes(row.id) &&
  149. row.status !== 1
  150. );
  151. // 设置选中状态
  152. this.$nextTick(() => {
  153. selectedRows.forEach(row => {
  154. this.$refs.customerList.toggleRowSelection(row, true);
  155. });
  156. });
  157. }
  158. },
  159. // 多选处理
  160. handleSelectionChange(selection) {
  161. this.selectedUsers = selection.filter(item =>
  162. item.status !== 1
  163. );
  164. },
  165. // 批量绑定选择
  166. handleBatchBind() {
  167. if (this.selectedUsers.length === 0) {
  168. this.$message.warning("请至少选择一个用户");
  169. return;
  170. }
  171. // 发送所有选中的用户数据
  172. this.selectedUsers.forEach(user => {
  173. this.$emit("bindQwUser", user);
  174. });
  175. // 清空选择
  176. this.clearSelection();
  177. this.$emit('close'); // 通知父组件关闭对话框
  178. },
  179. // 添加一个新的方法用于清除选择
  180. clearSelection() {
  181. this.selectedUsers = [];
  182. this.preSelectedUserIds = [];
  183. if (this.$refs.customerList) {
  184. this.$refs.customerList.clearSelection();
  185. }
  186. },
  187. // 设置已选中的用户(由父组件调用)
  188. setSelectedUsers(users) {
  189. this.preSelectedUserIds = users.map(user => user.id);
  190. this.selectedUsers = [...users];
  191. // 如果数据已经加载,直接设置选中状态
  192. if (this.customerList.length > 0) {
  193. this.setPreSelectedItems();
  194. }
  195. },
  196. // 取消选择
  197. cancelSelect() {
  198. this.$refs.customerList.clearSelection();
  199. this.selectedUsers = [];
  200. },
  201. // 取消按钮
  202. cancel() {
  203. this.open = false;
  204. this.reset();
  205. this.clearSelection(); // 清除选择
  206. },
  207. /** 搜索按钮操作 */
  208. handleQuery() {
  209. this.queryParams.pageNum = 1;
  210. this.getList();
  211. },
  212. /** 重置按钮操作 */
  213. resetQuery() {
  214. this.resetForm("queryForm");
  215. this.queryParams.corpId= this.myQwCompanyList[0].dictValue;
  216. this.handleQuery();
  217. },
  218. }
  219. };
  220. </script>
  221. <style>
  222. .el-tag + .el-tag {
  223. margin-left: 10px;
  224. }
  225. .button-new-tag {
  226. margin-left: 10px;
  227. height: 32px;
  228. line-height: 30px;
  229. padding-top: 0;
  230. padding-bottom: 0;
  231. }
  232. .input-new-tag {
  233. width: 90px;
  234. margin-left: 10px;
  235. vertical-align: bottom;
  236. }
  237. .el-dialog__wrapper{
  238. z-index: 100000;
  239. }
  240. </style>