import { upcloud_base_common } from '@/config/serviceSettings'
const baseUrl = '/api/upcloud-base-wh-dev-mysql-eistest'
const remote = (type) => {
  return {
    remoteUrl: {
      url: upcloud_base_common + `/dict/listbytype/?dicttypeCodes=${type}`,
      method: 'post',
    },
    replaceFields: {
      label: 'dictName',
      value: 'dictCode',
    },
    autoLoad: true,
  }
}
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 + '/eisStationService/station/platform',
    headers: {
      'Content-Type': 'application/JSON',
    },
    method: 'post',
  },
  items: [
    {
      span: 8,
      type: 'input',
      name: 'stationNo',
      label: '站台编号',
      value: '',
    },
    {
      span: 8,
      type: 'input',
      name: 'areaNo',
      label: '站台区域',
      value: '',
    },
    // {
    //   // labelname = '区域', span = 24, required = true, name = 'startRegion'
    //   ...area('站台区域', 6, false, 'areaNo'),
    // },
    {
      span: 8,
      type: 'row',
      label: '创建时间',
      list: [
        {
          type: 'date',
          name: 'starttime',
          placeholder: '请输入开始日期',
          value: '',
          format: 'YYYY-MM-DD HH:mm:ss',
          style: 'padding-right:5px;',
        },
        {
          type: 'date',
          name: 'endTime',
          placeholder: '请输入结束日期',
          format: 'YYYY-MM-DD HH:mm:ss',
          value: '',
        },
      ],
    },
    {
      span: 8,
      type: 'select',
      name: 'type',
      label: '站台类型',
      value: '',
      options: [
        { label: '调拨拣选站台', value: 1 },
        { label: '门店整件站台', value: 2 },
        { label: '门店拆零站台', value: 3 },
      ],
    },

    {
      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: 'stationNo',
      key: 'stationNo',
      align: 'center',
      title: '站台编号',
    },
    {
      title: '站台区域',
      dataIndex: 'areaNo',
      align: 'center',
      key: 'areaNo',
    },
    {
      title: '站台类型',
      dataIndex: 'type',
      align: 'center',
      key: 'type',
      ...remote('type'),
      //   customRender(text) {
      //     text == 1 && (text = '调拨拣选站台')
      //     text == 2 && (text = '门店整件站台')
      //     text == 3 && (text = '门店拆零站台')
      //     return text
      //   },
    },
    {
      title: '是否锁定',
      key: 'isLock',
      dataIndex: 'isLock',
      align: 'center',
    },
    {
      title: '最大缓存数',
      key: 'maxCacheCount',
      dataIndex: 'maxCacheCount',
      align: 'center',
    },

    {
      title: '索取状态',
      dataIndex: 'claim',
      align: 'center',
      key: 'claim',
      scopedSlots: { customRender: 'claim' },
      //   customRender(text) {
      //     text == 0 && (text = '不索取')
      //     text == 1 && (text = '索取')
      //     return text
      //   },
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      align: 'center',
      key: 'createTime',
    },

    {
      title: '操作',
      key: 'operation',
      scopedSlots: { customRender: 'operation' },
      //   fixed: 'right',
      align: 'center',
    },
  ],
  Modelitems: [
    {
      span: 24,
      type: 'input',
      name: 'stationNo',
      required: true,
      label: '站台编号',
      value: '',
    },
    {
      span: 24,
      type: 'input',
      name: 'id',
      hidden: true,
      label: 'id',
      value: '',
    },

    {
      span: 24,
      type: 'number',
      // hidden: true,
      name: 'maxCacheCount',
      label: '最大缓存数',
      value: '',
    },
    {
      span: 24,
      type: 'input',
      hidden: true,
      name: 'createTime',
      label: 'createTime',
      value: '',
    },
    // {
    //   span: 24,
    //   type: 'input',
    //   name: 'areaNo',
    //   required: true,
    //   label: '站台区域',
    //   value: ''
    // },
    {
      // labelname = '区域', span = 24, required = true, name = 'startRegion'
      ...area('站台区域', 24, true, 'areaNo'),
    },

    {
      span: 24,
      type: 'select',
      required: true,
      name: 'type',
      label: '站台类型',
      value: 1,
      options: [
        { label: '调拨拣选站台', value: 1 },
        { label: '门店整件站台', value: 2 },
        { label: '门店拆零站台', value: 3 },
      ],
    },
    {
      span: 24,
      type: 'radio',
      required: true,
      name: 'isLock',
      label: '是否锁定',
      value: 0,
      options: [
        {
          value: 0,
          label: '开启',
        },
        {
          value: 1,
          label: '关闭',
        },
      ],
    },
    {
      span: 24,
      type: 'radio',
      name: 'claim',
      required: true,
      label: '是否索取',
      value: 1,
      options: [
        {
          value: 0,
          label: '不索取',
        },
        {
          value: 1,
          label: '索取',
        },
      ],
    },
  ],
  details: {
    currentArea: '当前节点区域',
    nextArea: '下个节点区域',
    routeTaskState: '任务状态',
    routeExecuteState: '执行状态',
    currentLocation: '当前节点点位',
    nextLocation: '下个节点点位',
    deviceTask_id: '设备任务ID',
    deviceNo: '执行设备编号',
    arriveTime: '到位时间',
    errorMsg: '错误消息',
    updateTime: '修改时间',
  },
}
export default config
