index.vue 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--部门数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
  8. </div>
  9. <div class="head-container">
  10. <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" @node-click="handleNodeClick" />
  11. </div>
  12. </el-col>
  13. <!--用户数据-->
  14. <el-col :span="20" :xs="24">
  15. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  16. <el-form-item label="员工后台昵称" prop="nickName">
  17. <el-input v-model="queryParams.nickName" placeholder="请输入员工后台昵称" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
  18. </el-form-item>
  19. <el-form-item label="手机号码" prop="phonenumber">
  20. <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="员工状态" clearable size="small" style="width: 240px" @change="handleQuery">
  24. <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="企微状态" prop="qwStatus">
  28. <el-select v-model="queryParams.qwStatus" placeholder="企微绑定状态" clearable size="small" style="width: 240px" @change="handleQuery">
  29. <el-option v-for="dict in qwStatusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="创建时间">
  33. <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  37. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  38. </el-form-item>
  39. </el-form>
  40. <el-row :gutter="10" class="mb8">
  41. <el-col :span="1.5">
  42. <el-button plain type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['company:user:add']">新增</el-button>
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button plain type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['company:user:edit']">修改</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button plain type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['company:user:remove']">删除</el-button>
  49. </el-col>
  50. <!-- <el-col :span="1.5">
  51. <el-button plain type="info" icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['company:user:import']">导入</el-button>
  52. </el-col> -->
  53. <el-col :span="1.5">
  54. <el-button plain type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['company:user:export']">导出</el-button>
  55. </el-col>
  56. <el-col :span="1.5">
  57. <el-button
  58. type="primary"
  59. plain
  60. size="mini"
  61. @click="synOpen=true"
  62. v-hasPermi="['qw:user:sync']"
  63. >同步企微员工和部门</el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button
  67. type="primary"
  68. plain
  69. size="mini"
  70. @click="synNameOpen=true"
  71. v-hasPermi="['qw:user:sync']"
  72. >同步企微员工名称</el-button>
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="primary"
  77. plain
  78. size="mini"
  79. :disabled="multiple"
  80. @click="handerCompanyUserAreaList"
  81. >批量设置销售所属区域(原有的暂用)</el-button>
  82. </el-col>
  83. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  84. </el-row>
  85. <el-table height="500" border v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  86. <el-table-column type="selection" width="50" align="center" />
  87. <el-table-column label="ID" align="center" prop="userId" :show-overflow-tooltip="true" />
  88. <el-table-column label="员工后台账号" align="center" prop="userName" :show-overflow-tooltip="true" width="100" />
  89. <el-table-column label="员工后台昵称" align="center" prop="nickName" :show-overflow-tooltip="true" 员工后台 width="100"/>
  90. <el-table-column label="部门" align="center" prop="deptName" :show-overflow-tooltip="true" />
  91. <el-table-column label="手机号码" align="center" prop="phonenumber" width="120" />
  92. <el-table-column label="状态" align="center">
  93. <template slot-scope="scope">
  94. <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="企微状态" align="center">
  98. <template slot-scope="scope">
  99. <dict-tag :options="qwStatusOptions" :value="scope.row.qwStatus"/>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="区域" align="center" prop="addressId">
  103. </el-table-column>
  104. <el-table-column label="创建时间" sortable align="center" prop="createTime" width="160">
  105. <template slot-scope="scope">
  106. <span>{{ parseTime(scope.row.createTime) }}</span>
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
  110. <template slot-scope="scope">
  111. <el-button
  112. v-if="scope.row.qwStatus == 0"
  113. size="mini"
  114. type="text"
  115. icon="el-icon-edit"
  116. @click="qwBind(scope.row)"
  117. v-hasPermi="['qw:user:bind']"
  118. >绑定企微</el-button>
  119. <el-button
  120. v-else
  121. size="mini"
  122. type="text"
  123. icon="el-icon-edit"
  124. @click="qwBind(scope.row)"
  125. v-hasPermi="['qw:user:bind']"
  126. >查或换绑企微</el-button>
  127. <el-button v-if="scope.row.userType !== '00'" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['company:user:edit']">修改</el-button>
  128. <el-button v-if="scope.row.userType !== '00'" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['company:user:remove']">删除</el-button>
  129. <el-button size="mini" type="text" icon="el-icon-key" @click="handleResetPwd(scope.row)" v-hasPermi="['company:user:resetPwd']">重置密码</el-button>
  130. </template>
  131. </el-table-column>
  132. </el-table>
  133. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  134. </el-col>
  135. </el-row>
  136. <el-dialog title="绑定企微账号" :visible.sync="qwOpen" width="800px" append-to-body >
  137. <el-form ref="form" :model="form" label-width="80px" >
  138. <el-form-item label="查询" prop="companyUserId">
  139. <el-button type="primary" icon="el-icon-search" @click="selectQwUser()" size="mini">搜索账号</el-button>
  140. </el-form-item>
  141. <el-form-item label="企微账号" prop="companyUserId">
  142. <el-tag
  143. style="margin-left: 5px"
  144. size="medium"
  145. :key="id"
  146. v-for="id in qwUser"
  147. closable
  148. :disable-transitions="false"
  149. @close="handleClosegroupUser(id)">
  150. <span v-for="list in qwUserList" :key="list.qwUserId" v-if="list.id==id">{{list.qwUserName}}({{list.corpName}})
  151. </span>
  152. </el-tag>
  153. </el-form-item>
  154. </el-form>
  155. <div slot="footer" class="dialog-footer">
  156. <el-button type="primary" @click="qwSubmitForm">绑 定</el-button>
  157. <el-button @click="qwCancel">取 消</el-button>
  158. </div>
  159. </el-dialog>
  160. <el-dialog title="选择企微主体" :visible.sync="synOpen" width="800px" append-to-body>
  161. <el-form label-width="80px">
  162. <el-form-item label="企微公司" prop="corpId">
  163. <el-select v-model="synform.corpId" placeholder="企微公司" >
  164. <el-option
  165. v-for="dict in myQwCompanyList"
  166. :key="dict.dictValue"
  167. :label="dict.dictLabel"
  168. :value="dict.dictValue"
  169. />
  170. </el-select>
  171. </el-form-item>
  172. </el-form>
  173. <div slot="footer" class="dialog-footer">
  174. <el-button type="primary" @click="synSubmitForm">确 定</el-button>
  175. <el-button @click="synOpen=false">取 消</el-button>
  176. </div>
  177. </el-dialog>
  178. <el-dialog title="选择企微主体" :visible.sync="synNameOpen" width="800px" append-to-body>
  179. <el-form label-width="80px">
  180. <el-form-item label="企微公司" prop="corpId">
  181. <el-select v-model="synNameform.corpId" placeholder="企微公司" >
  182. <el-option
  183. v-for="dict in myQwCompanyList"
  184. :key="dict.dictValue"
  185. :label="dict.dictLabel"
  186. :value="dict.dictValue"
  187. />
  188. </el-select>
  189. </el-form-item>
  190. </el-form>
  191. <div slot="footer" class="dialog-footer">
  192. <el-button type="primary" @click="synNameSubmitForm">确 定</el-button>
  193. <el-button @click="synNameOpen=false">取 消</el-button>
  194. </div>
  195. </el-dialog>
  196. <!-- 添加或修改参数配置对话框 -->
  197. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  198. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  199. <el-row>
  200. <el-col :span="12">
  201. <!-- <el-form-item label="员工账号" prop="userName">-->
  202. <!-- <el-input v-model="form.userName" placeholder="请输入员工后台账号" />-->
  203. <!-- </el-form-item>-->
  204. <el-form-item label="员工姓名" prop="nickName">
  205. <el-input v-model="form.nickName" placeholder="请输入员工后台昵称" />
  206. </el-form-item>
  207. </el-col>
  208. <el-col :span="12">
  209. <el-form-item label="归属部门" prop="deptId">
  210. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
  211. </el-form-item>
  212. </el-col>
  213. </el-row>
  214. <el-row>
  215. <el-col :span="12">
  216. <el-form-item label="手机号码" prop="phonenumber">
  217. <el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11" />
  218. </el-form-item>
  219. </el-col>
  220. <el-col :span="12">
  221. <el-form-item label="邮箱" prop="email">
  222. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  223. </el-form-item>
  224. </el-col>
  225. </el-row>
  226. <el-row>
  227. <el-col :span="12">
  228. <el-form-item label="员工账号" prop="userName">
  229. <el-input v-model="form.userName" placeholder="请输入员工工号" />
  230. </el-form-item>
  231. </el-col>
  232. <el-col :span="12">
  233. <el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
  234. <el-input v-model="form.password" placeholder="请输入用户密码" type="password" show-password />
  235. </el-form-item>
  236. </el-col>
  237. </el-row>
  238. <el-row>
  239. <el-col :span="12">
  240. <el-form-item label="员工性别">
  241. <el-select v-model="form.sex" placeholder="请选择">
  242. <el-option v-for="dict in sexOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
  243. </el-select>
  244. </el-form-item>
  245. </el-col>
  246. <el-col :span="12">
  247. <el-form-item label="状态">
  248. <el-radio-group v-model="form.status">
  249. <el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
  250. </el-radio-group>
  251. </el-form-item>
  252. </el-col>
  253. </el-row>
  254. <el-row>
  255. <el-col :span="12">
  256. <el-form-item label="岗位">
  257. <el-select v-model="form.postIds" multiple placeholder="请选择">
  258. <el-option v-for="item in postOptions" :key="item.postId" :label="item.postName" :value="item.postId" :disabled="item.status == 1"></el-option>
  259. </el-select>
  260. </el-form-item>
  261. </el-col>
  262. <el-col :span="12">
  263. <el-form-item label="角色">
  264. <el-select v-model="form.roleIds" multiple placeholder="请选择">
  265. <el-option v-for="item in roleOptions" :key="item.roleId" :label="item.roleName" :value="item.roleId" :disabled="item.status == 1"></el-option>
  266. </el-select>
  267. </el-form-item>
  268. </el-col>
  269. </el-row>
  270. <el-row>
  271. <el-col :span="12">
  272. <el-form-item label="身份证号">
  273. <el-input v-model="form.idCard" placeholder="请输入身份证号" maxlength="18" />
  274. </el-form-item>
  275. </el-col>
  276. <el-col :span="12">
  277. <el-form-item label="销售区域" prop="addressId">
  278. <el-select v-model="form.addressId" filterable placeholder="请选择所属销售的区域" style="width: 200px;">
  279. <el-option
  280. v-for="item in citysAreaList"
  281. :key="item.cityId"
  282. :label="item.cityName"
  283. :value="item.cityId"
  284. ></el-option>
  285. </el-select>
  286. </el-form-item>
  287. </el-col>
  288. </el-row>
  289. <!-- <el-row>-->
  290. <!-- <el-col :span="24">-->
  291. <!-- <el-form-item label="数据权限">-->
  292. <!-- <el-radio-group v-model="form.userType">-->
  293. <!-- <el-radio v-for="dict in userTypeOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>-->
  294. <!-- </el-radio-group>-->
  295. <!-- </el-form-item>-->
  296. <!-- </el-col>-->
  297. <!-- </el-row>-->
  298. <el-row>
  299. <el-col :span="24">
  300. <el-form-item label="看课域名">
  301. <el-input
  302. v-model="form.domain"
  303. style="width: 250px"
  304. placeholder="请生成域名"
  305. @change="onDomainBlur"
  306. disabled
  307. ></el-input>
  308. <el-button type="primary" style="margin-left: 20px" @click="generateDomain">生成域名</el-button>
  309. </el-form-item>
  310. </el-col>
  311. </el-row>
  312. <el-row>
  313. <el-col :span="24">
  314. <el-form-item label="备注">
  315. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  316. </el-form-item>
  317. </el-col>
  318. </el-row>
  319. </el-form>
  320. <div slot="footer" class="dialog-footer">
  321. <el-button type="primary" @click="submitForm">确 定</el-button>
  322. <el-button @click="cancel">取 消</el-button>
  323. </div>
  324. </el-dialog>
  325. <!-- &lt;!&ndash; 用户导入对话框 &ndash;&gt;-->
  326. <!-- <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>-->
  327. <!-- <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>-->
  328. <!-- <i class="el-icon-upload"></i>-->
  329. <!-- <div class="el-upload__text">-->
  330. <!-- 将文件拖到此处,或-->
  331. <!-- <em>点击上传</em>-->
  332. <!-- </div>-->
  333. <!-- <div class="el-upload__tip" slot="tip">-->
  334. <!-- <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
  335. <!-- <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>-->
  336. <!-- </div>-->
  337. <!-- <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>-->
  338. <!-- </el-upload>-->
  339. <!-- <div slot="footer" class="dialog-footer">-->
  340. <!-- <el-button type="primary" @click="submitFileForm">确 定</el-button>-->
  341. <!-- <el-button @click="upload.open = false">取 消</el-button>-->
  342. <!-- </div>-->
  343. <!-- </el-dialog>-->
  344. <el-dialog :title="user.title" :visible.sync="user.open" width="1000px" append-to-body>
  345. <selectUser ref="selectUser" @bindQwUser="bindQwUser"></selectUser>
  346. </el-dialog>
  347. <el-dialog :title="companyUserArea.title" :visible.sync="companyUserArea.open" width="300px" append-to-body>
  348. <el-select v-model="addressId" filterable placeholder="请选择所属销售的区域" style="width: 200px;">
  349. <el-option
  350. v-for="item in citysAreaList"
  351. :key="item.cityId"
  352. :label="item.cityName"
  353. :value="item.cityId"
  354. ></el-option>
  355. </el-select>
  356. <div slot="footer" style="text-align: center;">
  357. <el-button type="primary" @click="submitFormArea(addressId)">确 定</el-button>
  358. <el-button @click="cancelArea">取 消</el-button>
  359. </div>
  360. </el-dialog>
  361. </div>
  362. </template>
  363. <script>
  364. import {
  365. qwList,
  366. delUser,
  367. addUser,
  368. getUser,
  369. updateUser,
  370. exportUser,
  371. resetUserPwd,
  372. changeUserStatus,
  373. importTemplate,
  374. getCitysAreaList,
  375. updateCompanyUserAreaList,
  376. generateSubDomain
  377. } from "../../../api/company/companyUser";
  378. import { getToken } from "@/utils/auth";
  379. import { treeselect } from "@/api/company/companyDept";
  380. import Treeselect from "@riophae/vue-treeselect";
  381. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  382. import {bindQwUser, getQwUserList, addQwUser, getQwUser, getQwUserByIds,addQwUserName} from '@/api/qw/user';
  383. import { syncDept } from '@/api/qw/qwDept';
  384. import { getMyQwUserList,getMyQwCompanyList } from "@/api/qw/user";
  385. import selectUser from "@/views/company/components/selectQwUser.vue";
  386. import { getConfigByKey } from "@/api/company/companyConfig";
  387. export default {
  388. name: "User",
  389. components: { Treeselect ,selectUser},
  390. data() {
  391. return {
  392. // 遮罩层
  393. loading: false,
  394. qwUserList:[],
  395. qwUserId:[],
  396. myQwCompanyList:[],
  397. qwUser:[],
  398. user:{
  399. open:false,
  400. title:"搜索企业"
  401. },
  402. // 选中数组
  403. ids: [],
  404. synform:{corpId:null},
  405. synOpen:false,
  406. synNameform:{corpId:null},
  407. synNameOpen:false,
  408. // 非单个禁用
  409. single: true,
  410. // 非多个禁用
  411. multiple: true,
  412. // 显示搜索条件
  413. showSearch: true,
  414. // 总条数
  415. total: 0,
  416. // 用户表格数据
  417. userList: null,
  418. // 弹出层标题
  419. title: "",
  420. // 部门树选项
  421. deptOptions: undefined,
  422. // 是否显示弹出层
  423. open: false,
  424. qwOpen:false,
  425. // 部门名称
  426. deptName: undefined,
  427. // 日期范围
  428. dateRange: [],
  429. // 状态数据字典
  430. statusOptions: [],
  431. // 性别状态字典
  432. sexOptions: [],
  433. // 岗位选项
  434. postOptions: [],
  435. // 角色选项
  436. roleOptions: [],
  437. userTypeOptions:[
  438. { "dictLabel": "临时管理员","dictValue": "02"},
  439. { "dictLabel": "普通用户","dictValue": "01"}
  440. ],
  441. qwForm:{
  442. id:null,
  443. companyUserId:null,
  444. },
  445. companyUserArea:{
  446. open:false,
  447. title:"分配区域",
  448. },
  449. //选择的区域
  450. addressId:null,
  451. citysAreaList:[],
  452. // 表单参数
  453. form: {},
  454. form1: {},
  455. defaultProps: {
  456. children: "children",
  457. label: "label",
  458. },
  459. // // 用户导入参数
  460. // upload: {
  461. // // 是否显示弹出层(用户导入)
  462. // open: false,
  463. // // 弹出层标题(用户导入)
  464. // title: "",
  465. // // 是否禁用上传
  466. // isUploading: false,
  467. // // 是否更新已经存在的用户数据
  468. // updateSupport: 0,
  469. // // 设置上传的请求头部
  470. // headers: { Authorization: "Bearer " + getToken() },
  471. // // 上传的地址
  472. // url: process.env.VUE_APP_BASE_API + "/system/user/importData",
  473. // },
  474. // 查询参数
  475. queryParams: {
  476. pageNum: 1,
  477. pageSize: 10,
  478. userName: null,
  479. phonenumber: null,
  480. status: null,
  481. deptId: null,
  482. qwStatus:null,
  483. },
  484. qwStatusOptions:[],
  485. // 表单校验
  486. rules: {
  487. userName: [
  488. { required: true, message: "员工工号不能为空", trigger: "blur" },
  489. ],
  490. nickName: [
  491. { required: true, message: "员工姓名不能为空", trigger: "blur" },
  492. ],
  493. deptId: [
  494. { required: true, message: "归属部门不能为空", trigger: "blur" },
  495. ],
  496. addressId: [
  497. { required: true, message: "销售所属区域不能为空", trigger: "blur" },
  498. ],
  499. password: [
  500. { required: true, message: "员工密码不能为空", trigger: "blur" },
  501. {
  502. pattern: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,20}$/,
  503. message: "密码长度为 8-20 位,必须包含字母、数字和特殊字符",
  504. trigger: ["blur", "change"],
  505. }
  506. ],
  507. idCard: [
  508. { required: true, message: "身份证号不能为空", trigger: "blur" },
  509. ],
  510. // email: [
  511. // { required: true, message: "邮箱地址不能为空", trigger: "blur" },
  512. // {
  513. // type: "email",
  514. // message: "'请输入正确的邮箱地址",
  515. // trigger: ["blur", "change"],
  516. // },
  517. // ],
  518. phonenumber: [
  519. { required: true, message: "手机号码不能为空", trigger: "blur" },
  520. {
  521. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  522. message: "请输入正确的手机号码",
  523. trigger: "blur",
  524. },
  525. ],
  526. },
  527. };
  528. },
  529. watch: {
  530. // 根据名称筛选部门树
  531. deptName(val) {
  532. this.$refs.tree.filter(val);
  533. },
  534. },
  535. created() {
  536. this.getList();
  537. this.getTreeselect();
  538. this.getDicts("sys_normal_disable").then((response) => {
  539. this.statusOptions = response.data;
  540. });
  541. this.getDicts("company_user_sex").then((response) => {
  542. this.sexOptions = response.data;
  543. });
  544. this.getDicts("sys_qw_user_status").then(response => {
  545. this.qwStatusOptions = response.data;
  546. });
  547. getConfigByKey("his.login").then(response => {
  548. this.form1 =JSON.parse(response.data.configValue);
  549. });
  550. getCitysAreaList().then(res=>{
  551. this.citysAreaList=res.data;
  552. })
  553. getMyQwCompanyList().then(response => {
  554. this.myQwCompanyList = response.data;
  555. });
  556. },
  557. methods: {
  558. onDomainBlur() {
  559. if (this.form.domain!=null){
  560. let value = this.form.domain.trim();
  561. // 强制只保留第一个 http://
  562. const httpCount = (value.match(/http:\/\//g) || []).length;
  563. if (httpCount > 1) {
  564. value = value.replace(/(http:\/\/)+/, 'http://'); // 只留第一个
  565. }
  566. // 如果不是 http:// 开头,自动补充
  567. if (!value.startsWith('http://')) {
  568. value = 'http://' + value.replace(/^https?:\/\//, ''); // 去掉其他 http(s):// 再补
  569. }
  570. this.form.domain = value; // 重新赋值,保证输入正确
  571. // 正则校验最终格式,提醒用户
  572. const domainPattern = /^http:\/\/([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;
  573. if (!domainPattern.test(this.form.domain)) {
  574. return this.$message.error('请输入正确格式的域名,如:http://xxx.xxx.com');
  575. }
  576. }
  577. },
  578. /** 查询用户列表 */
  579. getList() {
  580. this.loading = true;
  581. qwList(this.addDateRange(this.queryParams, this.dateRange)).then(
  582. (response) => {
  583. this.userList = response.rows;
  584. this.total = response.total;
  585. this.loading = false;
  586. console.log(" this.userList ", this.userList )
  587. }
  588. );
  589. },
  590. selectQwUser(){
  591. this.user.open=true;
  592. },
  593. handleClosegroupUser(list){
  594. const index = this.qwUser.findIndex(t => t === list);
  595. if (index !== -1) {
  596. this.qwUser.splice(index, 1);
  597. }
  598. },
  599. /** 查询部门下拉树结构 */
  600. getTreeselect() {
  601. treeselect().then((response) => {
  602. this.deptOptions = response.data;
  603. });
  604. },
  605. // 筛选节点
  606. filterNode(value, data) {
  607. if (!value) return true;
  608. return data.label.indexOf(value) !== -1;
  609. },
  610. // 节点单击事件
  611. handleNodeClick(data) {
  612. this.queryParams.deptId = data.id;
  613. this.getList();
  614. },
  615. // 用户状态修改
  616. handleStatusChange(row) {
  617. let text = row.status === "0" ? "启用" : "停用";
  618. this.$confirm(
  619. '确认要"' + text + '""' + row.userName + '"用户吗?',
  620. "警告",
  621. {
  622. confirmButtonText: "确定",
  623. cancelButtonText: "取消",
  624. type: "warning",
  625. }
  626. )
  627. .then(function () {
  628. return changeUserStatus(row.userId, row.status);
  629. })
  630. .then(() => {
  631. this.msgSuccess(text + "成功");
  632. })
  633. .catch(function () {
  634. row.status = row.status === "0" ? "1" : "0";
  635. });
  636. },
  637. // 取消按钮
  638. cancel() {
  639. this.open = false;
  640. this.reset();
  641. },
  642. submitFormArea(address){
  643. const uIds = this.ids;
  644. if (address == null){
  645. this.$message.error("请选择地区");
  646. return;
  647. }
  648. updateCompanyUserAreaList({userIds:uIds,addressId:address}).then(res=>{
  649. this.companyUserArea.open=false;
  650. this.getList();
  651. this.msgSuccess("操作成功");
  652. })
  653. },
  654. cancelArea(){
  655. this.companyUserArea.open=false;
  656. this.addressId=null;
  657. },
  658. qwCancel() {
  659. this.qwOpen = false;
  660. this.qwUserId=null;
  661. },
  662. handerCompanyUserAreaList(){
  663. this.companyUserArea.open=true;
  664. },
  665. // 表单重置
  666. reset() {
  667. this.form = {
  668. userId: undefined,
  669. deptId: undefined,
  670. userName: undefined,
  671. nickName: undefined,
  672. password: undefined,
  673. idCard: undefined,
  674. phonenumber: undefined,
  675. userType: "01",
  676. email: undefined,
  677. sex: undefined,
  678. status: "0",
  679. remark: undefined,
  680. domain: null,
  681. postIds: [],
  682. roleIds: [],
  683. };
  684. this.resetForm("form");
  685. },
  686. /** 搜索按钮操作 */
  687. handleQuery() {
  688. this.queryParams.page = 1;
  689. this.getList();
  690. },
  691. /** 重置按钮操作 */
  692. resetQuery() {
  693. this.dateRange = [];
  694. this.resetForm("queryForm");
  695. this.handleQuery();
  696. },
  697. // 多选框选中数据
  698. handleSelectionChange(selection) {
  699. this.ids = selection.map((item) => item.userId);
  700. this.single = selection.length != 1;
  701. this.multiple = !selection.length;
  702. },
  703. /** 新增按钮操作 */
  704. handleAdd() {
  705. this.reset();
  706. this.getTreeselect();
  707. getUser().then((response) => {
  708. this.postOptions = response.posts;
  709. this.roleOptions = response.roles;
  710. this.open = true;
  711. this.title = "添加员工";
  712. this.form.password = this.form1.loginPassword;
  713. console.log(" this.form1 ", this.form1)
  714. });
  715. },
  716. qwBind(row){
  717. this.qwUser=[];
  718. this.qwUserList=[];
  719. this.qwForm.companyUserId=row.userId
  720. getUser(row.userId).then((response) => {
  721. if(response.data.qwUserId!=null){
  722. this.qwUser=((response.data.qwUserId).split(",").map(Number))
  723. getQwUserByIds(this.qwUser).then(res => {
  724. this.qwUserList=res.data;
  725. })
  726. // this.qwUser.forEach(item => {
  727. // getQwUser(item).then(response => {
  728. // this.qwUserList.push(response.data);
  729. // });
  730. // });
  731. }
  732. this.qwOpen = true;
  733. });
  734. },
  735. bindQwUser(row){
  736. this.user.open=false;
  737. if (!this.qwUserList.some(item => item.id == row.id)) {
  738. this.qwUserList.push(row)
  739. }
  740. if (!this.qwUser.some(item => item == row.id)) {
  741. this.qwUser.push(row.id);
  742. }
  743. },
  744. /** 修改按钮操作 */
  745. handleUpdate(row) {
  746. this.reset();
  747. this.getTreeselect();
  748. const userId = row.userId || this.ids;
  749. getUser(userId).then((response) => {
  750. this.form = response.data;
  751. this.postOptions = response.posts;
  752. this.roleOptions = response.roles;
  753. this.form.postIds = response.postIds;
  754. this.form.roleIds = response.roleIds;
  755. this.open = true;
  756. this.title = "修改员工";
  757. this.form.password = "";
  758. });
  759. },
  760. /** 重置密码按钮操作 */
  761. handleResetPwd(row) {
  762. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  763. confirmButtonText: "确定",
  764. cancelButtonText: "取消",
  765. inputPlaceholder: "8-20 位,包含字母、数字和特殊字符",
  766. inputValidator: (value) => {
  767. const pattern = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,20}/;
  768. const hasChinese = /[\u4e00-\u9fa5]/.test(value);
  769. const hasFullWidth = /[!-~]/.test(value);
  770. if (hasChinese) return '不能包含中文字符';
  771. if (hasFullWidth) return '不能包含全角符号,请使用英文输入法';
  772. if (!pattern.test(value)) return '密码格式错误:需包含字母、数字和英文特殊字符,长度为 8-20 位';
  773. return true;
  774. }
  775. })
  776. .then(({ value }) => {
  777. resetUserPwd(row.userId, value).then((response) => {
  778. if (response.code === 200) {
  779. this.msgSuccess("修改成功,新密码是:" + value);
  780. }
  781. });
  782. })
  783. .catch(() => {});
  784. },
  785. /** 提交按钮 */
  786. submitForm: function () {
  787. this.onDomainBlur();
  788. const domainPattern = /^http:\/\/([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;
  789. if (this.form.domain!=null && !domainPattern.test(this.form.domain)) {
  790. this.$message.error('请输入正确格式的域名,如:http://xxx.xxx.com');
  791. return;
  792. }
  793. this.$refs["form"].validate((valid) => {
  794. if (valid) {
  795. if (this.form.userId != undefined) {
  796. updateUser(this.form).then((response) => {
  797. if (response.code === 200) {
  798. this.msgSuccess("修改成功");
  799. this.open = false;
  800. this.getList();
  801. }
  802. });
  803. } else {
  804. addUser(this.form).then((response) => {
  805. if (response.code === 200) {
  806. this.msgSuccess("新增成功");
  807. this.open = false;
  808. this.getList();
  809. }
  810. });
  811. }
  812. }
  813. });
  814. },
  815. /**
  816. * 同步企业微信员工
  817. */
  818. synSubmitForm() {
  819. this.synOpen=false;
  820. this.loading=true;
  821. /*this.msgSuccess("");
  822. let loadingRock = this.$loading({
  823. lock: true,
  824. text: '同步中.....请等待.....请不要重复点击!!',
  825. spinner: 'el-icon-loading',
  826. background: 'rgba(0, 0, 0, 0.7)'
  827. });*/
  828. addQwUser(this.synform.corpId).then(response => {
  829. //this.msgSuccess("同步成功");
  830. this.msgSuccess("正在同步中...");
  831. this.getList();
  832. this.synOpen=false;
  833. }).finally(()=>{
  834. this.loading=false;
  835. this.synOpen=false;
  836. //loadingRock.close();
  837. });
  838. },
  839. synNameSubmitForm() {
  840. this.synNameOpen=false;
  841. this.loading=true;
  842. addQwUserName(this.synNameform.corpId).then(response => {
  843. // this.msgSuccess("同步成功");
  844. this.msgSuccess("正在同步中...");
  845. this.getList();
  846. this.synNameOpen=false;
  847. }).finally(()=>{
  848. this.loading=false;
  849. this.synNameOpen=false;
  850. //loadingRock.close();
  851. });
  852. },
  853. /**
  854. * 同步企业微信部门
  855. */
  856. qwSyncDept(){
  857. syncDept().then(response => {
  858. this.msgSuccess("同步成功");
  859. this.getList();
  860. }).catch(()=>{
  861. this.msgError("同步失败:"+response.msg);
  862. })
  863. },
  864. qwSubmitForm(){
  865. let loadingRock = this.$loading({
  866. lock: true,
  867. text: '绑定中.....同步客户信息中.....',
  868. spinner: 'el-icon-loading',
  869. background: 'rgba(0, 0, 0, 0.7)'
  870. });
  871. this.qwForm.id = (this.qwUser).join(',');
  872. bindQwUser(this.qwForm).then(response => {
  873. this.msgSuccess("绑定成功");
  874. this.qwOpen = false;
  875. this.getList();
  876. this.qwUserId=null;
  877. this.qwUser=[];
  878. }).finally(res=>{
  879. loadingRock.close()
  880. });
  881. },
  882. /** 删除按钮操作 */
  883. handleDelete(row) {
  884. const userIds = row.userId || this.ids;
  885. this.$confirm(
  886. '是否确认删除员工编号为"' + userIds + '"的数据项?【注意:删除后绑定的企业微信相关信息可能会错乱!!】',
  887. "警告",
  888. {
  889. confirmButtonText: "确定",
  890. cancelButtonText: "取消",
  891. type: "warning",
  892. }
  893. )
  894. .then(function () {
  895. return delUser(userIds);
  896. })
  897. .then(() => {
  898. this.getList();
  899. this.msgSuccess("删除成功");
  900. })
  901. .catch(function () {});
  902. },
  903. /** 导出按钮操作 */
  904. handleExport() {
  905. const queryParams = this.queryParams;
  906. this.$confirm("是否确认导出所有用户数据项?", "警告", {
  907. confirmButtonText: "确定",
  908. cancelButtonText: "取消",
  909. type: "warning",
  910. })
  911. .then(function () {
  912. return exportUser(queryParams);
  913. })
  914. .then((response) => {
  915. this.download(response.msg);
  916. })
  917. .catch(function () {});
  918. },
  919. // /** 导入按钮操作 */
  920. // handleImport() {
  921. // this.upload.title = "用户导入";
  922. // this.upload.open = true;
  923. // },
  924. /** 下载模板操作 */
  925. importTemplate() {
  926. importTemplate().then((response) => {
  927. this.download(response.msg);
  928. });
  929. },
  930. // 文件上传中处理
  931. handleFileUploadProgress(event, file, fileList) {
  932. this.upload.isUploading = true;
  933. },
  934. // 文件上传成功处理
  935. handleFileSuccess(response, file, fileList) {
  936. this.upload.open = false;
  937. this.upload.isUploading = false;
  938. this.$refs.upload.clearFiles();
  939. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  940. this.getList();
  941. },
  942. // 提交上传文件
  943. submitFileForm() {
  944. this.$refs.upload.submit();
  945. },
  946. generateDomain(){
  947. let queryParams;
  948. if(this.form.userId){
  949. queryParams= {
  950. 'userId': this.form.userId,
  951. }
  952. }
  953. generateSubDomain(queryParams).then(response => {
  954. this.form.domain=response.data
  955. });
  956. },
  957. },
  958. };
  959. </script>