import UserAPI from "@/api/onlineShop/goodsGroupconfig";

import DeptAPI from "@/api/product/specificationsconfig";

import type { ISearchConfig } from "@/components/CURD/types";

const searchConfig: ISearchConfig = {
  pageName: "sys:user",
  formItems: [
    {
      type: "input",
      label: "商品名称",
      prop: "name",
      attrs: {
        placeholder: "请输入商品名称",
        clearable: true,
        style: {
          width: "200px",
        },
      },
    },
    {
      type: "select",
      label: "商品分类",
      prop: "categoryId",
      attrs: {
        placeholder: "请选择商品分类",
        clearable: true,
        style: {
          width: "200px",
        },
      },
      options: [],
      async initFn(formItem) {
        formItem.options = await UserAPI.getList();
      },
    },

    {
      type: "tree-select",
      label: "商品规格",
      prop: "specId",
      attrs: {
        placeholder: "请选择商品规格",
        data: [],
        filterable: true,
        "check-strictly": true,
        "render-after-expand": false,
        clearable: true,
        style: {
          width: "200px",
        },
        props: {
          label: 'name', // 指定节点显示的文本字段为 name
          value: 'id'    // 指定节点的值字段为 id
        }
      },
      async initFn(formItem) {
        formItem.attrs.data = await DeptAPI.getPage();
        // 注意:如果initFn函数不是箭头函数,this会指向此配置项对象,那么也就可以用this来替代形参formItem
        // this.attrs!.data = await DeptAPI.getOptions();
      },
    },
    {
      type: "date-picker",
      label: "日期",
      prop: "times",
      attrs: {
        type: "daterange",
        "range-separator": "~",
        "start-placeholder": "开始时间",
        "end-placeholder": "截止时间",
        "value-format": "YYYY-MM-DD",
        style: {
          width: "240px",
        },
      }
    },
    {
      type: "select",
      label: "排序",
      prop: "orderBy",
      attrs: {
        placeholder: "请选择商品分类",
        clearable: true,
        style: {
          width: "200px",
        },
      },
      options: [{
        label: "创建时间",
        value: "create_time asc"
      }, {
        label: "数量由低到高",
        value: "stock_number asc"
      }],
    },
  ],
};

export default searchConfig;
