import {getByParentId} from "../../api/mall/categoryinfo";

export const grouponOption = {
    height: 'auto',
    calcHeight: 30,
    border: true,
    index: false,
    viewBtn: true,
    delBtn:false,
    editBtn: false,
    addBtn: false,
    selection: true,
    // dialogClickModal: false,
    labelWidth: 150,
    searchIcon: true,
    searchIndex: 3,
    menu: false,
    tip: false,
    column: [
    {
        label: "商品封面",
        prop: "goodsCover",
        addDisplay: false,
        viewDisplay: false,
        editDisplay: false,
        type: 'img',
    },
    {
        label: "商品名称",
        prop: "goodsName",
        search: true,
        width: 280,
        overHidden: true,
    },
    {
        label: "规格",
        prop: "goodsSpec",
        editDisplay: false,
        rules: [{
            required: true,
            message: "请输入规格",
            trigger: "blur"
        }]
    },
    {
        label: "供应商",
        prop: "supplierName",
        search: true,
        addDisplay: false,
        editDisplay: false
    },
    {
        label: "分类",
        prop: "categoryIdArr",
        hide: true,
        search: true,
        lazy: true,
        rules: [{
            required: true,
            message: "请选择分类",
            trigger: "blur"
        }],
        type: "cascader",
        filterable: true,
        checkStrictly: true,
        lazyLoad(node, resolve) {
            let parentId;
            let stop_level = 2;
            let level = node.level;
            let list = [];

            if (node.level === 0) {
                parentId = 0;
                getByParentId(0).then((res) => {
                    list = res.data.data;
                    list = (list || []).map(ele => {
                        return Object.assign(ele, {
                            leaf: level >= stop_level
                        })
                    })
                    resolve(list)
                })
            } else {
                parentId = node.data.id;
                getByParentId(node.data.id).then((res) => {
                    list = res.data.data;
                    list = (list || []).map(ele => {
                        return Object.assign(ele, {
                            leaf: level >= stop_level
                        })
                    })
                    resolve(list)
                })
            }
        },
        props: {
            label: "title",
            value: "key"
        },
    },
    {
        label: "品牌",
        prop: "brandId",
        hide: true,
        search: true,
        rules: [{
            required: true,
            message: "请选择品牌",
            trigger: "blur"
        }],
        type: "select",
        remote: true,
        dicUrl: "/api/mall/brandsinfo/getByName?brandName={{key}}",
        props: {
            label: "brandName",
            value: "id"
        },
        dataType: "string",
    },
    {
        label: "价格",
        prop: "salePrice",
        precision: 2,
        type: "number",
        formatter:(val,value)=>{
            return Number(value).toFixed(2);
        },
        rules: [{
            required: true,
            message: "请输入销售价",
            trigger: "blur"
        }],
    },
    ]
}
