import { httpList, httpStatus } from "/@/api/serviceParam/supplierBrand";

import { h } from "vue";
import dayjs from "dayjs";
import { ContentConfig } from "/@/components/PageContent";
import { ElImage, ElTag } from "element-plus";
import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";

const columns = [
  {
    prop: "gyscode",
    label: "供应商编号",
    minWidth: "140px",
  },
  {
    prop: "gysname",
    label: "供应商名称",
    minWidth: "140px",
  },
  {
    prop: "brand_name",
    label: "品牌",
    minWidth: "100px",
  },
  {
    prop: "status",
    label: "状态",
    minWidth: "60",
    _slot_: "status",
  },
  {
    label: "状态",
    prop: "status",
    width: 100,
    cellRenderer: ({ row }) => {
      return h(ElTag,
        { type: String(row.status) === "1" ? "success" : "danger" },
        { default: () => (String(row.status) === "1" ? "启用" : "禁用") }
      );
    }
  },
  {
    prop: "brand_book",
    label: "授权图",
    // _slot_: "brand_book",
    minWidth: "60px",
    cellRenderer({ row }){
      const imgs = row.brand_book ? row.brand_book.split(",") : [];
      return imgs.map(url => {
        return h(ElImage, {
          src: url,
          style: { height: "20px" },
          previewSrcList: [url],
          previewTeleported: true
        });
      });
    }
  },

  {
    prop: "long",
    label: "授权类型",
    minWidth: "70",
    cellRenderer: ({ row }) => {
      return h(ElTag,
        { type: String(row.long) === "0" ? "success" : "danger" },
        { default: () => (String(row.long) === "1" ? "非长期" : "长期") }
      );
    }
  },
  {
    prop: "longTime",
    label: "授权日期",
    minWidth: "180",
    cellRenderer({ row }){
      return row.starttime.split(" ")[0] + ' ~ ' +  (String(row.long) === "0" ? "长期有效" : row.endtime.split(" ")[0])
    }
  },
  {
    prop: "creater",
    label: "创建人",
    minWidth: "60px",
  },
  {
    prop: "addtime",
    label: "添加时间",
    minWidth: "145px",
  },
  {
    prop: "",
    label: "操作",
    fixed: "right",
    width: "140px",
    _noset_: true,
    slot: "operation",
  },
];

const contentConfig: ContentConfig = {
  title: "公司账号角色查询",
  columns,
  apis: {
    httpList,
    httpAdd: true,
    httpStatus,
    httpUpdate: true
  }
};

export default contentConfig;
