index.vue 12 KB

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