/* eslint-disable prettier/prettier */
import { h } from "vue";
import { ElImage, ElTag } from "element-plus";
import { DescriptionColumns } from "/@/components/BasicDescriptions";
import { FormConfig } from "/@/components/PageSearch";
import { createTooltip } from "/@/utils/tooltip";
import { GOOD_OPTIONS } from "/@/config/status";
// import { payWayOptions, sendWayOptions, supplyAreaOptions } from "./_options";

export const projectFormConfig: FormConfig = {
  labelWidth: "100px",
  formItems: [
    {
      label: "商品名称",
      field: "good_name",
      type: "input",
      placeholder: "商品名称",
      span: 24
    },
    {
      label: "封面图",
      field: "good_cover_img",
      type: "img_upload",
      placeholder: "封面图",
      span: 8
    },
    {
      label: "商品类型",
      field: "type",
      type: "select",
      options: GOOD_OPTIONS,
      placeholder: "商品类型",
      span: 8
    },
    {
      label: "单位",
      field: "unit_id",
      placeholder: "单位",
      span: 8,
      slot: "unit_id"
    },

    {
      label: "起订量",
      field: "moq",
      type: "number",
      placeholder: "起订量",
      otherOptions: {
        precision: 0,
        step: 1,
        "controls-position": "right",
        min: 0,
        max: 99999999
      },
      span: 8
    },
    {
      label: "步长",
      field: "step",
      type: "number",
      placeholder: "步长",
      span: 8,
      otherOptions: {
        precision: 0,
        step: 1,
        "controls-position": "right",
        min: 0,
        max: 99999999
      }
    },
    {
      label: "售价",
      field: "price",
      type: "number",
      placeholder: "售价",
      span: 8,
      otherOptions: {
        precision: 2,
        step: 1,
        "controls-position": "right",
        min: 0,
        max: 99999999
      }
    },
    {
      label: "轮播图",
      type: "img_upload_list",
      field: "good_banner_img",
      placeholder: "轮播图",
      span: 24
    },
    {
      label: "详情图",
      field: "good_img",
      type: "img_upload_list",
      placeholder: "详情图",
      span: 24
    },
    {
      label: "商品参数",
      type: "array",
      field: "good_param",
      placeholder: "商品参数",
      slot: "good_param",
      span: 24
    },

    {
      label: "备注",
      field: "good_remark",
      type: "textarea",
      placeholder: "备注",
      span: 24
    }
  ]
};

//平台商品详情字段
export const platformGoodColumns: DescriptionColumns = [
  {
    field: "good_name",
    label: "商品名称",
    span: 24,
    render: (goodname, { skuCode, speclist }) => {
      const goodName = speclist
        ? speclist
            .map(({ spec_name, spec_value }) => `${spec_name}[${spec_value}]`)
            .join("_")
        : "";

      return createTooltip(
        goodname + "_" + goodName,
        "商品编号： " + skuCode,
        360
      );
    }
  },
  {
    field: "good_img",
    label: "商品主图",
    span: 12,
    render: good_img => {
      const previewSrcList = good_img ? good_img.split(",") : [];
      return previewSrcList.map(src =>
        h(ElImage, {
          previewSrcList: [src],
          src,
          previewTeleported: true,
          style: {
            height: "20px",
            width: "20px"
          }
        })
      );
    }
  },
  {
    field: "good_info_img",
    label: "商品详情图",
    span: 12,
    render: good_info_img => {
      return h(ElImage, {
        previewSrcList: [good_info_img],
        src: good_info_img,
        previewTeleported: true,
        style: {
          height: "20px",
          width: "20px"
        }
      });
    }
  },
  {
    field: "company",
    label: "业务企业名称",
    span: 8,
    render: (company, { companyNo }) =>
      createTooltip(company, "业务企业编号: " + companyNo, 360)
  },
  {
    field: "platform_name",
    label: "所属平台",
    span: 8
  },
  {
    field: "brand_name",
    label: "品牌",
    span: 8
  },
  {
    field: "cat_info",
    label: "分类",
    span: 8,
    render(cat_info) {
      return cat_info ? cat_info.map(({ name }) => name).join("_") : "";
    }
  },
  {
    field: "unit",
    span: 8,
    label: "单位"
  },
  {
    field: "is_stock",
    label: "是否库存品",
    span: 6,
    render(is_stock) {
      return h(ElTag, null, {
        default: () => (is_stock !== "0" ? "库存品" : "非库存品")
      });
    }
  },
  // {
  //   field: "supply_area",
  //   label: "供货区域",
  //   span: 6,
  //   render(supply_area) {
  //     return h(ElTag, null, {
  //       default: () =>
  //         supplyAreaOptions.find(({ id }) => supply_area === id)?.label || "--"
  //     });
  //   }
  // },
  {
    field: "good_type",
    label: "是否定制",
    span: 8,
    render(good_type) {
      return h(ElTag, null, {
        default: () => (good_type !== "0" ? "是" : "否")
      });
    }
  },
  {
    field: "tax",
    label: "税点",
    append: "%",
    span: 4
  },
  {
    field: "delivery_day",
    label: "物流时间",
    append: "天",
    span: 4
  },
  {
    field: "lead_time",
    label: "供货周期",
    append: "天",
    span: 4
  },
  {
    field: "sample_day",
    label: "调样周期",
    append: "天",
    span: 4
  },
  {
    field: "exclusive",
    label: "专属类型",
    span: 6,
    render(exclusive) {
      return exclusive ? exclusive.map(({ name }) => name).join("/") : "";
    }
  },
  {
    field: "weight",
    label: "商品总克重",
    append: "g",
    span: 6
  },
  {
    field: "noble",
    label: "贵金属信息",
    render(
      _,
      {
        noble_weight,
        noble_metal,
        noble_name,
        gold_price,
        is_gold_price,
        is_diff,
        config,
        other_config
      }
    ) {
      if (!noble_metal) {
        return "";
      }

      const weight = noble_weight ? `${noble_weight}g-${noble_name}` : "";

      const price = gold_price ? gold_price : "0";

      const isGoldPrice = is_gold_price === "0" ? "不" : "";

      const diff = is_diff === "1" ? "有" : "无";

      return `${weight}${price}元/g-${isGoldPrice}启用实时金价-${diff}工差-${config}-${other_config}`;
    }
  },
  {
    field: "delivery_place_cn",
    label: "发货地",
    span: 8
  },
  {
    field: "customized",
    label: "工期",
    span: 8
  },
  {
    field: "cgder",
    label: "供应商负责人",
    span: 4
  },
  {
    field: "good_creater",
    label: "商品创建人",
    span: 4
  },
  {
    field: "after_sales",
    label: "售后说明",
    span: 24
  },
  {
    field: "good_remark",
    label: "商品备注",
    span: 24
  },

  {
    field: "craft_desc",
    label: "工艺说明",
    span: 24
  }
];

