import { genWarehouseAuthSearchModal, genCargoownerAuthSearchModal } from '@/views/kzyWMS/SearchModal'
import qs from 'qs'
import request from '@/utils/request'
import { sorter } from '@/views/kzyWMS/utils/sort'
import { changecargoOwnerfun } from '@/views/kzyWMS/utils/setCargoOwner'
import { SERVICE_DATA_API_BASE, upcloud_base_strategy, upcloud_base_gsp } from '@/config/serviceSettings'

const tablecolumns = function(that) {
  return {
    gridform: {
      ref: 'form',
      items: [
        //genWarehouseAuthSearchModal 仓库

        ...genWarehouseAuthSearchModal(1, true, false, null, changecargoOwnerfun, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),
        ...genCargoownerAuthSearchModal(1, true, false, null, null, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),
        // {
        //     type: 'input',
        //     span: 6,
        //     name: 'status1',
        //     label: '单据编号',
        //     value: '', //初始化值

        //   },
        {
          type: 'radio',
          span: 6,
          name: 'status',
          label: '状态',
          value: '20', //初始化值
          options: [
            { label: '未确认', value: '20' },
            { label: '已确认', value: '35' }
          ]
        },
        {
          span: 6,
          type: 'buttonGroup',
          style: { textAlign: 'left' },
          options: [
            {
              value: '查询',
              icon: 'search',
              btnType: 'primary',
              style: 'margin-right:10px;margin-left:10px;',
              htmlType: 'submit'
            },
            {
              value: '重置',
              name: 'ccz',
              icon: 'redo',
              on: {
                click(event, form) {
                  form.resetFields()
                }
              }
            }
          ]
        }
      ]
    },

    //主表
    MainTable: {
      edit: false,
      // edit: true,
      title: '明细列表',
      // /strategy/v1/page
      remoteUrl: {
        url: upcloud_base_gsp + '/gspUnqualifiedLoss/listPage',
        headers: {
          'Content-Type': 'application/JSON'
        },
        method: 'get'
      },
      ref: 'MainTable',
      rowkey: 'id',
      columns: sorter([
        {
          title: '单据编号',
          dataIndex: 'code',
          key: 'code'
        },
        {
          title: '单据来源',
          dataIndex: 'source',
          key: 'source',
          customRender(text) {
            text = '不合格品库存'
            return text
          }
        },

        {
          title: '仓库',
          dataIndex: 'warehouseName',
          key: 'warehouseName'
        },
        {
          title: '货主',
          dataIndex: 'cargoOwnerName',
          key: 'cargoOwnerName'
        },
        {
          title: '状态',
          dataIndex: 'status',
          key: 'status',
          scopedSlots: { customRender: 'status' },
          customRender(text) {
            //   console.log(text, '=====')
            if (text) {
              // { label: '未确认', value: '20' },
              // { label: '已确认', value: '35' }
              switch (text) {
                case '20':
                  text = '未确认'
                  break
                case '35':
                  text = '已确认'
                  break
              }
              return text
            } else return
          }
        },
        {
          title: '申请人',
          key: 'creatorName',
          dataIndex: 'creatorName'
        },
        {
          title: '申请时间',
          key: 'gmtCreate',
          dataIndex: 'gmtCreate'
        },
        {
          title: '意见',
          key: 'opinion',
          hidden: true,
          dataIndex: 'opinion'
        },

        {
          title: '审核时间',
          hidden: true,
          key: 'auditDate',
          dataIndex: 'auditDate'
        },
        {
          title: '审核意见',
          key: 'auditText',
          dataIndex: 'auditText',
          width: 100
          //   scopedSlots: { customRender: 'auditText1' }
        },
        {
          title: '二级审核员',

          key: 'secondAuditOperator',
          dataIndex: 'secondAuditOperator'
        },
        {
          title: '二级审核时间',

          key: 'secondAuditDate',
          dataIndex: 'secondAuditDate'
        },
        {
          title: '二级审核意见',

          key: 'secondAuditText',
          dataIndex: 'secondAuditText'
        },
        {
          title: '二级审核结论',
          key: 'secondStatus',
          dataIndex: 'secondStatus',
          customRender(text) {
            //   console.log(text, '=====')
            text == '10' && (text = '通过')
            text == '11' && (text = '驳回')
            return text
          }
        }

        //   {
        //     title: '操作',
        //     key: 'operation',
        //     scopedSlots: { customRender: 'operation' },
        //     align: 'center'
        //   }
      ])
    },
    //   详情表
    SubTable: {
      title: '明细列表',
      remoteUrl: {
        url: upcloud_base_gsp + '/gspUnqualifiedLoss/findDetailByMstId	',
        headers: {
          'Content-Type': 'application/JSON'
        },
        method: 'get'
      },
      ref: 'rule',
      rowkey: 'id',
      columns: sorter([
        {
          title: '商品编码',
          key: 'itemCode',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemCode'
        },
        {
          title: '商品名称',
          key: 'itemName',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemName'
        },
        {
          title: '商品大类',
          key: 'itemHealthCategory',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthCategory'
        },
        {
          title: '商品规格',
          key: 'specification',
          width: 150,
          ellipsis: true,
          dataIndex: 'specification'
        },
        {
          title: '生产厂家',
          key: 'manufacturerName',
          width: 150,
          ellipsis: true,
          dataIndex: 'manufacturerName'
        },
        {
          title: '产地',
          key: 'countryOriginName',
          width: 150,
          ellipsis: true,
          dataIndex: 'countryOriginName'
        },
        {
          title: '包装数量',
          key: 'caseConversionRate',
          width: 150,
          ellipsis: true,
          dataIndex: 'caseConversionRate'
        },
        {
          title: '包装单位',
          key: 'caseUom',
          width: 150,
          ellipsis: true,
          dataIndex: 'caseUom'
        },
        {
          title: '是否追溯',
          key: 'itemHealthSuperviseflag',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemHealthSuperviseflag',
          customRender(text, record, index) {
            text ? (text = '是') : (text = '否')
            return text
          }
        },
        {
          title: '货位',
          key: 'locatorCode',
          width: 150,
          ellipsis: true,
          dataIndex: 'locatorCode'
        },
        {
          title: '货位ID',
          key: 'locatorId',
          ellipsis: true,
          hidden: true,
          dataIndex: 'locatorId'
        },
        {
          title: '报损数量',
          key: 'lossQty',
          dataIndex: 'lossQty',
          width: 100,
          scopedSlots: { customRender: 'number' }
        },
        {
          title: '部门意见',
          width: 150,
          key: 'opinion',
          ellipsis: true,
          dataIndex: 'opinion'
        },
        {
          title: '批准文号',
          key: 'itemHealthApprovalNbr',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthApprovalNbr'
        },
        {
          title: '上市许可持有人',
          key: 'itemHealthListedLicensor',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthListedLicensor'
        },
        {
          title: '注册证号',
          key: 'itemHealthRegisterNbr',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthRegisterNbr'
        },
        {
          title: '日期',
          dataIndex: 'refBillDate',
          hidden: true,
          ellipsis: true,
          key: 'refBillDate'
        },
        {
          title: '原单据编号',
          dataIndex: 'refBillId',

          hidden: true,
          ellipsis: true,
          key: 'refBillId'
        },
        {
          title: '不合格品来源',
          dataIndex: 'refBillType',
          hidden: true,
          ellipsis: true,
          key: 'refBillType',
          width: 100,
          customRender(text, record, index) {
            text == 1 ? ((text = '入库') ? text == 2 : (text = '移库')) : (text = '暂无')
            return text
          }
        },
        {
          title: '不合格原因',
          dataIndex: 'unqualifiedReason',
          hidden: true,
          ellipsis: true,
          key: 'unqualifiedReason'
        },
        {
          title: '不合格数量',
          dataIndex: 'unqualifiedQty',
          key: 'unqualifiedQty',
          hidden: true
        },

        {
          title: '助记码',
          key: 'itemAssistantCode',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemAssistantCode'
        },

        {
          title: '批号',
          key: 'lotNum',
          width: 150,
          ellipsis: true,
          dataIndex: 'lotNum'
        }

        //   {
        //     title: '操作',
        //     key: 'operation',
        //     align: 'center',
        //     scopedSlots: { customRender: 'operation' }
        //   }
      ])
    },
    modalItems: {
      rowkey: 'locatorId',
      remoteUrl: {
        url: SERVICE_DATA_API_BASE + '/search/page',
        method: 'post'
      },
      remoteBefore(vn, params) {
        let p = { ...params }
        p.data = {
          num: '589130005049643008',
          pageNum: params.data.pageNum,
          pageSize: params.data.pageSize,
          params: params.data
        }
        return p
      },
      title: '提取商品',
      gridformref: 'form',
      ref: 'modelFormType',
      items: [
        //genWarehouseAuthSearchModal 仓库

        ...genWarehouseAuthSearchModal(1, true, false, null, changecargoOwnerfun, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),
        ...genCargoownerAuthSearchModal(1, true, false, null, null, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),

        {
          type: 'select',
          span: 6,
          name: 'refBillType',
          label: '不合格品来源',
          value: '', //初始化值
          options: [
            { label: '所有', value: '' },
            { label: '入库', value: '1' },
            { label: '移库', value: '2' }
          ]
        },
        {
          type: 'input',
          span: 6,
          name: 'itemId',
          label: '商品',
          placeholder: '请输入产品名称或助记码或产品编',
          value: '' //初始化值
        },
        {
          span: 24,
          type: 'buttonGroup',
          style: { textAlign: 'right' },
          options: [
            {
              value: '查询',
              icon: 'search',
              btnType: 'primary',
              style: 'margin-right:10px;margin-left:10px;',
              htmlType: 'submit'
            },
            {
              value: '重置',

              name: 'ccz',
              icon: 'redo',
              on: {
                click(event, form) {
                  form.resetFields()
                }
              }
            }
          ]
        }
      ],
      columns: [
        {
          title: '日期',
          dataIndex: 'refBillDate',
          ellipsis: true,
          key: 'refBillDate'
        },
        {
          title: '原单据编号',
          dataIndex: 'refBillId',
          ellipsis: true,
          key: 'refBillId'
        },
        {
          title: '不合格品来源',
          dataIndex: 'refBillType',
          ellipsis: true,
          key: 'refBillType',
          width: 100,
          customRender(text, record, index) {
            text == 1 ? ((text = '入库') ? text == 2 : (text = '移库')) : (text = '暂无')
            return text
          }
        },
        {
          title: '不合格原因',
          dataIndex: 'unqualifiedReason',
          ellipsis: true,
          key: 'unqualifiedReason'
        },
        {
          title: '不合格数量',
          dataIndex: 'unqualifiedQty',
          key: 'unqualifiedQty',
          hidden: true
        },

        {
          title: '数量',
          key: 'lossQty',
          dataIndex: 'lossQty',
          width: 100,
          scopedSlots: { customRender: 'number' }
        },
        {
          title: '所在部门意见',
          key: 'opinion',
          ellipsis: true,
          dataIndex: 'opinion'
        },
        {
          title: '商品编码',
          key: 'itemCode',
          ellipsis: true,
          dataIndex: 'itemCode'
        },
        {
          title: '商品名称',
          key: 'itemName',
          ellipsis: true,
          dataIndex: 'itemName'
        },
        {
          title: '助记码',
          key: 'itemAssistantCode',
          ellipsis: true,
          dataIndex: 'itemAssistantCode'
        },
        {
          title: '生产厂家',
          key: 'manufacturerName',
          ellipsis: true,
          dataIndex: 'manufacturerName'
        },
        {
          title: '货位',
          key: 'locatorCode',
          ellipsis: true,
          dataIndex: 'locatorCode'
        },
        {
          title: '货位ID',
          key: 'locatorId',
          ellipsis: true,
          hidden: true,
          dataIndex: 'locatorId'
        },
        {
          title: '批号',
          key: 'lotNum',
          ellipsis: true,
          dataIndex: 'lotNum'
        },
        {
          title: '是否追溯',
          key: 'itemHealthSuperviseflag',
          ellipsis: true,
          dataIndex: 'itemHealthSuperviseflag',
          customRender(text, record, index) {
            text ? (text = '是') : (text = '否')
            return text
          }
        },
        {
          title: '商品规格',
          key: 'specification',
          ellipsis: true,
          dataIndex: 'specification'
        },
        {
          title: '产地',
          key: 'countryOriginName',
          ellipsis: true,
          dataIndex: 'countryOriginName'
        },

        {
          title: '上市许可持有人',
          key: 'itemHealthListedLicensor',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthListedLicensor'
        },
        {
          title: '包装数量',
          key: 'caseConversionRate',
          ellipsis: true,
          dataIndex: 'caseConversionRate'
        },
        {
          title: '包装单位',
          key: 'caseUom',
          ellipsis: true,
          dataIndex: 'caseUom'
        }
      ],
      ModalItemsOpinion: {
        ref: 'Opinion',
        items: [
          {
            type: 'input',
            span: 12,
            name: 'opinion',
            label: '意见',
            value: '' //初始化值
          }
        ]
      }
    }
  }
}

export default tablecolumns
