import moment  from 'moment';
import store  from '@/store';
import API from '../../api/default';
import { genWarehouseAuthSearchModal } from  '@/views/kzyWMS/SearchModal';


const grid = { span:8, labelCol:{span:6} }

const items = [
	// 仓库
		...genWarehouseAuthSearchModal(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,
						})
					}
				},
				{ span: 8, labelCol: { span: 6 } }
  ),
  {
    type: "input",
    name: "item",
    label: "商品名称/编码",
    value: "",
    ...grid,
  },
      // {
      //   ...grid,
      //   type: "p-checkbox",
      //   name: 'char',
      //   label: '是否允许超补',
      // }
    
  
  /* {
  		...grid,
  		type: 'buttonGroup',
  		style: { textAlign: 'center' },
  		options: [
  		   {value: '保存',icon: 'save',btnType: 'primary',style: 'margin-right:16px',htmlType: 'submit'},
  		   {value: '重置',name: 'ccz',icon: 'redo',
  			on: {
  			  click(event, form) {
  				form.resetFields();
  				 form.setFieldsValue({
  				  	warehouseName: '',
  					warehouseId:'',
  				 });
  					}
  				}
  			}
  	 ]} */
]


let itemId = ''
let batchId = ''
const columns =  [
    { type: "txt", dataIndex: 'cargoOwnerName', title: '货主名称', key: 'cargoOwnerName' },
    { type: "txt",dataIndex: 'itemHealthCategoryName', title: '商品分类', key: 'itemHealthCategoryName' },
    { type: "txt",dataIndex: 'itemName', title: '商品名称', key: 'itemName' },
    { type: "txt", dataIndex: 'itemCode', title: '商品编码', key: 'itemCode' },
    { type: "txt",dataIndex: 'containerCode', title: '容器号', key: 'containerCode' },
    { type: "txt",dataIndex: 'sjQuantity', title: '零货数量', key: 'sjQuantity' },
    { type: "txt",dataIndex: 'sjHLimitPer', title: '零货库存货位限定上限占比', key: 'sjHLimitPer', scopedSlots: { customRender: 'sjHLimitPer' } },
    { type: "txt",dataIndex: 'avlQuantity', title: '可补数量', key: 'avlQuantity' },
    { type: "txt",dataIndex: 'avlNum', title: '可补件数', key: 'avlNum' },
    { type: "txt",dataIndex: 'totalReplenishQuantity', title: '应补数量', key: 'totalReplenishQuantity' },
    { type: "txt",dataIndex: 'totalReplenishNum', title: '应补件数', key: 'totalReplenishNum',},
    { type: "txt",dataIndex: 'pieceQuantity', title: '实补数量', key: 'pieceQuantity',customRender:(text,rows,index)=>rows.caseConversionRate*rows.pieceNum },
    { type: "number",dataIndex: 'pieceNum', title: '实补件数', key: 'pieceNum',style:"color:red",slots:{title:'pieceNum'} },
    { type: "txt",dataIndex: 'caseConversionRate', title: '包装数量', key: 'caseConversionRate' },
    { type: "txt",dataIndex: 'warehouseCategoryCode', title: '库别', key: 'warehouseCategoryCode' },
    { type: "txt",dataIndex: 'caseUom', title: '包装单位', key: 'caseUom' },  
    { type: "txt",dataIndex: 'specification', title: '规格说明', key: 'specification' },
    { type: "txt",dataIndex: 'manufacturerId', title: '生产厂家', key: 'manufacturerId' },
    { type: "txt",dataIndex: 'countryOriginId', title: '产地', key: 'countryOriginId' },
    { type: "txt",dataIndex: 'managementLotNbr', title: '批准文号', key: 'managementLotNbr' },
    { type: "txt",dataIndex: 'stockHigherLimit', title: '库存上限', key: 'stockHigherLimit' },
    { type: "txt",dataIndex: 'stockLowerLimit', title: '库存下限', key: 'stockLowerLimit' },
  ]
