import {
  httpList,
  httpDelete,
  httpStatus,
  httpUpdate
} from "/@/api/system/wechatManager";

import { h } from "vue";
import dayjs from "dayjs";
import { ContentConfig } from "/@/components/PageContent";
import { ElTag } from "element-plus";

const options = [
  { value: '1', label: '已关注', type: 'success' },
  { value: '2', label: '已冻结', type: 'danger' },
  { value: '4', label: '未关注', type: 'warning' },
]

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    minWidth: 60,
    align: "left",
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "ID",
    prop: "id",
    width: 60,
  },
  {
    label: "手机号",
    prop: "mobile",
    minWidth: 120,
    align: "left"
  },
  {
    label: "名称",
    prop: "nickname",
    minWidth: 80
  },
  {
    label: "openid",
    prop: "openid",
    minWidth: 150
  },
  {
    label: "关注状态",
    prop: "status",
    width: 100,
    cellRenderer: ({ row }) => {
      return h(
        ElTag,
        {
          type: options.find(({ value }) => value === String(row.status))?.type || 'success'
        },
        {
          default: () => options.find(({ value }) => value === String(row.status))?.label || '--'
        }
      );
    }
  },
  {
    label: "创建时间",
    minWidth: 140,
    prop: "addtime",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "关注时间",
    minWidth: 140,
    prop: "addtime",
    formatter: ({ subscribe_time }) => dayjs(subscribe_time).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 80,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "微信账号权限管理",
  columns,
  responseCode: 0,
  deleteProp: "payNo",
  statusRowProp: ({ companyCode: companyNo }) => ({ companyNo }),
  apis: {
    httpList,
    httpDelete,
    httpAdd: true,
    httpStatus,
    httpUpdate
  }
};

export default contentConfig;
