let grid = {
  labelCol: { span: 10 },
  wrapperCol: { span: 14 },
  // span: 12,
  //    高度
  itemHeight: "50px",
};
let a = {
  style: { textAlign: "center" },
};

import { checkStation, getGoodsInfoByShelves } from "../api";
import { REGEX_letter } from "@/views/util";

export function formItems(self) {
  return [
    { hidden: true, type: "input", name: "taskId", label: "taskId", value: "" },
    { hidden: true, type: "input", name: "id", label: "id", value: "" },
    { hidden: true, type: "input", name: "goodsId", label: "goodsId", value: "" },
    { hidden: true, type: "input", name: "targetGoodsId", label: "targetGoodsId", value: "" },
    { hidden: true, type: "input", name: "goodsOwnerId", label: "goodsOwnerId", value: "" },
    { hidden: true, type: "input", name: "goodsPackId", label: "goodsPackId", value: "" },
    { hidden: true, type: "input", name: "ownerGoodsId", label: "ownerGoodsId", value: "" },
    { hidden: true, type: "input", name: "bigType", label: "bigType", value: "" },
    { hidden: true, type: "input", name: "lotId", label: "lotId", value: "" },
    { hidden: true, type: "input", name: "conserveNo", label: "conserveNo", value: "" },
    { hidden: true, type: "input", name: "actualAllocation", label: "actualAllocation", value: "" },
    { hidden: true, type: "input", name: "conserveFlag", label: "conserveFlag", value: "" },
    { hidden: true, type: "input", name: "planes", label: "planes", value: "" },
    { hidden: true, type: "input", name: "bizPropertyId", label: "bizPropertyId", value: "" },

    {
      span: 24,
      type: "input",
      className: "input-md",
      size: "large",
      name: "stationNo",
      label: "工作站",
      value: "",
      size: "large",
      labelCol: { span: 10 },
      wrapperCol: { span: 5 },
      itemHeight: "50px",
      on: {
        change(event, uid) {
          // const params = self.$refs.itemForm.form.getFieldsValue().stationNo
          // console.log(event.target._value)
          // let data = (event.target._value).toUpperCase()
          // console.log(uid,'datadata')
          // self.$refs.itemForm.form.setFieldsValue({palletLocation: '219999'})
        },
        pressEnter() {
          const params = self.$refs.itemForm.form.getFieldsValue().stationNo;
          // if (!REGEX_letter(params)) {
          //   self.$message.error('请输入大写字母！')
          //   return
          // }
          checkStation({ stationNo: params.toUpperCase() }).then((res) => {
            if (!res.success) {
              self.$message.warning(self.$lang(res.message));
              return;
            }
            if (!res.data) {
              self.message = "请调出货架";
            } else {
              // self.$refs.itemForm.form.setFieldsValue(res.data)
            }
            self.$refs.itemForm.form.resetFields();
            self.$refs.itemForm.form.setFieldsValue({ stationNo: params });
            self.$message.success(self.$lang("验证成功"));
            self.stationNo = params;
          });
        },
      },
    },

    {
      type: "input",
      className: "input-md",
      size: "large",
      name: "palletLocation",
      label: "原货位",
      value: "",
      span: 12,
      ...grid,
      on: {
        pressEnter(event) {
          // if (!REGEX_letter(self.$refs.itemForm.form.getFieldsValue().palletLocation)) {
          //   self.$message.error('请输入大写字母！')
          //   return
          // }
          let inPalletLocation = self.$refs.itemForm.form.getFieldsValue().inPalletLocation.toUpperCase();
          console.log(inPalletLocation, "inPalletLocation");
          if (inPalletLocation == "XN0001" && inPalletLocation == event.target._value) {
            self.$message.error("目标货位与货位不能同为虚拟货位");
            self.$refs.itemForm.form.setFieldsValue({ inPalletLocation: "" });
            return;
          }
          const params = self.$refs.itemForm.form.getFieldsValue();
          if (!params.stationNo) {
            self.$message.warning(self.$lang("请先扫描站台号"));
            return;
          }
          self.getgoodsinfo(event.target._value.toUpperCase());
          return;
          // getGoodsInfoByShelves({
          //   stationNo: params.stationNo,
          //   palletLocation: params.palletLocation
          // }).then((res) => {
          //   if (!res.success) {
          //     self.$exception(res)
          //   }
          //   self.$refs.itemForm.form.setFieldsValue(res.data)
          //   self.message = "请扫描目的货位"
          // })
        },
      },
    },
    {
      type: "input",
      className: "input-md",
      size: "large",
      name: "palletNo",

      ...grid,
      label: "原货架/原托盘",
      value: "",
      span: 12,
      disabled: true,
    },

    {
      type: "input",
      className: "input-md",
      size: "large",
      name: "inPalletLocation",
      label: "目的货位",
      value: "",
      span: 12,
      ...grid,
      on: {
        pressEnter() {
          // if (!REGEX_letter(self.$refs.itemForm.form.getFieldsValue().inPalletLocation)) {
          //   self.$message.error('请输入大写字母！')
          //   return
          // }
          let palletLocation = self.$refs.itemForm.form.getFieldsValue().palletLocation.toUpperCase();
          if (palletLocation == "XN0001" && palletLocation == event.target._value) {
            self.$message.error("目标货位与货位不能同为虚拟货位");
            self.$refs.itemForm.form.setFieldsValue({ inPalletLocation: "" });
            return;
          }
          if (event.target._value.toUpperCase() == "XN0001") {
            self.getTargetContainer();
            return;
          }
          const params = self.$refs.itemForm.form.getFieldsValue();
          if (!params.stationNo && !params.palletLocation) {
            self.$message.warning(self.$lang("请先扫描站台号与原货位"));
            return;
          }
          var a = params.inPalletLocation.substring(0, 6);
          console.log(params.inPalletLocation, a, "params.containerNo ");
          getGoodsInfoByShelves({
            stationNo: params.stationNo,
            palletLocation: params.palletLocation.toUpperCase(),
            inPalletLocation: params.inPalletLocation.toUpperCase(),
            goodsId: params.goodsId,
          }).then((res) => {
            if (!res.success) {
              self.targetContainerReset();
              self.$exception(res);
              return;
            }
            if (!res.data) {
              self.$message.warning(self.$lang("目标货格无商品，可转入"));
            }
            if (res.data.containerNo) {
              self.$refs.itemForm.form.setFieldsValue({
                containerNo: res.data.containerNo,
                storeQty: res.data.storeQty,
                targetGoodsId: res.data.goodsId,
              });
              return;
            } else {
              self.$refs.itemForm.form.setFieldsValue({
                containerNo: params.inPalletLocation.substring(0, 6),
                storeQty: res.data.storeQty,
                targetGoodsId: res.data.goodsId,
              });
            }
          });
        },
      },
    },
    { type: "input", className: "input-md", size: "large", name: "containerNo", ...grid, label: "目的货架/目标托盘", value: "", span: 12, ...grid, disabled: true },

    { type: "", name: "", label: "", value: "", span: 24 },

    { type: "input", className: "input-md", size: "large", name: "itemCode", label: "商品条码", value: "", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "itemName", label: "商品名称", value: "", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "manufacturerId", label: "生产厂家", value: "", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "cargoOwnerName", label: "货主", value: "", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "specification", label: "规格", value: "", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "manufacturerLotNum", label: "批号", value: "", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "qty", label: "原货位数量", value: "", size: "large", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "itemHealthCategoryName", label: "商品大类", value: "", size: "large", span: 12, ...grid, disabled: true },
    { type: "input", className: "input-md", size: "large", name: "storeQty", label: "目的货位数量", value: 0, size: "large", span: 12, ...grid, disabled: true },
    // {  type: 'input', className: 'input-md', size: 'large', name: 'goodsStatus', label: '商品状态', value: '', size: "large", span: 12, disabled: true },
  ];
}

