import Vue from 'vue' export default function getTrashList (payload = {}, option = {}) { 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: [], }, }, } // 操作项 const 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', width: 80, }, img: { nodeType: 'image', payload: { key: 'img', title: '商品图片', width: 80, height: 80, }, }, sale_name: { title: '商品名称', key: 'sale_name', align: 'center', }, category_name1: { title: '一级分类', key: 'category_name1', align: 'center', }, category_name2: { title: '二级分类', key: 'category_name2', align: 'center', }, category_name3: { title: '三级分类', key: 'category_name3', align: 'center', }, price: { title: '商品价格', key: 'price', align: 'center', }, } const sortColumns = {} // 表格扩展(数据操作) const columnsExtra = { nodeType: 'action', payload: { title: '操作', list: [ { title: '还原', action: 'handleTrashList', actionOption: { status: 1, type: 'one', }, props: { loading: false, type: 'primary', }, }, { title: '删除', action: 'handleTrashList', actionOption: { status: 0, type: 'one', }, props: { loading: false, type: 'warning', }, }, ], }, } const sortColumnsExtra = {} try { const isSort = option.type === 'sort' if (isSort) payload.per_page = 1000 const { data, extra, meta } = await Vue.http.get('/product/product?is_delete=1', { params: payload, }) const response = { filters: isSort ? [] : extra.filters.map(key => filters[key]).filter(Boolean), 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: '回收站列表', batches: [ { value: 'handleTrashList', label: '批量删除', option: { status: 0 } }, { value: 'handleTrashList', label: '批量还原', option: { status: 1 } }, ], } // 是否有批量操作 response.columns.unshift({ type: 'selection', width: 60, align: 'center', }) resolve(response) } catch (e) { reject(e) } }) }