/* eslint-disable */
import React from 'react';
import weixin from 'weixin-js-sdk';
import { Flex, Button, ListView, Toast, Tabs, Badge,} from 'antd-mobile-v2';
import { createForm } from 'rc-form';
import 'antd-mobile-v2/dist/antd-mobile.css';
import CommobileBase from './CommobileBase';
import CommobileBillEvent from './CommobileBillEvent';
import CommobileViewMaster from './CommobileViewMaster';
import commonConfig from '../../utils/config';
import * as commonUtils from '../../utils/utils';
import ShowType from './CommobileComponent';
import CommobileToolBar from './CommobileToolBar';
import styles from '../mobile.less';
import add from '../../assets/mobile/add-select.svg';
import scan from '../../assets/mobile/scanning.svg';
import close from '../../assets/mobile/close.svg';
import * as commonFunc from '../../components/Common/commonFunc';
import BarCodeUtil from './BarCodeUtil';
import preView from '../components/preView';
import * as commonServices from "../../services/services";
import indexStyles from '../../routes/mobile/IndexMobile.less';
import ModalList from '../components/modal';
import CommonMobileList from './CommobileModalList';

const dataSource = new ListView.DataSource({
  rowHasChanged: (row1, row2) => row2,
});
const tabs = [
  { title: <Badge text="">明细</Badge> },
  { title: <Badge text="">汇总</Badge> },
];
let _this = {};
class CommobileBill extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      tabPage: 0,
      visible: false,
    };
    _this = this;
  }

  // eslint-disable-next-line react/sort-comp
  handleClick = async (name, type, sId) => {
    if (name === 'BtnSave') {
      this.props.onSubmit();
    } else if (name === 'BtnUpd') {
      this.props.onEdit(name);
    } else if (type === 'add') {
      this.props.onDataRowAdd(name);
    } else if (type === 'del') {
      const { app, [`${name}Data`]: tableData } = this.props;
      let { [`${name}DelData`]: tableDelData } = this.props;
      tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
      if (sId !== '') {
        const tableDataIndex = tableData.findIndex(item => item.sId === sId);
        if (tableDataIndex > -1) {
          const slaveDataFilter = tableData[tableDataIndex];
          tableData.splice(tableDataIndex, 1);
          slaveDataFilter.handleType = 'del';
          tableDelData.push(slaveDataFilter);
        }
        this.props.onSaveState({
          [`${name}Data`]: tableData,
          [`${name}DelData`]: tableDelData,
          [`${name}SelectedRowKeys`]: [],
        });
      } else {
        Toast.fail(commonFunc.showMessage(app.commonConst, 'pleaseChooseDelData')); // 请选择删除数据
      }
    } else if (type === 'scan' || name === 'BtnScan' || name === 'BtnScanPda') {
      BarCodeUtil.startScan(async (type, code) => {
        const {
          slaveConfig, sModelsId, masterData, slaveData, sModelsType, masterConfig,
        } = this.props;
        /* 规则定义
        材料
        sDefineNo: codeArr[0],  --唯一码
        sMaterialsName: codeArr[1], --材料名称
        sMaterialsStyle: codeArr[2], --材料规格
        dAuxiliaryQty: codeArr[3],  --数量
        sWareHouseName: codeArr[4], --仓库名称
        sLocationName: codeArr[5], --名称
        sDefineNo2: codeArr[6], --二维码
        tInStoreDate: codeArr[7], --入库日期
        sMaterialsId: codeArr[8], --材料ID
        sWareHouseId: codeArr[9], --仓库ID
        sLocationId: codeArr[10], --sLocationId
        成品
        sDefineNo: codeArr[0],  --唯一码
        sProductName: codeArr[1], --产品名称
        sProductStyle: codeArr[2], --产品规格
        dProductQty: codeArr[3], --产品数量
        sWarehouseName: codeArr[4], --仓库名称
        sLocationName: codeArr[5], --仓库名称
        sDefineNo2: codeArr[6], --二维码
        tInStoreDate: codeArr[7], --入库日期
        sProductId: codeArr[8], --产品ID
        sWareHouseId: codeArr[9], --仓库ID
        sLocationId: codeArr[10],
        sCustomerName: codeArr[11], --客户名称
        sCustomerShort: codeArr[12],
        sOrderNo: codeArr[13], --订单号
        sWorkOrderNo: codeArr[14], --工单号
        sCustomerOrderNo: codeArr[15], --客户编号
        sCustomerProductNo: codeArr[16], --客户产品编号
        */
        // const slaveData = [];
        let slaveDataObj = {};
        let masterdataObj = {};
        let slaveDataObjAdd = {};
        let masterDataObjAdd = {};
        if (commonUtils.isEmptyObject(code)) {
          Toast.fail('二维码扫码失败！', 1);
          return;
        }
        const codeArr = code.split('|');
        let models = '';
        if (codeArr.length === 12) { /* 材料 */
          models = 'Materials';
        } else if (codeArr.length === 17) { /* 成品 */
          models = 'Product';
        } else {
          models = 'Single'; /* 单一的 */
        }
        if (models === 'Single') { /* sModelsType === 'purchase/purchaseInstore' 扫码入库、扫码领料(唯一码) */
          /* 取第一条码 */
          const sDefineNo = codeArr.length > 0 ? codeArr[0] : '';
          /* 如果条码已存在，提示 */
          // const iIndex = slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sDefineNo) && item.sDefineNo === sDefineNo);
          // if (iIndex > -1) {
          //   Toast.fail('条码已存在!!!', 1);
          //   return;
          // }
          /* 读取扫码配置 */
          let btnScanConfigs;
          if (name === 'BtnScanPda') {
            btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sControlName.indexOf('_pda') > -1);
          } else {
            btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.sControlName.indexOf('BtnScan') > -1);
          }

          const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
          const sDefineNoName = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sActiveKey : 'sDefineNo';

          masterdataObj = {
            ...masterData, [sDefineNoName] : sDefineNo
          };
          /* 唯一码调接口 */
          let sqlDataRow ={};
          if(commonUtils.isNotEmptyArr(btnScanConfigs)) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', btnScanConfigs[0], masterdataObj);

            if( name === 'BtnScanPda') {
              this.handleSqlDropDownData({
                sqlDropDownData,
                fieldConfig: { ...btnScanConfigs?.[0] || [], sName: sDefineNoName },
                masterdataObj,
                slaveDataNew: slaveData,
                sFieldName: sDefineNoName ,
              })
              return;
            }

            if(commonUtils.isNotEmptyArr(sqlDropDownData)) {
              sqlDataRow = sqlDropDownData[0];
            }
          }
          slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, masterdataObj) }; // 取主表赋值字段
          if(commonUtils.isNotEmptyObject(sqlDataRow)) {
            slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, sqlDataRow) }; // 取接口数据源赋值字段
          }
          slaveDataObj.sParentId = masterdataObj.sId;
          if (commonUtils.isNotEmptyArr(slaveData)) {
            const len = slaveData.length;
            const sDefineNoNew = slaveData[len - 1][sDefineNoName];
            const { handleType } = slaveData[len - 1];
            /* 若slaveData 最后一条数据没有条形码，则赋值条形码；否则新增一条数据 */
            if (commonUtils.isEmptyObject(sDefineNoNew)) {
              slaveDataObj.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
               // slaveData[len - 1] = slaveDataObj;
              slaveData[len - 1] = { ...slaveData[len-1], ...slaveDataObj};
            } else {
              slaveDataObj.sId = commonUtils.createSid();
              slaveDataObj.handleType = 'add';
              slaveData.push(slaveDataObj);
            }
          } else {
            slaveDataObj.sId = commonUtils.createSid();
            slaveDataObj.handleType = 'add';
            slaveData.push(slaveDataObj);
          }
          if (sModelsType === 'scan/productionmaterials') { /* 只有扫码领料连续扫码 */
            this.handleClick('slave', 'scan'); /* 连续扫码 */
          }
        } else if (models === 'Materials') { /* sModelsType === 'materialsStock/productionmaterials' */
          /* 取第一条码 */
          const sDefineNo = codeArr.length > 0 ? codeArr[0] : '';
          /* 如果条码已存在，提示 */
          // const iIndex = commonUtils.isNotEmptyArr(slaveData) ? slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sDefineNo) && item.sDefineNo === sDefineNo) : -1;
          // if (iIndex > -1) {
          //   Toast.fail('条码已存在!!!', 1);
          //   return;
          // }
          const dateStr = codeArr.length > 7 && commonUtils.isNotEmptyObject(codeArr[7])? codeArr[7].replace(/-/g, '/') : undefined;
          // const date = new Date(dataStr);
          slaveDataObjAdd = {
            sDefineNo: codeArr.length > 0 ? codeArr[0] : '',
            sMaterialsName: codeArr.length > 1 ? codeArr[1] : '',
            sMaterialsStyle: codeArr.length > 2 ? codeArr[2] : '',
            dAuxiliaryQty: codeArr.length > 3 ? commonUtils.isNull(Number(codeArr[3]), 0) : '',
            sDefineNo2: codeArr.length > 6 ? codeArr[6] : '',
            sMaterialsId: codeArr.length > 8 ? codeArr[8] : '',
            sWareHouseId: codeArr.length > 9 ? codeArr[9] : '',
            sLocationId: codeArr.length > 10 ? codeArr[10] : '',
            dMaterialsQty: codeArr.length > 11 ? commonUtils.isNull(Number(codeArr[11]), 0) : '',
            tInStoreDate: dateStr,
          };
          masterdataObj = {
            ...masterData, ...slaveDataObjAdd,
          };
          /* 读取扫码配置 */
          const btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.sControlName.indexOf('BtnScan.slave') > -1);
          // if(commonUtils.isEmptyArr(btnScanConfigs)) {
          //   Toast.fail('请配置扫码按钮!!!', 1);
          //   return;
          // }
          const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
          let sqlDataRow ={};
          if(commonUtils.isNotEmptyArr(btnScanConfigs)) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', btnScanConfigs[0], masterdataObj);
            if(commonUtils.isNotEmptyArr(sqlDropDownData)) {
              sqlDataRow = sqlDropDownData[0];
            }
          }
          if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) { /* 拿原始从表值 */
            const len = slaveData.length;
            const sDefineNoNew = slaveData[len - 1].sDefineNo;
            if (commonUtils.isEmptyArr(sDefineNoNew)) {
              slaveDataObj = { ...slaveDataObj, ...slaveData[len - 1] };
            }
          }
          slaveDataObj = { ...slaveDataObjAdd, ...commonFunc.getAssignFieldValue(AssignField, masterData) }; // 取赋值字段
          if(commonUtils.isNotEmptyObject(sqlDataRow)) {
            slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, sqlDataRow) }; // 取接口数据源赋值字段
          }

          // slaveDataObj.sDefineNo = sDefineNo;
          slaveDataObj.sId = commonUtils.createSid();
          slaveDataObj.iOrder = 1;
          console.log('slaveDataObj1111', slaveDataObj);
          const slaveDataConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave : '';
          const materialsNameConfig = slaveDataConfig.filter(item => item.sName === 'sMaterialsId');
          const sWareHouseNameConfig = slaveDataConfig.filter(item => item.sName === 'sWareHouseId');
          const sLocationNameConfig = slaveDataConfig.filter(item => item.sName === 'sLocationId');
          const onDataRowAdd = this.props.onDataRowAdd(name, true);
          const materialseAssignField = commonUtils.isNotEmptyArr(materialsNameConfig) ? materialsNameConfig[0].sAssignField : '';
          const sWareHouseNameAssignField = commonUtils.isNotEmptyArr(sWareHouseNameConfig) ? sWareHouseNameConfig[0].sAssignField : '';
          const sLocationNameAssignField = commonUtils.isNotEmptyArr(sLocationNameConfig) ? sLocationNameConfig[0].sAssignField : '';

          let materialsNameDropDownData = [];
          let sWareHouseNamedropDownData = [];
          let sLocationNamedropDownData = [];
          if (commonUtils.isNotEmptyObject(materialsNameConfig[0]) && materialsNameConfig[0].sDropDownType === 'sql') {
            materialsNameDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', materialsNameConfig[0], slaveData);
          }
          if (commonUtils.isNotEmptyObject(sWareHouseNameConfig[0]) && sWareHouseNameConfig[0].sDropDownType === 'sql') {
            sWareHouseNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sWareHouseNameConfig[0], slaveData);
          }
          if (commonUtils.isNotEmptyObject(sLocationNameConfig[0]) && sLocationNameConfig[0].sDropDownType === 'sql') {
            sLocationNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', sLocationNameConfig[0], masterData);
          }
          // }
          let materialsNameDataOne;
          let sWareHouseNameDataOne;
          let sLocationNameDataOne;
          if (!commonUtils.isEmpty(materialsNameDropDownData)) {
            if (codeArr.length > 1) {
              materialsNameDataOne = materialsNameDropDownData.filter(item => item.sMaterialsName === codeArr[1]);
            }
          }
          if (!commonUtils.isEmpty(sWareHouseNamedropDownData)) {
            if (codeArr.length > 4) {
              sWareHouseNameDataOne = sWareHouseNamedropDownData.filter(item => item.sName === codeArr[4]);
            }
          }
          if (!commonUtils.isEmpty(sLocationNamedropDownData)) {
            if (codeArr.length > 5) {
              sLocationNameDataOne = sLocationNamedropDownData.filter(item => item.sName === codeArr[5]);
            }
          }
          const newCopyTo = {};
          newCopyTo.master = masterdataObj;
          newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
          let materialsDataDetiale = {};
          let sWareHouseNameDataDetiale = {};
          let sLocationNameDataDetiale = {};
          materialsDataDetiale = { ...commonFunc.getAssignFieldValue(materialseAssignField, materialsNameDataOne[0], newCopyTo) };
          sWareHouseNameDataDetiale = { ...commonFunc.getAssignFieldValue(sWareHouseNameAssignField, sWareHouseNameDataOne[0], newCopyTo) };
          sLocationNameDataDetiale = { ...commonFunc.getAssignFieldValue(sLocationNameAssignField, sLocationNameDataOne[0], newCopyTo) };
          slaveDataObj = {
            ...slaveDataObj,
            ...onDataRowAdd,
            ...materialsDataDetiale,
            ...sWareHouseNameDataDetiale,
            ...slaveDataObjAdd,
            ...sLocationNameDataDetiale,
          };
          masterdataObj = { ...masterdataObj, ...sLocationNameDataDetiale, ...sWareHouseNameDataDetiale };
        } else if (sModelsType === 'Product') { // 扫码待发货 sales/salesSgoods
          /* 取第一条码 */
          const sDefineNo = codeArr.length > 0 ? codeArr[0] : '';
          /* 如果条码已存在，提示 */
          // const iIndex = commonUtils.isNotEmptyArr(slaveData) ? slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sDefineNo) && item.sDefineNo === sDefineNo) : -1;
          // if (iIndex > -1) {
          //   Toast.fail('条码已存在!!!', 1);
          //   return;
          // }
          const dateStr = codeArr.length > 7 && commonUtils.isNotEmptyObject(codeArr[7])? codeArr[7].replace(/-/g, '/') : undefined;
          slaveDataObjAdd = {
            sCustomerShort: codeArr.length > 12 ? codeArr[12] : '',
            sOrderNo: codeArr.length > 13 ? codeArr[13] : '',
            sWorkOrderNo: codeArr.length > 14 ? codeArr[14] : '',
            sCustomerOrderNo: codeArr.length > 15 ? codeArr[15] : '',
            sCustomerProductNo: codeArr.length > 13 ? codeArr[16] : '',
            sDefineNo: codeArr.length > 0 ? codeArr[0] : '',
            sDefineNo2: codeArr.length > 6 ? codeArr[6] : '',
            dProductQty: codeArr.length > 3 ? commonUtils.isNull(Number(codeArr[3]), 0): '',
            tInStoreDate: dateStr,
          };
          masterdataObj = {
            ...masterData, ...slaveDataObjAdd,
          };
          // masterDataObjAdd = {
          //   sCustomerShort: codeArr.length > 12 ? codeArr[12] : '', sDefineNo: sDefineNo,
          // };
          /* 读取多条扫码配置 */
          const btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.sControlName.indexOf('BtnScan.slave') > -1);
          const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
          if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) { /* 拿原始从表值 */
            const len = slaveData.length;
            const sDefineNoNew = slaveData[len - 1].sDefineNo;
            if (commonUtils.isEmptyArr(sDefineNoNew)) {
              slaveDataObj = { ...slaveDataObj, ...slaveData[len - 1] };
            }
          }
          /* 唯一码调接口 */
          let sqlDataRow ={};
          if(commonUtils.isNotEmptyArr(btnScanConfigs)) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', btnScanConfigs[0], masterdataObj);
            if(commonUtils.isNotEmptyArr(sqlDropDownData)) {
              sqlDataRow = sqlDropDownData[0];
            }
          }
          slaveDataObj = { ...slaveDataObjAdd, ...commonFunc.getAssignFieldValue(AssignField, masterdataObj) }; // 取赋值字段
          if(commonUtils.isNotEmptyObject(sqlDataRow)) {
            slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, sqlDataRow) }; // 取接口数据源赋值字段
          }
          // slaveDataObj.sDefineNo = sDefineNo;
          slaveDataObj.sId = commonUtils.createSid();
          slaveDataObj.iOrder = 1;
          const slaveDataConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave : '';
          const sWareHouseNameConfig = slaveDataConfig.filter(item => item.sName === 'sWareHouseId'); // 仓库名称
          const sLocationNameConfig = slaveDataConfig.filter(item => item.sName === 'sLocationId');// 库区库位
          const sProductNameConfig = slaveDataConfig.filter(item => item.sName === 'sProductId');// 产品名称


          const onDataRowAdd = this.props.onDataRowAdd(name, true);
          const sWareHouseNameAssignField = commonUtils.isNotEmptyArr(sWareHouseNameConfig) ? sWareHouseNameConfig[0].sAssignField : '';
          const sLocationNameAssignField = commonUtils.isNotEmptyArr(sLocationNameConfig) ? sLocationNameConfig[0].sAssignField : '';
          const sProductNameAssignField = commonUtils.isNotEmptyArr(sProductNameConfig) ? sProductNameConfig[0].sAssignField : '';


          let sWareHouseNamedropDownData = [];
          let sLocationNamedropDownData = [];
          let sProductNamedropDownData = [];
          if (commonUtils.isNotEmptyObject(sWareHouseNameConfig[0]) && sWareHouseNameConfig[0].sDropDownType === 'sql') {
            sWareHouseNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sWareHouseNameConfig[0], slaveData);
          }
          if (commonUtils.isNotEmptyObject(sLocationNameConfig[0]) && sLocationNameConfig[0].sDropDownType === 'sql') {
            sLocationNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', sLocationNameConfig[0], masterData);
          }
          if (commonUtils.isNotEmptyObject(sProductNameConfig[0]) && sProductNameConfig[0].sDropDownType === 'sql') {
            sProductNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sProductNameConfig[0], slaveData);
          }
          let sWareHouseNameDataOne;
          let sLocationNameDataOne;
          let sProductNameDataOne;
          if (!commonUtils.isEmpty(sWareHouseNamedropDownData)) {
            if (codeArr.length > 4) {
              sWareHouseNameDataOne = sWareHouseNamedropDownData.filter(item => item.sName === codeArr[4]);
            }
          }
          if (!commonUtils.isEmpty(sLocationNamedropDownData)) {
            if (codeArr.length > 5) {
              sLocationNameDataOne = sLocationNamedropDownData.filter(item => item.sName === codeArr[5]);
            }
          }
          if (!commonUtils.isEmpty(sProductNamedropDownData)) {
            if (codeArr.length > 1) {
              sProductNameDataOne = sProductNamedropDownData.filter(item => item.sProductName === codeArr[1]);
            }
          }
          const newCopyTo = {};
          newCopyTo.master = masterData;
          newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
          let sWareHouseNameDataDetiale = {};
          let sLocationNameDataDetiale = {};
          let sProductNameDataDetiale = {};
          sWareHouseNameDataDetiale = { ...commonFunc.getAssignFieldValue(sWareHouseNameAssignField, sWareHouseNameDataOne[0], newCopyTo) };
          sLocationNameDataDetiale = { ...commonFunc.getAssignFieldValue(sLocationNameAssignField, sLocationNameDataOne[0], newCopyTo) };
          sProductNameDataDetiale = { ...commonFunc.getAssignFieldValue(sProductNameAssignField, sProductNameDataOne[0], newCopyTo) };
          slaveDataObj = {
            ...slaveDataObj,
            ...onDataRowAdd,
            ...sWareHouseNameDataDetiale,
            ...slaveDataObjAdd,
            ...sProductNameDataDetiale,
            ...sLocationNameDataDetiale,
          };
          masterdataObj = {
            ...masterData,
            ...sLocationNameDataDetiale,
            ...masterDataObjAdd,
            ...sWareHouseNameDataDetiale,
          };
        } else {
          Toast.fail('二维码不存在!!!', 1);
        }
        if (models !== 'Single') {
          slaveData.push(slaveDataObj);
        }
        this.props.onSaveState({ slaveData, masterData: masterdataObj });
      });
    } else if (type === 'scan1') {
      BarCodeUtil.startScan(async (type, code) => {
        const {
          slaveConfig, sModelsId, masterData, slaveData, sModelsType,
        } = this.props;
        // const slaveData = [];
        let slaveDataObj = {};
        let masterdataObj = {};
        let slaveDataObjAdd = {};
        let masterDataObjAdd = {};
        const codeArr = code.split('|');
        if (sModelsType === 'materialsStock/productionmaterials') {
          const dataStr = codeArr[10].replace(/-/g, '/');
          const date = new Date(dataStr);
          slaveDataObjAdd = {
            sMaterialsStyle: codeArr[1],
            sDefineNo: codeArr[4],
            sDefineNo2: codeArr[5],
            dAuxiliaryQty: codeArr[7],
            tInStoreDate: date,
          };
          const slaveDataConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave : '';
          const materialsNameConfig = slaveDataConfig.filter(item => item.sName === 'sMaterialsId');
          const sWareHouseNameConfig = slaveDataConfig.filter(item => item.sName === 'sWareHouseId');
          const sLocationNameConfig = slaveDataConfig.filter(item => item.sName === 'sLocationId');
          const onDataRowAdd = this.props.onDataRowAdd(name, true);
          const materialseAssignField = commonUtils.isNotEmptyArr(materialsNameConfig) ? materialsNameConfig[0].sAssignField : '';
          const sWareHouseNameAssignField = commonUtils.isNotEmptyArr(sWareHouseNameConfig) ? sWareHouseNameConfig[0].sAssignField : '';
          const sLocationNameAssignField = commonUtils.isNotEmptyArr(sLocationNameConfig) ? sLocationNameConfig[0].sAssignField : '';

          let materialsNameDropDownData = [];
          let sWareHouseNamedropDownData = [];
          let sLocationNamedropDownData = [];
          if (commonUtils.isNotEmptyObject(materialsNameConfig[0]) && materialsNameConfig[0].sDropDownType === 'sql') {
            materialsNameDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', materialsNameConfig[0], slaveData);
          }
          if (commonUtils.isNotEmptyObject(sWareHouseNameConfig[0]) && sWareHouseNameConfig[0].sDropDownType === 'sql') {
            sWareHouseNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sWareHouseNameConfig[0], slaveData);
          }
          if (commonUtils.isNotEmptyObject(sLocationNameConfig[0]) && sLocationNameConfig[0].sDropDownType === 'sql') {
            sLocationNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', sLocationNameConfig[0], masterData);
          }
          // }
          let materialsNameDataOne;
          let sWareHouseNameDataOne;
          let sLocationNameDataOne;
          if (!commonUtils.isEmpty(materialsNameDropDownData)) {
            materialsNameDataOne = materialsNameDropDownData.filter(item => item.sMaterialsName === codeArr[6]);
          }
          if (!commonUtils.isEmpty(sWareHouseNamedropDownData)) {
            sWareHouseNameDataOne = sWareHouseNamedropDownData.filter(item => item.sName === codeArr[2]);
          }
          if (!commonUtils.isEmpty(sLocationNamedropDownData)) {
            sLocationNameDataOne = sLocationNamedropDownData.filter(item => item.sName === codeArr[3]);
          }
          const newCopyTo = {};
          newCopyTo.master = masterData;
          newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
          let materialsDataDetiale = {};
          let sWareHouseNameDataDetiale = {};
          let sLocationNameDataDetiale = {};
          materialsDataDetiale = { ...commonFunc.getAssignFieldValue(materialseAssignField, materialsNameDataOne[0], newCopyTo) };
          sWareHouseNameDataDetiale = { ...commonFunc.getAssignFieldValue(sWareHouseNameAssignField, sWareHouseNameDataOne[0], newCopyTo) };
          sLocationNameDataDetiale = { ...commonFunc.getAssignFieldValue(sLocationNameAssignField, sLocationNameDataOne[0], newCopyTo) };
          slaveDataObj = {
            ...onDataRowAdd,
            ...materialsDataDetiale,
            ...sWareHouseNameDataDetiale,
            ...slaveDataObjAdd,
            ...sLocationNameDataDetiale,
          };
          masterdataObj = { ...masterData, ...sLocationNameDataDetiale, ...sWareHouseNameDataDetiale };
        } else if (sModelsType === 'sales/salesSgoods') { // 扫码待发货
          const dataStr = codeArr[12].replace(/-/g, '/');
          const date = new Date(dataStr);
          slaveDataObjAdd = {
            sOrderNo: codeArr[9],
            sWorkOrderNo: codeArr[8],
            sCustomerOrderNo: codeArr[10],
            sCustomerProductNo: codeArr[11],
            sDefineNo: codeArr[3],
            sDefineNo2: codeArr[4],
            dProductQty: codeArr[6],
            tInStoreDate: date,
          };
          masterDataObjAdd = {
            sCustomerShort: codeArr[7],
          };
          const slaveDataConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave : '';
          const sWareHouseNameConfig = slaveDataConfig.filter(item => item.sName === 'sWareHouseId'); // 仓库名称
          const sLocationNameConfig = slaveDataConfig.filter(item => item.sName === 'sLocationId');// 库区库位
          const sProductNameConfig = slaveDataConfig.filter(item => item.sName === 'sProductId');// 产品名称


          const onDataRowAdd = this.props.onDataRowAdd(name, true);
          const sWareHouseNameAssignField = commonUtils.isNotEmptyArr(sWareHouseNameConfig) ? sWareHouseNameConfig[0].sAssignField : '';
          const sLocationNameAssignField = commonUtils.isNotEmptyArr(sLocationNameConfig) ? sLocationNameConfig[0].sAssignField : '';
          const sProductNameAssignField = commonUtils.isNotEmptyArr(sProductNameConfig) ? sProductNameConfig[0].sAssignField : '';


          let sWareHouseNamedropDownData = [];
          let sLocationNamedropDownData = [];
          let sProductNamedropDownData = [];
          if (commonUtils.isNotEmptyObject(sWareHouseNameConfig[0]) && sWareHouseNameConfig[0].sDropDownType === 'sql') {
            sWareHouseNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sWareHouseNameConfig[0], slaveData);
          }
          if (commonUtils.isNotEmptyObject(sLocationNameConfig[0]) && sLocationNameConfig[0].sDropDownType === 'sql') {
            sLocationNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', sLocationNameConfig[0], masterData);
          }
          if (commonUtils.isNotEmptyObject(sProductNameConfig[0]) && sProductNameConfig[0].sDropDownType === 'sql') {
            sProductNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sProductNameConfig[0], slaveData);
          }
          let sWareHouseNameDataOne;
          let sLocationNameDataOne;
          let sProductNameDataOne;
          if (!commonUtils.isEmpty(sWareHouseNamedropDownData)) {
            sWareHouseNameDataOne = sWareHouseNamedropDownData.filter(item => item.sName === codeArr[1]);
          }
          if (!commonUtils.isEmpty(sLocationNamedropDownData)) {
            sLocationNameDataOne = sLocationNamedropDownData.filter(item => item.sName === codeArr[2]);
          }
          if (!commonUtils.isEmpty(sProductNamedropDownData)) {
            sProductNameDataOne = sProductNamedropDownData.filter(item => item.sProductName === codeArr[5]);
          }
          const newCopyTo = {};
          newCopyTo.master = masterData;
          newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
          let sWareHouseNameDataDetiale = {};
          let sLocationNameDataDetiale = {};
          let sProductNameDataDetiale = {};
          sWareHouseNameDataDetiale = { ...commonFunc.getAssignFieldValue(sWareHouseNameAssignField, sWareHouseNameDataOne[0], newCopyTo) };
          sLocationNameDataDetiale = { ...commonFunc.getAssignFieldValue(sLocationNameAssignField, sLocationNameDataOne[0], newCopyTo) };
          sProductNameDataDetiale = { ...commonFunc.getAssignFieldValue(sProductNameAssignField, sProductNameDataOne[0], newCopyTo) };
          slaveDataObj = {
            ...onDataRowAdd,
            ...sWareHouseNameDataDetiale,
            ...slaveDataObjAdd,
            ...sProductNameDataDetiale,
            ...sLocationNameDataDetiale,
          };
          masterdataObj = {
            ...masterData,
            ...sLocationNameDataDetiale,
            ...masterDataObjAdd,
            ...sWareHouseNameDataDetiale,
          };
        } else if (sModelsType === 'purchase/purchaseInstore' || sModelsType === 'scan/productionmaterials') { /* 扫码入库、扫码领料(唯一码) */
          const { masterConfig } = this.props;
          /* 取第一条码 */
          const sDefineNo = codeArr[0];
          /* 如果条码已存在，提示 */
          const iIndex = slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sDefineNo) && item.sDefineNo === sDefineNo);
          if (iIndex > -1) {
            Toast.fail('条码已存在!!!', 1);
            return;
          }
          masterdataObj = {
            ...masterData,
          };
          /* 读取扫码配置 */
          const btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.sControlName.indexOf('BtnScan') > -1);
          const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
          if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) { /* 拿原始从表值 */
            const len = slaveData.length;
            const sDefineNoNew = slaveData[len - 1].sDefineNo;
            if (commonUtils.isEmptyArr(sDefineNoNew)) {
              slaveDataObj = { ...slaveDataObj, ...slaveData[len - 1] };
            }
          }
          slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, masterData) }; // 取赋值字段
          slaveDataObj.sDefineNo = sDefineNo;
          slaveDataObj.sId = commonUtils.createSid();
          if (commonUtils.isNotEmptyArr(slaveData)) {
            const len = slaveData.length;
            const sDefineNoNew = slaveData[len - 1].sDefineNo;
            const { handleType } = slaveData[len - 1];
            /* 若slaveData 最后一条数据没有条形码，则赋值条形码；否则新增一条数据 */
            if (commonUtils.isEmptyArr(sDefineNoNew)) {
              slaveDataObj.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
              slaveData[len - 1] = slaveDataObj;
            } else {
              slaveDataObj.handleType = 'add';
              slaveData.push(slaveDataObj);
            }
          } else {
            slaveDataObj.handleType = 'add';
            slaveData.push(slaveDataObj);
          }
          if (sModelsType === 'scan/productionmaterials') { /* 只有扫码领料连续扫码 */
            this.handleClick('slave', 'scan'); /* 连续扫码 */
          }
        } else {
          Toast.fail('二维码不存在!!!', 1);
        }
        if (sModelsType !== 'purchase/purchaseInstore' && sModelsType !== 'scan/productionmaterials') {
          slaveData.push(slaveDataObj);
        }
        this.props.onSaveState({ slaveData, masterData: masterdataObj });
      });
    } else if (commonUtils.isNotEmptyObject(name) && name.includes('BtnScan')) { /* 主表 扫流转码 */
      BarCodeUtil.startScan(async (type, code) => {
        const { masterConfig } = this.props;
        let { masterData } = this.props;
        let masterdataObj = {};
        const codeArr = code.split('|');
        if (commonUtils.isNotEmptyObject(codeArr)) { /* 扫流转码功能 */
          /* 取第一条码 */
          const sDefineNo = codeArr[0];
          /* 如果条码已存在，提示 */
          masterData.sDefineNo = sDefineNo;
          masterdataObj = {
            ...masterData,
          };
          /* 读取扫码配置 */
          const btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.bVisible && item.sControlName.indexOf('BtnScan') > -1);
          const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
          masterData = { ...masterdataObj, ...commonFunc.getAssignFieldValue(AssignField, masterData) }; // 取赋值字段
          masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
          // this.handleClick('slave', 'scan'); /* 连续扫码 */
        } else {
          Toast.fail('二维码不存在!!!', 1);
        }
        this.props.onSaveState({ masterData });
      });
    } else if (name === 'BtnCamera') { /* 手机调动摄像头拍照 */
      this.handleCamera();
    } else if (name === 'BtnPhoto') { /* 手机相册选择图片 */
      this.handleGetPhoto();
    } else if (name === 'BtnCancel') {
      window.history.back(-1);
    } else if (name === 'BtnExamine') {
      this.props.onAudit(1);
    } else if (name === 'BtnCancelExamine') {
      /* 销审 */
      this.props.onAudit(0);
    }
  }
  handleCamera = () => {
    BarCodeUtil.getImage();
  }
  handleGetPhoto = () => {
    BarCodeUtil.getPhoto();
  }

  /**pda扫码数据 */
  fieldConfig = React.createRef();
  masterdataObj = React.createRef();
  ModalList = React.createRef();
  selectedRowkeys = React.createRef();
  cancelValue = React.createRef();

  modalProps = {
    title: <div style={{ fontSize: 18, fontWeight: 'bold'}}>请选择</div>,
    cancelAction: () => this.cancelAction(),
    submitAction: () => {
      this.handleAddPdaValue(this.selectedRowkeys.current);
      this.setState({ visible: false });
    },
  };

  setSelectedRowkeys = (v) => {
    this.selectedRowkeys.current = v;
  }
  /**打开弹窗 */
  openModalList = () => {
    this.setState({ visible: true });
  }

  handleMasterFieldScan = (fieldConfig, tbName, record, newValue, cancelValue) => {
    this.cancelValue.current = cancelValue;
    this.handlePdaFieldScan(fieldConfig, tbName, record, newValue); /* PDA扫码逻辑 */
  }

  clearCache = () => {
    this.fieldConfig.current = null;
    this.masterdataObj.current = null;
  }

  /**
   * 关闭弹框
   */
  cancelAction = () => {
    this.setSelectedRowkeys(null);
    this.cancelValue.current && this.cancelValue.current();
    this.clearCache();
    this.setState({ visible: false });
  }

  filterSlaveData = (v) => {
    if (!this.fieldConfig.current) return [];
    const sFieldName = this.fieldConfig.current.sName;
    const { slaveData } = this.props;
    return v.filter(i => i && !slaveData?.find(j => j && j[sFieldName] ===  i[sFieldName]));
  }

  /**
   * pda 扫描
   * @returns
   */
  handlePdaFieldScan = async (fieldConfig, tbName, record, newValue) => {
    const {
      sModelsId, masterData,
    } = this.props;
    const { slaveData: slaveDataNew } = this.props;
    const code = newValue;
    if (commonUtils.isEmptyObject(code) || typeof code !== 'string') {
      return;
    }
    if (commonUtils.isEmptyObject(fieldConfig)) {
      Toast.fail('未配置PDA!');
      return;
    }
    const sFieldName = fieldConfig.sName;
    let masterdataObj = masterData;
    masterdataObj = {
      ...masterData, [sFieldName]: code,
    };
    const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', fieldConfig, masterdataObj);
    this.handleSqlDropDownData({ sqlDropDownData, fieldConfig, masterdataObj, slaveDataNew, sFieldName });
  }

  handleSqlDropDownData = (v) => {
    const { sqlDropDownData, fieldConfig, slaveDataNew, sFieldName } = v;
    let { masterdataObj } = v;
    if (!Array.isArray(sqlDropDownData) || commonUtils.isEmptyArr(sqlDropDownData)) {
      Toast.fail('暂无数据', 1);
      this.clearCache();
      return;
    }
    this.fieldConfig.current = fieldConfig;
    this.masterdataObj.current = masterdataObj;
    if (sqlDropDownData.length === 1) {
      /* 如果条码已存在，提示 */
      const iFIndex = commonUtils.isNotEmptyArr(slaveDataNew) ? slaveDataNew.findIndex(item => item[sFieldName] === sqlDropDownData[0][sFieldName]) : -1;
      if (iFIndex > -1) {
        this.cancelValue.current && this.cancelValue.current();
        this.cancelValue.current = null;
        Toast.fail('条码已存在!', 1);
        this.clearCache();
        return;
      }
      this.setSelectedRowkeys(sqlDropDownData);
      this.handleAddPdaValue(sqlDropDownData);
    }else if(sqlDropDownData.length > 1) {
      /* 数据赋值到主表 */
      const AssignField = commonUtils.isNotEmptyArr(this.fieldConfig.current) ? this.fieldConfig.current?.sAssignField : '';
      masterdataObj = {...masterdataObj,  ...commonFunc.getAssignFieldValue(AssignField, sqlDropDownData[0]) };
      this.masterdataObj.current = masterdataObj;
    }
    if(sqlDropDownData.length > 1 ) {
      this.openModalList();
    }
    return;
  }

  /**
   * pda扫描添加数据
   * @returns
   */
  handleAddPdaValue = (value) => {
    let { slaveData: slaveDataNew } = this.props;
    this.cancelValue.current && this.cancelValue.current();
    this.cancelValue.current = null;
    if (!this.fieldConfig.current ||
       !this.masterdataObj.current ||
        !Array.isArray(value) || !value.length) {
          this.clearCache();
          this.setSelectedRowkeys(null);
          return
      };
    let masterdataObj = this.masterdataObj.current;
    const sFieldName = this.fieldConfig.current.sName;
    const AssignField = commonUtils.isNotEmptyArr(this.fieldConfig.current) ? this.fieldConfig.current?.sAssignField : '';
    if (commonUtils.isEmptyArr(slaveDataNew)) {
      slaveDataNew = [];
    }
    value.forEach((sqlDataRow) => {
      let slaveDataObj = {};
      masterdataObj = {...masterdataObj,  ...commonFunc.getAssignFieldValue(AssignField, sqlDataRow) };
      slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, masterdataObj) }; // 取主表赋值字段
      if (commonUtils.isNotEmptyObject(sqlDataRow)) {
        slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, sqlDataRow) }; // 取接口数据源赋值字段
      }
      slaveDataObj.sId = commonUtils.createSid();
      slaveDataObj.handleType = 'add';
      slaveDataObj.sParentId = masterdataObj.sId;
      slaveDataNew.push(slaveDataObj);
    });
    if (commonUtils.isNotEmptyObject(masterdataObj)) {
      const handleType = commonUtils.isEmpty(masterdataObj.handleType) ? 'update' : masterdataObj.handleType;
      masterdataObj = { ...masterdataObj, [sFieldName]: '', handleType };
    }
    this.clearCache();
    this.setSelectedRowkeys(null);
    this.props.onSaveState({ slaveData: slaveDataNew, masterData: masterdataObj });
  }

  handleGetWxCode  = async (successHandler) => {
    let scanResult = '';
    const { app } = this.props;
    // eslint-disable-next-line prefer-destructuring,no-unused-vars
    const userinfo = app.userinfo;
    const myUrl = location.href;
    const configUrl = `${commonConfig.server_host}wechat/getWxToken`;
    const values = {
      url: myUrl,
      sBrandsId: userinfo.sBrandsId,
      sSubsidiaryId: userinfo.sSubsidiaryId,
    };
    // const values = {
    //   url: myUrl,
    //   sBrandsId: '1111111111',
    //   sSubsidiaryId: '1111111111',
    // };
    const configReturn = (await commonServices.postValueService(null, values, configUrl)).data;
    console.log('configReturn::', configReturn, values);
    if (configReturn.code === 1) {
      const { rows } = configReturn.dataset;/* 获取费用分摊单据配置 */
      if (commonUtils.isNotEmptyArr(rows)) {
        const appId = rows[0].appId.toString();
        const nonceStr = rows[0].nonceStr.toString();
        const signature = rows[0].signature.toString();
        const timestamp = rows[0].timestamp.toString();
        weixin.config({
          beta: true, // 必须这么写，否则wx.invoke调用形式的jsapi会有问题
          debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
          appId, // 必填，公众号的唯一标识
          timestamp, // 必填，生成签名的时间戳    <%= Html.Encode(ViewData["timestamp" ]) %>
          nonceStr, // 必填，生成签名的随机串
          signature, // 必填，签名
          jsApiList: ['checkJsApi', 'scanQRCode'], // 必填，需要使用的JS接口列表, 这里只需要调用扫一扫
        });
        weixin.ready(() => {
          weixin.checkJsApi({ // 判断当前客户端版本是否支持指定JS接口
            jsApiList: ['scanQRCode'],
            success(res) { // 以键值对的形式返回，可用true，不可用false。如：{"checkResult":{"scanQRCode":true},"errMsg":"checkJsApi:ok"}
              console.log(res);
              if (res.checkResult.scanQRCode !== true) {
                Toast.fail(`URL不对，当前URL：${myUrl}请使用正式地址！`);
              }
            },
            // eslint-disable-next-line no-unused-vars
            fail(res) { // 检测getNetworkType该功能失败时处理
              Toast.fail('checkJsApi error');
            },


          }); // wx.ready结束
          weixin.scanQRCode({
            desc: 'scanQRCode desc',
            needResult: 0, // 默认为0，扫描结果由企业微信处理，1则直接返回扫描结果，
            scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
            success(res) {
              // console.log("调用扫描成功",res);
              scanResult = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
              if (commonUtils.isNotEmptyObject(scanResult)) {
                const codeResult = scanResult.split(',');
                if (codeResult.length > 1) {
                  scanResult = codeResult[1];
                }
              }
              successHandler(scanResult);
              // console.log('微信扫码结果：', scanResult);
            },
            error(res) {
              // console.log(res);
              if (res.errMsg.indexOf('function_not_exist') > 0) {
                Toast.fail('版本过低请升级');
              }
            },
          });
        });
      } else {
        Toast.fail(configReturn.msg);
      }
    } else {
      Toast.fail(configReturn.msg);
    }
    return scanResult;
  }

  handleWxScan = async () => {
    this.handleGetWxCode((code) => {
      if (!commonUtils.isEmpty(code)) {
        this.handleWxBusiness(code);
      }
    });
  }

  handleWxBusiness = async (code) => {
    const {
      slaveConfig, sModelsId, masterData, slaveData, sModelsType,
    } = this.props;
    // const slaveData = [];
    let slaveDataObj = {};
    let masterdataObj = {};
    let slaveDataObjAdd = {};
    let masterDataObjAdd = {};
    const codeArr = code.split('|');
    if (sModelsType === 'materialsStock/productionmaterials') {
      const dataStr = codeArr[10].replace(/-/g, '/');
      const date = new Date(dataStr);
      slaveDataObjAdd = {
        sMaterialsStyle: codeArr[1],
        sDefineNo: codeArr[4],
        sDefineNo2: codeArr[5],
        dAuxiliaryQty: codeArr[7],
        tInStoreDate: date,
      };
      const slaveDataConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave : '';
      const materialsNameConfig = slaveDataConfig.filter(item => item.sName === 'sMaterialsId');
      const sWareHouseNameConfig = slaveDataConfig.filter(item => item.sName === 'sWareHouseId');
      const sLocationNameConfig = slaveDataConfig.filter(item => item.sName === 'sLocationId');
      const onDataRowAdd = this.props.onDataRowAdd(name, true);
      const materialseAssignField = commonUtils.isNotEmptyArr(materialsNameConfig) ? materialsNameConfig[0].sAssignField : '';
      const sWareHouseNameAssignField = commonUtils.isNotEmptyArr(sWareHouseNameConfig) ? sWareHouseNameConfig[0].sAssignField : '';
      const sLocationNameAssignField = commonUtils.isNotEmptyArr(sLocationNameConfig) ? sLocationNameConfig[0].sAssignField : '';

      let materialsNameDropDownData = [];
      let sWareHouseNamedropDownData = [];
      let sLocationNamedropDownData = [];
      if (commonUtils.isNotEmptyObject(materialsNameConfig[0]) && materialsNameConfig[0].sDropDownType === 'sql') {
        materialsNameDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', materialsNameConfig[0], slaveData);
      }
      if (commonUtils.isNotEmptyObject(sWareHouseNameConfig[0]) && sWareHouseNameConfig[0].sDropDownType === 'sql') {
        sWareHouseNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sWareHouseNameConfig[0], slaveData);
      }
      if (commonUtils.isNotEmptyObject(sLocationNameConfig[0]) && sLocationNameConfig[0].sDropDownType === 'sql') {
        sLocationNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', sLocationNameConfig[0], masterData);
      }
      // }
      let materialsNameDataOne;
      let sWareHouseNameDataOne;
      let sLocationNameDataOne;
      if (!commonUtils.isEmpty(materialsNameDropDownData)) {
        materialsNameDataOne = materialsNameDropDownData.filter(item => item.sMaterialsName === codeArr[6]);
      }
      if (!commonUtils.isEmpty(sWareHouseNamedropDownData)) {
        sWareHouseNameDataOne = sWareHouseNamedropDownData.filter(item => item.sName === codeArr[2]);
      }
      if (!commonUtils.isEmpty(sLocationNamedropDownData)) {
        sLocationNameDataOne = sLocationNamedropDownData.filter(item => item.sName === codeArr[3]);
      }
      const newCopyTo = {};
      newCopyTo.master = masterData;
      newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
      let materialsDataDetiale = {};
      let sWareHouseNameDataDetiale = {};
      let sLocationNameDataDetiale = {};
      materialsDataDetiale = { ...commonFunc.getAssignFieldValue(materialseAssignField, materialsNameDataOne[0], newCopyTo) };
      sWareHouseNameDataDetiale = { ...commonFunc.getAssignFieldValue(sWareHouseNameAssignField, sWareHouseNameDataOne[0], newCopyTo) };
      sLocationNameDataDetiale = { ...commonFunc.getAssignFieldValue(sLocationNameAssignField, sLocationNameDataOne[0], newCopyTo) };
      slaveDataObj = {
        ...onDataRowAdd,
        ...materialsDataDetiale,
        ...sWareHouseNameDataDetiale,
        ...slaveDataObjAdd,
        ...sLocationNameDataDetiale,
      };
      masterdataObj = { ...masterData, ...sLocationNameDataDetiale, ...sWareHouseNameDataDetiale };
    } else if (sModelsType === 'sales/salesSgoods') { // 扫码待发货
      const dataStr = codeArr[12].replace(/-/g, '/');
      const date = new Date(dataStr);
      slaveDataObjAdd = {
        sOrderNo: codeArr[9],
        sWorkOrderNo: codeArr[8],
        sCustomerOrderNo: codeArr[10],
        sCustomerProductNo: codeArr[11],
        sDefineNo: codeArr[3],
        sDefineNo2: codeArr[4],
        dProductQty: codeArr[6],
        tInStoreDate: date,
      };
      masterDataObjAdd = {
        sCustomerShort: codeArr[7],
      };
      const slaveDataConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave : '';
      const sWareHouseNameConfig = slaveDataConfig.filter(item => item.sName === 'sWareHouseId'); // 仓库名称
      const sLocationNameConfig = slaveDataConfig.filter(item => item.sName === 'sLocationId');// 库区库位
      const sProductNameConfig = slaveDataConfig.filter(item => item.sName === 'sProductId');// 产品名称


      const onDataRowAdd = this.props.onDataRowAdd(name, true);
      const sWareHouseNameAssignField = commonUtils.isNotEmptyArr(sWareHouseNameConfig) ? sWareHouseNameConfig[0].sAssignField : '';
      const sLocationNameAssignField = commonUtils.isNotEmptyArr(sLocationNameConfig) ? sLocationNameConfig[0].sAssignField : '';
      const sProductNameAssignField = commonUtils.isNotEmptyArr(sProductNameConfig) ? sProductNameConfig[0].sAssignField : '';


      let sWareHouseNamedropDownData = [];
      let sLocationNamedropDownData = [];
      let sProductNamedropDownData = [];
      if (commonUtils.isNotEmptyObject(sWareHouseNameConfig[0]) && sWareHouseNameConfig[0].sDropDownType === 'sql') {
        sWareHouseNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sWareHouseNameConfig[0], slaveData);
      }
      if (commonUtils.isNotEmptyObject(sLocationNameConfig[0]) && sLocationNameConfig[0].sDropDownType === 'sql') {
        sLocationNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', sLocationNameConfig[0], masterData);
      }
      if (commonUtils.isNotEmptyObject(sProductNameConfig[0]) && sProductNameConfig[0].sDropDownType === 'sql') {
        sProductNamedropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', sProductNameConfig[0], slaveData);
      }
      let sWareHouseNameDataOne;
      let sLocationNameDataOne;
      let sProductNameDataOne;
      if (!commonUtils.isEmpty(sWareHouseNamedropDownData)) {
        sWareHouseNameDataOne = sWareHouseNamedropDownData.filter(item => item.sName === codeArr[1]);
      }
      if (!commonUtils.isEmpty(sLocationNamedropDownData)) {
        sLocationNameDataOne = sLocationNamedropDownData.filter(item => item.sName === codeArr[2]);
      }
      if (!commonUtils.isEmpty(sProductNamedropDownData)) {
        sProductNameDataOne = sProductNamedropDownData.filter(item => item.sProductName === codeArr[5]);
      }
      const newCopyTo = {};
      newCopyTo.master = masterData;
      newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
      let sWareHouseNameDataDetiale = {};
      let sLocationNameDataDetiale = {};
      let sProductNameDataDetiale = {};
      sWareHouseNameDataDetiale = { ...commonFunc.getAssignFieldValue(sWareHouseNameAssignField, sWareHouseNameDataOne[0], newCopyTo) };
      sLocationNameDataDetiale = { ...commonFunc.getAssignFieldValue(sLocationNameAssignField, sLocationNameDataOne[0], newCopyTo) };
      sProductNameDataDetiale = { ...commonFunc.getAssignFieldValue(sProductNameAssignField, sProductNameDataOne[0], newCopyTo) };
      slaveDataObj = {
        ...onDataRowAdd,
        ...sWareHouseNameDataDetiale,
        ...slaveDataObjAdd,
        ...sProductNameDataDetiale,
        ...sLocationNameDataDetiale,
      };
      masterdataObj = {
        ...masterData,
        ...sLocationNameDataDetiale,
        ...masterDataObjAdd,
        ...sWareHouseNameDataDetiale,
      };
    } else if (sModelsType === 'purchase/purchaseInstore' || sModelsType === 'scan/productionmaterials') { /* 扫码入库、扫码领料(唯一码) */
      const { masterConfig } = this.props;
      /* 取第一条码 */
      const sDefineNo = codeArr[0];
      /* 如果条码已存在，提示 */
      const iIndex = slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sDefineNo) && item.sDefineNo === sDefineNo);
      if (iIndex > -1) {
        Toast.fail('条码已存在!!!', 1);
        return;
      }
      masterdataObj = {
        ...masterData,
      };
      /* 读取扫码配置 */
      const btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.bVisible && item.sControlName.indexOf('BtnScan') > -1);
      const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
      slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, masterData) }; // 取赋值字段
      slaveDataObj.sDefineNo = sDefineNo;
      slaveDataObj.sId = commonUtils.createSid();
      if (commonUtils.isNotEmptyArr(slaveData)) {
        const len = slaveData.length;
        const sDefineNoNew = slaveData[len - 1].sDefineNo;
        const { handleType } = slaveData[len - 1];
        /* 若slaveData 最后一条数据没有条形码，则赋值条形码；否则新增一条数据 */
        if (commonUtils.isEmptyArr(sDefineNoNew)) {
          slaveDataObj.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
          slaveData[len - 1] = slaveDataObj;
        } else {
          slaveDataObj.handleType = 'add';
          slaveData.push(slaveDataObj);
        }
      } else {
        slaveDataObj.handleType = 'add';
        slaveData.push(slaveDataObj);
      }
      this.handleClick('slave', 'scan'); /* 连续扫码 */
    } else {
      Toast.fail('二维码不存在!!!', 1);
    }
    if (sModelsType !== 'purchase/purchaseInstore' && sModelsType !== 'scan/productionmaterials') {
      slaveData.push(slaveDataObj);
    }
    this.props.onSaveState({ slaveData, masterData: masterdataObj });
  }

  /* 页签切换 */
  // eslint-disable-next-line no-unused-vars
  handleTabClick =(index, tab) => {
    const { slaveData, slaveSumConfig, masterData, sModelsType } = this.props;
    let { slaveSumData }= this.props;

    /* 盘点走单独的逻辑体 */
    console.log('slaveSumData', slaveSumData);
    if(commonUtils.isNotEmptyObject(slaveSumConfig) && slaveSumConfig.sGrd && slaveSumConfig.sGrd.includes('sumTableSelect')) {
      if(commonUtils.isNotEmptyArr(slaveData) && commonUtils.isNotEmptyArr(slaveSumData)) {
        const groupedData = commonUtils.groupBy(slaveData, item => item.sMaterialsId + '-' +  commonUtils.isNull(item.sMaterialsStyle, '') +  commonUtils.isNull(item.sDefineNo, '') + '-'
          + commonUtils.isNull(item.sLocationId, '') + commonUtils.isNull(item.sWareHouseId, ''));
        console.log('分组::', groupedData);
        /* 对分组内的数据进行数据汇总 */
        if (commonUtils.isNotEmptyObject(groupedData)) {
          for (const key of Object.keys(groupedData)) {
            const eachData = groupedData[key];
            if (commonUtils.isNotEmptyArr(eachData)) {
              console.log('eachData:', eachData);
              let dAuxiliarySumQty = 0; /* 采购数量  */
              let dMaterialsSumQty = 0; /* 采购计价数量  */
              eachData.forEach((item) => {
                /* 采购 */
                dAuxiliarySumQty += commonUtils.convertToNum(commonUtils.isNull(item.dAuxiliaryQty, 0), 2);
                dMaterialsSumQty += commonUtils.convertToNum(commonUtils.isNull(item.dMaterialsQty, 0), 2);
              });

              /* 从汇总表数据集中 找到相同批次规格的汇总表 然后更新数据 */
              const eachRow =  eachData[0];
              const iIndex = slaveSumData.findIndex(obj => obj.sMaterialsId ===eachRow.sMaterialsId && obj.sMaterialsStyle ===eachRow.sMaterialsStyle &&
                obj.sDefineNo === eachRow.sDefineNo && obj.sLocationId === eachRow.sLocationId && obj.sWareHouseId === eachRow.sWareHouseId);
              console.log('iIndex:', iIndex);
              if(iIndex > -1) {
                const sumRow = slaveSumData[iIndex];
                const addState = {};
                const minus =  dAuxiliarySumQty -  commonUtils.isNull(sumRow.dOriginalAuxiliaryQty, 0);
                addState.dProfitLossAuxiliaryQty = commonUtils.convertFixNum(minus, 2); /* 盘盈数 */
                addState.dAuxiliaryQty = dAuxiliarySumQty; /* 数量 */
                addState.handleType = commonUtils.isEmpty(sumRow.handleType) ? 'update' : sumRow.handleType;
                console.log('盘盈数字:', minus);
                slaveSumData[iIndex] = { ...slaveSumData[iIndex], ...addState};
              }

            }
          }
        }
      }


    }else {

      /* 汇总明细 */
      slaveSumData = [];
      console.log('sModelsType:', sModelsType);
      if (commonUtils.isNotEmptyArr(slaveData)) {
        let slaveSumRow = {};
        let dProductTotalQty = 0; /* 总到货数 */
        let dMaterialsTotalQty = 0; /* 总计价数 */
        slaveData.forEach((slaveItem, index) => {
          if (index === 0) {
            slaveSumRow = JSON.parse(JSON.stringify(slaveItem));
          }
          if (sModelsType && sModelsType.includes('purchase/')) {
            dProductTotalQty += commonUtils.convertToNum(commonUtils.isNull(slaveItem.dAuxiliaryQty, 0));
            dMaterialsTotalQty += commonUtils.convertToNum(commonUtils.isNull(slaveItem.dMaterialsQty, 0));
          } else {
            dProductTotalQty += commonUtils.convertToNum(commonUtils.isNull(slaveItem.dProductQty, 0));
          }
        });
        /* 根据sSqlConditionId汇总 */
        if (sModelsType && sModelsType.includes('purchase/')) {
          const groupedData = commonUtils.groupBy(slaveData, item => item.sSqlConditionId);
          console.log('分组::', groupedData);
          /* 对分组内的数据进行数据汇总 */
          if (commonUtils.isNotEmptyObject(groupedData)) {
            for (const key of Object.keys(groupedData)) {
              const eachData = groupedData[key];
              if (commonUtils.isNotEmptyArr(eachData)) {
                console.log('eachData:', eachData);
                let dAuxiliarySumQty = 0; /* 采购数量  */
                let dMaterialsSumQty = 0; /* 采购计价数量  */
                let dEscrowAuxiliarySumQty = 0; /* 代管数量 */
                let dEscrowSumQty = 0; /* 代管计价数 */
                let dGiveAuxiliarySumQty = 0; /* 赠送数 */
                let dGiveSumQty = 0; /* 赠送计价数 */
                eachData.forEach((item) => {
                  /* 采购 */
                  console.log('类型:', item.iType);
                  if ((commonUtils.isNull(item.iType), 0) === 0) {
                    dAuxiliarySumQty += commonUtils.convertToNum(commonUtils.isNull(item.dAuxiliaryQty, 0), 2);
                    dMaterialsSumQty += commonUtils.convertToNum(commonUtils.isNull(item.dMaterialsQty, 0), 2);
                  }

                  if (item.iType === 1) {
                    dAuxiliarySumQty += commonUtils.convertToNum(commonUtils.isNull(item.dAuxiliaryQty, 0), 2);
                    dMaterialsSumQty += commonUtils.convertToNum(commonUtils.isNull(item.dMaterialsQty, 0), 2);
                  }
                  /* 代管 */
                  else if (item.iType === 2) {
                    dEscrowAuxiliarySumQty += commonUtils.convertToNum(commonUtils.isNull(item.dAuxiliaryQty, 0), 2);
                    dEscrowSumQty += commonUtils.convertToNum(commonUtils.isNull(item.dMaterialsQty, 0), 2);
                  }

                  /* 赠送 */
                  else if (item.iType === 3) {
                    dGiveAuxiliarySumQty += commonUtils.convertToNum(commonUtils.isNull(item.dAuxiliaryQty, 0), 2);
                    dGiveSumQty += commonUtils.convertToNum(commonUtils.isNull(item.dMaterialsQty, 0), 2);
                  }
                });
                const newSum = JSON.parse(JSON.stringify(eachData[0]));

                newSum.dAuxiliaryQty = dAuxiliarySumQty;
                newSum.dMaterialsQty = dMaterialsSumQty;

                newSum.dEscrowAuxiliaryQty = dEscrowAuxiliarySumQty;
                newSum.dEscrowQty = dEscrowSumQty;

                newSum.dGiveAuxiliaryQty = dGiveAuxiliarySumQty;
                newSum.dGiveQty = dGiveSumQty;

                newSum.dPurchaseArrivalQty = dProductTotalQty; /* 到货总数 */
                newSum.dPurchaseQty = dMaterialsTotalQty; /* 总计价数量 */
                newSum.dSrcQty = masterData.dSrcAuxiliaryQty; /* 源单数量 */

                slaveSumRow.handleType = 'add';
                slaveSumData.push(newSum);


              }
            }
          }
        } else {
          const groupedData = commonUtils.groupBy(slaveData, item => item.sSqlConditionId);
          console.log('产品分组::', groupedData);
          /* 对分组内的数据进行数据汇总 */
          if (commonUtils.isNotEmptyObject(groupedData)) {
            for (const key of Object.keys(groupedData)) {
              const eachData = groupedData[key];
              let dProductSumQty = 0; /* 产品数量  */
              if (commonUtils.isNotEmptyArr(eachData)) {
                eachData.forEach((item) => {
                  dProductSumQty += commonUtils.convertToNum(commonUtils.isNull(item.dProductQty, 0), 2);
                });
                const newSum = JSON.parse(JSON.stringify(eachData[0]));
                newSum.dProductQty = dProductSumQty;
                slaveSumRow.handleType = 'add';
                slaveSumData.push(newSum);
              }

            }
          }
          // slaveSumRow.sProductName = commonUtils.isNotEmptyObject(masterData) ? masterData.sProductName : '';
          // slaveSumRow.dProductQty = dProductTotalQty;
          // slaveSumRow.handleType = 'add';
          // slaveSumData.push(slaveSumRow);
        }

      }
    }
    console.log('汇总表数据', slaveSumData);
    console.log('主表数据', masterData);
    this.setState({ tabPage: index });
    this.props.onSaveState({ slaveSumData })

  }

  getViewValue = (showConfig, record) => {
    let sValue = record === undefined ? undefined : record[showConfig.sName];
    if (showConfig.sDropDownType === 'const') {
      let showDropDown = [];
      if (typeof showConfig.showDropDown === 'object') {
        // eslint-disable-next-line prefer-destructuring
        showDropDown = showConfig.showDropDown;
      } else {
        showDropDown = commonUtils.objectToArr(commonUtils.convertStrToObj(showConfig.showDropDown));
      }
      let iIndex = commonUtils.isEmpty(record[showConfig.sName]) ? -1 : showDropDown.findIndex(item => item.sId === record[showConfig.sName].toString());
      if (iIndex === -1 && record[showConfig.sName] === '') {
        iIndex = showDropDown.findIndex(item => item.sId === '');
      }
      sValue = iIndex > -1 ? showDropDown[iIndex].value : record[showConfig.sName];
    }
    return sValue;
  };

  render() {
    const {
      slaveConfig, slaveData: slaveDataOld, sModelsId, enabled, app, sUseInfo, onReturnForm, masterData, masterConfig, slaveSumConfig,  slaveSumData: slaveSumDataOld,
      sModelsType, content, dispatch,
    } = this.props;
    const commonListProps = {
      app,
      content,
      sModelsId: this.fieldConfig.current?.sActiveId || sModelsId,
      sModelsType: sModelsType,
      formRoute: '/indexMobile/commobileBill',
      dispatch,
      bNotSearch: true,
    };
    const { tabPage } = this.state;
    onReturnForm(this.props.form);


    const slaveSumDataOld2 = slaveSumDataOld === undefined ? [] : slaveSumDataOld;
    const slaveSumData = dataSource.cloneWithRows(slaveSumDataOld2);


    const dWidth = document.documentElement.clientWidth || document.body.clientWidth; /* 获取手机视窗宽度 */
    const dHeight = document.documentElement.clientHeight || document.body.clientHeight; /* 获取手机视窗宽度 */
    const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
    const style = {
      display: 'flex',
      justifyContent: 'center',
      alignItems: 'center',
    };
    const btnStyle = {
      fontSize: '15px',
      backgroundColor: '#f0f0f0',
      display: 'flex',
      justifyContent: 'center',
      alignItems: 'center',
    };

    const rowSum = (rowData, sectionID, rowID) => {
      return (
        <div style={{ backgroundColor: '#f0f0f0',  marginBottom: '8px', borderBottom:'6px solid rgb(236, 236, 237)' }} key={rowID}>
          {commonUtils.isEmptyObject(slaveSumConfig) ? '' : slaveSumConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '').map((child) => {
            const sMemo = child.sName.toLowerCase().endsWith('memo');
            // sUseInfo是指被其他单据调用，或者被审核
            let enabledNew = (enabled && !child.bReadonly && !child.specialControl && commonUtils.isEmpty(sUseInfo));
            if (child.iTag === 1) {
              enabledNew = false;
            } else if (child.iTag === 3) {
              enabledNew = true;
            }
            const showTypeProps = {
              app,
              masterData,
              record: rowData,
              sId: rowData.sId, /*   修改当前编号(数据格式:字符串)   */
              name: 'slave',
              form: this.props.form,
              formId: sModelsId,
              getSqlDropDownData: this.props.getSqlDropDownData,
              getSqlCondition: this.props.getSqlCondition,
              handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
              getFloatNum: this.props.getFloatNum,
              getDateFormat: this.props.getDateFormat,
              onChange: this.props.onDataChange,
              showConfig: child,
              formItemLayout: sMemo ? formItemLayout : {},
              textArea: sMemo,
              enabled: enabledNew,
              dataValue: rowData[child.sName],
              bTable: true,
              onFilterDropDownData: this.props.onFilterDropDownData,
              onSaveState: this.props.onSaveState,
            };
            return (
              <ShowType {...showTypeProps} />
            );
          })}
          {slaveSumConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName.includes('spicture')).map((item) => {
            if (item.sName.includes('spicture') && commonUtils.isNotEmptyObject(rowData.spicture)) {
              const { token } = app;
              let imgBox = '';
              const picAddr = commonUtils.isNotEmptyObject(rowData.spicture) ? rowData.spicture.split(',') : '';
              const previewImageArr = [];
              if (commonUtils.isNotEmptyArr(picAddr)) {
                picAddr.forEach((item) => {
                  const dataPreviewUrl = `${commonConfig.file_host}file/download?savePathStr=${item}&width=${dWidth}&&height=${dHeight}&sModelsId=100&token=${token}`; /* 预览 */
                  previewImageArr.push(dataPreviewUrl);
                });
                const dataUrl = `${commonConfig.file_host}file/download?savePathStr=${picAddr[0]}&width=60&&height=60&sModelsId=100&token=${token}`; /* 缩略图 */
                // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
                imgBox = <div className="spictureStyle" key={rowID}> <img src={dataUrl} alt="img" onFocus={() => 0} onClick={e => preView(previewImageArr, e)} /></div>;
              }
              return imgBox;
            } else {
              return '';
            }
          })}
        </div>
      );
    };

    /* 汇总页签 */
    const TabComponentSum = props => {
      return (
        <div className="commobileBillContainer">
          <form style={{ paddingBottom: '47px' }}>
            {commonUtils.isEmptyArr(slaveSumDataOld) && false ?
              <div>
                <Flex className={styles.ProcessReportMobile}>
                  {
                    slaveConfig && slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenAdd' && item.bVisible).length ?
                      <Flex.Item style={style}>
                        <Button type="button" inline disabled={!enabled} onClick={this.handleClick.bind(this, 'slave', 'add')} style={btnStyle}>
                          增加
                          <img src={add} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="add" />
                        </Button>
                      </Flex.Item> : ''
                  }
                  {
                    slaveConfig && slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenScan' && item.bVisible).length ?
                      <Flex.Item style={style}>
                        <Button type="button" inline disabled={!enabled} onClick={ commonConfig.isWeiXin ? this.handleWxScan.bind(this, 'slave', 'scan') : this.handleClick.bind(this, 'slave', 'scan')} style={btnStyle}>
                          扫码
                          <img src={scan} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="scan" />
                        </Button>
                      </Flex.Item> : ''
                  }
                </Flex>
              </div> :
              <div className={styles.listViewStyle}>
                <ListView
                  dataSource={slaveSumData}
                  renderRow={rowSum}
                  pageSize={commonConfig.pageSize}
                  initialListSize={0}
                  onScroll={() => {}}
                  scrollRenderAheadDistance={500}
                  onEndReachedThreshold={10}
                  className={styles.listView}
                />
              </div>
            }
          </form>
        </div>
      );
    }

    const conditionValue = this.fieldConfig.current && this.masterdataObj.current ?
      this.props.getSqlCondition(this.fieldConfig.current, 'master', this.masterdataObj.current) : null;
    /**
     * pda扫描弹窗
     */
    const ModalListProps = {
        ...this.modalProps,
        visible: this.state.visible,
        content: <CommonMobileList
          {
            ...{
            ...commonListProps,
            // returnFilterCondition: conditionValue ? [conditionValue] : [],
            conditonValues :conditionValue,
            needCheck: true,
            setSelectedRowkeys: this.setSelectedRowkeys,
            filterSlaveData: this.filterSlaveData,
            }
          } />
      }

    const otherProps = {
      handleMasterFieldScan: this.handleMasterFieldScan,
    }

    return (
      <div>
        {
          commonUtils.isNotEmptyObject(slaveSumConfig) ?
            <Tabs
              tabs={tabs}
              initialPage={0}
              onChange={(tab, index) => this.handleTabClick(index, tab)}
              onTabClick={(tab, index) => { console.log('onTabClick', index, tab); }}
            >
              {tabPage === 0 ? <div className={indexStyles.newContainer}>  <TabComponentSlave {...this.props} ModalListProps={ModalListProps} {...otherProps} /></div> : ''}
              {tabPage === 1 ? <div className={indexStyles.newContainer}>  <TabComponentSum {...this.props} /> </div> : ''}
            </Tabs> :
            <div className={indexStyles.newContainer}>  <TabComponentSlave {...this.props} ModalListProps={ModalListProps} {...otherProps}/> </div>
        }
      </div>

    );
  }
}