const columns2 =  [
    { type: "txt", dataIndex: 'cargoOwnerName', title: '货主名称', key: 'cargoOwnerName' },
    { type: "txt",dataIndex: 'itemHealthCategoryName', title: '商品分类', key: 'itemHealthCategoryName' },
    { type: "txt",dataIndex: 'itemName', title: '商品名称', key: 'itemName' },
    { type: "txt", dataIndex: 'itemCode', title: '商品编码', key: 'itemCode' },
    { type: "txt",dataIndex: 'sjQuantity', title: '零货数量', key: 'sjQuantity' },
    { type: "txt",dataIndex: 'sjHLimitPer', title: '零货库存货位限定上限占比', key: 'sjHLimitPer', scopedSlots: { customRender: 'sjHLimitPer' }, },
    { type: "txt",dataIndex: 'abctype', title: 'BC属性', key: 'abctype' },
    { type: "txt",dataIndex: 'avlQuantity', title: '可补数量', key: 'avlQuantity' },
    { type: "txt",dataIndex: 'avlNum', title: '可补件数', key: 'avlNum' },
    { type: "txt",dataIndex: 'totalReplenishQuantity', title: '应补数量', key: 'totalReplenishQuantity' },
    { type: "txt",dataIndex: 'totalReplenishNum', title: '应补件数', key: 'totalReplenishNum',},
    { type: "txt",dataIndex: 'pieceQuantity', title: '实补数量', key: 'pieceQuantity',customRender:(text,rows,index)=>rows.caseConversionRate*rows.pieceNum },
    { type: "number",dataIndex: 'pieceNum', title: '实补件数', key: 'pieceNum',style:"color:red",slots:{title:'pieceNum'} },
    { type: "txt",dataIndex: 'caseConversionRate', title: '包装数量', key: 'caseConversionRate' },
    { type: "txt",dataIndex: 'warehouseCategoryCode', title: '库别', key: 'warehouseCategoryCode' },
    { type: "txt",dataIndex: 'caseUom', title: '包装单位', key: 'caseUom' },
    { type: "txt",dataIndex: 'specification', title: '规格说明', key: 'specification' },
    { type: "txt",dataIndex: 'manufacturerId', title: '生产厂家', key: 'manufacturerId' },
    { type: "txt",dataIndex: 'countryOriginId', title: '产地', key: 'countryOriginId' },
    { type: "txt",dataIndex: 'managementLotNbr', title: '批准文号', key: 'managementLotNbr' },
    { type: "txt",dataIndex: 'stockHigherLimit', title: '库存上限', key: 'stockHigherLimit' },
    { type: "txt",dataIndex: 'stockLowerLimit', title: '库存下限', key: 'stockLowerLimit' },
  ]

export function detailConfig(self) {
  return [
    {
      key: 'one', checkedKey: 'main',
      btns: [
        { label: '查询', click() { } },
        { label: '重置', click() { 
          let refMain = self.queryRefFromName('main')
          let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
          refMain.form.enableItem(['warehouseName', 'cargoOwnerCode'])
          ref.delItems() // 删除附表信息
        } },
        {
          label: '保存', click() {
          alert(222)
         } },
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          btns: [
            // { label: '辅助功能1', click() { } },
          ],
          item: { type: 'p-grid-form', config: items }
        },
      ]
    },
    {
      key: 'two', checkedKey: 'baseMtlItemUomConversionsList',
      list: [
        {
          key: 'baseMtlItemUomConversionsList',
          tab: '移货位明细',
          btns: [
            {
              label: '新增', click() {
                let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
                let refMain = self.queryRefFromName('main')
                // console.log(self.getData())
                let formsVal = refMain.form.getFieldsValue()
                if (!formsVal.cargoOwnerId) return self.$message.warn('请选择货主')
                ref.addItem() // 新增
                // self.formsVal = formsVal  disabled
                refMain.form.disableItem() // form禁用
            } },
            {
              label: '删除', click() {
                self.$confirm({
                  content: self.$lang('确定删除?'),
                  onOk: () => {
                    let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
                    ref.delSelectedItems()
                  }
                })
            } },
          ],
          item: {
            type: 'p-table-edit',
            config: columns(self),
            rowKey: '_row_count',
            rowSelectType: 2,
            colChange({ record, name, value }) {
            }
          }
        },
      ]
    },
  ];
}


 export { items,columns,columns2 }