account.vue 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. <template>
  2. <div class="app-container">
  3. <div class="tree-container">
  4. <div style="padding: 10px; display: flex">
  5. <el-button
  6. icon="el-icon-refresh-right"
  7. size="small"
  8. @click="refreshDepartment()"
  9. style="padding: 9px 10px; margin-right: 6px"
  10. ></el-button>
  11. <el-input
  12. placeholder="输入关键字进行过滤"
  13. size="small"
  14. clearable
  15. v-model="filterText"
  16. >
  17. </el-input>
  18. </div>
  19. <el-tree
  20. :data="departmentList"
  21. :props="defaultProps"
  22. default-expand-all
  23. highlight-current
  24. :expand-on-click-node="false"
  25. :filter-node-method="filterNode"
  26. @node-click="handleNodeClick"
  27. node-key="id"
  28. ref="listTree"
  29. >
  30. <div class="custom-tree-node" slot-scope="{ node, data }">
  31. <i
  32. :class="
  33. data.children && data.children.length > 0
  34. ? 'el-icon-folder-opened'
  35. : 'el-icon-document-remove'
  36. "
  37. ></i
  38. ><span>{{ node.label }}</span>
  39. </div>
  40. </el-tree>
  41. </div>
  42. <div class="mymain-container">
  43. <div class="screen-container">
  44. <!-- <div class="top clearfix">
  45. <div class="title fl">条件筛选</div>
  46. </div> -->
  47. <el-form
  48. ref="screenForm"
  49. :model="screenForm"
  50. label-width="70px"
  51. size="mini"
  52. label-position="left"
  53. >
  54. <el-row :gutter="20">
  55. <el-col :xs="24" :sm="12" :lg="6">
  56. <el-form-item label="账号名称" prop="name">
  57. <el-input
  58. v-model="screenForm.name"
  59. placeholder="请输入账号名称"
  60. ></el-input>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :xs="24" :sm="12" :lg="6">
  64. <el-form-item label="角色" prop="name">
  65. <el-select
  66. class="selectStyle"
  67. v-model="screenForm.roleId"
  68. placeholder="请选择"
  69. filterable
  70. >
  71. <el-option
  72. v-for="(v, i) in roleList"
  73. :key="i"
  74. :label="v.name"
  75. :value="v.adminRoleId"
  76. >
  77. </el-option>
  78. </el-select>
  79. </el-form-item>
  80. </el-col>
  81. <el-col :xs="24" :sm="12" :lg="12" class="tr">
  82. <el-form-item label="">
  83. <el-button size="mini" @click="resetScreenForm">清空</el-button>
  84. <el-button size="mini" type="primary" @click="submitScreenForm"
  85. >搜索</el-button
  86. >
  87. </el-form-item>
  88. </el-col>
  89. </el-row>
  90. </el-form>
  91. </div>
  92. <div class="btn-group clearfix" style="margin-top: 20px">
  93. <div class="fl">
  94. <el-button size="mini" type="primary" @click="openAccountForm('add')"
  95. >添加账号</el-button
  96. >
  97. </div>
  98. <div class="fr">
  99. <el-button
  100. size="mini"
  101. @click="handleDownload"
  102. v-if="checkBtnRole('download')"
  103. >下载导入模板</el-button
  104. >
  105. <ExportButton
  106. class="import-btn"
  107. :exUrl="'/admin/user/user/listExport'"
  108. :exParams="exParams"
  109. />
  110. <el-upload
  111. class="import-btn"
  112. v-if="checkBtnRole('import')"
  113. action=""
  114. :http-request="handleImport"
  115. :file-list="importFileList"
  116. :show-file-list="false"
  117. >
  118. <!-- v-if="checkBtnRole('import')" -->
  119. <el-button size="mini" type="primary" :loading="importLoading">{{
  120. importLoading ? "导入中..." : "导入"
  121. }}</el-button>
  122. </el-upload>
  123. <!--
  124. <el-button size="small" type="primary" @click="handleExport">导出</el-button>
  125. <el-button size="small" type="primary" :loading="importLoading" @click="clickImport">{{ importLoading ? '导入中...' : '导入' }}</el-button>
  126. -->
  127. </div>
  128. </div>
  129. <div class="table">
  130. <el-table
  131. v-loading="listLoading"
  132. :data="dataList"
  133. element-loading-text="Loading"
  134. border
  135. fit
  136. highlight-current-row
  137. stripe
  138. >
  139. <!-- <el-table-column align="center" type="selection" width="55" fixed></el-table-column> -->
  140. <el-table-column
  141. show-overflow-tooltip
  142. align="center"
  143. label="账号"
  144. prop="userName"
  145. min-width="120"
  146. ></el-table-column>
  147. <el-table-column
  148. show-overflow-tooltip
  149. align="center"
  150. label="用户名"
  151. prop="nickName"
  152. min-width="160"
  153. ></el-table-column>
  154. <el-table-column
  155. show-overflow-tooltip
  156. align="center"
  157. label="角色"
  158. prop="roleName"
  159. min-width="100"
  160. ></el-table-column>
  161. <el-table-column
  162. show-overflow-tooltip
  163. align="center"
  164. label="创建时间"
  165. prop="createTime"
  166. min-width="160"
  167. ></el-table-column>
  168. <el-table-column
  169. show-overflow-tooltip
  170. align="center"
  171. label="最后登录时间"
  172. prop="lastLoginTime"
  173. min-width="160"
  174. ></el-table-column>
  175. <el-table-column
  176. show-overflow-tooltip
  177. align="center"
  178. label="状态"
  179. class-name="status-col"
  180. >
  181. <template slot-scope="scope">
  182. <el-tag
  183. size="mini"
  184. :type="scope.row.status ? 'success' : 'danger'"
  185. >{{ scope.row.status ? "正常" : "冻结" }}</el-tag
  186. >
  187. </template>
  188. </el-table-column>
  189. <el-table-column align="center" label="操作" min-width="160">
  190. <template slot-scope="scope">
  191. <template v-if="checkBtnRole('status')">
  192. <el-popconfirm
  193. v-if="scope.row.status"
  194. style="margin-right: 10px"
  195. title="确定冻结吗?"
  196. @onConfirm="changeStatus(scope.row.adminUserId, 0)"
  197. >
  198. <el-button slot="reference" type="text">冻结</el-button>
  199. </el-popconfirm>
  200. <el-popconfirm
  201. v-else
  202. style="margin-right: 10px"
  203. title="确定恢复吗?"
  204. @onConfirm="changeStatus(scope.row.adminUserId, 1)"
  205. >
  206. <el-button slot="reference" type="text">恢复</el-button>
  207. </el-popconfirm>
  208. </template>
  209. <el-button
  210. type="text"
  211. @click="openAccountForm('edit', scope.row.adminUserId)"
  212. v-if="checkBtnRole('edit')"
  213. >编辑</el-button
  214. >
  215. <el-button
  216. type="text"
  217. @click="handleReset(scope.row.adminUserId)"
  218. v-if="checkBtnRole('reset')"
  219. >重置密码</el-button
  220. >
  221. <!-- <el-popconfirm style="margin-left: 10px;" title="确定删除吗?" @onConfirm="deleteAccount(scope.row.id)" v-if="checkBtnRole('del')">
  222. <el-button slot="reference" type="text">删除</el-button>
  223. </el-popconfirm> -->
  224. </template>
  225. </el-table-column>
  226. </el-table>
  227. </div>
  228. <div class="pagination clearfix">
  229. <div class="fr">
  230. <el-pagination
  231. @size-change="handleSizeChange"
  232. @current-change="handleCurrentChange"
  233. :current-page="currentPage"
  234. :page-sizes="[10, 20, 30, 50]"
  235. :page-size="10"
  236. layout="total, sizes, prev, pager, next, jumper"
  237. :total="listTotal"
  238. >
  239. </el-pagination>
  240. </div>
  241. </div>
  242. </div>
  243. <!-- 添加编辑账号 -->
  244. <el-dialog
  245. :title="AccountFormType == 'add' ? '添加账号' : '编辑账号'"
  246. :visible.sync="AccountFormVisible"
  247. :show-close="false"
  248. width="40%"
  249. :close-on-click-modal="false"
  250. >
  251. <el-form
  252. ref="AccountForm"
  253. :model="AccountForm"
  254. :rules="AccountFormRules"
  255. label-position="left"
  256. label-width="80px"
  257. >
  258. <el-form-item label="账号" prop="account">
  259. <el-input
  260. v-model="AccountForm.account"
  261. autocomplete="off"
  262. placeholder="请输入账号"
  263. ></el-input>
  264. </el-form-item>
  265. <el-form-item label="用户名" prop="nickName">
  266. <el-input
  267. v-model="AccountForm.nickName"
  268. autocomplete="off"
  269. placeholder="请输入用户名"
  270. ></el-input>
  271. </el-form-item>
  272. <el-form-item label="角色组" prop="role">
  273. <el-select
  274. v-model="AccountForm.role"
  275. placeholder="请选择角色组"
  276. style="width: 100%"
  277. filterable
  278. >
  279. <el-option
  280. :label="item.name"
  281. :value="item.adminRoleId"
  282. v-for="(item, index) in roleList"
  283. :key="index"
  284. ></el-option>
  285. </el-select>
  286. </el-form-item>
  287. <el-form-item
  288. label="部门"
  289. prop="department"
  290. v-show="roleObj.type === 0"
  291. >
  292. <el-tree
  293. :data="departmentList"
  294. show-checkbox
  295. :check-strictly="true"
  296. node-key="adminWebsitId"
  297. ref="tree"
  298. highlight-current
  299. :props="props"
  300. >
  301. </el-tree>
  302. </el-form-item>
  303. <el-form-item
  304. label="经销商"
  305. prop="dealer"
  306. v-show="roleObj.type === 0 && roleObj.name === '经销商'"
  307. >
  308. <el-select
  309. v-model="AccountForm.dealer"
  310. placeholder="请选择经销商"
  311. style="width: 100%"
  312. filterable
  313. >
  314. <el-option
  315. :label="item.name"
  316. :value="item.id"
  317. v-for="(item, index) in dealerList"
  318. :key="index"
  319. ></el-option>
  320. </el-select>
  321. </el-form-item>
  322. <el-form-item
  323. label="商户"
  324. prop="merchant"
  325. v-show="roleObj.type === 1 || roleObj.type === 2"
  326. >
  327. <el-select
  328. v-model="AccountForm.merchant"
  329. placeholder="请选择商户"
  330. style="width: 100%"
  331. filterable
  332. >
  333. <el-option
  334. :label="item.adminCompanyName"
  335. :value="item.adminCompanyId"
  336. v-for="(item, index) in merchantList"
  337. :key="index"
  338. ></el-option>
  339. </el-select>
  340. </el-form-item>
  341. <el-form-item
  342. label="集团公司"
  343. prop="isGroup"
  344. v-show="roleObj.type === 0 && roleObj.name === '经销商'"
  345. >
  346. <el-radio-group v-model="AccountForm.isGroup">
  347. <el-radio :label="true">是</el-radio>
  348. <el-radio :label="false">否</el-radio>
  349. </el-radio-group>
  350. </el-form-item>
  351. <el-form-item
  352. label="所属集团"
  353. prop="company"
  354. v-show="
  355. roleObj.type === 0 &&
  356. roleObj.name === '经销商' &&
  357. !AccountForm.isGroup
  358. "
  359. >
  360. <el-select
  361. v-model="AccountForm.company"
  362. placeholder="请选择所属集团"
  363. style="width: 100%"
  364. filterable
  365. >
  366. <el-option
  367. :label="item.name"
  368. :value="item.id"
  369. v-for="(item, index) in dealerList"
  370. :key="index"
  371. ></el-option>
  372. </el-select>
  373. </el-form-item>
  374. <el-form-item
  375. label="是否折让"
  376. prop="isDiscount"
  377. v-show="roleObj.type === 0 && roleObj.name === '经销商'"
  378. >
  379. <el-radio-group v-model="AccountForm.isDiscount">
  380. <el-radio :label="true">是</el-radio>
  381. <el-radio :label="false">否</el-radio>
  382. </el-radio-group>
  383. </el-form-item>
  384. <el-form-item
  385. label="密码"
  386. prop="newPassword"
  387. v-if="AccountFormType == 'add'"
  388. >
  389. <el-input
  390. v-model="AccountForm.newPassword"
  391. ref="password1"
  392. autocomplete="off"
  393. placeholder="请输入密码"
  394. :type="passwordType1"
  395. ></el-input>
  396. <span class="show-pwd" @click="showPwd(1)">
  397. <svg-icon
  398. :icon-class="passwordType1 === 'password' ? 'eye' : 'eye-open'"
  399. />
  400. </span>
  401. </el-form-item>
  402. <el-form-item
  403. label="确认密码"
  404. prop="confirmPassword"
  405. v-if="AccountFormType == 'add'"
  406. >
  407. <el-input
  408. v-model="AccountForm.confirmPassword"
  409. ref="password2"
  410. autocomplete="off"
  411. placeholder="请再次输入密码"
  412. :type="passwordType2"
  413. ></el-input>
  414. <span class="show-pwd" @click="showPwd(2)">
  415. <svg-icon
  416. :icon-class="passwordType2 === 'password' ? 'eye' : 'eye-open'"
  417. />
  418. </span>
  419. </el-form-item>
  420. <el-form-item label="可用仓库" prop="correspondIds">
  421. <el-select
  422. multiple
  423. v-model="AccountForm.correspondIds"
  424. placeholder="请选择可用仓库"
  425. style="width: 100%"
  426. filterable
  427. >
  428. <el-option
  429. :label="item.name"
  430. :value="item.id"
  431. v-for="(item, index) in stockList"
  432. :key="index"
  433. ></el-option>
  434. </el-select>
  435. </el-form-item>
  436. <el-form-item label="物料分类" prop="k3CategoryIds">
  437. <el-select
  438. multiple
  439. v-model="AccountForm.k3CategoryIds"
  440. placeholder="请选择物料分类"
  441. style="width: 100%"
  442. filterable
  443. >
  444. <el-option
  445. :label="item.name"
  446. :value="item.id"
  447. v-for="(item, index) in categoryList"
  448. :key="index"
  449. ></el-option>
  450. </el-select>
  451. </el-form-item>
  452. </el-form>
  453. <div slot="footer" class="dialog-footer">
  454. <el-button @click="cancelAccountForm">取 消</el-button>
  455. <el-button type="primary" @click="submitAccountForm">确 定</el-button>
  456. </div>
  457. </el-dialog>
  458. <!-- 重置密码 -->
  459. <el-dialog
  460. title="重置密码"
  461. :visible.sync="resetFormVisible"
  462. :show-close="false"
  463. width="40%"
  464. :close-on-click-modal="false"
  465. >
  466. <el-form
  467. ref="resetForm"
  468. :model="resetForm"
  469. :rules="resetFormRules"
  470. label-position="left"
  471. label-width="100px"
  472. >
  473. <el-form-item label="输入新密码" prop="newPassword">
  474. <el-input
  475. v-model="resetForm.newPassword"
  476. ref="password1"
  477. autocomplete="off"
  478. placeholder="请输入新密码"
  479. :type="passwordType1"
  480. ></el-input>
  481. <span class="show-pwd" @click="showPwd(1)">
  482. <svg-icon
  483. :icon-class="passwordType1 === 'password' ? 'eye' : 'eye-open'"
  484. />
  485. </span>
  486. </el-form-item>
  487. <el-form-item label="确认密码" prop="confirmPassword">
  488. <el-input
  489. v-model="resetForm.confirmPassword"
  490. ref="password2"
  491. autocomplete="off"
  492. placeholder="请再次输入新密码"
  493. :type="passwordType2"
  494. ></el-input>
  495. <span class="show-pwd" @click="showPwd(2)">
  496. <svg-icon
  497. :icon-class="passwordType2 === 'password' ? 'eye' : 'eye-open'"
  498. />
  499. </span>
  500. </el-form-item>
  501. </el-form>
  502. <div slot="footer" class="dialog-footer">
  503. <el-button @click="cancelResetForm">取 消</el-button>
  504. <el-button type="primary" @click="submitResetForm">确 定</el-button>
  505. </div>
  506. </el-dialog>
  507. </div>
  508. </template>
  509. <script>
  510. import {
  511. getStockListStock,
  512. getDepartmentList,
  513. getAccountList,
  514. addAccount,
  515. editAccount,
  516. deleteAccount,
  517. getAccountDetail,
  518. getRoleList,
  519. getMerchantList,
  520. changeAccountStatus,
  521. resetPassword,
  522. } from "@/api/setting";
  523. import { getDealerList, getCategoryList } from "@/api/common";
  524. import { findElem, downloadFiles, handleImportTwo } from "@/utils/util";
  525. export default {
  526. data() {
  527. var validatePass = (rule, value, callback) => {
  528. if (value === "") {
  529. callback(new Error("请输入新密码"));
  530. } else if (value && value.length < 6) {
  531. callback(new Error("密码长度至少6位"));
  532. } else {
  533. if (this.resetForm.confirmPassword !== "") {
  534. this.$refs.resetForm.validateField("confirmPassword");
  535. }
  536. callback();
  537. }
  538. };
  539. var validatePass2 = (rule, value, callback) => {
  540. if (value === "") {
  541. callback(new Error("请再次输入密码"));
  542. } else if (value !== this.resetForm.newPassword) {
  543. callback(new Error("两次输入密码不一致"));
  544. } else {
  545. callback();
  546. }
  547. };
  548. var validatePass3 = (rule, value, callback) => {
  549. if (value === "") {
  550. callback(new Error("请输入新密码"));
  551. } else if (value && value.length < 6) {
  552. callback(new Error("密码长度至少6位"));
  553. } else {
  554. if (this.AccountForm.confirmPassword !== "") {
  555. this.$refs.AccountForm.validateField("confirmPassword");
  556. }
  557. callback();
  558. }
  559. };
  560. var validatePass4 = (rule, value, callback) => {
  561. if (value === "") {
  562. callback(new Error("请再次输入密码"));
  563. } else if (value !== this.AccountForm.newPassword) {
  564. callback(new Error("两次输入密码不一致"));
  565. } else {
  566. callback();
  567. }
  568. };
  569. return {
  570. stockList: [], //仓库列表
  571. baseURL: process.env.VUE_APP_BASE_API,
  572. dataList: null, // 列表数据
  573. moduleList: null, // 模块列表
  574. listLoading: true, // 列表加载loading
  575. screenForm: {
  576. // 筛选表单数据
  577. name: "", // 名称
  578. roleId: "",
  579. },
  580. currentPage: 1, // 当前页码
  581. pageSize: 10, // 每页数量
  582. listTotal: 0, // 列表总数
  583. selectDepartment: null, // 选中的部门
  584. AccountFormType: "add",
  585. AccountFormVisible: false,
  586. AccountForm: {
  587. account: "", // 账号
  588. nickName: "", // 用户名
  589. merchant: "", // 商户
  590. dealer: "", //经销商
  591. role: "", // 角色组
  592. correspondIds: [], //仓库
  593. isGroup: false,
  594. company: "",
  595. isDiscount: true,
  596. newPassword: "", // 新密码
  597. confirmPassword: "", // 确认密码
  598. k3CategoryIds: [],
  599. },
  600. AccountFormRules: {
  601. account: [{ required: true, message: "请输入账号", trigger: "blur" }],
  602. nickName: [
  603. { required: true, message: "请输入用户名", trigger: "blur" },
  604. ],
  605. role: [{ required: true, message: "请选择角色组", trigger: "change" }],
  606. correspondIds: [
  607. { required: true, message: "请选择可用仓库", trigger: "change" },
  608. ],
  609. k3CategoryIds: [
  610. { required: true, message: "请选择物料分类", trigger: "change" },
  611. ],
  612. newPassword: [
  613. { required: true, validator: validatePass3, trigger: "blur" },
  614. ],
  615. confirmPassword: [
  616. { required: true, validator: validatePass4, trigger: "blur" },
  617. ],
  618. },
  619. editAccountId: null,
  620. categoryList: [],
  621. filterText: "",
  622. departmentList: [],
  623. defaultProps: {
  624. children: "children",
  625. label: "name",
  626. },
  627. props: {
  628. multiple: true,
  629. value: "adminWebsitId",
  630. label: "name",
  631. children: "children",
  632. },
  633. tableSelection: [],
  634. importLoading: false, // 导入加载loading
  635. importFileList: [], // 导入列表
  636. resetId: null,
  637. resetFormVisible: false,
  638. resetForm: {
  639. newPassword: "", // 新密码
  640. confirmPassword: "", // 确认密码
  641. },
  642. resetFormRules: {
  643. newPassword: [
  644. { required: true, validator: validatePass, trigger: "blur" },
  645. ],
  646. confirmPassword: [
  647. { required: true, validator: validatePass2, trigger: "blur" },
  648. ],
  649. },
  650. roleList: [], // 角色列表
  651. roleObj: {}, // 选中的角色
  652. merchantList: [],
  653. dealerList: [],
  654. passwordType1: "password",
  655. passwordType2: "password",
  656. };
  657. },
  658. computed: {
  659. exParams() {
  660. return {
  661. userName: this.screenForm.name,
  662. };
  663. },
  664. },
  665. watch: {
  666. filterText(val) {
  667. this.$refs.listTree.filter(val);
  668. },
  669. "AccountForm.role"() {
  670. if (this.AccountForm.role) {
  671. let index = findElem(
  672. this.roleList,
  673. "adminRoleId",
  674. this.AccountForm.role
  675. );
  676. this.roleObj = this.roleList[index];
  677. }
  678. },
  679. },
  680. async created() {
  681. this.getTree();
  682. this.getList();
  683. this.getStockList();
  684. await this.getRoleList();
  685. },
  686. methods: {
  687. //获取仓库仓位对应关系列表
  688. async getStockList() {
  689. let res = await getStockListStock({ pageSize: -1, pageNum: 1 });
  690. this.stockList = res.data.records;
  691. },
  692. // 查询按钮权限
  693. checkBtnRole(value) {
  694. // let btnRole = this.$route.meta.roles;
  695. // if(!btnRole) {return true}
  696. // let index = btnRole.indexOf(value);
  697. // return index >= 0 ? true : false;
  698. return true;
  699. },
  700. // 获取角色列表
  701. async getRoleList() {
  702. const result = await new Promise((resolve, reject) => {
  703. getRoleList({ pageNum: 1, pageSize: -1 })
  704. .then((res) => {
  705. this.roleList = res.data.records;
  706. resolve(res.data);
  707. })
  708. .catch((res) => {
  709. resolve([]);
  710. });
  711. });
  712. return result;
  713. },
  714. // 获取金蝶品类
  715. async getCategoryList() {
  716. const result = await new Promise((resolve, reject) => {
  717. getCategoryList({ pageNum: 1, pageSize: -1 })
  718. .then((res) => {
  719. this.categoryList = res.data.records;
  720. resolve(res.data);
  721. })
  722. .catch((res) => {
  723. resolve([]);
  724. });
  725. });
  726. return result;
  727. },
  728. // 获取商户列表
  729. async getMerchantList() {
  730. const result = await new Promise((resolve, reject) => {
  731. getMerchantList({
  732. pageNum: 1,
  733. pageSize: -1,
  734. })
  735. .then((res) => {
  736. this.merchantList = res.data.records;
  737. resolve(res.data.records);
  738. })
  739. .catch((res) => {
  740. resolve([]);
  741. });
  742. });
  743. return result;
  744. },
  745. // 获取经销商列表
  746. async getDealerList() {
  747. const result = await new Promise((resolve, reject) => {
  748. getDealerList({
  749. pageNum: 1,
  750. pageSize: -1,
  751. bindUser: false,
  752. })
  753. .then((res) => {
  754. this.dealerList = res.data.records;
  755. resolve(res.data.records);
  756. })
  757. .catch((res) => {
  758. resolve([]);
  759. });
  760. });
  761. return result;
  762. },
  763. // 获取部门列表
  764. getTree() {
  765. getDepartmentList().then((res) => {
  766. this.departmentList = res.data;
  767. });
  768. },
  769. // 获取账号列表
  770. getList() {
  771. this.listLoading = true;
  772. let params = {
  773. pageNum: this.currentPage,
  774. pageSize: this.pageSize,
  775. adminWebsitId: this.selectDepartment
  776. ? this.selectDepartment.adminWebsitId
  777. : "",
  778. userName: this.screenForm.name,
  779. roleId: this.screenForm.roleId,
  780. };
  781. getAccountList(params).then((res) => {
  782. this.dataList = res.data.records;
  783. this.listTotal = res.data.total;
  784. this.listLoading = false;
  785. });
  786. },
  787. // 更改每页数量
  788. handleSizeChange(val) {
  789. this.pageSize = val;
  790. this.currentPage = 1;
  791. this.getList();
  792. },
  793. // 更改当前页
  794. handleCurrentChange(val) {
  795. this.currentPage = val;
  796. this.getList();
  797. },
  798. // 提交筛选表单
  799. submitScreenForm() {
  800. this.currentPage = 1;
  801. this.getList();
  802. },
  803. // 重置筛选表单
  804. resetScreenForm() {
  805. this.$refs.screenForm.resetFields();
  806. this.currentPage = 1;
  807. this.getList();
  808. },
  809. // 筛选部门
  810. filterNode(value, data) {
  811. if (!value) return true;
  812. return data.name.indexOf(value) !== -1;
  813. },
  814. // 选择部门
  815. handleNodeClick(data) {
  816. console.log(data);
  817. if (
  818. this.selectDepartment &&
  819. data.adminWebsitId === this.selectDepartment.adminWebsitId
  820. ) {
  821. this.$refs.listTree.setCurrentKey(null);
  822. this.selectDepartment = null;
  823. } else {
  824. this.selectDepartment = data;
  825. }
  826. this.getList();
  827. },
  828. // 刷新部门
  829. refreshDepartment() {
  830. this.$refs.listTree.setCurrentKey(null);
  831. this.selectDepartment = null;
  832. this.getTree();
  833. this.getList();
  834. },
  835. // 打开 新增编辑 账号表单
  836. async openAccountForm(type, id) {
  837. this.AccountFormType = type;
  838. this.AccountFormVisible = true;
  839. await this.getMerchantList();
  840. await this.getDealerList();
  841. await this.getRoleList();
  842. await this.getCategoryList();
  843. if (type == "add") {
  844. if (this.selectDepartment) {
  845. this.$refs.tree.setCheckedKeys([this.selectDepartment.adminWebsitId]);
  846. }
  847. }
  848. if (type == "edit") {
  849. this.editAccountId = id;
  850. getAccountDetail({ adminUserId: id }).then((res) => {
  851. console.log(res, 78787);
  852. this.AccountForm.account = res.data.userName;
  853. this.AccountForm.role = res.data.roleId;
  854. this.AccountForm.nickName = res.data.nickName;
  855. this.AccountForm.merchant = res.data.companyWechatId;
  856. this.AccountForm.dealer = res.data.customerId;
  857. this.AccountForm.isGroup = res.data.isGroupCompany;
  858. this.AccountForm.company = res.data.parentCustomerId;
  859. this.AccountForm.isDiscount = res.data.isZr;
  860. this.AccountForm.correspondIds = res.data.stockCorrespondList;
  861. this.AccountForm.k3CategoryIds = res.data.k3CategoryList;
  862. this.$refs.tree.setCheckedKeys(res.data.adminWebsitIds || []);
  863. });
  864. }
  865. },
  866. // 取消 新增编辑 账号表单
  867. cancelAccountForm() {
  868. this.AccountFormVisible = false;
  869. this.$refs.AccountForm.resetFields();
  870. this.passwordType1 = "password";
  871. this.passwordType2 = "password";
  872. },
  873. // 提交 账号表单
  874. submitAccountForm() {
  875. console.log(this.AccountForm.correspondIds);
  876. this.$refs.AccountForm.validate((valid) => {
  877. if (valid) {
  878. const categoryIds = [];
  879. this.categoryList.map((k) => {
  880. this.AccountForm.k3CategoryIds.map((i) => {
  881. if (i == k.id) {
  882. categoryIds.push({
  883. k3CategoryId: k.id,
  884. k3CategoryName: k.name,
  885. k3CategoryNumber: k.number,
  886. });
  887. }
  888. });
  889. });
  890. let params = {
  891. userName: this.AccountForm.account,
  892. nickName: this.AccountForm.nickName,
  893. roleId: this.AccountForm.role,
  894. password: this.AccountForm.newPassword,
  895. correspondIds: this.AccountForm.correspondIds,
  896. categoryIds,
  897. };
  898. if (this.roleObj.type === 0) {
  899. params.adminWebsitIds = this.$refs.tree.getCheckedKeys();
  900. if (this.roleObj.name === "经销商") {
  901. params.customerId = this.AccountForm.dealer;
  902. params.isGroupCompany = this.AccountForm.isGroup;
  903. params.parentCustomerId = this.AccountForm.company;
  904. params.isZr = this.AccountForm.isDiscount;
  905. }
  906. } else {
  907. params.adminCompanyId = this.AccountForm.merchant;
  908. }
  909. if (this.AccountFormType == "edit") {
  910. params.adminUserId = this.editAccountId;
  911. editAccount(params).then((res) => {
  912. this.cancelAccountForm();
  913. this.getList();
  914. this.$successMsg("编辑成功");
  915. });
  916. } else {
  917. addAccount(params).then((res) => {
  918. this.cancelAccountForm();
  919. this.getList();
  920. this.$successMsg("添加成功");
  921. });
  922. }
  923. }
  924. });
  925. },
  926. // 表格选择列
  927. handleTableSelection(val) {
  928. this.tableSelection = val;
  929. },
  930. // 批量删除账号
  931. batchDeleteAccount() {
  932. if (this.tableSelection.length < 1) {
  933. return this.$errorMsg("至少选择一名账号");
  934. }
  935. this.$confirm(`确定删除选中的账号吗?`, "提示", {
  936. confirmButtonText: "确定",
  937. cancelButtonText: "取消",
  938. type: "warning",
  939. })
  940. .then(() => {
  941. let AccountIds = [];
  942. this.tableSelection.forEach((item) => {
  943. AccountIds.push(item.id);
  944. });
  945. deleteAccount({ id: AccountIds.join(",") }).then((res) => {
  946. this.$successMsg();
  947. this.getTree();
  948. this.getList();
  949. });
  950. })
  951. .catch(() => {});
  952. },
  953. // 删除账号
  954. deleteAccount(id) {
  955. deleteAccount({ id: id }).then((res) => {
  956. this.$successMsg();
  957. this.getTree();
  958. this.getList();
  959. });
  960. },
  961. // 操作 - 更改状态(type: 禁用0,启用1)
  962. changeStatus(id, type) {
  963. type = type ? true : false;
  964. changeAccountStatus({ adminUserId: id, status: type }).then((res) => {
  965. this.getList();
  966. this.$successMsg();
  967. });
  968. },
  969. // 显示隐藏密码
  970. showPwd(num) {
  971. if (num == 1) {
  972. if (this.passwordType1 === "password") {
  973. this.passwordType1 = "";
  974. } else {
  975. this.passwordType1 = "password";
  976. }
  977. this.$nextTick(() => {
  978. this.$refs.password1.focus();
  979. });
  980. }
  981. if (num == 2) {
  982. if (this.passwordType2 === "password") {
  983. this.passwordType2 = "";
  984. } else {
  985. this.passwordType2 = "password";
  986. }
  987. this.$nextTick(() => {
  988. this.$refs.password2.focus();
  989. });
  990. }
  991. },
  992. // 重置密码
  993. handleReset(id) {
  994. this.resetId = id;
  995. this.resetFormVisible = true;
  996. },
  997. // 取消重置密码
  998. cancelResetForm() {
  999. this.resetFormVisible = false;
  1000. this.passwordType1 = "password";
  1001. this.passwordType2 = "password";
  1002. this.$refs.resetForm.resetFields();
  1003. },
  1004. // 提交重置密码
  1005. submitResetForm() {
  1006. this.$refs.resetForm.validate((valid) => {
  1007. if (valid) {
  1008. let params = {
  1009. password: this.resetForm.newPassword,
  1010. adminUserId: this.resetId,
  1011. };
  1012. resetPassword(params).then((res) => {
  1013. this.cancelResetForm();
  1014. this.getList();
  1015. this.$successMsg();
  1016. });
  1017. }
  1018. });
  1019. },
  1020. // 导出
  1021. handleExport() {
  1022. let screenData = {
  1023. adminWebsitId: this.selectDepartment
  1024. ? this.selectDepartment.websitId
  1025. : "",
  1026. keyword: this.screenForm.name,
  1027. };
  1028. downloadFiles("wechat/enterprise/export", screenData);
  1029. },
  1030. // 下载导入模版
  1031. handleDownload() {
  1032. downloadFiles("/admin/user/download");
  1033. },
  1034. clickImport() {
  1035. if (!this.selectDepartment) {
  1036. return this.$errorMsg("请选择部门");
  1037. } else {
  1038. document.querySelector(".import-btn input").click();
  1039. }
  1040. },
  1041. // 导入
  1042. async handleImport(param) {
  1043. console.log(param);
  1044. this.importLoading = true;
  1045. const file = param.file;
  1046. const formData = new FormData();
  1047. formData.append("file", file);
  1048. let result = await handleImportTwo("/admin/user/importUser", formData);
  1049. this.importLoading = false;
  1050. this.importFileList = [];
  1051. // console.log(result,999);
  1052. if (result) {
  1053. this.$alert(result.message, "导入成功", {
  1054. confirmButtonText: "确定",
  1055. });
  1056. let blob = new Blob([result], {
  1057. type: "application/vnd.ms-excel,charset=utf-8",
  1058. });
  1059. let urll = window.URL.createObjectURL(blob);
  1060. let link = document.createElement("a");
  1061. link.download = "导入失败数据.xlsx";
  1062. link.href = urll;
  1063. link.click();
  1064. this.getList();
  1065. } else {
  1066. this.$alert(result.message, "导入失败", {
  1067. confirmButtonText: "确定",
  1068. });
  1069. }
  1070. },
  1071. },
  1072. };
  1073. </script>
  1074. <style scoped lang="scss">
  1075. .import-btn {
  1076. display: inline-block;
  1077. margin-left: 10px;
  1078. }
  1079. .app-container {
  1080. display: flex;
  1081. .tree-container {
  1082. width: 18%;
  1083. height: calc(100vh - 110px);
  1084. flex-shrink: 0;
  1085. background: #f5f5f5;
  1086. margin-right: 2%;
  1087. display: flex;
  1088. flex-direction: column;
  1089. overflow-y: hidden;
  1090. .el-tree {
  1091. height: 100%;
  1092. background: none;
  1093. width: 100%;
  1094. overflow: scroll;
  1095. // ::v-deep .el-tree-node:focus > .el-tree-node__content {
  1096. // color: #ffffff;
  1097. // background-color: #409EFF;
  1098. // }
  1099. ::v-deep > .el-tree-node {
  1100. display: inline-block;
  1101. min-width: 100%;
  1102. }
  1103. ::v-deep .el-tree-node > .el-tree-node__content {
  1104. padding-right: 10px;
  1105. align-self: baseline;
  1106. }
  1107. ::v-deep .el-tree-node.is-current > .el-tree-node__content {
  1108. background-color: #409eff;
  1109. .custom-tree-node {
  1110. i {
  1111. color: #fff;
  1112. }
  1113. span {
  1114. color: #fff;
  1115. }
  1116. }
  1117. }
  1118. ::v-deep .el-tree-node > .el-tree-node__children {
  1119. overflow: unset;
  1120. }
  1121. .custom-tree-node {
  1122. i {
  1123. font-size: 14px;
  1124. color: #999;
  1125. }
  1126. span {
  1127. font-size: 14px;
  1128. margin-left: 6px;
  1129. color: #666;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. .mymain-container {
  1135. width: 80%;
  1136. margin-top: 0;
  1137. }
  1138. }
  1139. ::v-deep .el-divider--vertical {
  1140. margin: 0 15px;
  1141. }
  1142. .show-pwd {
  1143. position: absolute;
  1144. right: 15px;
  1145. top: 0;
  1146. font-size: 16px;
  1147. cursor: pointer;
  1148. user-select: none;
  1149. }
  1150. </style>