| | |
| | | <selectProduct ref="selectProduct" @success="handlePageChange" @result="search"/> |
| | | </TableLayout> |
| | | </template> |
| | | |
| | | <script> |
| | | import BaseTable from '@/components/base/BaseTable' |
| | | import TableLayout from '@/layouts/TableLayout' |
| | | import Pagination from '@/components/common/Pagination' |
| | | import OperaGoodsWindow from '@/components/business/OperaGoodsWindow' |
| | | import selectProduct from '@/components/business/selectProduct' |
| | | import { brand, category, importExcel } from '@/api/system/common.js' |
| | | import { updateDisableById, queryById, exportDoc, batchUpdateDisableById } from '@/api/business/goods.js' |
| | | export default { |
| | | name: 'Goods', |
| | | extends: BaseTable, |
| | | components: { TableLayout, Pagination, OperaGoodsWindow, selectProduct }, |
| | | data () { |
| | | return { |
| | | // 搜索 |
| | | searchForm: { |
| | | id: '', |
| | | name: '', |
| | | status: '', |
| | | categoryId: '', |
| | | brandId: '', |
| | | type: '' |
| | | }, |
| | | ids: '', |
| | | categoryList: [], |
| | | brandList: [], |
| | | statusList: [ |
| | | { name: '启用', id: 0 }, |
| | | { name: '禁用', id: 1 } |
| | | ], |
| | | typeList: [ |
| | | { name: '自建', id: 0 }, |
| | | { name: '拉取', id: 1 } |
| | | ] |
| | | } |
| | | }, |
| | | created () { |
| | | this.config({ |
| | | module: '商品', |
| | | api: '/business/goods', |
| | | 'field.id': 'id', |
| | | 'field.main': 'name' |
| | | }) |
| | | this.search() |
| | | this.getbrand() |
| | | this.getcategory() |
| | | }, |
| | | methods: { |
| | | handleSelectionChange(e) { |
| | | let arr = e.map(item => item.id) |
| | | this.ids = arr.join(',') |
| | | console.log(this.ids) |
| | | <script> |
| | | import BaseTable from '@/components/base/BaseTable' |
| | | import TableLayout from '@/layouts/TableLayout' |
| | | import Pagination from '@/components/common/Pagination' |
| | | import OperaGoodsWindow from '@/components/business/OperaGoodsWindow' |
| | | import selectProduct from '@/components/business/selectProduct' |
| | | import { brand, category, importExcel } from '@/api/system/common.js' |
| | | import { updateDisableById, queryById, exportDoc, batchUpdateDisableById } from '@/api/business/goods.js' |
| | | export default { |
| | | name: 'Goods', |
| | | extends: BaseTable, |
| | | components: { TableLayout, Pagination, OperaGoodsWindow, selectProduct }, |
| | | data () { |
| | | return { |
| | | // 搜索 |
| | | searchForm: { |
| | | id: '', |
| | | name: '', |
| | | status: '', |
| | | categoryId: '', |
| | | brandId: '', |
| | | type: '' |
| | | }, |
| | | // 批量上下架 |
| | | bulkOperation(type) { |
| | | if (!this.ids) { |
| | | this.$message.warning({ message: '至少选择一项内容' }) |
| | | return |
| | | } |
| | | batchUpdateDisableById({ |
| | | ids: this.ids, |
| | | status: type |
| | | }).then(res => { |
| | | this.$message.success({ message: res }) |
| | | this.handlePageChange() |
| | | }) |
| | | }, |
| | | downloadFile() { |
| | | exportDoc({}) |
| | | .then(response => { |
| | | this.download(response) |
| | | }) |
| | | .catch(e => { |
| | | this.$tip.apiFailed(e) |
| | | }) |
| | | }, |
| | | rowStyle() { |
| | | return "text-align:center"; |
| | | }, |
| | | importFile() { |
| | | this.$refs.upload.click() |
| | | }, |
| | | uplaodFile(e) { |
| | | const FORMDATE = new FormData() |
| | | FORMDATE.append('file', e.target.files[0]) |
| | | // 请求接口 |
| | | importExcel(FORMDATE) |
| | | .then(res => { |
| | | console.log(res) |
| | | this.search() |
| | | }) |
| | | .catch ((err) => { |
| | | this.$message.error(err.message) |
| | | }) |
| | | this.$refs.upload.value = null |
| | | }, |
| | | edit(id) { |
| | | queryById(id) |
| | | .then(res => { |
| | | let obj = { |
| | | id: res.id, |
| | | name: res.name, |
| | | categoryId: res.categoryId, |
| | | brandId: res.brandId, |
| | | zdPrice: res.zdPrice, |
| | | price: res.price, |
| | | attrFirstIds: res.attrFirstIds ? this.turnNum(res.attrFirstIds.split(',')) : [], |
| | | attrFirstNames: res.attrFirstNames, |
| | | attrSecodIds: res.attrSecodIds ? this.turnNum(res.attrSecodIds.split(',')) : [], |
| | | attrSecodNames: res.attrSecodNames, |
| | | imgurl: res.imgurl, |
| | | multifileList: [], |
| | | files: [], |
| | | ztList: res.imgurl ? [{ url: res.prefixUrl + res.imgurl }] : [], |
| | | pzList: [], |
| | | attrFirstList: [], |
| | | attrSecodList: [] |
| | | } |
| | | if (res.multifileList.length > 0) { |
| | | res.multifileList.forEach(item => { |
| | | obj.multifileList.push({ fileurl: item.fileurl, name: item.name, url: res.prefixUrl + item.fileurl }) |
| | | obj.files.push({ fileurl: item.fileurl, name: item.name, url: res.prefixUrl + item.fileurl }) |
| | | }) |
| | | } |
| | | this.$refs.operaGoodsWindow.open('编辑商品', obj) |
| | | }) |
| | | }, |
| | | changeStatus(item) { |
| | | updateDisableById({ |
| | | id: item.id, |
| | | status: item.status |
| | | }).then(res => { |
| | | this.$tip.apiSuccess('更新成功') |
| | | }).finally(() => { |
| | | this.search() |
| | | }).catch(err => { |
| | | this.$message.warning({ message: err.message }) |
| | | }) |
| | | }, |
| | | turnNum (nums) { |
| | | for(let i=0;i<nums.length;i++){ |
| | | nums[i] = parseInt(nums[i]) |
| | | } |
| | | return nums; |
| | | }, |
| | | getbrand() { |
| | | brand({}) |
| | | .then(res => { |
| | | this.brandList = res |
| | | }) |
| | | }, |
| | | getcategory() { |
| | | category({}) |
| | | .then(res => { |
| | | this.categoryList = res |
| | | }) |
| | | } |
| | | ids: '', |
| | | categoryList: [], |
| | | brandList: [], |
| | | statusList: [ |
| | | { name: '启用', id: 0 }, |
| | | { name: '禁用', id: 1 } |
| | | ], |
| | | typeList: [ |
| | | { name: '自建', id: 0 }, |
| | | { name: '拉取', id: 1 } |
| | | ] |
| | | } |
| | | }, |
| | | created () { |
| | | this.config({ |
| | | module: '商品', |
| | | api: '/business/goods', |
| | | 'field.id': 'id', |
| | | 'field.main': 'name' |
| | | }) |
| | | this.search() |
| | | this.getbrand() |
| | | this.getcategory() |
| | | }, |
| | | methods: { |
| | | // handleSelectionChange(e) { |
| | | // let arr = e.map(item => item.id) |
| | | // this.ids = arr.join(',') |
| | | // console.log(this.ids) |
| | | // }, |
| | | // 批量上下架 |
| | | bulkOperation (type) { |
| | | if (this.tableData.selectedRows.length === 0) { |
| | | // if (!this.ids) { |
| | | this.$message.warning({ message: '至少选择一项内容' }) |
| | | return |
| | | } |
| | | const idList = this.tableData.selectedRows.map(item => item.id) |
| | | batchUpdateDisableById({ |
| | | ids: idList.join(','), |
| | | status: type |
| | | }).then(res => { |
| | | this.$message.success({ message: res }) |
| | | this.handlePageChange() |
| | | }) |
| | | }, |
| | | downloadFile() { |
| | | exportDoc({}) |
| | | .then(response => { |
| | | this.download(response) |
| | | }) |
| | | .catch(e => { |
| | | this.$tip.apiFailed(e) |
| | | }) |
| | | }, |
| | | rowStyle() { |
| | | return "text-align:center"; |
| | | }, |
| | | importFile() { |
| | | this.$refs.upload.click() |
| | | }, |
| | | uplaodFile(e) { |
| | | const FORMDATE = new FormData() |
| | | FORMDATE.append('file', e.target.files[0]) |
| | | // 请求接口 |
| | | importExcel(FORMDATE) |
| | | .then(res => { |
| | | console.log(res) |
| | | this.search() |
| | | }) |
| | | .catch ((err) => { |
| | | this.$message.error(err.message) |
| | | }) |
| | | this.$refs.upload.value = null |
| | | }, |
| | | edit(id) { |
| | | queryById(id) |
| | | .then(res => { |
| | | let obj = { |
| | | id: res.id, |
| | | name: res.name, |
| | | categoryId: res.categoryId, |
| | | brandId: res.brandId, |
| | | zdPrice: res.zdPrice, |
| | | price: res.price, |
| | | attrFirstIds: res.attrFirstIds ? this.turnNum(res.attrFirstIds.split(',')) : [], |
| | | attrFirstNames: res.attrFirstNames, |
| | | attrSecodIds: res.attrSecodIds ? this.turnNum(res.attrSecodIds.split(',')) : [], |
| | | attrSecodNames: res.attrSecodNames, |
| | | imgurl: res.imgurl, |
| | | multifileList: [], |
| | | files: [], |
| | | ztList: res.imgurl ? [{ url: res.prefixUrl + res.imgurl }] : [], |
| | | pzList: [], |
| | | attrFirstList: [], |
| | | attrSecodList: [] |
| | | } |
| | | if (res.multifileList.length > 0) { |
| | | res.multifileList.forEach(item => { |
| | | obj.multifileList.push({ fileurl: item.fileurl, name: item.name, url: res.prefixUrl + item.fileurl }) |
| | | obj.files.push({ fileurl: item.fileurl, name: item.name, url: res.prefixUrl + item.fileurl }) |
| | | }) |
| | | } |
| | | this.$refs.operaGoodsWindow.open('编辑商品', obj) |
| | | }) |
| | | }, |
| | | changeStatus(item) { |
| | | updateDisableById({ |
| | | id: item.id, |
| | | status: item.status |
| | | }).then(res => { |
| | | this.$tip.apiSuccess('更新成功') |
| | | }).finally(() => { |
| | | this.search() |
| | | }).catch(err => { |
| | | this.$message.warning({ message: err.message }) |
| | | }) |
| | | }, |
| | | turnNum (nums) { |
| | | for(let i=0;i<nums.length;i++){ |
| | | nums[i] = parseInt(nums[i]) |
| | | } |
| | | return nums; |
| | | }, |
| | | getbrand() { |
| | | brand({}) |
| | | .then(res => { |
| | | this.brandList = res |
| | | }) |
| | | }, |
| | | getcategory() { |
| | | category({}) |
| | | .then(res => { |
| | | this.categoryList = res |
| | | }) |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | } |
| | | </script> |