123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- 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)
- }
- })
- }
|