index.vue 13 KB

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