index.vue 40 KB

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