index.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="24">
  4. <!--用户数据-->
  5. <el-col :span="24" :xs="24">
  6. <el-form
  7. :model="queryParams"
  8. ref="queryForm"
  9. :inline="true"
  10. v-show="showSearch"
  11. label-width="68px"
  12. >
  13. <div class="query-box">
  14. <div class="query-box__left">
  15. <el-form-item label="" prop="name">
  16. <el-input
  17. v-model="queryParams.name"
  18. placeholder="请输入医疗机构名称"
  19. clearable
  20. size="small"
  21. style="width: 240px"
  22. @keyup.enter.native="handleQuery"
  23. />
  24. </el-form-item>
  25. <el-form-item label="" prop="communityId">
  26. <el-select
  27. v-model="queryParams.communityId"
  28. filterable
  29. clearable
  30. placeholder="请选择医共体"
  31. >
  32. <el-option
  33. v-for="item in cimmunity"
  34. :key="item.id"
  35. :label="item.name"
  36. :value="item.id"
  37. :disabled="item.state == 1 ? false : true"
  38. >
  39. </el-option>
  40. </el-select>
  41. </el-form-item>
  42. </div>
  43. <div class="query-box__right">
  44. <el-form-item>
  45. <el-button
  46. type="primary"
  47. icon="el-icon-search"
  48. size="mini"
  49. @click="handleQuery"
  50. >搜索</el-button
  51. >
  52. <el-button
  53. icon="el-icon-refresh"
  54. size="mini"
  55. @click="resetQuery"
  56. >重置</el-button
  57. >
  58. </el-form-item>
  59. </div>
  60. </div>
  61. </el-form>
  62. <el-row :gutter="10" class="mb8">
  63. <el-col :span="1.5">
  64. <el-button
  65. type="primary"
  66. plain
  67. icon="el-icon-plus"
  68. size="mini"
  69. @click="handleAdd"
  70. v-hasPermi="['system:user:add']"
  71. >新增</el-button
  72. >
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="danger"
  77. plain
  78. icon="el-icon-delete"
  79. size="mini"
  80. :disabled="multiple"
  81. @click="handleDelete"
  82. v-hasPermi="['system:user:remove']"
  83. >删除</el-button
  84. >
  85. </el-col>
  86. </el-row>
  87. <el-table
  88. v-loading="loading"
  89. :data="userList"
  90. @selection-change="handleSelectionChange"
  91. border
  92. >
  93. <el-table-column type="selection" width="50" align="center" />
  94. <!-- <el-table-column
  95. label="序号"
  96. align="center"
  97. key="userId"
  98. prop="userId"
  99. v-if="columns[0].visible"
  100. /> -->
  101. <el-table-column type="index" width="55" align="center" label="序号" />
  102. <el-table-column
  103. label="医共体"
  104. align="center"
  105. key="communityName"
  106. prop="communityName"
  107. v-if="columns[1].visible"
  108. :show-overflow-tooltip="true"
  109. />
  110. <el-table-column
  111. label="登录名"
  112. align="center"
  113. key="userName"
  114. prop="userName"
  115. v-if="columns[2].visible"
  116. :show-overflow-tooltip="true"
  117. />
  118. <el-table-column
  119. label="中文名"
  120. align="center"
  121. key="nickName"
  122. prop="nickName"
  123. v-if="columns[3].visible"
  124. :show-overflow-tooltip="true"
  125. />
  126. <el-table-column
  127. label="医疗机构"
  128. align="center"
  129. key="mechanismName"
  130. prop="mechanismName"
  131. v-if="columns[4].visible"
  132. width="180"
  133. />
  134. <el-table-column
  135. label="手机号码"
  136. align="center"
  137. key="phonenumber"
  138. prop="phonenumber"
  139. v-if="columns[4].visible"
  140. width="120"
  141. />
  142. <el-table-column
  143. label="性别"
  144. align="center"
  145. key="sex"
  146. prop="sex"
  147. v-if="columns[4].visible"
  148. width="120"
  149. >
  150. <template slot-scope="scope">
  151. <dict-tag :options="sexOptions" :value="scope.row.sex" />
  152. </template>
  153. </el-table-column>
  154. <el-table-column
  155. label="状态"
  156. align="center"
  157. key="status"
  158. prop="status"
  159. v-if="columns[4].visible"
  160. width="120"
  161. >
  162. <template slot-scope="scope">
  163. {{ scope.row.status == 0 ? "正常" : "禁用" }}
  164. </template>
  165. </el-table-column>
  166. <!-- <el-table-column
  167. label="角色"
  168. align="center"
  169. key="roleIds"
  170. prop="roleIds"
  171. v-if="columns[4].visible"
  172. width="120"
  173. /> -->
  174. <el-table-column
  175. label="创建人"
  176. align="center"
  177. key="createBy"
  178. prop="createBy"
  179. v-if="columns[4].visible"
  180. width="120"
  181. />
  182. <el-table-column
  183. label="操作"
  184. align="center"
  185. width="160"
  186. class-name="small-padding fixed-width"
  187. >
  188. <template slot-scope="scope" v-if="scope.row.userId !== 1">
  189. <el-button
  190. size="mini"
  191. type="primary"
  192. style="width: 40px"
  193. @click="handleUpdate(scope.row)"
  194. v-hasPermi="['system:user:edit']"
  195. >修改</el-button
  196. >
  197. <el-button
  198. size="mini"
  199. type="primary"
  200. style="width: 40px"
  201. @click="handleDelete(scope.row)"
  202. v-hasPermi="['system:user:remove']"
  203. >删除</el-button
  204. >
  205. <el-dropdown
  206. size="mini"
  207. @command="(command) => {handleCommand(command, scope.row)}"
  208. v-hasPermi="['system:user:resetPwd', 'system:user:edit']"
  209. >
  210. <span class="el-dropdown-link">
  211. <i class="el-icon-d-arrow-right el-icon--right"></i>更多
  212. </span>
  213. <el-dropdown-menu slot="dropdown">
  214. <el-dropdown-item
  215. command="handleResetPwd"
  216. icon="el-icon-key"
  217. v-hasPermi="['system:user:resetPwd']"
  218. >重置密码</el-dropdown-item
  219. >
  220. <el-dropdown-item
  221. command="handleAuthRole"
  222. icon="el-icon-circle-check"
  223. v-hasPermi="['system:user:edit']"
  224. >分配角色</el-dropdown-item
  225. >
  226. </el-dropdown-menu>
  227. </el-dropdown>
  228. </template>
  229. </el-table-column>
  230. </el-table>
  231. <pagination
  232. v-show="total > 0"
  233. :total="total"
  234. :page.sync="queryParams.pageNum"
  235. :limit.sync="queryParams.pageSize"
  236. @pagination="getList"
  237. />
  238. </el-col>
  239. </el-row>
  240. <!-- 添加或修改参数配置对话框 -->
  241. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  242. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  243. <el-form-item
  244. v-if="form.userId == undefined"
  245. label="登录名"
  246. prop="userName"
  247. >
  248. <el-input
  249. v-model="form.userName"
  250. placeholder="请输入登陆名"
  251. maxlength="30"
  252. />
  253. </el-form-item>
  254. <el-form-item label="中文名" prop="nickName">
  255. <el-input
  256. v-model="form.nickName"
  257. placeholder="请输入中文名"
  258. maxlength="30"
  259. />
  260. </el-form-item>
  261. <el-form-item
  262. v-if="form.userId == undefined"
  263. label="密码"
  264. prop="password"
  265. >
  266. <el-input
  267. v-model="form.password"
  268. placeholder="请输入密码"
  269. type="password"
  270. maxlength="20"
  271. show-password
  272. />
  273. </el-form-item>
  274. <el-form-item label="角色" prop="roleIds">
  275. <el-select
  276. v-model="form.roleIds"
  277. multiple
  278. placeholder="请选择"
  279. style="width: 100%"
  280. >
  281. <el-option
  282. v-for="item in roleOptions"
  283. :key="item.roleId"
  284. :label="item.roleName"
  285. :value="item.roleId"
  286. :disabled="item.status == 2"
  287. ></el-option>
  288. </el-select>
  289. </el-form-item>
  290. <el-form-item prop="communityId" label="医共体名称">
  291. <el-select
  292. v-model="form.communityId"
  293. filterable
  294. placeholder="请选择医共体"
  295. @change="handleChangeCommunity"
  296. style="width: 100%"
  297. >
  298. <el-option
  299. v-for="item in cimmunity"
  300. :key="item.id"
  301. :label="item.name"
  302. :value="item.id"
  303. :disabled="item.state == 2"
  304. >
  305. </el-option>
  306. </el-select>
  307. </el-form-item>
  308. <el-form-item label="医疗机构名称" prop="mechanismId">
  309. <el-form-item prop="mechanismId">
  310. <el-select
  311. v-model="form.mechanismId"
  312. filterable
  313. placeholder="请选择医疗机构"
  314. style="width: 100%"
  315. >
  316. <el-option
  317. v-for="item in mechanism"
  318. :key="item.id"
  319. :label="item.name"
  320. :value="item.id"
  321. >
  322. </el-option>
  323. </el-select>
  324. </el-form-item>
  325. </el-form-item>
  326. <el-form-item label="使用范围" prop="pharmacyList">
  327. <!-- <el-input v-model="form.range" placeholder="MedicalPharmacyList" /> -->
  328. <el-tree
  329. :data="MedicalPharmacyList"
  330. :show-checkbox="true"
  331. node-key="id"
  332. @check="treeCheck"
  333. :check-strictly="false"
  334. :default-expand-all="true"
  335. :default-checked-keys="pharmacyListArr"
  336. ref="treeCheck"
  337. >
  338. </el-tree>
  339. </el-form-item>
  340. <el-form-item label="性别">
  341. <el-select
  342. v-model="form.sex"
  343. placeholder="请选择"
  344. style="width: 100%"
  345. >
  346. <el-option
  347. v-for="dict in sexOptions"
  348. :key="dict.dictValue"
  349. :label="dict.dictLabel"
  350. :value="dict.dictValue"
  351. ></el-option>
  352. </el-select>
  353. </el-form-item>
  354. <el-form-item label="手机号码" prop="phonenumber">
  355. <el-input
  356. v-model="form.phonenumber"
  357. placeholder="请输入手机号码"
  358. maxlength="11"
  359. />
  360. </el-form-item>
  361. <!-- <el-col :span="12">
  362. <el-form-item label="归属部门" prop="deptId"> -->
  363. <!-- <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" /> -->
  364. <!-- </el-form-item>
  365. </el-col> -->
  366. <!-- <el-row>
  367. <el-col :span="12"> </el-col>
  368. <el-col :span="12">
  369. <el-form-item label="邮箱" prop="email">
  370. <el-input
  371. v-model="form.email"
  372. placeholder="请输入邮箱"
  373. maxlength="50"
  374. />
  375. </el-form-item>
  376. </el-col>
  377. </el-row>
  378. <el-row>
  379. <el-col :span="12"> </el-col>
  380. <el-col :span="12"> </el-col>
  381. </el-row>
  382. <el-row>
  383. <el-col :span="12"> </el-col>
  384. <el-col :span="12">
  385. <el-form-item label="状态">
  386. <el-radio-group v-model="form.status">
  387. <el-radio
  388. v-for="dict in statusOptions"
  389. :key="dict.dictValue"
  390. :label="dict.dictValue"
  391. >{{ dict.dictLabel }}</el-radio
  392. >
  393. </el-radio-group>
  394. </el-form-item>
  395. </el-col>
  396. </el-row>
  397. <el-row>
  398. <el-col :span="12">
  399. <el-form-item label="岗位">
  400. <el-select v-model="form.postIds" multiple placeholder="请选择">
  401. <el-option
  402. v-for="item in postOptions"
  403. :key="item.postId"
  404. :label="item.postName"
  405. :value="item.postId"
  406. :disabled="item.status == 1"
  407. ></el-option>
  408. </el-select>
  409. </el-form-item>
  410. </el-col>
  411. <el-col :span="12"> </el-col>
  412. </el-row>
  413. <el-row>
  414. <el-col :span="24">
  415. <el-form-item label="备注">
  416. <el-input
  417. v-model="form.remark"
  418. type="textarea"
  419. placeholder="请输入内容"
  420. ></el-input>
  421. </el-form-item>
  422. </el-col>
  423. </el-row> -->
  424. </el-form>
  425. <div slot="footer" class="dialog-footer">
  426. <el-button type="primary" @click="submitForm">确 定</el-button>
  427. <el-button @click="cancel">取 消</el-button>
  428. </div>
  429. </el-dialog>
  430. <!-- 用户导入对话框 -->
  431. <el-dialog
  432. :title="upload.title"
  433. :visible.sync="upload.open"
  434. width="400px"
  435. append-to-body
  436. >
  437. <el-upload
  438. ref="upload"
  439. :limit="1"
  440. accept=".xlsx, .xls"
  441. :headers="upload.headers"
  442. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  443. :disabled="upload.isUploading"
  444. :on-progress="handleFileUploadProgress"
  445. :on-success="handleFileSuccess"
  446. :auto-upload="false"
  447. drag
  448. >
  449. <i class="el-icon-upload"></i>
  450. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  451. <div class="el-upload__tip text-center" slot="tip">
  452. <div class="el-upload__tip" slot="tip">
  453. <el-checkbox v-model="upload.updateSupport" />
  454. 是否更新已经存在的用户数据
  455. </div>
  456. <span>仅允许导入xls、xlsx格式文件。</span>
  457. <el-link
  458. type="primary"
  459. :underline="false"
  460. style="font-size: 12px; vertical-align: baseline"
  461. @click="importTemplate"
  462. >下载模板</el-link
  463. >
  464. </div>
  465. </el-upload>
  466. <div slot="footer" class="dialog-footer">
  467. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  468. <el-button @click="upload.open = false">取 消</el-button>
  469. </div>
  470. </el-dialog>
  471. </div>
  472. </template>
  473. <script>
  474. import {
  475. listUser,
  476. getUser,
  477. delUser,
  478. addUser,
  479. updateUser,
  480. exportUser,
  481. resetUserPwd,
  482. changeUserStatus,
  483. importTemplate,
  484. } from "@/api/system/user";
  485. import { getToken } from "@/utils/auth";
  486. import { listMedicalMechanism } from "@/api/medical/mechanism";
  487. import { listCommunity } from "@/api/medical/community";
  488. import { listMedicalPharmacy } from "@/api/pharmacy/MedicalPharmacy";
  489. import { listMechanismId } from "@/api/medical/mechanism";
  490. import { boundary } from "@/api/pharmacy/storage";
  491. export default {
  492. name: "User",
  493. components: {},
  494. data() {
  495. return {
  496. pharmacyListArr: [],
  497. MedicalPharmacyList: [],
  498. cimmunity: [], //医共体ID
  499. mechanism: [],
  500. // 遮罩层
  501. loading: true,
  502. // 导出遮罩层
  503. exportLoading: false,
  504. // 选中数组
  505. ids: [],
  506. // 非单个禁用
  507. single: true,
  508. // 非多个禁用
  509. multiple: true,
  510. // 显示搜索条件
  511. showSearch: true,
  512. // 总条数
  513. total: 0,
  514. // 用户表格数据
  515. userList: null,
  516. // 弹出层标题
  517. title: "",
  518. // 部门树选项
  519. deptOptions: undefined,
  520. // 是否显示弹出层
  521. open: false,
  522. // 部门名称
  523. deptName: undefined,
  524. // 默认密码
  525. initPassword: undefined,
  526. // 日期范围
  527. dateRange: [],
  528. // 状态数据字典
  529. statusOptions: [],
  530. // 性别状态字典
  531. sexOptions: [],
  532. // 岗位选项
  533. postOptions: [],
  534. // 角色选项
  535. roleOptions: [],
  536. // 表单参数
  537. form: {
  538. boundary: [],
  539. },
  540. defaultProps: {
  541. children: "children",
  542. label: "label",
  543. },
  544. // 用户导入参数
  545. upload: {
  546. // 是否显示弹出层(用户导入)
  547. open: false,
  548. // 弹出层标题(用户导入)
  549. title: "",
  550. // 是否禁用上传
  551. isUploading: false,
  552. // 是否更新已经存在的用户数据
  553. updateSupport: 0,
  554. // 设置上传的请求头部
  555. headers: { Authorization: "Bearer " + getToken() },
  556. // 上传的地址
  557. url: process.env.VUE_APP_BASE_API + "/system/user/importData",
  558. },
  559. // 查询参数
  560. queryParams: {
  561. pageNum: 1,
  562. pageSize: 10,
  563. name: undefined,
  564. phonenumber: undefined,
  565. status: undefined,
  566. deptId: undefined,
  567. },
  568. // 列信息
  569. columns: [
  570. { key: 0, label: `用户编号`, visible: true },
  571. { key: 1, label: `用户名称`, visible: true },
  572. { key: 2, label: `用户昵称`, visible: true },
  573. { key: 3, label: `部门`, visible: true },
  574. { key: 4, label: `手机号码`, visible: true },
  575. { key: 5, label: `状态`, visible: true },
  576. { key: 6, label: `创建时间`, visible: true },
  577. ],
  578. // 表单校验
  579. rules: {
  580. userName: [
  581. { required: true, message: "用户名称不能为空", trigger: "blur" },
  582. {
  583. min: 2,
  584. max: 20,
  585. message: "用户名称长度必须介于 2 和 20 之间",
  586. trigger: "blur",
  587. },
  588. ],
  589. nickName: [
  590. { required: true, message: "用户昵称不能为空", trigger: "blur" },
  591. ],
  592. roleIds: [{ required: true, message: "角色不能为空", trigger: "blur" }],
  593. communityId: [
  594. { required: true, message: "医共体名称不能为空", trigger: "blur" },
  595. ],
  596. password: [
  597. { required: true, message: "用户密码不能为空", trigger: "blur" },
  598. {
  599. min: 5,
  600. max: 20,
  601. message: "用户密码长度必须介于 5 和 20 之间",
  602. trigger: "blur",
  603. },
  604. ],
  605. email: [
  606. {
  607. type: "email",
  608. message: "'请输入正确的邮箱地址",
  609. trigger: ["blur", "change"],
  610. },
  611. ],
  612. phonenumber: [
  613. {
  614. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  615. message: "请输入正确的手机号码",
  616. trigger: "blur",
  617. },
  618. ],
  619. },
  620. };
  621. },
  622. watch: {
  623. // 根据名称筛选部门树
  624. deptName(val) {
  625. this.$refs.tree.filter(val);
  626. },
  627. },
  628. created() {
  629. this.getList();
  630. this.getCommunityList();
  631. // this.getTreeselect();
  632. this.getDicts("sys_normal_disable").then((response) => {
  633. this.statusOptions = response.data;
  634. });
  635. this.getDicts("sys_user_sex").then((response) => {
  636. this.sexOptions = response.data;
  637. });
  638. this.getConfigKey("sys.user.initPassword").then((response) => {
  639. this.initPassword = response.msg;
  640. });
  641. },
  642. methods: {
  643. // 去重
  644. unique(arr) {
  645. const res = new Map();
  646. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1));
  647. },
  648. // 树状图选择
  649. treeCheck(e, v) {
  650. const checkArr = v.checkedNodes;
  651. const indexArr = [];
  652. for (let i in checkArr) {
  653. //console.log(checkArr, "99");
  654. let obj = {
  655. id: checkArr[i].id,
  656. name: checkArr[i].label,
  657. };
  658. indexArr.push(obj);
  659. }
  660. this.form.pharmacyList = this.unique(indexArr);
  661. },
  662. /** 查询药房列表 */
  663. getMedicalPharmacy() {
  664. this.loading = true;
  665. boundary({
  666. communityId: this.form.communityId
  667. }).then((response) => {
  668. //console.log(response.data, "7766555444");
  669. response.data.forEach(v => {
  670. v.label = v.name
  671. })
  672. this.MedicalPharmacyList = response.data;
  673. // this.MedicalPharmacyList = this.handleTree(
  674. // response.data,
  675. // "id",
  676. // "parentId"
  677. // );
  678. // _readNodes(this.MedicalPharmacyList);
  679. // function _readNodes(nodes = [], arr = []) {
  680. // for (let item of nodes) {
  681. // item.label = item.label;
  682. // item.value = item.id;
  683. // if (item.children && item.children.length)
  684. // _readNodes(item.children, arr);
  685. // }
  686. // }
  687. this.loading = false;
  688. });
  689. },
  690. /** 通过医共体id查询机构 **/
  691. handleChangeCommunity() {
  692. //console.log(this.form.communityId);
  693. if (this.form.communityId) {
  694. this.getMechanismList(this.form.communityId);
  695. this.form.mechanismId = "";
  696. }
  697. this.getMedicalPharmacy();
  698. },
  699. /** 查询医共体列表 */
  700. getCommunityList() {
  701. listCommunity().then((response) => {
  702. this.cimmunity = response.rows;
  703. });
  704. },
  705. /** 查询医疗机构名称 **/
  706. getMechanismList(id) {
  707. listMechanismId(id).then((response) => {
  708. this.mechanism = response.data;
  709. });
  710. },
  711. /** 查询用户列表 */
  712. getList() {
  713. this.loading = true;
  714. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
  715. (response) => {
  716. this.userList = response.rows;
  717. //console.log("getList", this.userList);
  718. this.total = response.total;
  719. this.loading = false;
  720. }
  721. );
  722. },
  723. // 筛选节点
  724. filterNode(value, data) {
  725. if (!value) return true;
  726. return data.label.indexOf(value) !== -1;
  727. },
  728. // 节点单击事件
  729. handleNodeClick(data) {
  730. this.queryParams.deptId = data.id;
  731. this.getList();
  732. },
  733. // 用户状态修改
  734. handleStatusChange(row) {
  735. let text = row.status === "0" ? "启用" : "停用";
  736. this.$confirm(
  737. '确认要"' + text + '""' + row.userName + '"用户吗?',
  738. "警告",
  739. {
  740. confirmButtonText: "确定",
  741. cancelButtonText: "取消",
  742. type: "warning",
  743. }
  744. )
  745. .then(function () {
  746. return changeUserStatus(row.userId, row.status);
  747. })
  748. .then(() => {
  749. this.msgSuccess(text + "成功");
  750. })
  751. .catch(function () {
  752. row.status = row.status === "0" ? "1" : "0";
  753. });
  754. },
  755. // 取消按钮
  756. cancel() {
  757. this.open = false;
  758. this.reset();
  759. },
  760. // 表单重置
  761. reset() {
  762. this.form = {
  763. boundary: [],
  764. communityId: "",
  765. mechanismId: "",
  766. userId: undefined,
  767. deptId: undefined,
  768. userName: undefined,
  769. nickName: undefined,
  770. password: undefined,
  771. phonenumber: undefined,
  772. email: undefined,
  773. sex: undefined,
  774. status: "0",
  775. remark: undefined,
  776. postIds: [],
  777. roleIds: [],
  778. };
  779. this.pharmacyListArr = [];
  780. this.MedicalPharmacyList = []
  781. this.resetForm("form");
  782. },
  783. /** 搜索按钮操作 */
  784. handleQuery() {
  785. this.queryParams.pageNum = 1;
  786. this.getList();
  787. },
  788. /** 重置按钮操作 */
  789. resetQuery() {
  790. this.dateRange = [];
  791. this.resetForm("queryForm");
  792. this.handleQuery();
  793. },
  794. // 多选框选中数据
  795. handleSelectionChange(selection) {
  796. this.ids = selection.map((item) => item.userId);
  797. this.single = selection.length != 1;
  798. this.multiple = !selection.length;
  799. },
  800. // 更多操作触发
  801. handleCommand(command, row) {
  802. switch (command) {
  803. case "handleResetPwd":
  804. this.handleResetPwd(row);
  805. break;
  806. case "handleAuthRole":
  807. this.handleAuthRole(row);
  808. break;
  809. default:
  810. break;
  811. }
  812. },
  813. /** 新增按钮操作 */
  814. handleAdd() {
  815. this.reset();
  816. // this.getTreeselect();
  817. this.$nextTick(() => {
  818. this.$refs.treeCheck.setCheckedKeys((this.pharmacyListArr = []));
  819. });
  820. getUser().then((response) => {
  821. this.postOptions = response.posts;
  822. this.roleOptions = response.roles;
  823. this.open = true;
  824. this.title = "添加用户";
  825. this.form.password = this.initPassword;
  826. });
  827. },
  828. /** 修改按钮操作 */
  829. handleUpdate(row) {
  830. this.reset();
  831. // this.getTreeselect();
  832. const userId = row.userId || this.ids;
  833. getUser(userId).then((response) => {
  834. if (!response.data.pharmacyList) {
  835. response.data.pharmacyList = [];
  836. }
  837. this.form = response.data;
  838. this.getMedicalPharmacy();
  839. //console.log(response.data.pharmacyList, "999");
  840. response.data.pharmacyList.map((item) => {
  841. this.pharmacyListArr.push(item.id);
  842. });
  843. this.$nextTick(() => {
  844. this.$refs.treeCheck.setCheckedKeys(this.pharmacyListArr);
  845. });
  846. this.postOptions = response.posts;
  847. this.roleOptions = response.roles;
  848. this.form.postIds = response.postIds;
  849. this.form.roleIds = response.roleIds;
  850. this.open = true;
  851. this.title = "修改用户";
  852. this.form.password = "";
  853. this.getMechanismList(response.data.communityId);
  854. });
  855. },
  856. /** 重置密码按钮操作 */
  857. handleResetPwd(row) {
  858. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  859. confirmButtonText: "确定",
  860. cancelButtonText: "取消",
  861. closeOnClickModal: false,
  862. inputPattern: /^.{5,20}$/,
  863. inputErrorMessage: "用户密码长度必须介于 5 和 20 之间",
  864. })
  865. .then(({ value }) => {
  866. resetUserPwd(row.userId, value).then((response) => {
  867. this.msgSuccess("修改成功,新密码是:" + value);
  868. });
  869. })
  870. .catch(() => {});
  871. },
  872. /** 分配角色操作 */
  873. handleAuthRole: function (row) {
  874. const userId = row.userId;
  875. this.$router.push("/system/user-auth/role/" + userId);
  876. },
  877. /** 提交按钮 */
  878. submitForm: function () {
  879. this.$refs["form"].validate((valid) => {
  880. if (valid) {
  881. if (this.form.userId != undefined) {
  882. updateUser(this.form).then((response) => {
  883. this.msgSuccess("修改成功");
  884. this.open = false;
  885. this.getList();
  886. });
  887. } else {
  888. addUser(this.form).then((response) => {
  889. this.msgSuccess("新增成功");
  890. this.open = false;
  891. this.getList();
  892. });
  893. }
  894. }
  895. });
  896. },
  897. /** 删除按钮操作 */
  898. handleDelete(row) {
  899. const userIds = row.userId || this.ids;
  900. this.$confirm("确定需要删除已选数据吗?", "警告", {
  901. confirmButtonText: "确定",
  902. cancelButtonText: "取消",
  903. type: "warning",
  904. })
  905. .then(function () {
  906. return delUser(userIds);
  907. })
  908. .then(() => {
  909. this.getList();
  910. this.msgSuccess("删除成功");
  911. })
  912. .catch(() => {});
  913. },
  914. /** 导出按钮操作 */
  915. async handleExport() {
  916. this.exportLoading = true;
  917. try {
  918. await this.$confirm("是否确认导出所有用户数据项?", "警告", {
  919. confirmButtonText: "确定",
  920. cancelButtonText: "取消",
  921. type: "warning",
  922. });
  923. const data = await exportUser(this.queryParams)
  924. this.$message.success(`导出 ${data.name} 成功`);
  925. } catch (e) {}
  926. this.exportLoading = false;
  927. },
  928. /** 导入按钮操作 */
  929. handleImport() {
  930. this.upload.title = "用户导入";
  931. this.upload.open = true;
  932. },
  933. /** 下载模板操作 */
  934. importTemplate() {
  935. importTemplate().then((response) => {
  936. this.$message.success(`下载模板 ${response.name} 成功`);
  937. });
  938. },
  939. // 文件上传中处理
  940. handleFileUploadProgress(event, file, fileList) {
  941. this.upload.isUploading = true;
  942. },
  943. // 文件上传成功处理
  944. handleFileSuccess(response, file, fileList) {
  945. this.upload.open = false;
  946. this.upload.isUploading = false;
  947. this.$refs.upload.clearFiles();
  948. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  949. this.getList();
  950. },
  951. // 提交上传文件
  952. submitFileForm() {
  953. this.$refs.upload.submit();
  954. },
  955. },
  956. };
  957. </script>