index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <div>
  3. <el-row v-if="isShow">
  4. <el-col :span="5">
  5. <basic-container>
  6. <avue-tree
  7. :option="treeOption"
  8. :data="treeData"
  9. @node-click="nodeClick"
  10. />
  11. </basic-container>
  12. </el-col>
  13. <el-col :span="19">
  14. <basic-container>
  15. <avue-crud
  16. :option="option"
  17. :search.sync="search"
  18. :table-loading="loading"
  19. :data="data"
  20. ref="crud"
  21. v-model="form"
  22. @row-del="rowDel"
  23. @row-update="rowUpdate"
  24. @row-save="rowSave"
  25. :before-open="beforeOpenE"
  26. :page.sync="page"
  27. @search-change="searchChange"
  28. @search-reset="searchReset"
  29. @selection-change="selectionChange"
  30. @current-change="currentChange"
  31. @size-change="sizeChange"
  32. @refresh-change="refreshChange"
  33. @on-load="onLoad"
  34. >
  35. <template slot="menuLeft">
  36. <el-button
  37. type="primary"
  38. size="small"
  39. icon="el-icon-bottom"
  40. @click="excelBox = true"
  41. >导入
  42. </el-button>
  43. <el-button
  44. icon="el-icon-printer"
  45. size="small"
  46. type="primary"
  47. @click.stop="openReport()"
  48. >报表打印
  49. </el-button>
  50. <el-button
  51. type="warning"
  52. size="small"
  53. :disabled="selectionList.length == 0"
  54. icon="el-icon-delete"
  55. @click="batchDelete"
  56. >批量删除
  57. </el-button>
  58. </template>
  59. <template slot-scope="scope" slot="corpId">
  60. <span>{{ scope.row.corpName }}</span>
  61. </template>
  62. <template slot-scope="scope" slot="menu">
  63. <!-- <el-button-->
  64. <!-- type="text"-->
  65. <!-- icon="el-icon-view"-->
  66. <!-- size="small"-->
  67. <!-- @click.stop="beforeOpenPage(scope.row, scope.index)"-->
  68. <!-- >查看-->
  69. <!-- </el-button>-->
  70. <el-button
  71. type="text"
  72. icon="el-icon-edit"
  73. size="small"
  74. @click.stop="editOpen(scope.row, scope.index)"
  75. >编辑
  76. </el-button>
  77. <el-button
  78. type="text"
  79. icon="el-icon-delete"
  80. size="small"
  81. @click.stop="rowDel(scope.row, scope.index)"
  82. >删除
  83. </el-button>
  84. <!-- <el-button-->
  85. <!-- type="text"-->
  86. <!-- icon="el-icon-delete"-->
  87. <!-- size="small"-->
  88. <!-- >下架-->
  89. <!-- </el-button>-->
  90. </template>
  91. <template slot="cnameIntSearch">
  92. <el-input
  93. placeholder="请输入 产品名称"
  94. size="small"
  95. v-model="search.cnameInt"
  96. ></el-input>
  97. </template>
  98. </avue-crud>
  99. <el-dialog
  100. title="导入产品"
  101. append-to-body
  102. :visible.sync="excelBox"
  103. :close-on-click-modal="false"
  104. width="555px"
  105. >
  106. <avue-form
  107. :option="excelOption"
  108. v-model="excelForm"
  109. :upload-after="uploadAfter"
  110. >
  111. <template slot="excelTemplate">
  112. <el-button type="primary" @click="derivation">
  113. 点击下载<i class="el-icon-download el-icon--right"></i>
  114. </el-button>
  115. </template>
  116. </avue-form>
  117. <p style="text-align: center;color: #DC0505">
  118. 温馨提示 第一次导入时请先下载模板
  119. </p>
  120. </el-dialog>
  121. </basic-container>
  122. </el-col>
  123. <report-dialog
  124. :switchDialog="switchDialog"
  125. @onClose="onClose()"
  126. ></report-dialog>
  127. </el-row>
  128. <detail-page
  129. ref="detail"
  130. @goBack="goBack"
  131. :detailData="detailData"
  132. v-else
  133. ></detail-page>
  134. </div>
  135. </template>
  136. <script>
  137. import {
  138. getList,
  139. getUser,
  140. getUserPlatform,
  141. remove,
  142. updatePlatform,
  143. add,
  144. grant,
  145. getDeptLazyTree,
  146. getDeptTree
  147. } from "@/api/basicData/commodityType";
  148. import { getRoleTree } from "@/api/system/role";
  149. import { mapGetters } from "vuex";
  150. import website from "@/config/website";
  151. import { getToken } from "@/util/auth";
  152. import option from "./configuration/mainList.json";
  153. import detailPage from "./detailsPageEdit";
  154. import reportDialog from "@/components/report-dialog/main";
  155. export default {
  156. components: {
  157. reportDialog,
  158. detailPage
  159. },
  160. data() {
  161. return {
  162. form: {},
  163. search: {},
  164. switchDialog: false,
  165. roleBox: false,
  166. excelBox: false,
  167. platformBox: false,
  168. initFlag: true,
  169. selectionList: [],
  170. query: {},
  171. loading: true,
  172. platformLoading: false,
  173. page: {
  174. pageSize: 10,
  175. currentPage: 1,
  176. total: 0
  177. },
  178. platformPage: {
  179. pageSize: 10,
  180. currentPage: 1,
  181. total: 0
  182. },
  183. init: {
  184. roleTree: [],
  185. deptTree: []
  186. },
  187. props: {
  188. label: "title",
  189. value: "key"
  190. },
  191. roleGrantList: [],
  192. roleTreeObj: [],
  193. treeDeptId: "",
  194. treeData: [],
  195. treeOption: {
  196. nodeKey: "id",
  197. lazy: true,
  198. treeLoad: function(node, resolve) {
  199. const parentId = node.level === 0 ? 0 : node.data.id;
  200. getDeptLazyTree(parentId).then(res => {
  201. resolve(
  202. res.data.data.map(item => {
  203. return {
  204. ...item,
  205. leaf: !item.hasChildren
  206. };
  207. })
  208. );
  209. });
  210. },
  211. addBtn: false,
  212. menu: false,
  213. size: "small",
  214. props: {
  215. labelText: "标题",
  216. label: "title",
  217. value: "value",
  218. children: "children"
  219. }
  220. },
  221. option: option,
  222. data: [],
  223. platformQuery: {},
  224. platformSelectionList: [],
  225. platformData: [],
  226. platformForm: {},
  227. excelForm: {},
  228. excelOption: {
  229. submitBtn: false,
  230. emptyBtn: false,
  231. column: [
  232. {
  233. label: "模板下载",
  234. prop: "excelTemplate",
  235. formslot: true,
  236. span: 24
  237. },
  238. {
  239. label: "模板上传",
  240. prop: "excelFile",
  241. type: "upload",
  242. drag: true,
  243. loadText: "模板上传中,请稍等",
  244. span: 24,
  245. propsHttp: {
  246. res: "data"
  247. },
  248. tip: "请上传 .xls,.xlsx 标准格式文件",
  249. action: "/api/blade-client/goodsdesc/import-desc-info"
  250. }
  251. ]
  252. },
  253. isShow: true,
  254. detailData: {}
  255. };
  256. },
  257. mounted() {
  258. option.height = window.innerHeight - 255;
  259. },
  260. methods: {
  261. derivation() {
  262. window.open(
  263. `/api/blade-client/goodsdesc/export-template-info?${
  264. this.website.tokenHeader
  265. }=${getToken()}`
  266. );
  267. },
  268. uploadAfter(res, done, loading, column) {
  269. window.console.log(column);
  270. this.excelBox = false;
  271. this.refreshChange();
  272. done();
  273. },
  274. nodeClick(data) {
  275. this.treeDeptId = data.id;
  276. this.page.currentPage = 1;
  277. this.onLoad(this.page);
  278. },
  279. initData(tenantId) {
  280. getDeptTree().then(res => {
  281. const column = this.findObject(this.option.column, "goodsTypeId");
  282. column.dicData = res.data.data;
  283. });
  284. },
  285. submitRole() {
  286. const roleList = this.$refs.treeRole.getCheckedKeys().join(",");
  287. grant(this.ids, roleList).then(() => {
  288. this.roleBox = false;
  289. this.$message({
  290. type: "success",
  291. message: "操作成功!"
  292. });
  293. this.onLoad(this.page);
  294. });
  295. },
  296. rowSave(row, done, loading) {
  297. row.goodsTypeId = row.goodsTypeId.join(",");
  298. add(row).then(
  299. () => {
  300. this.initFlag = false;
  301. this.onLoad(this.page);
  302. this.$message({
  303. type: "success",
  304. message: "操作成功!"
  305. });
  306. done();
  307. },
  308. error => {
  309. window.console.log(error);
  310. loading();
  311. }
  312. );
  313. },
  314. rowUpdate(row, index, done, loading) {
  315. row.goodsTypeId = row.goodsTypeId.join(",");
  316. add(row).then(
  317. () => {
  318. this.initFlag = false;
  319. this.onLoad(this.page);
  320. this.$message({
  321. type: "success",
  322. message: "操作成功!"
  323. });
  324. done();
  325. },
  326. error => {
  327. window.console.log(error);
  328. loading();
  329. }
  330. );
  331. },
  332. //批量删除
  333. batchDelete() {
  334. this.$confirm("确定批量删除数据?", {
  335. confirmButtonText: "确定",
  336. cancelButtonText: "取消",
  337. type: "warning"
  338. }).then(() => {
  339. let batchDeleteList = this.selectionList.map(item => {
  340. return item.id;
  341. });
  342. remove(batchDeleteList.join(",")).then(res => {
  343. if (res.data.success) {
  344. this.$message.success("删除成功!");
  345. this.refreshChange();
  346. }
  347. });
  348. });
  349. },
  350. //查看跳转页面
  351. beforeOpenPage(row, index) {
  352. this.detailData = {
  353. id: row.id,
  354. seeDisabled: true
  355. };
  356. this.isShow = false;
  357. },
  358. //新增跳转页面
  359. beforeOpenE(row, index) {
  360. this.detailData = {
  361. goodsTypeId: this.treeDeptId
  362. };
  363. this.isShow = false;
  364. },
  365. //编辑跳转页面
  366. editOpen(row, index) {
  367. this.detailData = {
  368. id: row.id
  369. };
  370. this.isShow = false;
  371. },
  372. //删除触发
  373. rowDel(row, index, done) {
  374. this.$confirm("确定将选择数据删除?", {
  375. confirmButtonText: "确定",
  376. cancelButtonText: "取消",
  377. type: "warning"
  378. })
  379. .then(() => {
  380. return remove(row.id);
  381. })
  382. .then(() => {
  383. this.onLoad(this.page);
  384. this.$message({
  385. type: "success",
  386. message: "操作成功!"
  387. });
  388. done();
  389. });
  390. },
  391. searchReset() {
  392. this.query = {};
  393. this.treeDeptId = "";
  394. this.onLoad(this.page);
  395. },
  396. searchChange(params, done) {
  397. this.query = params;
  398. this.page.currentPage = 1;
  399. this.onLoad(this.page, params);
  400. done();
  401. },
  402. selectionChange(list) {
  403. this.selectionList = list;
  404. },
  405. selectionClear() {
  406. this.selectionList = [];
  407. this.$refs.crud.toggleSelection();
  408. },
  409. handleGrant() {
  410. if (this.selectionList.length === 0) {
  411. this.$message.warning("请选择至少一条数据");
  412. return;
  413. }
  414. this.roleTreeObj = [];
  415. if (this.selectionList.length === 1) {
  416. this.roleTreeObj = this.selectionList[0].roleId.split(",");
  417. }
  418. getRoleTree().then(res => {
  419. this.roleGrantList = res.data.data;
  420. this.roleBox = true;
  421. });
  422. },
  423. handlePlatform() {
  424. this.platformBox = true;
  425. },
  426. handleImport() {
  427. this.excelBox = true;
  428. },
  429. handleTemplate() {
  430. window.open(
  431. `/api/blade-user/export-template?${
  432. this.website.tokenHeader
  433. }=${getToken()}`
  434. );
  435. },
  436. //新增编辑查看触发
  437. async beforeOpen(done, type) {
  438. if (["add"].includes(type)) {
  439. this.option.column.forEach(e => {
  440. if (e.prop == "goodsTypeId") {
  441. this.$set(this.option.column, 2, { ...e, value: this.treeDeptId });
  442. }
  443. });
  444. }
  445. if (["edit", "view"].includes(type)) {
  446. await getUser(this.form.id).then(res => {
  447. this.form = res.data.data;
  448. // this.form.goodsTypeId = [this.form.goodsTypeId.replace(/\"/g,"")]
  449. console.log(this.form.hasOwnProperty("goodsTypeId"));
  450. if (this.form.hasOwnProperty("goodsTypeId")) {
  451. this.form.goodsTypeId = this.form.goodsTypeId.split(",");
  452. }
  453. });
  454. }
  455. if (["add", "edit"].includes(type)) {
  456. this.initData(0);
  457. }
  458. this.initFlag = true;
  459. done();
  460. },
  461. currentChange(currentPage) {
  462. this.page.currentPage = currentPage;
  463. },
  464. sizeChange(pageSize) {
  465. this.page.pageSize = pageSize;
  466. },
  467. refreshChange() {
  468. this.onLoad(this.page, this.query);
  469. },
  470. onLoad(page, params = {}) {
  471. this.loading = true;
  472. getList(
  473. page.currentPage,
  474. page.pageSize,
  475. Object.assign(params, this.query),
  476. this.treeDeptId
  477. ).then(res => {
  478. const data = res.data.data;
  479. this.data = data.records;
  480. this.page.total = res.data.data.total;
  481. this.loading = false;
  482. this.selectionClear();
  483. });
  484. },
  485. platformRowUpdate(row, index, done, loading) {
  486. updatePlatform(row.id, row.userType, row.userExt).then(
  487. () => {
  488. this.platformOnLoad(this.platformPage);
  489. this.$message({
  490. type: "success",
  491. message: "操作成功!"
  492. });
  493. done();
  494. },
  495. error => {
  496. window.console.log(error);
  497. loading();
  498. }
  499. );
  500. },
  501. openReport() {
  502. this.switchDialog = !this.switchDialog;
  503. },
  504. onClose(val) {
  505. this.switchDialog = val;
  506. },
  507. platformBeforeOpen(done, type) {
  508. if (["edit", "view"].includes(type)) {
  509. getUserPlatform(this.platformForm.id).then(res => {
  510. this.platformForm = res.data.data;
  511. });
  512. }
  513. done();
  514. },
  515. platformSearchReset() {
  516. this.platformQuery = {};
  517. this.platformOnLoad(this.platformPage);
  518. },
  519. platformSearchChange(params, done) {
  520. this.platformQuery = params;
  521. this.platformPage.currentPage = 1;
  522. this.platformOnLoad(this.platformPage, params);
  523. done();
  524. },
  525. platformSelectionChange(list) {
  526. this.platformSelectionList = list;
  527. },
  528. platformSelectionClear() {
  529. this.platformSelectionList = [];
  530. this.$refs.platformCrud.toggleSelection();
  531. },
  532. platformCurrentChange(currentPage) {
  533. this.platformPage.currentPage = currentPage;
  534. },
  535. platformSizeChange(pageSize) {
  536. this.platformPage.pageSize = pageSize;
  537. },
  538. platformRefreshChange() {
  539. this.platformOnLoad(this.platformPage, this.platformQuery);
  540. },
  541. platformOnLoad(page, params = {}) {
  542. this.platformLoading = true;
  543. getList(
  544. page.currentPage,
  545. page.pageSize,
  546. Object.assign(params, this.query),
  547. this.treeDeptId
  548. ).then(res => {
  549. const data = res.data.data;
  550. this.platformPage.total = data.total;
  551. this.platformData = data.records;
  552. this.platformLoading = false;
  553. this.selectionClear();
  554. });
  555. },
  556. goBack() {
  557. this.detailData = this.$options.data().detailData;
  558. this.isShow = true;
  559. }
  560. }
  561. };
  562. </script>
  563. <style>
  564. .el-scrollbar {
  565. height: 100%;
  566. }
  567. </style>