const CommobileBillComponent = createForm()(CommobileBill);

const TabComponentSlave = (props) => {

  const { masterConfig, masterData, slaveData: slaveDataOld, slaveConfig, sModelsId, enabled, app, sUseInfo } = props;

  const slaveDataOld2 = slaveDataOld === undefined ? [] : slaveDataOld;
  const slaveData = dataSource.cloneWithRows(slaveDataOld2);

  const style = {
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center',
  };

  const btnStyle = {
    fontSize: '15px',
    backgroundColor: '#f0f0f0',
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center',
  };

  const BtnStyle = {
    type: 'default',
    color: 'red',
    border: 'none',
    backgroundColor: '#f0f0f0',
    fontSize: '15px',
  };
  const divStyle = {
    display: 'flex',
    justifyContent: 'space-between',
    background: ' #f0f0f0',
  };
  const row = (rowData, sectionID, rowID) => {
    return (
      <div style={{ backgroundColor: '#f0f0f0' }} key={rowID}>
        <Flex className={styles.ProcessReportMobile}>
          {/* eslint-disable-next-line react/jsx-no-duplicate-props */}
          {
            slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenAdd' && item.bVisible).length ?
              <Flex.Item style={style}>
                <Button type="button" inline disabled={!enabled} onClick={_this.handleClick.bind(_this, 'slave', 'add')} style={btnStyle}>
                  增加
                  <img src={add} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="add" />
                </Button>
              </Flex.Item> : ''
          }
          {
            slaveConfig && slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenScan' && item.bVisible).length ?
              <Flex.Item style={style}>
                <Button type="button" inline disabled={!enabled} onClick={_this.handleClick.bind(_this, 'slave', 'scan')} style={btnStyle}>
                  扫码
                  <img src={scan} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="scan" />
                </Button>
              </Flex.Item> : ''
          }
          {
            slaveConfig && slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenDel' && item.bVisible).length ?
              <Flex.Item style={style}>
                <Button type="button" inline disabled={!enabled} onClick={_this.handleClick.bind(_this, 'slave', 'del', rowData.sId)} style={btnStyle}>
                  删除
                  <img src={close} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="close" />
                </Button>
              </Flex.Item> : ''
          }
        </Flex>
        {commonUtils.isEmptyObject(slaveConfig) ? '' : slaveConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '').map((child) => {
          const sMemo = child.sName.toLowerCase().endsWith('memo');
          // sUseInfo是指被其他单据调用，或者被审核
          let enabledNew = (enabled && !child.bReadonly && !child.specialControl && commonUtils.isEmpty(sUseInfo));
          if (child.iTag === 1) {
            enabledNew = false;
          } else if (child.iTag === 3) {
            enabledNew = true;
          }
          const showTypeProps = {
            app,
            masterData,
            record: rowData,
            sId: rowData.sId, /*   修改当前编号(数据格式:字符串)   */
            name: 'slave',
            form: props.form,
            formId: sModelsId,
            getSqlDropDownData: props.getSqlDropDownData,
            getSqlCondition: props.getSqlCondition,
            handleSqlDropDownNewRecord: props.handleSqlDropDownNewRecord,
            getFloatNum: props.getFloatNum,
            getDateFormat: props.getDateFormat,
            onChange: props.onDataChange,
            showConfig: child,
            formItemLayout: sMemo ? formItemLayout : {},
            textArea: sMemo,
            enabled: enabledNew,
            dataValue: rowData[child.sName],
            bTable: true,
            onFilterDropDownData: props.onFilterDropDownData,
            onSaveState: props.onSaveState,
          };
          return (
            <ShowType {...showTypeProps} />
          );
        })}
        {slaveConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName.includes('spicture')).map((item) => {
          if (item.sName.includes('spicture') && commonUtils.isNotEmptyObject(rowData.spicture)) {
            const { token } = app;
            let imgBox = '';
            const picAddr = commonUtils.isNotEmptyObject(rowData.spicture) ? rowData.spicture.split(',') : '';
            const previewImageArr = [];
            if (commonUtils.isNotEmptyArr(picAddr)) {
              picAddr.forEach((item) => {
                const dataPreviewUrl = `${commonConfig.file_host}file/download?savePathStr=${item}&width=${dWidth}&&height=${dHeight}&sModelsId=100&token=${token}`; /* 预览 */
                previewImageArr.push(dataPreviewUrl);
              });
              const dataUrl = `${commonConfig.file_host}file/download?savePathStr=${picAddr[0]}&width=60&&height=60&sModelsId=100&token=${token}`; /* 缩略图 */
              // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
              imgBox = <div className="spictureStyle" key={rowID}> <img src={dataUrl} alt="img" onFocus={() => 0} onClick={e => preView(previewImageArr, e)} /></div>;
            }
            return imgBox;
          } else {
            return '';
          }
        })}
      </div>
    );
  };

  const f1 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[0];
  const f2 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[1];
  const f3 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[2];
  const f4 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[3];
  const f5 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[4];
  const f6 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[5];
  const f7 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[6];
  const f8 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[7];
  const f9 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[8];
  const f10 = commonUtils.isEmptyObject(masterConfig) ? {} : masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1)[9];

  return (
    <div className="commobileBillContainer">
      <div style={{ padding: '5px 0' }} className={styles.onlyWordBg}>
        <Flex style={{ padding: '0 15px 5px 15px' }}>
          {
            f1 ? <Flex.Item className={styles.wordsFlow} style={{ color: '#fff', fontWeight: 'bold', fontSize: '17px' }}>{f1.showName} : {_this.getViewValue(f1, masterData)}</Flex.Item> : ''
          }
          {
            f2 ? <Flex.Item className={`${styles.wordsFlow} ${styles.fr}`} style={{ fontSize: '17px' }}>{f2.showName} : {_this.getViewValue(f2, masterData)}</Flex.Item> : ''
          }
        </Flex>
        <Flex style={{ padding: '0 15px 5px 15px' }}>
          {
            f3 ? <Flex.Item className={styles.wordsFlow} style={{ fontSize: '17px' }}>{f3.showName} : {_this.getViewValue(f3, masterData)}</Flex.Item> : ''
          }
        </Flex>
        <Flex style={{ padding: '0 15px 5px 15px' }}>
          {
            f4 ? <Flex.Item className={styles.wordsFlow} style={{ fontSize: '17px' }}>{f4.showName} : {_this.getViewValue(f4, masterData)}</Flex.Item> : ''
          }
        </Flex>
        <Flex style={{ padding: '0 15px 5px 15px' }}>
          {
            f5 ? <Flex.Item className={styles.wordsFlow} style={{ fontSize: '17px' }}>{f5.showName} : {_this.getViewValue(f5, masterData)}</Flex.Item> : ''
          }
          {
            f6 ? <Flex.Item className={`${styles.wordsFlow} ${styles.fr}`} style={{ fontSize: '17px' }}>{f6.showName} : {_this.getViewValue(f6, masterData)}</Flex.Item> : ''
          }
        </Flex>
        <Flex style={{ padding: '0 15px 5px 15px' }}>
          {
            f7 ? <Flex.Item className={styles.wordsFlow} style={{ fontSize: '17px' }}>{f7.showName} : {_this.getViewValue(f7, masterData)}</Flex.Item> : ''
          }
          {
            f8 ? <Flex.Item className={`${styles.wordsFlow} ${styles.fr}`} style={{ fontSize: '17px' }}>{f8.showName} : {_this.getViewValue(f8, masterData)}</Flex.Item> : ''
          }
        </Flex>
        <Flex style={{ padding: '0 15px 0px 15px' }}>
          {
            f9 ? <Flex.Item className={styles.wordsFlow} style={{ fontSize: '17px' }}>{f9.showName} : {_this.getViewValue(f9, masterData)}</Flex.Item> : ''
          }
          {
            f10 ? <Flex.Item className={`${styles.wordsFlow} ${styles.fr}`} style={{ fontSize: '17px' }}>{f10.showName} : {_this.getViewValue(f10, masterData)}</Flex.Item> : ''
          }
        </Flex>
      </div>
      <form style={{ paddingBottom: '47px' }}>
        <div className="flex-container" style={{ color: 'white' }}>
          <CommobileViewMaster {...props} iTag={1} />
          <CommobileViewMaster {...props} onMasterFieldScan={props.handleMasterFieldScan}/>
        </div>
        {commonUtils.isEmptyArr(slaveDataOld) ?
          <div>
            <Flex className={styles.ProcessReportMobile}>
              {
                slaveConfig && slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenAdd' && item.bVisible).length ?
                  <Flex.Item style={style}>
                    <Button type="button" inline disabled={!enabled} onClick={_this.handleClick.bind(_this, 'slave', 'add')} style={btnStyle}>
                      增加
                      <img src={add} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="add" />
                    </Button>
                  </Flex.Item> : ''
              }
              {
                slaveConfig && slaveConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnChildrenScan' && item.bVisible).length ?
                  <Flex.Item style={style}>
                    <Button type="button" inline disabled={!enabled} onClick={ commonConfig.isWeiXin ? _this.handleWxScan.bind(_this, 'slave', 'scan') : _this.handleClick.bind(_this, 'slave', 'scan')} style={btnStyle}>
                      扫码
                      <img src={scan} className={styles.iconStyle} style={!enabled ? { opacity: 0.3 } : { opacity: 1 }} alt="scan" />
                    </Button>
                  </Flex.Item> : ''
              }
            </Flex>
          </div> :
          <div className={styles.listViewStyle}>
            <ListView
              dataSource={slaveData}
              renderRow={row}
              pageSize={commonConfig.pageSize}
              initialListSize={0}
              onScroll={() => {}}
              scrollRenderAheadDistance={500}
              onEndReachedThreshold={10}
              className={styles.listView}
            />
          </div>
        }
        <div
          className={`${styles.ProcessReportMobile} commobileBillToolbar`}
          style={{
            position: 'fixed', bottom: '0', width: '100%', zIndex: 1,
          }}
        >
          <CommobileToolBar {...props} btnStyle={BtnStyle} divStyle={divStyle} onButtonClick={_this.handleClick} />
        </div>
      </form>
      <ModalList {...props.ModalListProps}/>
    </div>
  );
}

export default CommobileBase(CommobileBillEvent(CommobileBillComponent));

