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 baseUrl = '/api/service-ai-eis-precall-center-eistest'
const baseUrl1 = '/api/upcloud-base-wh-dev-mysql-eistest'
const goods = function (labelname = '区域', span = 24, required = true, name = 'startLocation') {
  return {
    span: span,
    type: 'searchModal',
    name: name,
    label: labelname,
    required: required,
    targetClick: true,
    targetValueKey: 'locationNo',
    value: '',
    remoteUrl: {
      url: '/api/upcloud-base-wh-dev-mysql-eistest/eisLocator/goods/page',
      method: 'post',
    },
    doneBefore: function (res) {
      console.log(res)
      //   res.data.list = res.data.list.filter(item => item.areaType == 20)
      return res
    },
    toolBar: {
      items: [
        {
          span: 8,
          type: 'input',
          name: 'locationNo',
          label: '货位编号',
          value: '',
        },
        {
          span: 8,
          type: 'input',
          name: 'groupNo',
          label: '货位组编号',
          value: '',
        },
        {
          span: 8,
          type: 'input',
          name: 'areaNo',
          label: '区域',
          value: '',
        },

        {
          span: 8,
          type: 'input',
          name: 'limitHeight',
          label: '限高',
          value: '',
        },
      ],
    },
    on: {
      search: () => {
        //   this.params = { name: 'hdwss' }
      },
      change: (event, value, rowData, form) => {},
    },

    tableConfig: {
      remoteBefore: function (vnode, remoteUrl) {
        console.log(remoteUrl)
        // remoteUrl.params.areaType = 20
        return remoteUrl
      },
      columns: [
        {
          dataIndex: 'locationNo',
          key: 'locationNo',
          align: 'center',
          ellipsis: true,
          title: '货位编号',
        },
        {
          title: '货位组编号',
          dataIndex: 'groupNo',
          ellipsis: true,
          //   scopedSlots: { customRender: 'groupNo' },
          align: 'center',
          key: 'groupNo',
        },
        {
          title: '区域编号',
          dataIndex: 'areaNo',
          ellipsis: true,
          align: 'center',
          key: 'areaNo',
          customRender(text) {
            text == 1 && (text = '出库口')
            text == 2 && (text = '在线拣选')
            return text
          },
        },
        {
          title: '位置类型',
          ellipsis: true,
          key: 'locationType',
          dataIndex: 'locationType',
          align: 'center',
          customRender(text) {
            text == 1 && (text = '存储位')
            text == 2 && (text = '工作位')
            text == 3 && (text = '输送线点位')
            return text
          },
        },
      ],
    },
  }
}
const remote = {
  remoteUrl: {
    url: baseUrl1 + '/eisStoreAreaDirectionService/area/findDistinctSourceAreaNo',
    method: 'post',
  },
  replaceFields: {
    label: 'sourceAreaNo',
    value: 'sourceAreaNo',
  },
  autoLoad: true,
}
let sourceAreaNo //起点区域
let targetAreaNo //终点区域
let storeAreaDirectionId //区域id
let areaData //区域对象
const config = function (that) {
  return {
    remoteUrl: {
      url: baseUrl + '/precallconfig/page',
      headers: {
        'Content-Type': 'application/JSON',
      },
      method: 'post',
    },
    items: [
      {
        // labelname = '区域', span = 24, required = true, name = 'startRegion'
        // ...area('起始区域', 6, false, 'sourceAreaNo'),
        span: 8,
        type: 'input',
        name: 'sourceAreaNo',
        label: '起始区域',
        value: '',
      },
      {
        // labelname = '区域', span = 24, required = true, name = 'startRegion'
        // ...area('目标区域', 6, false, 'targetAreaNo'),
        span: 8,
        type: 'input',
        name: 'targetAreaNo',
        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: 'sourceAreaNo',
        key: 'sourceAreaNo',
        align: 'center',
        title: '起点区域',
      },
      {
        title: '终点区域',
        dataIndex: 'targetAreaNo',
        align: 'center',
        key: 'targetAreaNo',
        customRender(text) {
          //   text == 10 && (text = '区域')
          //   text == 20 && (text = '接驳口')

          return text
        },
      },
      {
        title: '设备系统',
        dataIndex: 'deviceSystem',
        ellipsis: true,
        align: 'center',
        key: 'deviceSystem',
      },
      {
        title: '预召唤点位',
        key: 'preLocationNo',
        ellipsis: true,
        dataIndex: 'preLocationNo',
        align: 'center',
      },

      {
        title: '最大任务数',
        dataIndex: 'maxTaskCount',
        ellipsis: true,
        align: 'center',
        key: 'maxTaskCount',
      },
      {
        title: '延迟时间（单位:s）',
        key: 'delayTime',
        ellipsis: true,
        dataIndex: 'delayTime',
        align: 'center',
      },

      {
        title: '创建时间',
        dataIndex: 'createTime',
        ellipsis: true,
        align: 'center',
        key: 'createTime',
      },
      {
        title: '是否开启',
        dataIndex: 'isAvailable',
        align: 'center',
        ellipsis: true,
        key: 'isAvailable',
        scopedSlots: { customRender: 'isAvailable' },
      },

      {
        title: '操作',
        key: 'operation',
        scopedSlots: { customRender: 'operation' },
        // fixed: 'right',
        align: 'center',
      },
    ],
    Modelitems: [
      {
        span: 24,
        type: 'input',
        name: 'id',
        hidden: true,
        label: 'id',
        value: '',
      },
      {
        span: 24,
        type: 'select',
        name: 'sourceAreaNo',
        required: true,
        label: '起点区域',
        ...remote,
        // destroyOptions: true,
        value: '',
        on: {
          change(value, label, options, form) {
            console.log(form.getFieldsValue())
            console.log(value)
            sourceAreaNo = value
          },
        },
      },
      {
        span: 24,
        type: 'select',
        name: 'targetAreaNo',
        required: true,
        label: '终点区域',
        remoteUrl: {
          url: baseUrl1 + '/eisStoreAreaDirectionService/area/findBySourceAreaNo',
          method: 'post',
        },
        remoteBefore: (res, remoteParams) => {
          console.log(res)
          remoteParams.data = {
            sourceAreaNo,
          }
          //   console.log(remoteParams, sourceAreaNo)
          return remoteParams
        },
        replaceFields: {
          label: 'targetAreaNo',
          value: 'targetAreaNo',
        },
        autoLoad: false,
        destroyOptions: true,
        /* done: function(data) {
          console.log(data)
          storeAreaDirectionId = data[0].id
          return data
        },
        on: {
          change(value, label, options, form) {
            // console.log(form.getFieldsValue())
            // console.log(value)
            targetAreaNo = value
            // console.log(sourceAreaNo, targetAreaNo)
            form.setFieldsValue({ storeAreaDirectionId })
          }
        }, */
        done: function (data) {
          areaData = data
          return data
        },
        on: {
          change(value, label, options, form) {
            // console.log(form.getFieldsValue())
            // console.log(value)
            targetAreaNo = value
            // console.log(sourceAreaNo, targetAreaNo)
            areaData.map((item) => {
              if (item.sourceAreaNo == sourceAreaNo && item.targetAreaNo == targetAreaNo) {
                form.setFieldsValue({ storeAreaDirectionId: item.id })
              }
            })
          },
        },
        value: '',
      },
      //   storeAreaDirectionId
      {
        span: 24,
        type: 'input',
        disabled: true,
        name: 'storeAreaDirectionId',
        // required: true,
        label: '区域方向ID',
        value: '',
      },

      {
        span: 24,
        type: 'input',
        name: 'delayTime',
        required: true,
        label: '延迟时间',
        value: '',
      },
      {
        span: 24,
        type: 'input',
        name: 'maxTaskCount',
        required: true,
        label: '最大任务数',
        value: '',
      },

      {
        span: 24,
        type: 'select',
        name: 'deviceSystem',
        required: true,
        label: '设备系统',
        value: '',
        options: [
          { label: 'GCS', value: 'GCS' },
          { label: 'RCS', value: 'RCS' },
          { label: 'SPS', value: 'SPS' },
        ],
      },
      {
        span: 24,
        type: 'input',
        name: 'preLocationNo',
        required: true,
        label: '预召唤点位',
        value: '',
      },
      //   {
      //     // labelname = '区域', span = 24, required = true, name = 'startRegion'
      //     ...area('预召唤点位', 24, true, 'preLocationNo')
      //   }
    ],
    details: {
      currentArea: '当前节点区域',
      nextArea: '下个节点区域',
      routeTaskState: '任务状态',
      routeExecuteState: '执行状态',
      currentLocation: '当前节点点位',
      nextLocation: '下个节点点位',
      deviceTask_id: '设备任务ID',
      deviceNo: '执行设备编号',
      arriveTime: '到位时间',
      errorMsg: '错误消息',
      updateTime: '修改时间',
    },
  }
}

export default config
