index.vue 34 KB

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