account.vue 35 KB

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