account.vue 28 KB

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