account.vue 33 KB

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