index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <div>
  3. <basic-container>
  4. <el-row>
  5. <el-col :span="4">
  6. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick" style="height:73vh;"
  7. @save="corpTypeVisible = true">
  8. </avue-tree>
  9. </el-col>
  10. <el-col :span="20">
  11. <avue-crud :option="option" :search.sync="search" v-model="form" :table-loading="loading" :data="dataList"
  12. ref="crud" :key="key" @on-load="onLoad" @selection-change="selectionChange"
  13. :before-open="beforeOpen"
  14. @row-update="rowUpdate" @search-change="searchChange" @refresh-change="refreshChange"
  15. @row-del="rowDel"
  16. @resetColumn="resetColumnTwo('crud', 'option', 'optionList', 273)"
  17. @saveColumn="saveColumnTwo('crud', 'option', 'optionList', 273)" :page.sync="page">
  18. <template slot="filesListForm">
  19. <c-upload :data="form.filesList" display basic deleteUrl="/api/blade-sales-part/productLaunchFiles/remove"
  20. :enumerationValue="160"/>
  21. </template>
  22. <template slot="detailsTextForm">
  23. <avue-ueditor v-model="form.detailsText" :options="optionsUeditor"></avue-ueditor>
  24. </template>
  25. <template slot-scope="{type,size,row,index}" slot="menu">
  26. <el-button :size="size" :type="type" @click="$refs.crud.rowEdit(row, index)">编辑
  27. </el-button>
  28. <el-button :size="size" :type="type" @click="$refs.crud.rowDel(row, index)">删除
  29. </el-button>
  30. <el-tooltip :content="`${row.upAndDownShelves == 0?'上架':'下架'}`" placement="top">
  31. <el-switch
  32. style="margin-left: 10px"
  33. v-model="row.upAndDownShelves"
  34. @change="check(row)"
  35. :active-value="1"
  36. :inactive-value="0">
  37. </el-switch>
  38. </el-tooltip>
  39. </template>
  40. <template slot-scope="{type,size,row,$index}" slot="menuLeft">
  41. <el-button class="el-icon-document-copy" :disabled="selectionList.length === 0" type="primary"
  42. size="small"
  43. @click="change(row, 'up')">批量上架
  44. </el-button>
  45. <el-button class="el-icon-document-copy" :disabled="selectionList.length === 0" type="danger" size="small"
  46. @click="change(row, 'down')">批量下架
  47. </el-button>
  48. <el-button class="el-icon-bottom" type="warning" size="small" @click="excelBox = true">
  49. 导入
  50. </el-button>
  51. </template>
  52. </avue-crud>
  53. </el-col>
  54. </el-row>
  55. </basic-container>
  56. <el-dialog title="添加产品" append-to-body :visible.sync="excelBox" :close-on-click-modal="false" width="555px">
  57. <avue-form :option="excelOption" v-model="excelForm" :upload-after="uploadAfter">
  58. <template slot="excelTemplate">
  59. <el-button type="primary" @click="derivation">
  60. 点击下载<i class="el-icon-download el-icon--right"></i>
  61. </el-button>
  62. </template>
  63. </avue-form>
  64. <p style="text-align: center;color: #DC0505">
  65. 温馨提示 第一次导入时请先下载模板
  66. </p>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script>
  71. import {
  72. getList,
  73. submit,
  74. batchOperationProductLaunch,
  75. getDetail,
  76. listAll,
  77. remove
  78. } from "@/api/tirePartsMall/basicData/listingManagement/index.js";
  79. import {getToken} from "@/util/auth";
  80. export default {
  81. name: "index",
  82. data() {
  83. return {
  84. optionsUeditor: {
  85. //普通上传地址
  86. // action:'https://avuejs.com/imgupload',
  87. action: "/api/blade-resource/oss/endpoint/put-file",
  88. headers: {"Blade-Auth": "Bearer " + getToken()},
  89. props: {
  90. res: "data",
  91. url: 'link'
  92. }
  93. },
  94. excelForm: {},
  95. excelOption: {
  96. submitBtn: false,
  97. emptyBtn: false,
  98. column: [
  99. {
  100. label: "模板下载",
  101. prop: "excelTemplate",
  102. formslot: true,
  103. span: 24
  104. },
  105. {
  106. label: "模板上传",
  107. prop: "excelFile",
  108. type: "upload",
  109. drag: true,
  110. loadText: "模板上传中,请稍等",
  111. span: 24,
  112. propsHttp: {
  113. res: "data"
  114. },
  115. tip: "请上传 .xls,.xlsx 标准格式文件",
  116. action: "/api/blade-sales-part/productLaunch/import-productLaunch"
  117. }
  118. ]
  119. },
  120. treeOption: {
  121. addBtn: false,
  122. menu: false,
  123. size: "small",
  124. props: {
  125. labelText: "标题",
  126. label: "cname",
  127. value: "id",
  128. }
  129. },
  130. excelBox: false,
  131. corpTypeVisible: false,
  132. treeData: [],
  133. loading: false,
  134. search: {},
  135. form: {},
  136. dataList: [],
  137. selectionList: [],
  138. page: {
  139. pageSize: 20,
  140. currentPage: 1,
  141. total: 0,
  142. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  143. },
  144. key: 0,
  145. option: {},
  146. optionList: {
  147. viewBtn: false,
  148. editBtn: false,
  149. delBtn: false,
  150. addBtn: false,
  151. index: true,
  152. span: 8,
  153. border: true,
  154. selection: true,
  155. height: "auto",
  156. searchMenuPosition: "right",
  157. align: "center",
  158. menuWidth: 150,
  159. searchSpan: 8,
  160. searchIcon: true,
  161. searchIndex: 2,
  162. highlightCurrentRow: true,
  163. dialogWidth: "90%",
  164. column: [{
  165. label: '商品名称',
  166. prop: 'cname',
  167. search: true,
  168. disabled: true,
  169. overHidden: true,
  170. }, {
  171. label: '规格型号',
  172. prop: 'specificationAndModel',
  173. disabled: true,
  174. search: true,
  175. overHidden: true,
  176. }, {
  177. label: '公司',
  178. prop: 'salesCompanyId',
  179. disabled: true,
  180. overHidden: true,
  181. type: 'select',
  182. props: {
  183. label: 'fullName',
  184. value: 'id'
  185. },
  186. dicUrl: '/api/blade-system/dept/top-list'
  187. }, {
  188. label: '库存',
  189. prop: 'inventory',
  190. disabled: true,
  191. overHidden: true,
  192. }, {
  193. label: '产品状态',
  194. prop: 'upAndDownShelves',
  195. filterable: true,
  196. display: false,
  197. search: true,
  198. hide: true,
  199. disabled: true,
  200. showColumn: false,
  201. type: 'select',
  202. dicData: [{
  203. label: "上架",
  204. value: 1
  205. }, {
  206. label: "下架",
  207. value: 0
  208. }]
  209. }, {
  210. label: "品牌",
  211. prop: "brandName",
  212. disabled: true,
  213. overHidden: true,
  214. }, {
  215. label: "售价1",
  216. prop: "priceOne",
  217. hide: true,
  218. showColumn: false,
  219. overHidden: true,
  220. }, {
  221. label: "售价2",
  222. prop: "priceTwo",
  223. hide: true,
  224. showColumn: false,
  225. overHidden: true,
  226. }, {
  227. label: "售价3",
  228. prop: "priceThree",
  229. hide: true,
  230. showColumn: false,
  231. overHidden: true,
  232. }, {
  233. label: "售价4",
  234. prop: "priceFour",
  235. hide: true,
  236. showColumn: false,
  237. overHidden: true,
  238. }, {
  239. label: "共享公司",
  240. prop: "salesCompanyName",
  241. // searchProp: "sharedCompanyList",
  242. search: true,
  243. overHidden: true,
  244. multiple: true,
  245. tags: true,
  246. type: 'select',
  247. props: {
  248. label: 'fullName',
  249. value: 'id'
  250. },
  251. dicUrl: '/api/blade-system/dept/deptList'
  252. }, {
  253. label: "详情附件",
  254. prop: "filesList",
  255. hide: true,
  256. showColumn: false,
  257. overHidden: true,
  258. span: 24,
  259. }, {
  260. label: "商品详情",
  261. prop: "detailsText",
  262. hide: true,
  263. span: 24,
  264. showColumn: false,
  265. overHidden: true,
  266. }]
  267. }
  268. }
  269. },
  270. activated() {
  271. listAll().then(res=>{
  272. this.treeData = res.data.data
  273. })
  274. this.onLoad(this.page, this.search)
  275. },
  276. async created() {
  277. this.option = await this.getColumnData(this.getColumnName(273), this.optionList);
  278. this.key++
  279. let i = 0;
  280. this.option.column.forEach(item => {
  281. if (item.search) i++
  282. })
  283. if (i % 3 !== 0) {
  284. const num = 3 - Number(i % 3)
  285. this.option.searchMenuSpan = num * 8;
  286. this.option.searchMenuPosition = "right";
  287. }
  288. },
  289. methods: {
  290. derivation() {
  291. window.open(
  292. `/api/blade-sales-part/productLaunch/export-productLaunch?${this.website.tokenHeader
  293. }=${getToken()}`
  294. );
  295. },
  296. uploadAfter(res, done, loading, column) {
  297. this.excelBox = false;
  298. this.refreshChange();
  299. done();
  300. },
  301. nodeClick(data) {
  302. this.search.brandId = data.id
  303. this.page.currentPage = 1;
  304. this.onLoad(this.page, this.search);
  305. },
  306. //刷新
  307. refreshChange() {
  308. this.onLoad(this.page, this.search)
  309. },
  310. searchChange(params, done) {
  311. console.log(params);
  312. console.log(params.$salesCompanyName);
  313. // sharedCompanyList
  314. this.search.sharedCompanyList = params.salesCompanyName;
  315. Vue.delete(params, 'salesCompanyName');
  316. Vue.delete(this.search, 'salesCompanyName');
  317. done();
  318. this.onLoad(this.page, params)
  319. },
  320. selectionChange(list) {
  321. this.selectionList = list
  322. },
  323. //打开表单前
  324. beforeOpen(done, type) {
  325. // 查看和编辑逻辑
  326. if (['view', 'edit'].includes(type)) {
  327. getDetail({id: this.form.id}).then(res => {
  328. this.form = res.data.data
  329. done();
  330. })
  331. }
  332. },
  333. rowDel(row,index){
  334. this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
  335. confirmButtonText: '确定',
  336. cancelButtonText: '取消',
  337. type: 'warning'
  338. }).then(()=>{
  339. remove(row.id).then((res)=>{
  340. this.$message({
  341. type: 'success',
  342. message: '删除成功!'
  343. });
  344. this.dataList.splice(index, 1);
  345. this.onLoad(this.page)
  346. })
  347. })
  348. },
  349. //编辑确定
  350. rowUpdate(form, index, done, loading) {
  351. if (this.form.filesList.length > 0) {
  352. let flag = this.form.filesList.some(item => {
  353. return item.$version == '主图'
  354. })
  355. if (!flag) {
  356. this.$message.warning('请选择主图')
  357. done()
  358. return
  359. }
  360. }
  361. submit({
  362. ...this.form
  363. }).then(res => {
  364. this.$message.success("修改成功")
  365. this.onLoad(this.page, this.search)
  366. done()
  367. }).catch((err) => {
  368. loading()
  369. })
  370. // submit({
  371. // ...form
  372. // }).then(res => {
  373. // this.onLoad(this.page, this.search)
  374. // done()
  375. // }).catch(() => {
  376. // loading()
  377. // })
  378. },
  379. check(row) {
  380. batchOperationProductLaunch({
  381. flag: row.upAndDownShelves,
  382. ids: row.id
  383. }).then(res => {
  384. this.onLoad(this.page, this.search)
  385. })
  386. },
  387. change(row, type) {
  388. let data = []
  389. for (let item of this.selectionList) {
  390. data.push(item.id)
  391. }
  392. if (type === "up") {
  393. // for (let item of this.selectionList) {
  394. // if (!Number(item.salesPrice)) return this.$message.error("上架失败,商城价格不能为0")
  395. // }
  396. this.$confirm('是否确认全部上架?', '提示', {
  397. confirmButtonText: '确定',
  398. cancelButtonText: '取消',
  399. type: 'warning'
  400. }).then(() => {
  401. batchOperationProductLaunch({
  402. flag: 1,
  403. ids: data.join(",")
  404. }).then(res => {
  405. this.onLoad(this.page, this.search)
  406. })
  407. })
  408. } else if (type === "down") {
  409. this.$confirm('是否确认全部下架?', '提示', {
  410. confirmButtonText: '确定',
  411. cancelButtonText: '取消',
  412. type: 'warning'
  413. }).then(() => {
  414. batchOperationProductLaunch({
  415. flag: 0,
  416. ids: data.join(",")
  417. }).then(res => {
  418. this.onLoad(this.page, this.search)
  419. })
  420. })
  421. }
  422. },
  423. onLoad(page, params = {}) {
  424. console.log(this.search);
  425. params = {
  426. ...params,
  427. current: page.currentPage,
  428. size: page.pageSize,
  429. ...Object.assign(params, this.search),
  430. billType: 0
  431. }
  432. this.loading = true
  433. getList(params).then(res => {
  434. this.dataList = res.data.data.records
  435. this.page.total = res.data.data.total
  436. this.$nextTick(() => {
  437. this.$refs.crud.doLayout();
  438. });
  439. this.loading = false
  440. }).finally(() => {
  441. this.loading = false
  442. })
  443. },
  444. //自定义列保存
  445. async saveColumnTwo(ref, option, optionBack, code) {
  446. /**
  447. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  448. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  449. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  450. */
  451. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  452. if (inSave) {
  453. this.$message.success("保存成功");
  454. //关闭窗口
  455. this.$nextTick(() => {
  456. this.$refs.crud.doLayout();
  457. });
  458. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  459. }
  460. },
  461. //自定义列重置
  462. async resetColumnTwo(ref, option, optionBack, code) {
  463. this[option] = this[optionBack];
  464. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  465. if (inSave) {
  466. this.$message.success("重置成功");
  467. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  468. this.$nextTick(() => {
  469. this.$refs.crud.doLayout();
  470. });
  471. }
  472. }
  473. }
  474. }
  475. </script>
  476. <style scoped></style>