//采反商品详情字段
export const commodityFeedbackColumns: DescriptionColumns = [
  {
    field: "good_name",
    label: "商品名称",
    span: 24,
    render: (goodname, { spuCode, speclist }) => {
      const goodName = speclist
        ? speclist
            .map(({ spec_name, spec_value }) => `${spec_name}[${spec_value}]`)
            .join("_")
        : "";

      return createTooltip(
        goodname + "_" + goodName,
        "上线商品编号： " + spuCode,
        360
      );
    }
  },

  {
    field: "cat_info",
    label: "分类",
    span: 8,
    render(cat_info) {
      return cat_info ? cat_info.map(({ name }) => name).join("_") : "";
    }
  },

  {
    field: "brand_name",
    label: "品牌",
    span: 8
  },

  // {
  //   field: "send_way",
  //   label: "发货方式",
  //   span: 8,
  //   render(send_way) {
  //     return h(ElTag, null, {
  //       default: () =>
  //         sendWayOptions.find(({ id }) => send_way === id)?.label || "--"
  //     });
  //   }
  // },
  {
    field: "unit",
    label: "单位",
    span: 4
  },
  {
    field: "tax",
    label: "税点",
    append: "%",
    span: 4
  },
  // {
  //   field: "pay_way",
  //   label: "付款方式",
  //   span: 4,
  //   render(pay_way) {
  //     return h(ElTag, null, {
  //       default: () =>
  //         payWayOptions.find(({ id }) => pay_way === id)?.label || "--"
  //     });
  //   }
  // },

  {
    field: "weight",
    label: "商品总克重",
    append: "g",
    span: 6
  },

  {
    field: "addtime",
    label: "反馈时间",
    span: 6
  },
  {
    field: "expire_day",
    label: "竞价有效期",
    append: "天",
    span: 4
  },

  {
    field: "delivery_day",
    label: "物流时间",
    append: "天",
    span: 4
  },
  {
    field: "work_day",
    label: "生产工期",
    append: "天",
    span: 4
  },
  {
    field: "cgder",
    label: "供应商负责人",
    span: 4
  },
  {
    field: "creater",
    label: "商品创建人",
    span: 4
  },
  {
    field: "supply_area",
    label: "供货区域",
    span: 4,
    render(supply_area) {
      return h(ElTag, null, {
        default: () =>
          supplyAreaOptions.find(({ id }) => supply_area === id)?.label || "--"
      });
    }
  },

  {
    field: "good_img",
    label: "商品图片",
    span: 24,
    render: good_img => {
      const previewSrcList = good_img ? good_img.split(",") : [];
      return previewSrcList.map(src =>
        h(ElImage, {
          previewSrcList: [src],
          src,
          previewTeleported: true,
          style: {
            height: "20px",
            width: "20px"
          }
        })
      );
    }
  },
  {
    field: "noble",
    label: "贵金属信息",
    span: 24,
    render(
      _,
      {
        noble_weight,
        noble_metal,
        noble_name,
        gold_price,
        is_gold_price,
        is_diff,
        config,
        other_config
      }
    ) {
      if (!noble_metal) {
        return "--";
      }

      const weight = noble_weight ? `${noble_weight}g-${noble_name}` : "";

      const price = gold_price ? gold_price : "0";

      const isGoldPrice = is_gold_price === "0" ? "不" : "";

      const diff = is_diff === "1" ? "有" : "无";

      return `${weight}${price}元/g-${isGoldPrice}启用实时金价-${diff}工差-${config}-${other_config}`;
    }
  },

  {
    field: "cost_desc",
    label: "工艺说明",
    span: 24
  },
  {
    field: "remark",
    label: "采返备注",
    span: 24
  }
];
