// const baseUrl = '/api/upcloud-base-wh-control-mysql-eistest'
const baseUrl = '/api/upcloud-base-wh-control-mysql-eistest'
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
    //   },
    toolBar: {
      rowId: 'id',
      items: [
        {
          type: 'input',
          name: 'areaNo',
          label: '区域编号',
          value: '',
        },
        {
          type: 'select',
          name: 'areaType',
          label: '区域类别',
          value: '',
          options: [
            { value: 10, label: '区域' },
            { value: 20, label: '接驳口' },
          ],
        },
      ],
    },
    on: {
      search: () => {
        //   this.params = { name: 'hdwss' }
      },
      change: (event, value, rowData, form) => {},
    },

    tableConfig: {
      rowKey: 'areaNo',
      remoteBefore: function (vnode, remoteUrl) {
        console.log(remoteUrl)
        // remoteUrl.params.areaType = 20
        return remoteUrl
      },
      columns: [
        {
          dataIndex: 'areaNo',
          title: '区域编号',
        },
        {
          title: '区域类别',
          dataIndex: 'areaType',
          align: 'center',
          key: 'areaType',
          customRender(text) {
            text == 10 && (text = '区域')
            text == 20 && (text = '接驳口')
            return text
          },
        },
      ],
    },
  }
}
const config = {
  remoteUrl: {
    url: baseUrl + '/eisAreaReserve/find',
    headers: {
      'Content-Type': 'application/JSON',
    },
    method: 'get',
  },
  items: [
    {
      // labelname = '区域', span = 24, required = true, name = 'startRegion'
      //   ...area('区域', 8, false, 'areaNo'),

      span: 8,
      type: 'input',
      name: 'areaNo',
      label: '区域',
      value: '',
    },

    {
      span: 8,
      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: 'areaNo',
      key: 'areaNo',
      align: 'center',
      title: '区域',
    },
    {
      title: '任务类型',
      dataIndex: 'taskType',
      align: 'center',
      key: 'taskType',
      customRender(text) {
        text == -1 && (text = '空托')
        text == 1 && (text = '任务托')
        return text
      },
    },
    {
      title: '预留类型',
      dataIndex: 'reserveType',
      align: 'center',
      key: 'reserveType',
      customRender(text) {
        text == 1 && (text = '数量')
        text == 2 && (text = '百分比')
        return text
      },
    },
    {
      title: '百分比/数量',
      key: 'reserveCount',
      dataIndex: 'reserveCount',
      scopedSlots: { customRender: 'reserveCount' },
      align: 'center',
    },

    {
      title: '操作',
      key: 'operation',
      scopedSlots: { customRender: 'operation' },
      //   fixed: 'right',
      align: 'center',
    },
  ],
  Modelitems: [
    {
      span: 24,
      type: 'input',
      name: 'id',
      hidden: true,
      label: 'id',
      value: '',
    },
    {
      // labelname = '区域', span = 24, required = true, name = 'startRegion'
      ...area('区域', 24, true, 'areaNo'),
    },
    {
      span: 24,
      type: 'select',
      required: true,
      name: 'taskType',
      label: '任务类型',
      value: '',
      options: [
        { label: '空托', value: -1 },
        { label: '任务托', value: 1 },
      ],
    },
    {
      span: 24,
      type: 'select',
      required: true,
      name: 'reserveType',
      label: '预留类型',
      value: '',
      options: [
        { label: '数量', value: 1 },
        { label: '百分比', value: 2 },
      ],
    },

    {
      span: 24,
      type: 'input',
      required: true,
      name: 'reserveCount',
      label: '数量',
      value: '',
    },
  ],
}
export default config
