account.vue 31 KB

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