import qs from 'qs'
import { upcloud_base_strategy } from '@/config/serviceSettings'
import {
  genWarehouseAuthSearchModal,
  genCargoownerAuthSearchModal,
  genBldgSearchModal
} from '@/views/kzyWMS/SearchModal'
import { changecargoOwnerfun } from '@/views/kzyWMS/utils/setCargoOwner'
const span8 = { span: 8, labelCol: { span: 6 } }
import { sorter } from '../../../utils/sort'
let warehouseId
let bldgId
const tablecolumns = {
  //策略表
  grid: {
    items: [
      {
        type: 'input',
        name: 'search',
        label: '查询条件',
        value: ''
      },
      ...genCargoownerAuthSearchModal(1, false, false, null, null, {
        span: 8
      }),
      ...genWarehouseAuthSearchModal(
        1,
        false,
        false,
        null,
        function(rowData, form) {
          //   console.log(rowData)
          //   warehouseId = rowData[0].companyId
          form.setFieldsValue({
            cargoOwnerCode: null,
            cargoOwnerId: null,
            cargoOwnerName: null
          })
        },
        {
          span: 8
        }
      ),
      ...genBldgSearchModal(
        1,
        false,
        false,
        function(res, p) {
          console.log(warehouseId)
          p.params.warehouseId = warehouseId
          return p
        },
        function(rowData, form) {
          bldgId = rowData[0].bldgId
          //   form.form.setFieldsValue({})
        },
        {
          span: 8
        }
      ),
      {
        span: 8,
        type: 'buttonGroup',
        style: { textAlign: 'left' },
        options: [
          {
            value: '查询',
            icon: 'search',
            btnType: 'primary',
            style: 'margin-right:10px;margin-left:30%;',
            htmlType: 'submit'
          },
          {
            value: '重置',
            name: 'ccz',
            icon: 'redo',
            on: {
              click(event, form) {
                console.log(form)
                console.log(form.resetFields())
              }
            }
          }
        ]
      }
    ]
  },
  MainTable: {
    ref: 'MainTable',
    rowkey: 'regId',
    detail: [
      {
        title: '参数类型',
        dataIndex: 'groupType',
        key: 'groupType',
        ellipsis: true
      },
      {
        title: '参数编号',
        dataIndex: 'regCode',
        ellipsis: true,
        key: 'regCode'
      },

      {
        title: '参数名称',
        dataIndex: 'regName',
        ellipsis: true,
        key: 'regName'
      },
      {
        title: '参数值',
        key: 'regValue',
        dataIndex: 'regValue',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '货主名称',
        key: 'cargoOwnerName',
        dataIndex: 'cargoOwnerName',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '货主号',
        key: 'cargoOwnerId',
        dataIndex: 'cargoOwnerId',
        ellipsis: true,
        align: 'center'
      },
      //   warehouseName
      {
        title: '仓库名称',
        key: 'warehouseName',
        dataIndex: 'warehouseName',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '建筑物名称',
        key: 'bldgName',
        dataIndex: 'bldgName',
        ellipsis: true,
        align: 'center'
      },

      {
        title: '仓库号',
        key: 'warehouseId',
        dataIndex: 'warehouseId',
        ellipsis: true,
        align: 'center'
      },

      {
        title: '创建人姓名',
        key: 'creatorName',
        dataIndex: 'creatorName',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '企业ID',
        key: 'enterpriseId',
        dataIndex: 'enterpriseId',
        align: 'center'
      },
      {
        title: '创建时间',
        key: 'gmtCreate',
        dataIndex: 'gmtCreate',
        align: 'center'
      },
      {
        title: '修改时间',
        key: 'gmtModified',
        dataIndex: 'gmtModified',
        align: 'center'
      },
      {
        title: '修改人姓名',
        key: 'modifierName',
        dataIndex: 'modifierName',
        align: 'center'
      },
      {
        title: '修改等级',
        key: 'modifyLevel',
        dataIndex: 'modifyLevel',
        align: 'center'
      },

      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        align: 'center'
      }
    ],
    columns: sorter([
      {
        title: '参数类型',
        dataIndex: 'groupType',
        ellipsis: true,
        key: 'groupType'
      },
      {
        title: '参数编号',
        dataIndex: 'regCode',
        ellipsis: true,
        key: 'regCode'
      },

      {
        title: '参数名称',
        dataIndex: 'regName',
        ellipsis: true,
        key: 'regName'
      },
      {
        title: '参数值',
        key: 'regValue',
        dataIndex: 'regValue',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '仓库名称',
        key: 'warehouseName',
        dataIndex: 'warehouseName',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '货主名称',
        key: 'cargoOwnerName',
        dataIndex: 'cargoOwnerName',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '建筑物名称',
        key: 'bldgName',
        dataIndex: 'bldgName',
        ellipsis: true,
        align: 'center'
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        ellipsis: true,
        align: 'center'
      },

      {
        title: '操作',
        key: 'operation',
        scopedSlots: { customRender: 'operation' },
        align: 'center'
      }
    ]),
    RemoteUrl: {
      url: upcloud_base_strategy + '/registry/list',
      method: 'post',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    },
    remoteBefore(vNode, remoteUrl) {
      //   console.log(vNode, remoteUrl)
      return { ...remoteUrl, data: qs.stringify(remoteUrl.data) }
    },
    doneBefore(res) {
      //   res.data.list.forEach(item => {
      //     // console.log(item)
      //     let a = Object.values(item)
      //     a = a.forEach(item1 => {
      //       item1 == null ? (item1 = '暂无数据') : ''
      //     })
      //     console.log(a)
      //   })

      return res
    }
  }
}

export default tablecolumns
