123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- import Vue from 'vue'
- import store from '@/store'
- export default function getProductList (payload = {}, option = {}) {
- const role = store.state.user.role
- // const role = 'shop'
- return new Promise(async (resolve, reject) => {
- // 筛选项
- const filters = {
- keyword: {
- type: 'input',
- title: '商品名称/编码',
- key: 'keyword',
- props: {
- placeholder: '商品名称/编码',
- clearable: true,
- },
- },
- category_id1: {
- type: 'select',
- title: '商品分类',
- key: 'category_id1',
- props: {
- placeholder: '商品分类',
- filterable: true,
- clearable: true,
- },
- option: {
- type: 'async',
- list: [],
- },
- },
- up_status: {
- type: 'select',
- title: '商品状态',
- key: 'up_status',
- props: {
- placeholder: '商品状态',
- filterable: true,
- clearable: true,
- },
- option: {
- list: [],
- },
- },
- }
- // 操作项
- let actions = [
- {
- title: '添加商品',
- action: 'goProductDetail',
- props: {
- type: 'primary',
- },
- },
- ]
- if (role !== 'shop') actions = []
- const sortActions = []
- // 表格项
- // "sale_name"
- const columns = {
- spu_code: {
- title: 'SKU编码',
- key: 'spu_code',
- align: 'center',
- width: 110,
- },
- id: {
- title: '商品ID',
- key: 'id',
- align: 'center',
- },
- img: {
- nodeType: 'image',
- payload: {
- key: 'img',
- title: '商品图片',
- width: 80,
- height: 80,
- },
- },
- 'name&sku_name': {
- title: '商品名称/编码',
- key: 'name&sku_name',
- align: 'center',
- width: 100,
- },
- sale_name: {
- title: '上架名称',
- key: 'sale_name',
- align: 'center',
- width: 100,
- },
- price: {
- title: '价格',
- key: 'price',
- align: 'center',
- width: 80,
- format: {
- type: 'price',
- },
- },
- category_name1: {
- title: '一级分类',
- key: 'category_name1',
- align: 'center',
- width: 100,
- },
- category_name2: {
- title: '二级分类',
- key: 'category_name2',
- align: 'center',
- width: 100,
- },
- category_name3: {
- title: '三级分类',
- key: 'category_name3',
- align: 'center',
- width: 100,
- },
- main_label_name: {
- title: '检测标签',
- key: 'main_label_name',
- align: 'center',
- width: 100,
- },
- label: {
- title: '商品标签',
- key: 'label',
- align: 'center',
- width: 100,
- render: (h, { row }) => {
- const element = []
- row.label.forEach(item => {
- element.push(h('div', [item]))
- })
- return h('div', {}, [element])
- },
- },
- total_stock: {
- title: '库存',
- key: 'total_stock',
- align: 'center',
- width: 80,
- },
- total_count: {
- title: '销量',
- key: 'total_count',
- align: 'center',
- width: 80,
- },
- up_status: {
- nodeType: 'iSwitch',
- payload: {
- title: role === 'shop' ? '上架' : '销售状态',
- key: role === 'shop' ? 'up_status' : 'sale_status',
- action: 'switchProduct',
- },
- },
- }
- const sortColumns = {}
- // 表格扩展(数据操作)
- const columnsExtra = {
- nodeType: 'action',
- payload: {
- title: '操作',
- list: [
- {
- title: role === 'shop' ? '编辑' : '查看',
- action: 'goProductDetail',
- props: {
- loading: false,
- type: 'primary',
- },
- },
- {
- title: '删除',
- action: 'deleteProductList',
- props: {
- loading: false,
- type: 'warning',
- },
- },
- ],
- },
- }
- if (role !== 'shop') columnsExtra.payload.list.splice(1, 1)
- const sortColumnsExtra = {}
- const url = role === 'shop' ? '/product/product' : '/product/operate/product'
- try {
- const isSort = option.type === 'sort'
- if (isSort) payload.per_page = 1000
- const { data, extra, meta } = await Vue.http.get(url, {
- params: payload,
- })
- const response = {
- filters: isSort ? [] : Object.keys(filters).map(i => filters[i]),
- actions: isSort ? sortActions : actions,
- data: data,
- columns: extra.columns
- .map(key => (isSort ? sortColumns : columns)[key])
- .filter(Boolean)
- .concat(isSort ? sortColumnsExtra : columnsExtra),
- page: isSort ? {} : meta.pagination,
- title: '商品列表',
- }
- resolve(response)
- } catch (e) {
- reject(e)
- }
- })
- }
|