// 调出货架
export function detailItem(self) {
  return [
    { hidden: true, type: "input", name: "taskId", label: "taskId", value: "" },
    { hidden: true, type: "input", name: "conserveNo", label: "conserveNo", value: "" },
    { hidden: true, type: "input", name: "actualAllocation", label: "actualAllocation", value: "" },
    { hidden: true, type: "input", name: "conserveFlag", label: "conserveFlag", value: "" },
    { hidden: true, type: "input", name: "planes", label: "planes", value: "" },

    { type: "input", name: "itemCode", label: "商品条码", value: "", span: 8 },
    { type: "input", name: "palletLocation", label: "货架编号", value: "", span: 8 },

    { type: "input", name: "itemName", label: "商品名称", value: "", span: 8 },

    { type: "input", name: "lotNo", label: "批号信息", value: "", span: 8 },
    {
      type: "buttonGroup",
      style: { textAlign: "right" },
      span: 24,
      options: [
        {
          value: "查询",
          icon: "search",
          btnType: "primary",
          style: "margin-right:10px",
          htmlType: "submit",
        },
        {
          value: "重置",
          icon: "redo",
          on: {
            click: () => {
              self.$refs.detailForm.form.resetFields();
            },
          },
        },
      ],
    },
  ];
}
export function throttle(fn, time) {
  let timer = null;
  time = time || 1000;
  return function (...args) {
    if (timer) {
      return;
    }
    const _this = this;
    timer = setTimeout(() => {
      timer = null;
    }, time);
    fn.apply(_this, args);
  };
}

