123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import Vue from 'vue'
- export default function getCategoryList (payload = {}, option = {}) {
- return new Promise(async (resolve, reject) => {
- // 筛选项
- const filters = {
- name: {
- type: 'input',
- title: '分类名称',
- key: 'name',
- props: {
- placeholder: '输入分类名称',
- clearable: true,
- },
- },
- }
- // 操作项
- const actions = [
- {
- title: '添加分类',
- action: 'goCategoryDetail',
- props: {
- type: 'primary',
- },
- },
- ]
- const sortActions = [
- {
- title: '保存',
- action: 'editCategorySort',
- props: {
- type: 'success',
- },
- },
- ]
- // 表格项
- const columns = {
- name: {
- title: '分类名称',
- key: 'name',
- align: 'center',
- width: 100,
- },
- level: {
- title: '级别',
- key: 'level',
- align: 'center',
- width: 80,
- format: {
- type: 'config',
- },
- },
- ico: {
- nodeType: 'image',
- payload: {
- key: 'ico',
- title: '分类图标',
- width: 80,
- height: 80,
- },
- },
- desc: {
- title: '分类描述',
- key: 'desc',
- align: 'center',
- },
- is_open: {
- nodeType: 'iSwitch',
- payload: {
- title: '开启',
- key: 'is_open',
- action: 'switchCategory',
- },
- },
- }
- const sortColumns = {
- name: {
- title: '分类名称',
- key: 'name',
- align: 'center',
- },
- level: {
- title: '级别',
- key: 'level',
- align: 'center',
- format: {
- type: 'config',
- },
- },
- sort: {
- nodeType: 'input',
- payload: {
- title: '排序',
- key: 'sort',
- props: {
- type: 'number',
- number: true,
- },
- },
- },
- }
- // 表格扩展(数据操作)
- const columnsExtra = {
- nodeType: 'action',
- payload: {
- title: '操作',
- list: [
- {
- title: '编辑',
- action: 'goCategoryDetail',
- props: {
- loading: false,
- },
- },
- {
- title: '删除',
- action: 'deleteCategory',
- },
- ],
- },
- }
- const sortColumnsExtra = {
- nodeType: 'action',
- payload: {
- title: '操作',
- list: [
- {
- title: '商品排序',
- action: 'goCategoryProductSort',
- props: {
- loading: false,
- type: 'primary',
- },
- },
- ],
- },
- }
- try {
- const isSort = option.type === 'sort'
- if (isSort) payload.per_page = 1000
- const { data, extra, meta } = await Vue.http.get('/product/category', {
- params: payload,
- })
- // 处理级别功能和操作
- const handleLevel = {
- level1 () {
- actions.push({
- title: '排序',
- action: 'goCategorySort',
- actionOption: {
- parent_id: 0,
- type: 'sort',
- },
- props: {
- type: 'primary',
- },
- })
- this.level2()
- },
- level2 () {
- columnsExtra.payload.list.unshift({
- title: '查看子分类',
- action: 'goCategoryList',
- props: {
- loading: false,
- type: 'primary',
- },
- },)
- },
- level3 () {},
- }
- if (data.length) handleLevel[`level${data[0].level}`]()
- // 返回数据
- const response = {
- filters: isSort ? [] : extra.filters.map(key => filters[key]).filter(Boolean),
- actions: isSort ? sortActions : actions,
- data,
- columns: extra.columns
- .map(key => (isSort ? sortColumns : columns)[key])
- .filter(Boolean)
- .concat(isSort ? sortColumnsExtra : columnsExtra),
- page: isSort ? {} : meta.pagination,
- }
- resolve(response)
- } catch (e) {
- reject(e)
- }
- })
- }
|