import { remote } from '@/views/EIS/remote/index.js'

// console.log(area)

const area = function (labelname = '区域', span = 24, required = true, name = 'startRegion') {
  return {
    span: span,
    type: 'searchModal',
    name: name,
    label: labelname,
    required: required,
    targetClick: true,
    targetValueKey: 'areaNo',
    value: '',
    remoteUrl: {
      url: '/api/upcloud-base-wh-dev-mysql-eistest/storeArea/getAll-storeArea',
    },
    //   doneBefore: function(res) {
    //     console.log(res)
    //     res.data.list = res.data.list.filter(item => item.areaType == 20)
    //     return res
    //   },

    on: {
      search: () => {
        //   this.params = { name: 'hdwss' }
      },
      change: (event, value, rowData, form) => {},
    },
    toolBar: {
      rowId: 'id',
      items: [
        {
          type: 'input',
          name: 'areaNo',
          label: '区域编号',
          value: '',
        },
        {
          type: 'select',
          name: 'areaType',
          label: '区域类别',
          value: '',
          options: [
            { value: 10, label: '区域' },
            { value: 20, label: '接驳口' },
          ],
        },
      ],
    },

    tableConfig: {
      rowKey: 'areaNo',
      remoteBefore: function (vnode, remoteUrl) {
        console.log(remoteUrl)
        remoteUrl.params.areaType = 10
        return remoteUrl
      },
      columns: [
        {
          dataIndex: 'areaNo',
          title: '区域编号',
        },
        {
          title: '区域类别',
          dataIndex: 'areaType',
          align: 'center',
          key: 'areaType',
          customRender(text) {
            text == 10 && (text = '区域')
            text == 20 && (text = '接驳口')
            return text
          },
        },
      ],
    },
  }
}
const baseUrl = '/api/service-ai-eis-business-center-eistest'

const config = function (that) {
  return {
    remoteUrl: {
      url: baseUrl + '/storeSupply/find',
      headers: {
        'Content-Type': 'application/JSON',
      },
      method: 'get',
    },
    items: [
      {
        // labelname = '区域', span = 24, required = true, name = 'startRegion'
        ...area('库存区域', 6, false, 'storeArea'),
      },
      {
        span: 24,
        type: 'buttonGroup',
        style: { textAlign: 'right' },
        options: [
          {
            value: '查询',
            icon: 'search',
            btnType: 'primary',
            style: 'margin-right:10px',
            htmlType: 'submit',
          },
          {
            value: '重置',
            icon: 'redo',
            style: 'margin-right:50px',
            on: {
              click: (event, form) => {
                console.log(form)
                form.resetFields()
              },
            },
          },
        ],
      },
    ],
    columns: [
      {
        dataIndex: 'id',
        key: 'id',
        align: 'center',
        hidden: true,
        title: 'id',
      },
      {
        dataIndex: 'sourceArea',
        key: 'sourceArea',
        align: 'center',
        title: '起始区域',
      },
      {
        dataIndex: 'targetArea',
        key: 'targetArea',
        align: 'center',
        title: '目标区域',
      },
      {
        title: '创建时间',
        dataIndex: 'createTime',
        align: 'center',
        key: 'createTime',
      },

      {
        dataIndex: 'isAvailable',
        key: 'isAvailable',
        scopedSlots: { customRender: 'isAvailable' },
        align: 'center',
        title: '是否开启',
      },

      {
        title: '操作',
        key: 'operation',
        scopedSlots: { customRender: 'operation' },
        width: 150,
        fixed: 'right',
        align: 'center',
      },
    ],
    Modelitems: [
      {
        // labelname = '区域', span = 24, required = true, name = 'startRegion'
        ...area('库存区域', 24, true, 'storeArea'),
      },
    ],
  }
}

export default config
