import moment from 'moment'
import { remote } from './remote'
import { grid } from "./common";
import { genWarehouseSearchModal,
		  genContainerSearchModal,
		} from "@/views/kzyWMS/SearchModal";
import { upcloud_base_wh } from "@/config/serviceSettings";
		
const items = [
  // ...genwarehouse(grid),
  // 仓库
  ...genWarehouseSearchModal(1, true, false,null, 
  		function (rowData, form) {
  			if (!rowData) {
  				form.setFieldsValue({
  					warehouseId: '',
  					warehouseCode:'',
  					warehouseName:''
  				})
  			} else {
  				form.setFieldsValue({
  					warehouseId: rowData[0].warehouseId,
  					warehouseCode: rowData[0].warehouseCode,
  					warehouseName: rowData[0].warehouseName,
  					dcId: rowData[0].dcId,
  					dcCode: rowData[0].dcCode,
  					dcName: rowData[0].dcName,
  				})
  			}
  		},
  		{ span: 6, labelCol: { span: 6 } }
  	),
  {
    type: 'input',
    name: 'containerCode',
    label: '容器编号',
    span: 6, labelCol: { span: 6 }
  },
  {
    type: 'select',
    name: 'containerType',
    label: '容器类型',
    ...remote('pub_container_containertype'),
    span: 6, labelCol: { span: 6 }
  },
  {
    span: 6, labelCol: { span: 6 },
    type: 'buttonGroup',
    style: { textAlign: 'right' },
    options: [
      {
        value: '查询',
        icon: 'search',
        btnType: 'primary',
        style: 'margin-left:50px;margin-right:10px;',
        htmlType: 'submit'
      },
      {
        value: '重置',
        name: 'ccz',
        icon: 'redo',
        on: {
          click(event, form) {
            form.resetFields()
          }
        }
      }
    ]
  }
]

const modalItems = [
  {type: 'input',name: 'dcId',label: '仓配中心id',hidden: true},
  {
    name: 'dcName',
    label: '仓配中心名称',
    type: 'searchModal',
    remoteUrl: { url: upcloud_base_wh+'/wmsdc/page', method: 'get' },
    rowKey: 'dcId',
    targetValueKey: 'dcName',
    required: true,
    disabled: true,
	...grid,
    toolBar: {
      items: [
        {
          type: 'input',
          name: 'dcCode',
          label: '仓配中心编码',
          value: ''
        },
        {
          type: 'input',
          name: 'dcName',
          label: '仓配中心名称',
          value: ''
        }
      ]
    },
    tableConfig: {
      columns: [
        {
          dataIndex: 'dcCode',
          title: '仓配中心编码'
        },
        {
          dataIndex: 'dcName',
          title: '仓配中心名称'
        }
      ]
    },
    on: {
      ok(event, value, rowData, form) {
        form.setFieldsValue({
          dcId: `${rowData[0].dcId}`
        })
      }
    }
  },
  // 仓库
  ...genWarehouseSearchModal(1, true, false,null, 
  		function (rowData, form) {
  			if (!rowData) {
  				form.setFieldsValue({
  					warehouseId: '',
  					warehouseCode:'',
  					warehouseName:''
  				})
  			} else {
  				form.setFieldsValue({
  					warehouseId: rowData[0].warehouseId,
  					warehouseCode: rowData[0].warehouseCode,
  					warehouseName: rowData[0].warehouseName,
					dcId: rowData[0].dcId,
					dcCode: rowData[0].dcCode,
					dcName: rowData[0].dcName,
  				})
  			}
  		},
  		{ span: 8, labelCol: { span: 6 } }
  	),
  /* {type: 'input',name: 'warehouseId',label: '仓库id',required: true,hidden: true},
  {
    type: 'searchModal',
    name: 'warehouseName',
    label: '仓库名称',
    required: true,
    remoteUrl: { url: upcloud_base_wh+'/warehouse/page', method: 'get' },
    rowKey: 'warehouseId',
    targetValueKey: 'warehouseName',
    required: true,
    toolBar: {
      items: [
        {
          type: 'input',
          name: 'warehouseCode',
          label: '仓库编码',
          value: ''
        },
        {
          type: 'input',
          name: 'warehouseName',
          label: '仓库名称',
          value: ''
        },
        {
          type: 'input',
          name: 'dcName',
          label: '仓配名称',
          value: ''
        }
      ]
    },
    tableConfig: {
      columns: [
        {
          dataIndex: 'warehouseCode',
          title: '仓库编码'
        },
        {
          dataIndex: 'warehouseName',
          title: '仓库名称'
        },
        {
          dataIndex: 'dcName',
          title: '仓配名称'
        }
      ]
    },
    on: {
      ok(event, value, rowData, form) {
        form.setFieldsValue({
          warehouseId: `${rowData[0].warehouseId}`,
          dcId: `${rowData[0].dcId}`,
          dcName: `${rowData[0].dcName}`,
          dcCode: `${rowData[0].dcCode}`
        })
      }
    }
  }, */
  {
    type: 'select',
    name: 'containerType',
    label: '容器类型',
	...grid,
    ...remote('pub_container_containertype')
  },
  {
    type: 'number',
    name: 'startNum',
    label: '起始号',
	...grid,
  },
  {
    type: 'number',
    name: 'endNum',
    label: '终止号',
	...grid,
  },
  {
    type: 'select',
    name: 'containerStatus',
    label: '容器状态',
    ...remote('pub_container_status'),
	...grid,
  },
  {
    type: 'switch',
    name: 'isEnable',
    label: '状态',
    value: true,
	...grid,
  }
]

const modalEditItems = [
  {
    type: 'select',
    name: 'containerType',
    label: '容器类型',
    ...remote('pub_container_containertype'),
    disabled: true
  },
  {
    type: 'input',
    name: 'containerCode',
    label: '容器编号',
    disabled: true
  },
  {
    type: 'select',
    name: 'containerStatus',
    label: '容器状态',
    ...remote('pub_container_status')
  },
  {
    type: 'switch',
    name: 'isEnable',
    label: '状态',
    value: true
  }
]

const columns = [
  {dataIndex: 'containerCode',title: '容器编号'},
  {dataIndex: 'containerType',title: '容器类型',scopedSlots: { customRender: 'containerType' }},
  {dataIndex: 'containerStatus',title: '容器状态',scopedSlots: { customRender: 'containerStatus' }},
  {dataIndex: 'warehouseName',title: '仓库名称'},
  {dataIndex: 'warehouseCode',title: '仓库编码'},
  {dataIndex: 'gmtCreate',title: '最后修改时间',customRender: text => {return moment(text).format('YYYY-MM-DD HH:mm:ss')}},
  {
    dataIndex: 'action',
    title: '操作',
    scopedSlots: { customRender: 'action' },
    width: 150,
	align:'center',
	fixed:'right',
  }
]

export { items, modalItems, modalEditItems, columns }
