index.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  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
  8. v-model="deptName"
  9. placeholder="请输入部门名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. />
  15. </div>
  16. <div class="head-container">
  17. <el-tree
  18. :data="deptOptions"
  19. :props="defaultProps"
  20. :expand-on-click-node="false"
  21. :filter-node-method="filterNode"
  22. ref="tree"
  23. default-expand-all
  24. @node-click="handleNodeClick"
  25. />
  26. </div>
  27. </el-col>
  28. <!--//用户数据-->
  29. <el-col :span="20" :xs="24">
  30. <el-card class="fiche">
  31. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"
  32. >收起</right-toolbar
  33. >
  34. <span
  35. style="
  36. margin-bottom: 10px;
  37. color: #333333;
  38. font: 14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial,
  39. sans-serif;
  40. "
  41. >所选条件:</span
  42. >
  43. <div style="float: right; margin-right: 1%">
  44. <el-button
  45. type="cyan"
  46. icon="el-icon-search"
  47. size="mini"
  48. @click="handleQuery"
  49. >搜索</el-button
  50. >
  51. <el-button
  52. icon="el-icon-refresh"
  53. size="mini"
  54. @click="resetQuery"
  55. style="float: "
  56. >重置</el-button
  57. >
  58. <column-setting
  59. :checkList="checkList"
  60. :tableList="tableList"
  61. :selfDom="selfDom"
  62. :tableId="tableId"
  63. style="margin-left: 5px"
  64. ></column-setting>
  65. </div>
  66. <hr style="margin-top: 16px" />
  67. <el-form
  68. :model="queryParams"
  69. ref="queryForm"
  70. :inline="true"
  71. v-show="showSearch"
  72. label-width="68px"
  73. >
  74. <el-form-item label="手机号" prop="userName">
  75. <el-input
  76. v-model="queryParams.userName"
  77. placeholder="请输入手机号"
  78. clearable
  79. size="small"
  80. style="width: 240px"
  81. @keyup.enter.native="handleQuery"
  82. />
  83. </el-form-item>
  84. <el-form-item label="用户姓名" prop="nickName">
  85. <el-input
  86. v-model="queryParams.nickName"
  87. placeholder="请输入用户姓名"
  88. clearable
  89. size="small"
  90. style="width: 240px"
  91. @keyup.enter.native="handleQuery"
  92. />
  93. </el-form-item>
  94. <el-form-item label="状态" prop="status">
  95. <el-select
  96. v-model="queryParams.status"
  97. placeholder="用户状态"
  98. clearable
  99. size="small"
  100. style="width: 240px"
  101. >
  102. <el-option
  103. v-for="dict in statusOptions"
  104. :key="dict.dictValue"
  105. :label="dict.dictLabel"
  106. :value="dict.dictValue"
  107. />
  108. </el-select>
  109. </el-form-item>
  110. <el-form-item label="创建时间">
  111. <el-date-picker
  112. v-model="dateRange"
  113. size="small"
  114. style="width: 240px"
  115. value-format="yyyy-MM-dd"
  116. type="daterange"
  117. range-separator="-"
  118. start-placeholder="开始日期"
  119. end-placeholder="结束日期"
  120. ></el-date-picker>
  121. </el-form-item>
  122. </el-form>
  123. </el-card>
  124. <el-row :gutter="10" class="mb8">
  125. <!-- <el-col :span="1.5" v-show="companyId != '000000'"> -->
  126. <el-col :span="1.5">
  127. <el-button
  128. type="primary"
  129. icon="el-icon-plus"
  130. size="mini"
  131. @click="handleAdd"
  132. v-hasPermi="['system:user:add']"
  133. >新增</el-button
  134. >
  135. </el-col>
  136. <el-col :span="1.5">
  137. <el-button
  138. type="warning"
  139. icon="el-icon-download"
  140. size="mini"
  141. @click="handleExport"
  142. v-hasPermi="['system:ownUser:export']"
  143. >导出</el-button
  144. >
  145. </el-col>
  146. </el-row>
  147. <el-table
  148. v-loading="loading"
  149. :data="userList"
  150. @selection-change="handleSelectionChange"
  151. stripe
  152. border
  153. >
  154. <!-- <el-table-column type="selection" width="50" align="center" /> -->
  155. <el-table-column label="序号" type="index" width="50" align="center">
  156. <template slot-scope="scope">
  157. <span>{{
  158. (queryParams.pageNum - 1) * queryParams.pageSize +
  159. scope.$index +
  160. 1
  161. }}</span>
  162. </template>
  163. </el-table-column>
  164. <el-table-column
  165. label="用户编号"
  166. align="center"
  167. prop="userId"
  168. v-if="uncheckList.userId"
  169. />
  170. <el-table-column
  171. label="手机号"
  172. align="center"
  173. prop="userName"
  174. :show-overflow-tooltip="true"
  175. v-if="uncheckList.userName"
  176. />
  177. <el-table-column
  178. label="用户姓名"
  179. align="center"
  180. prop="nickName"
  181. :show-overflow-tooltip="true"
  182. v-if="uncheckList.nickName"
  183. />
  184. <el-table-column
  185. label="状态"
  186. align="center"
  187. prop="state"
  188. v-if="uncheckList.state"
  189. >
  190. <template slot-scope="scope">
  191. <el-switch
  192. v-model="scope.row.status"
  193. active-value="0"
  194. inactive-value="1"
  195. @change="handleStatusChange(scope.row)"
  196. ></el-switch>
  197. </template>
  198. </el-table-column>
  199. <el-table-column
  200. label="创建时间"
  201. align="center"
  202. prop="createTime"
  203. width="160"
  204. v-if="uncheckList.createTime"
  205. >
  206. <template slot-scope="scope">
  207. <span>{{ parseTime(scope.row.createTime) }}</span>
  208. </template>
  209. </el-table-column>
  210. <el-table-column
  211. label="操作"
  212. align="center"
  213. width="160"
  214. class-name="small-padding fixed-width"
  215. >
  216. <template slot-scope="scope">
  217. <el-button
  218. size="mini"
  219. type="text"
  220. icon="el-icon-edit"
  221. @click="handleUpdate(scope.row)"
  222. v-hasPermi="['system:user:edit']"
  223. >修改</el-button
  224. >
  225. <el-button
  226. size="mini"
  227. type="text"
  228. icon="el-icon-edit"
  229. @click="handleChange(scope.row)"
  230. v-hasPermi="['system:ownUser:adminChange']"
  231. >变更权限</el-button
  232. >
  233. <el-button
  234. v-if="scope.row.userId !== 1"
  235. size="mini"
  236. type="text"
  237. icon="el-icon-delete"
  238. @click="handleDelete(scope.row)"
  239. v-hasPermi="['system:user:remove']"
  240. >删除</el-button
  241. >
  242. <el-button
  243. size="mini"
  244. type="text"
  245. icon="el-icon-key"
  246. @click="handleResetPwd(scope.row)"
  247. v-hasPermi="['system:user:resetPwd']"
  248. >重置</el-button
  249. >
  250. </template>
  251. </el-table-column>
  252. </el-table>
  253. <pagination
  254. v-show="total > 0"
  255. :total="total"
  256. :page.sync="queryParams.pageNum"
  257. :limit.sync="queryParams.pageSize"
  258. @pagination="getList"
  259. />
  260. </el-col>
  261. </el-row>
  262. <!-- 添加或修改参数配置对话框 -->
  263. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  264. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  265. <el-row>
  266. <!-- <el-form-item label="公司名称" prop="payroll" v-show="companyId == '000000'">
  267. <el-select v-model="form.companyId" @change="getRodept">
  268. <el-option
  269. v-for="(item, index) in companyList"
  270. :key="index" :label="item.scyName"
  271. :value="item.scyId">
  272. </el-option>
  273. </el-select>
  274. </el-form-item> -->
  275. <el-col :span="12">
  276. <el-form-item label="用户姓名" prop="nickName">
  277. <el-input
  278. v-model="form.nickName"
  279. placeholder="请输入用户姓名"
  280. maxlength="50"
  281. />
  282. </el-form-item>
  283. </el-col>
  284. <!-- <el-col :span="12" v-if="rodeptShow"> -->
  285. <el-col :span="12">
  286. <el-form-item label="归属部门" prop="deptId">
  287. <treeselect
  288. v-model="form.deptId"
  289. :options="rodeptOptions"
  290. :show-count="true"
  291. placeholder="请选择归属部门"
  292. />
  293. </el-form-item>
  294. </el-col>
  295. </el-row>
  296. <el-row>
  297. <el-col :span="12">
  298. <el-form-item label="邮箱" prop="email">
  299. <el-input
  300. v-model="form.email"
  301. placeholder="请输入邮箱"
  302. maxlength="50"
  303. />
  304. </el-form-item>
  305. </el-col>
  306. </el-row>
  307. <el-row>
  308. <el-col :span="12">
  309. <el-form-item label="手机号" prop="userName">
  310. <el-input
  311. v-model="form.userName"
  312. placeholder="请输入登录手机号"
  313. maxlength="11"
  314. :disabled="isUpdate"
  315. />
  316. </el-form-item>
  317. </el-col>
  318. </el-row>
  319. <el-row>
  320. <el-col :span="12">
  321. <el-form-item label="角色" prop="roleIds">
  322. <el-select v-model="form.roleIds" multiple placeholder="请选择">
  323. <el-option
  324. v-for="item in roleOptions"
  325. :key="item.roleId"
  326. :label="item.roleName"
  327. :value="item.roleId"
  328. v-if="item.status == 0"
  329. ></el-option>
  330. </el-select>
  331. </el-form-item>
  332. </el-col>
  333. </el-row>
  334. <el-row>
  335. <el-col :span="24">
  336. <el-form-item label="备注">
  337. <el-input
  338. v-model="form.remark"
  339. type="textarea"
  340. placeholder="请输入内容"
  341. maxlength="300"
  342. ></el-input>
  343. </el-form-item>
  344. </el-col>
  345. </el-row>
  346. </el-form>
  347. <div slot="footer" class="dialog-footer">
  348. <el-button type="primary" @click="submitForm">确 定</el-button>
  349. <el-button @click="cancel">取 消</el-button>
  350. </div>
  351. </el-dialog>
  352. <!-- 重置密码 -->
  353. <el-dialog
  354. :title="title"
  355. :visible.sync="openPassWord"
  356. width="700px"
  357. append-to-body
  358. >
  359. <el-form
  360. ref="form"
  361. :model="form"
  362. :rules="rulesPassWord"
  363. label-width="80px"
  364. >
  365. <el-row>
  366. <el-col :span="24">
  367. <el-form-item label="密码" prop="password">
  368. <el-input
  369. v-model="form.password"
  370. placeholder="请输入密码"
  371. show-password
  372. maxlength="20"
  373. ></el-input>
  374. </el-form-item>
  375. </el-col>
  376. </el-row>
  377. </el-form>
  378. <div slot="footer" class="dialog-footer">
  379. <el-button type="primary" @click="rulesSubmitForm">确 定</el-button>
  380. <el-button @click="cancel">取 消</el-button>
  381. </div>
  382. </el-dialog>
  383. <!-- 用户导入对话框 -->
  384. <el-dialog
  385. :title="upload.title"
  386. :visible.sync="upload.open"
  387. width="400px"
  388. append-to-body
  389. >
  390. <el-upload
  391. ref="upload"
  392. :limit="1"
  393. accept=".xlsx, .xls"
  394. :headers="upload.headers"
  395. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  396. :disabled="upload.isUploading"
  397. :on-progress="handleFileUploadProgress"
  398. :on-success="handleFileSuccess"
  399. :auto-upload="false"
  400. drag
  401. >
  402. <i class="el-icon-upload"></i>
  403. <div class="el-upload__text">
  404. 将文件拖到此处,或
  405. <em>点击上传</em>
  406. </div>
  407. <div class="el-upload__tip" slot="tip">
  408. <el-checkbox
  409. v-model="upload.updateSupport"
  410. />是否更新已经存在的用户数据
  411. <el-link type="info" style="font-size: 12px" @click="importTemplate"
  412. >下载模板</el-link
  413. >
  414. </div>
  415. <div class="el-upload__tip" style="color: red" slot="tip">
  416. 提示:仅允许导入“xls”或“xlsx”格式文件!
  417. </div>
  418. </el-upload>
  419. <div slot="footer" class="dialog-footer">
  420. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  421. <el-button @click="upload.open = false">取 消</el-button>
  422. </div>
  423. </el-dialog>
  424. </div>
  425. </template>
  426. <script>
  427. import {
  428. listUser,
  429. getUser,
  430. delUser,
  431. addUser,
  432. updateUser,
  433. resetUserPwd,
  434. changeUserStatus,
  435. getUserProfile,
  436. getNowUser,
  437. getRoleDept,
  438. companyList,
  439. adminChange,
  440. } from "@/api/system/user";
  441. import { getToken } from "@/utils/auth";
  442. import { treeselect } from "@/api/system/dept";
  443. import Treeselect from "@riophae/vue-treeselect";
  444. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  445. import { columnQuery, columnfilter } from "@/api/common/columnSetting";
  446. import ColumnSetting from "../../../components/Table/columnSetting.vue";
  447. export default {
  448. name: "User",
  449. components: { Treeselect, ColumnSetting },
  450. data() {
  451. return {
  452. //当前登录用户企业id
  453. signCompanyId: "",
  454. //姓名
  455. nameList: [],
  456. // 遮罩层
  457. loading: true,
  458. // 选中数组
  459. ids: [],
  460. // 非单个禁用
  461. single: true,
  462. // 非多个禁用
  463. multiple: true,
  464. // 显示搜索条件
  465. showSearch: true,
  466. rodeptShow: false,
  467. roleShow: false,
  468. // 总条数
  469. total: 0,
  470. // 用户表格数据
  471. userList: null,
  472. // 弹出层标题
  473. title: "",
  474. // 部门树选项
  475. deptOptions: undefined,
  476. rodeptOptions: undefined,
  477. // 是否显示弹出层
  478. open: false,
  479. openPassWord: false,
  480. //离职日期
  481. leave: false,
  482. // 部门名称
  483. deptName: undefined,
  484. // 默认密码
  485. initPassword: undefined,
  486. companyId: "",
  487. // 日期范围
  488. dateRange: [],
  489. // 状态数据字典
  490. statusOptions: [],
  491. // 性别状态字典
  492. sexOptions: [],
  493. //学历字典
  494. educationOptions: [],
  495. // 岗位选项
  496. postOptions: [],
  497. // 角色选项
  498. roleOptions: [],
  499. companyList: [],
  500. // 表单参数
  501. form: {},
  502. //筛选按钮的数据列表,与table表头的数据一致 --显示隐藏列用
  503. tableList: [
  504. {
  505. label: "userId",
  506. value: "用户编号",
  507. },
  508. {
  509. label: "userName",
  510. value: "手机号",
  511. },
  512. {
  513. label: "nickName",
  514. value: "用户姓名",
  515. },
  516. {
  517. label: "phonenumber",
  518. value: "手机号码",
  519. },
  520. {
  521. label: "state",
  522. value: "状态",
  523. },
  524. {
  525. label: "createTime",
  526. value: "创建时间",
  527. },
  528. ],
  529. checkList: [], //筛选列选中的数据列表--显示隐藏列用
  530. uncheckList: {}, //控制筛选列显示隐藏--显示隐藏列用
  531. selfDom: this,
  532. tableId: "/system/ownUser/list",
  533. defaultProps: {
  534. children: "children",
  535. label: "label",
  536. },
  537. // 用户导入参数
  538. upload: {
  539. // 是否显示弹出层(用户导入)
  540. open: false,
  541. // 弹出层标题(用户导入)
  542. title: "",
  543. // 是否禁用上传
  544. isUploading: false,
  545. // 是否更新已经存在的用户数据
  546. updateSupport: 0,
  547. // 设置上传的请求头部
  548. headers: { Authorization: "Bearer " + getToken() },
  549. // 上传的地址
  550. url: process.env.VUE_APP_BASE_API + "/system/user/importData",
  551. },
  552. // 查询参数
  553. queryParams: {
  554. pageNum: 1,
  555. pageSize: 10,
  556. userName: undefined,
  557. phonenumber: undefined,
  558. status: undefined,
  559. deptId: undefined,
  560. },
  561. uinParams: {
  562. ssId: null,
  563. ssName: null,
  564. pageNum: 1,
  565. pageSize: 10,
  566. },
  567. // 表单校验
  568. rules: {
  569. roleIds: [
  570. {
  571. required: true,
  572. message: "不能为空",
  573. trigger: "blur",
  574. },
  575. ],
  576. userName: [
  577. {
  578. required: true,
  579. message: "登陆名称不能为空",
  580. trigger: "blur",
  581. },
  582. {
  583. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  584. message: "请输入正确的手机号码",
  585. trigger: ["blur", "change"],
  586. },
  587. ],
  588. nickName: [
  589. {
  590. required: true,
  591. message: "用户姓名不能为空",
  592. trigger: "blur",
  593. },
  594. ],
  595. deptId: [
  596. {
  597. required: true,
  598. message: "归属部门不能为空",
  599. trigger: "blur",
  600. },
  601. ],
  602. postIds: [
  603. {
  604. required: true,
  605. message: "用户职级不能为空",
  606. trigger: "blur",
  607. },
  608. ],
  609. email: [
  610. /* {
  611. required: true,
  612. message: "邮箱地址不能为空",
  613. trigger: "blur",
  614. }, */
  615. {
  616. // type: "email",
  617. pattern:
  618. /^([a-z0-9A-Z]+[-|_|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$/,
  619. message: "邮箱格式不正确",
  620. trigger: ["blur", "change"],
  621. },
  622. ],
  623. phonenumber: [
  624. {
  625. required: true,
  626. message: "手机号码不能为空",
  627. trigger: "blur",
  628. },
  629. {
  630. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  631. message: "请输入正确的手机号码",
  632. trigger: ["blur", "change"],
  633. },
  634. ],
  635. },
  636. rulesPassWord: {
  637. password: [
  638. {
  639. required: true,
  640. message: "用户密码不能为空",
  641. trigger: "blur",
  642. },
  643. {
  644. min: 6,
  645. max: 20,
  646. message: "长度在 6 到 20 个字符",
  647. trigger: "blur",
  648. },
  649. {
  650. pattern: /^[a-zA-Z0-9\x21-\x7e]{6,20}$/,
  651. message: "密码只能包含大小写字母、数字或符号",
  652. trigger: ["blur", "change"],
  653. },
  654. ],
  655. },
  656. peoplpeName: false,
  657. isUpdate: false,
  658. };
  659. },
  660. watch: {
  661. // 根据名称筛选部门树
  662. deptName(val) {
  663. this.$refs.tree.filter(val);
  664. },
  665. },
  666. created() {
  667. this.getList();
  668. this.getNowUser();
  669. this.getTreeselect();
  670. this.getUserProfile();
  671. this.getDicts("sys_normal_disable").then((response) => {
  672. this.statusOptions = response.data;
  673. });
  674. this.getDicts("sys_user_sex").then((response) => {
  675. this.sexOptions = response.data;
  676. });
  677. this.getConfigKey("sys.user.initPassword").then((response) => {
  678. this.initPassword = response.msg;
  679. });
  680. this.getDicts("education").then((response) => {
  681. this.educationOptions = response.data;
  682. });
  683. },
  684. mounted() {
  685. this.columnQuery();
  686. },
  687. methods: {
  688. //获取当前客户是否之前设置过列展示隐藏
  689. columnQuery() {
  690. //获取页面路径
  691. var psfPagePath = window.location.pathname;
  692. //用请求后台的url作为唯一标识
  693. var psfTableName = this.tableId;
  694. var columnForm = {};
  695. columnForm.psfPagePath = psfPagePath;
  696. columnForm.psfTableName = psfTableName;
  697. columnQuery(columnForm).then((response) => {
  698. if (response.data && response.data.psfShowData) {
  699. this.checkList = response.data.psfShowData;
  700. }
  701. this.filter();
  702. });
  703. },
  704. //控制隐藏显示的函数
  705. filter(checkList) {
  706. if (!!checkList) {
  707. this.checkList = checkList;
  708. }
  709. columnfilter(this.selfDom);
  710. },
  711. //获取当前用户信息
  712. getNowUser() {
  713. getNowUser().then((response) => {
  714. this.signCompanyId = response.data.companyId;
  715. });
  716. },
  717. //根据企业id查询部门和角色信息
  718. getRodept(item) {
  719. this.$set(this.form, "deptId", null);
  720. this.$set(this.form, "roleIds", null);
  721. if (item) {
  722. this.rodeptShow = true;
  723. const companyId = item;
  724. getRoleDept(companyId).then((response) => {
  725. if (response.deptList.length > 0) {
  726. this.rodeptOptions = response.deptList;
  727. } else {
  728. this.rodeptOptions = undefined;
  729. }
  730. if (response.roleList.length > 0) {
  731. this.roleOptions = response.roleList;
  732. } else {
  733. this.roleOptions = [];
  734. }
  735. });
  736. }
  737. },
  738. getUserProfile() {
  739. var sscDomain = document.location.hostname;
  740. getUserProfile(sscDomain).then((response) => {
  741. this.companyId = response.data.companyId;
  742. });
  743. },
  744. /** 查询用户列表 */
  745. getList() {
  746. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
  747. (response) => {
  748. this.userList = response.rows;
  749. this.total = response.total;
  750. this.loading = false;
  751. }
  752. );
  753. },
  754. /** 查询部门下拉树结构 */
  755. getTreeselect() {
  756. treeselect().then((response) => {
  757. this.deptOptions = response.data;
  758. });
  759. },
  760. /** 查询部门下拉树结构 */
  761. getFormTreeselect() {
  762. treeselect().then((response) => {
  763. this.rodeptOptions = response.data;
  764. });
  765. },
  766. // 筛选节点
  767. filterNode(value, data) {
  768. if (!value) return true;
  769. return data.label.indexOf(value) !== -1;
  770. },
  771. // 节点单击事件
  772. handleNodeClick(data) {
  773. this.queryParams.deptId = data.id;
  774. this.getList();
  775. },
  776. // 用户状态修改
  777. handleStatusChange(row) {
  778. let text = row.status === "0" ? "解冻" : "冻结";
  779. this.$confirm("确认要" + text + '"' + row.userName + '"用户吗?', "警告", {
  780. confirmButtonText: "确定",
  781. cancelButtonText: "取消",
  782. type: "warning",
  783. })
  784. .then(function () {
  785. return changeUserStatus(row.userId, row.status);
  786. })
  787. .then(() => {
  788. this.msgSuccess(text + "成功");
  789. })
  790. .catch(function () {
  791. row.status = row.status === "0" ? "1" : "0";
  792. });
  793. },
  794. // 取消按钮
  795. cancel() {
  796. this.open = false;
  797. this.openPassWord = false;
  798. this.reset();
  799. },
  800. // 表单重置
  801. reset() {
  802. this.form = {
  803. userId: undefined,
  804. deptId: undefined,
  805. userName: undefined,
  806. nickName: undefined,
  807. password: undefined,
  808. phonenumber: null,
  809. email: undefined,
  810. sex: undefined,
  811. status: "0",
  812. remark: undefined,
  813. postIds: [],
  814. roleIds: [],
  815. nameList: [],
  816. };
  817. this.resetForm("form");
  818. },
  819. /** 搜索按钮操作 */
  820. handleQuery() {
  821. this.queryParams.page = 1;
  822. this.getList();
  823. },
  824. /** 重置按钮操作 */
  825. resetQuery() {
  826. this.dateRange = [];
  827. this.queryParams = {
  828. pageNum: 1,
  829. pageSize: 10,
  830. userName: undefined,
  831. phonenumber: undefined,
  832. status: undefined,
  833. deptId: undefined,
  834. };
  835. this.resetForm("queryForm");
  836. this.handleQuery();
  837. },
  838. // 多选框选中数据
  839. handleSelectionChange(selection) {
  840. this.ids = selection.map((item) => item.userId);
  841. this.single = selection.length != 1;
  842. this.multiple = !selection.length;
  843. },
  844. /** 新增按钮操作 */
  845. handleAdd() {
  846. this.roleShow = true;
  847. if (this.signCompanyId == "000000") {
  848. this.rodeptShow = false;
  849. } else if (this.signCompanyId != "000000") {
  850. this.rodeptShow = true;
  851. }
  852. this.isUpdate = false;
  853. this.reset();
  854. this.peoplpeName = false;
  855. this.getFormTreeselect();
  856. getUser().then((response) => {
  857. this.postOptions = response.posts;
  858. this.roleOptions = response.roles;
  859. this.open = true;
  860. this.leave = false;
  861. this.title = "添加用户";
  862. this.form.password = this.initPassword;
  863. });
  864. },
  865. /** 修改按钮操作 */
  866. handleUpdate(row) {
  867. if (this.signCompanyId == "000000") {
  868. this.rodeptShow = false;
  869. } else if (this.signCompanyId != "000000") {
  870. this.rodeptShow = true;
  871. }
  872. this.isUpdate = true;
  873. var self = this;
  874. this.reset();
  875. this.peoplpeName = true;
  876. this.getFormTreeselect();
  877. const userId = row.userId || this.ids;
  878. getUser(userId).then((response) => {
  879. this.uinParams.ssId = response.data.staffCode;
  880. this.form = response.data;
  881. if (this.signCompanyId == "000000") {
  882. companyList(userId).then((response) => {
  883. this.companyList = response.data;
  884. if (response.data.length > 0) {
  885. this.$set(this.form, "companyId", response.data[0].scyId);
  886. this.getRodept(response.data[0].scyId);
  887. }
  888. });
  889. }
  890. this.postOptions = response.posts;
  891. this.roleOptions = response.roles;
  892. this.form.postIds = response.postIds;
  893. this.$set(this.form, "roleIds", response.roleIds);
  894. // this.form.roleIds = response.roleIds;
  895. this.open = true;
  896. this.leave = true;
  897. this.title = "修改用户";
  898. this.form.password = "";
  899. this.query = this.form;
  900. });
  901. },
  902. /** 重置密码按钮操作 */
  903. handleResetPwd(row) {
  904. this.reset();
  905. this.getTreeselect();
  906. const userId = row.userId || this.ids;
  907. getUser(userId).then((response) => {
  908. this.openPassWord = true;
  909. this.title = "重置密码";
  910. this.form.userId = userId;
  911. });
  912. },
  913. rulesSubmitForm: function () {
  914. this.$refs["form"].validate((valid) => {
  915. if (valid) {
  916. const loading = this.$loading({
  917. lock: true,
  918. text: "Loading",
  919. spinner: "el-icon-loading",
  920. background: "rgba(0, 0, 0, 0.7)",
  921. });
  922. var userId = this.form.userId;
  923. var password = this.form.password;
  924. resetUserPwd(userId, password)
  925. .then((response) => {
  926. this.openPassWord = false;
  927. loading.close();
  928. this.msgSuccess("修改成功,新密码是:" + password);
  929. })
  930. .catch((response) => {
  931. loading.close();
  932. });
  933. }
  934. });
  935. },
  936. /** 提交按钮 */
  937. submitForm: function () {
  938. this.$refs["form"].validate((valid) => {
  939. if (valid) {
  940. if (this.form.userId != undefined) {
  941. const loading = this.$loading({
  942. lock: true,
  943. text: "Loading",
  944. spinner: "el-icon-loading",
  945. background: "rgba(0, 0, 0, 0.7)",
  946. });
  947. this.$set(this.form, "createTime", null);
  948. updateUser(this.form)
  949. .then((response) => {
  950. loading.close();
  951. this.msgSuccess("修改成功");
  952. this.open = false;
  953. this.getList();
  954. })
  955. .catch((response) => {
  956. loading.close();
  957. });
  958. } else {
  959. const loading = this.$loading({
  960. lock: true,
  961. text: "Loading",
  962. spinner: "el-icon-loading",
  963. background: "rgba(0, 0, 0, 0.7)",
  964. });
  965. addUser(this.form)
  966. .then((response) => {
  967. loading.close();
  968. this.msgSuccess("新增成功");
  969. this.open = false;
  970. this.getList();
  971. })
  972. .catch((response) => {
  973. loading.close();
  974. });
  975. }
  976. }
  977. });
  978. },
  979. /** 变更权限按钮操作 */
  980. handleChange(row) {
  981. const userIds = row.userId || this.ids;
  982. const nickNames = row.nickName || this.ids;
  983. this.$confirm(
  984. '是否确认将用户姓名为"' + nickNames + '"变更为管理员?',
  985. "警告",
  986. {
  987. confirmButtonText: "确定",
  988. cancelButtonText: "取消",
  989. type: "warning",
  990. }
  991. )
  992. .then(function () {
  993. return adminChange(userIds);
  994. })
  995. .then(() => {
  996. this.msgSuccess("变更成功");
  997. this.$store.dispatch("LogOut").then(() => {
  998. location.href = "/login";
  999. });
  1000. })
  1001. .catch(() => {
  1002. this.$message({
  1003. type: "warning",
  1004. message: "已取消变更",
  1005. });
  1006. });
  1007. },
  1008. /** 删除按钮操作 */
  1009. handleDelete(row) {
  1010. const userIds = row.userId || this.ids;
  1011. const nickNames = row.nickName || this.ids;
  1012. this.$confirm(
  1013. '是否确认删除用户姓名为"' + nickNames + '"的数据项?',
  1014. "警告",
  1015. {
  1016. confirmButtonText: "确定",
  1017. cancelButtonText: "取消",
  1018. type: "warning",
  1019. }
  1020. )
  1021. .then(function () {
  1022. return delUser(userIds);
  1023. })
  1024. .then(() => {
  1025. this.getList();
  1026. this.msgSuccess("删除成功");
  1027. })
  1028. .catch(() => {
  1029. this.$message({
  1030. type: "warning",
  1031. message: "已取消删除",
  1032. });
  1033. });
  1034. },
  1035. /** 导出按钮操作 */
  1036. // handleExport() {
  1037. // this.download('system/ownUser/export', {
  1038. // ...this.queryParams
  1039. // }, `用户数据_${new Date().getTime()}.xlsx`)
  1040. // },
  1041. handleExport() {
  1042. console.log(this.queryParams);
  1043. console.log(this.dateRange);
  1044. const loading = this.$loading({
  1045. lock: true,
  1046. text: "Loading",
  1047. spinner: "el-icon-loading",
  1048. background: "rgba(0, 0, 0, 0.7)",
  1049. });
  1050. this.download(
  1051. "system/ownUser/export",
  1052. {
  1053. ...this.queryParams,
  1054. ...this.dateRange,
  1055. },
  1056. `用户数据_${new Date().getTime()}.xlsx`
  1057. );
  1058. loading.close();
  1059. },
  1060. /** 导入按钮操作 */
  1061. handleImport() {
  1062. this.upload.title = "用户导入";
  1063. this.upload.open = true;
  1064. },
  1065. /** 下载模板操作 */
  1066. importTemplate() {
  1067. this.download(
  1068. "system/user/importTemplate",
  1069. {
  1070. ...this.queryParams,
  1071. },
  1072. `user_${new Date().getTime()}.xlsx`
  1073. );
  1074. },
  1075. // 文件上传中处理
  1076. handleFileUploadProgress(event, file, fileList) {
  1077. this.upload.isUploading = true;
  1078. },
  1079. // 文件上传成功处理
  1080. handleFileSuccess(response, file, fileList) {
  1081. this.upload.open = false;
  1082. this.upload.isUploading = false;
  1083. this.$refs.upload.clearFiles();
  1084. this.$alert(response.msg, "导入结果", {
  1085. dangerouslyUseHTMLString: true,
  1086. });
  1087. this.getList();
  1088. },
  1089. // 提交上传文件
  1090. submitFileForm() {
  1091. this.$refs.upload.submit();
  1092. },
  1093. },
  1094. };
  1095. </script>