account.vue 32 KB

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