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

export const goodsinfoOption = {
  height: 'auto',
  calcHeight: 30,
  border: true,
  index: false,
  viewBtn: true,
  delBtn:false,
  editBtn: true,
  // selection: true,
  dialogClickModal: false,
  labelWidth: 150,
  searchIcon: true,
  searchIndex: 3,
  column: [
    {
      label: "商品编号",
      search: true,
      prop: "id",
      overHidden: true,
      addDisplay: false,
      editDisplay: false,
      editDisabled: true,
      width: 160
    },
    {
      label: "商品封面",
      width: 80,
      prop: "goodsCover",
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false,
      type: 'img',
    },
    {
      label: "商品名称",
      prop: "goodsName",
      search: true,
      width: 280,
      overHidden: true,
      rules: [{
        required: true,
        message: "请输入商品名称",
        trigger: "blur"
      }]
    },
    {
      label: "供应商",
      prop: "supplierName",
      search: true,
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false,
    },
    {
      label: "品牌",
      prop: "brandDesc",
      hide: true,
      addDisplay: false,
      viewDisplay: 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: "discount",
      hide: true,
      rules: [{
        required: true,
        message: "请输入折扣",
        trigger: "blur"
      }],
    },
    {
      label: "价格",
      prop: "salePrice",
      precision: 2,
      type: "number",
      formatter:(val,value)=>{
        return Number(value).toFixed(2);
      },
      rules: [{
        required: true,
        message: "请输入销售价",
        trigger: "blur"
      }],
    },
    {
      label: "状态",
      prop: "isSale",
      search: true,
      slot:true,
      rules: [{
        required: true,
        message: "请输入是否上架",
        trigger: "blur"
      }],
      type: "select",
      dicUrl: "/api/blade-system/dict-biz/getEnumDict?enumName=GoodsStateEnum",
      props: {
        label: "name",
        value: "value"
      },
      dataType: "number",
    },
    {
      label: "审核状态",
      prop: "auditStatus",
      search: true,
      slot:true,
      type: "select",
      dicUrl: "/api/blade-system/dict-biz/getEnumDict?enumName=AuditStatusEnum",
      props: {
        label: "name",
        value: "value"
      },
      dataType: "number",
    },
    {
      label: "上架时间",
      prop: "saleTime",
      hide: true,
      addDisplay: false,
      viewDisplay: false,
      editDisplay: false,
      editDisabled: true,
    },
    {
      label: "总库存",
      prop: "totalStock",
      type: "number",
      hide: true,
      min: 1,
      rules: [
        {required: true, message: "请输入总库存", trigger: "blur"},
      ]
    },
    {
      label: "总销量",
      prop: "totalSales",
      hide: true,
      addDisplay: false,
      editDisplay: false,
    },
    {
      label: "总浏览量",
      prop: "totalViews",
      hide: true,
      addDisplay: false,
      editDisplay: false,
    },
    {
      label: "单位",
      prop: "unit",
      hide: true,
      rules: [{
        required: true,
        message: "请输入单位",
        trigger: "blur"
      }],
      type: "select",
      remote: true,
      dicUrl: "/api/mall/unit/all-list",
      props: {
        label: "name",
        value: "id"
      },
      dataType: "string",
    },
    {
      label: "产地",
      prop: "origin",
      hide: true,
    },
    {
      label: "创建时间",
      prop: "createTime",
      hide: true,
      addDisplay: false,
      editDisplay: false,
      editDisabled: false,
    },
    {
      label: '商品封面',
      prop: 'uploadCover',
      type: 'upload',
      listType: 'picture-img',
      loadText: '上传中，请稍等',
      accept: 'image/png, image/jpeg',
      fileSize: 1024,
      tip: '只能上传jpg/png文件，且不超过1M',
      span: 24,
      hide: true,
      propsHttp: {
        res: 'data',
        url: 'link',
      },
      action: "/api/blade-resource/oss/endpoint/put-file-attach"
    },
    {
      label: '商品轮播图',
      prop: 'slideshowList',
      type: 'upload',
      dataType: 'array',
      listType: 'picture-card',
      loadText: '上传中，请稍等',
      accept: 'image/png, image/jpeg',
      fileSize: 1024,
      tip: '只能上传jpg/png文件，且不超过1M',
      span: 24,
      hide: true,
      propsHttp: {
        res: 'data',
        url: 'link',
      },
      action: "/api/blade-resource/oss/endpoint/put-file-attach"
    },
    {
      label: '图文详情',
      prop: 'detailImgUrlList',
      type: 'upload',
      dataType: 'array',
      listType: 'picture-card',
      loadText: '上传中，请稍等',
      accept: 'image/png, image/jpeg',
      fileSize: 2048,
      tip: '只能上传jpg/png文件，且不超过2M',
      limit: 25,
      span: 24,
      hide: true,
      propsHttp: {
        res: 'data',
        url: 'link',
      },
      action: "/api/blade-resource/oss/endpoint/put-file-attach"
    },
  ]
}

export const goodsParamOption = {
  height:'auto',
  calcHeight: 30,
  tip: false,
  searchShow: true,
  searchMenuSpan: 6,
  border: true,
  index: true,
  viewBtn: false,
  selection: true,
  dialogClickModal: false,
  column: [
    {
      label: "主键",
      prop: "id",
      hide: true,
      addDisplay: false,
      editDisabled: true,
      editDisplay: false,
    },
    {
      label: "参数名",
      prop: "paramName",
      rules: [{
        required: true,
        message: "请输入参数名",
        trigger: "blur"
      }]
    },
    {
      label: "参数值",
      prop: "paramValue",
      rules: [{
        required: true,
        message: "请输入参数值",
        trigger: "blur"
      }]
    },
    {
      label: "商品id",
      prop: "goodsId",
      hide: true,
      addDisplay: false,
      editDisplay: false,
      editDisabled: true,
    },
    {
      label: "排序",
      prop: "sort",
      rules: [{
        required: true,
        message: "请输入排序",
        trigger: "blur"
      }]
    },
  ]
}