export function goodsbarItem(self) {
  return [
    {
      type: "input",
      name: "itemCode",
      label: "商品条码",
      value: "",
      span: 8,
      on: {
        pressEnter(KeyboardEvent, vonde) {
          self.checkApi("itemCode", KeyboardEvent, vonde);
        },
      },
    },
    {
      type: "input",
      name: "manufacturerLotNum",
      label: "批号",
      value: "",
      span: 8,
      on: {
        pressEnter(KeyboardEvent, vonde) {
          self.checkApi("itemCode", KeyboardEvent, vonde);
        },
      },
    },
    {
      type: "input",
      name: "itemName",
      label: "商品名称",
      value: "",
      span: 8,
      on: {
        pressEnter(KeyboardEvent, vonde) {
          self.checkApi("itemCode", KeyboardEvent, vonde);
        },
      },
    },
  ];
}
export const prinTableColumns = [
  { hidden: true, title: "taskId", dataIndex: "taskId" },
  { dataIndex: "cargoOwnerName", title: "货主" },
  { dataIndex: "itemCode", title: "商品条码" },
  { dataIndex: "itemName", title: "商品名称" },
  { dataIndex: "pieceConversionRate", title: "商品规格" },
  // { dataIndex: "goodsStatus", title: "商品状态"},
  { dataIndex: "packSize", title: "包装尺寸" },
  { dataIndex: "manufacturerLotNum", title: "批号" },
  { dataIndex: "qty", title: "库存数" },
  { dataIndex: "itemHealthCategoryName", title: "商品大类" },
];

export const tableColumns = [
  { hidden: true, title: "id", dataIndex: "id" },
  { hidden: true, title: "货主", dataIndex: "nodeType" },
  { title: "货架/托盘号", dataIndex: "palletNo" },
  { title: "货位", dataIndex: "palletLocation" },
  { title: "货位ABC属性", dataIndex: "palletAbcType" },
  // { title: '当前位置', dataIndex: 'sourceArea', },
  { title: "商品条码", dataIndex: "itemCode" },
  { title: "商品名称", dataIndex: "itemName", className: "v_top", sorter: (a, b) => (a.itemName ? a.itemName : "").localeCompare(b.itemName ? b.itemName : "") },
  { title: "商品ABC属性", dataIndex: "abcType" },
  { title: "货主", dataIndex: "cargoOwnerName", className: "v_top" },
  { title: "批号", dataIndex: "manufacturerLotNum", className: "v_top" },
  { title: "商品大类", dataIndex: "itemHealthCategoryName", className: "v_top" },
  { title: "数量", dataIndex: "qty", className: "v_top", sorter: (a, b) => a.qty - b.qty },
  { title: "操作", key: "operate", align: "center", scopedSlots: { customRender: "action" } },
];

export const containerColumns = [
  { hidden: true, title: "taskId", dataIndex: "taskId" },
  // { hidden: true, title: '货主', dataIndex: 'nodeType', },
  { dataIndex: "nodeType", title: "货主", key: "nodeType" },
  { dataIndex: "itemCode", title: "商品条码", key: "itemCode" },
  { dataIndex: "itemName", title: "商品名称", key: "itemName" },
  { dataIndex: "goodsType", title: "规格", key: "goodsType" },
  { dataIndex: "manufacturerLotNum", title: "批号", key: "manufacturerLotNum" },
  { dataIndex: "qty", title: "数量", key: "qty" },
  { dataIndex: "palletNo", title: "容器编号", key: "palletNo" },
  { dataIndex: "orderNo", title: "单据编号", key: "orderNo" },
];
