global.bussnessEle = {
  globeCustomerlist: {}, /* 客户列表 */
  globeProductlist: {}, /* 印件列表 */
  globeWareHouselist: {}, /* 仓库列表 */
  globeMaterialslist: {}, /* 材料列表 */
  globeSuppylist: {}, /* 材料供应商列表 */
  globeSalesManlist: {}, /* 销售列表 */
  globeGetPaylist: {}, /* 付款条件 */
  globeSenderlist: {}, /* 送货人 */
  globeCurrencylist: {}, /* 币别 */
  globeDeliverlist: {}, /* 送货方式 */
  globeTaxlist: {}, /* 税码 */
};

/* 在下拉得到数据之前，根据后台赋值字段，显示在控件上，等下拉加载之后再恢复正常 */
export function setValueBeforeLoad(masterData) {
  if (masterData.sCustomerId !== undefined && masterData.sCustomerName !== undefined) {
    clearlist('sCustomerId');
    if (Object.keys(global.bussnessEle.globeCustomerlist).length === 0) {
      const sCustomer = { sName: masterData.sCustomerName, sId: masterData.sCustomerId };
      global.bussnessEle.globeCustomerlist.length = 0;
      global.bussnessEle.globeCustomerlist = [];
      global.bussnessEle.globeCustomerlist.push(sCustomer);
    }
  } else if (masterData.sSupplyId !== undefined && masterData.sSupplyName !== undefined) {
    clearlist('sSupplyId');
    if (Object.keys(global.bussnessEle.globeSuppylist).length === 0) {
      const sObject = { sName: masterData.sSupplyName, sId: masterData.sSupplyId };
      global.bussnessEle.globeSuppylist.length = 0;
      global.bussnessEle.globeSuppylist = [];
      global.bussnessEle.globeSuppylist.push(sObject);
    }
  } else if (masterData.sProductId !== undefined && masterData.sProductName !== undefined) {
    clearlist('sProductId');
    if (Object.keys(global.bussnessEle.globeProductlist).length === 0) {
      const sObject = { sName: masterData.sProductName, sId: masterData.sProductId };
      global.bussnessEle.globeCustomerlist.length = 0;
      global.bussnessEle.globeCustomerlist = [];
      global.bussnessEle.globeCustomerlist.push(sObject);
    }
  } else if (masterData.sWareHouseId !== undefined && masterData.sWareHouseName !== undefined) {
    clearlist('sWareHouseId');
    if (Object.keys(global.bussnessEle.globeWareHouselist).length === 0) {
      const sObject = { sName: masterData.sWareHouseName, sId: masterData.sWareHouseId };
      global.bussnessEle.globeWareHouselist.length = 0;
      global.bussnessEle.globeWareHouselist = [];
      global.bussnessEle.globeWareHouselist.push(sObject);
    }
  } else if (masterData.sMaterialsId !== undefined && masterData.sMaterialsName !== undefined) {
    clearlist('sMaterialsId');
    if (Object.keys(global.bussnessEle.globeMaterialslist).length === 0) {
      const sObject = { sName: masterData.sMaterialsName, sId: masterData.sMaterialsId };
      global.bussnessEle.globeWareHouselist.length = 0;
      global.bussnessEle.globeWareHouselist = [];
      global.bussnessEle.globeWareHouselist.push(sObject);
    }
  } else if (masterData.sSalesManId !== undefined && masterData.sSalesManName !== undefined) {
    clearlist('sSalesManId');
    if (Object.keys(global.bussnessEle.globeSalesManlist).length === 0) {
      const sObject = { sName: masterData.sSalesManName, sId: masterData.sSalesManId };
      global.bussnessEle.globeSalesManlist.length = 0;
      global.bussnessEle.globeSalesManlist = [];
      global.bussnessEle.globeSalesManlist.push(sObject);
    }
  } else if (masterData.sTaxName !== undefined && masterData.sTaxName !== undefined) {
    clearlist('sTaxId');
    if (Object.keys(global.bussnessEle.globeTaxlist).length === 0) {
      const sObject = { sName: masterData.sTaxName, sId: masterData.sTaxId };
      global.bussnessEle.globeTaxlist.length = 0;
      global.bussnessEle.globeTaxlist = [];
      global.bussnessEle.globeTaxlist.push(sObject);
    }
  } else if (masterData.sGetPayId !== undefined && masterData.sGetPayName !== undefined) {
    clearlist('sGetPayId');
    if (Object.keys(global.bussnessEle.globeGetPaylist).length === 0) {
      const sObject = { sName: masterData.sGetPayName, sId: masterData.sGetPayId };
      global.bussnessEle.globeGetPaylist.length = 0;
      global.bussnessEle.globeGetPaylist = [];
      global.bussnessEle.globeGetPaylist.push(sObject);
    }
  } else if (masterData.sSenderId !== undefined && masterData.sSenderName !== undefined) {
    clearlist('sSenderId');
    if (Object.keys(global.bussnessEle.globeSenderlist).length === 0) {
      const sObject = { sName: masterData.sSenderName, sId: masterData.sSenderId };
      global.bussnessEle.globeSenderlist.length = 0;
      global.bussnessEle.globeSenderlist = [];
      global.bussnessEle.globeSenderlist.push(sObject);
    }
  } else if (masterData.sCurrency !== undefined) {
    clearlist('sCurrency');
    if (Object.keys(global.bussnessEle.globeCurrencylist).length === 0) {
      const sObject = { sName: masterData.sCurrencyName, sId: masterData.sCurrency };
      global.bussnessEle.globeCurrencylist.length = 0;
      global.bussnessEle.globeCurrencylist = [];
      global.bussnessEle.globeCurrencylist.push(sObject);
    }
  } else if (masterData.sDeliverId !== undefined && masterData.sDeliverName !== undefined) {
    clearlist('sDeliverId');
    if (Object.keys(global.bussnessEle.globeDeliverlist).length === 0) {
      const sObject = { sName: masterData.sDeliverName, sId: masterData.sDeliverId };
      global.bussnessEle.globeDeliverlist.length = 0;
      global.bussnessEle.globeDeliverlist = [];
      global.bussnessEle.globeDeliverlist.push(sObject);
    }
  }
  return true;
}

/* 清空列表 */
export function clearlist(masterData) {
  if (masterData === 'sCustomerId' || masterData === 'sCustomerName') {
    global.bussnessEle.globeCustomerlist.length = 0;
    global.bussnessEle.globeCustomerlist = [];
    global.bussnessEle.globeProductlist.length = 0;
    global.bussnessEle.globeProductlist = [];
  } else if (masterData === 'sProductId' || masterData === 'sProductName') {
    global.bussnessEle.globeProductlist.length = 0;
    global.bussnessEle.globeProductlist = [];
  } else if (masterData === 'sWareHouseId' || masterData === 'sWareHouseName') {
    global.bussnessEle.globeWareHouselist.length = 0;
    global.bussnessEle.globeWareHouselist = [];
    global.bussnessEle.globeMaterialslist.length = 0;
    global.bussnessEle.globeMaterialslist = [];
  } else if (masterData === 'sSupplyId' || masterData === 'sSupplyName') {
    global.bussnessEle.globeSuppylist.length = 0;
    global.bussnessEle.globeSuppylist = [];
  } else if (masterData === 'sMaterialsId' || masterData === 'sMaterialsName') {
    global.bussnessEle.globeMaterialslist.length = 0;
    global.bussnessEle.globeMaterialslist = [];
  } else if (masterData === 'sSalesManId' || masterData === 'sSalesManName') {
    global.bussnessEle.globeSalesManlist.length = 0;
    global.bussnessEle.globeSalesManlist = [];
  } else if (masterData === 'sGetPayId' || masterData === 'sGetPayName') {
    global.bussnessEle.globeGetPaylist.length = 0;
    global.bussnessEle.globeGetPaylist = [];
  } else if (masterData === 'sSenderId' || masterData === 'sSenderName') {
    global.bussnessEle.globeSenderlist.length = 0;
    global.bussnessEle.globeSenderlist = [];
  } else if (masterData === 'sCurrency') {
    global.bussnessEle.globeCurrencylist.length = 0;
    global.bussnessEle.globeCurrencylist = [];
  } else if (masterData === 'sDeliverId' || masterData === 'sDeliverName') {
    global.bussnessEle.globeDeliverlist.length = 0;
    global.bussnessEle.globeDeliverlist = [];
  } else if (masterData === 'sTaxId' || masterData === 'sTaxName') {
    global.bussnessEle.globeTaxlist.length = 0;
    global.bussnessEle.globeTaxlist = [];
  }

  return true;
}
/* 清空销售管理 下拉赋值数据 */
export function clearDropListCopyValue() {
  clearlist('sProductId');// 清空印件列表,因为每个客户不一样
  clearlist('sMaterialsId');// 清空材料列表,因为每个仓库不一样
  clearlist('sCustomerId');// 清空材料列表,因为每个仓库不一样
  // 当记录为1时, 并且只有两个元素Sid,sName,说明来自赋值，而不是从数据库中取得
  if (Object.keys(global.bussnessEle.globeCustomerlist).length === 1) {
    clearlist('sCustomerId');
  }
  if (Object.keys(global.bussnessEle.globeWareHouselist).length === 1) {
    clearlist('sWareHouseId');
  }
  if (Object.keys(global.bussnessEle.globeSalesManlist).length === 1) {
    clearlist('sSalesManId');
  }
  if (Object.keys(global.bussnessEle.globeGetPaylist).length === 1) {
    clearlist('sGetPayId');
  }
  if (Object.keys(global.bussnessEle.globeSenderlist).length === 1) {
    clearlist('sSenderId');
  }
  if (Object.keys(global.bussnessEle.globeCurrencylist).length === 1) {
    clearlist('sCurrency');
  }
  if (Object.keys(global.bussnessEle.globeDeliverlist).length === 1) {
    clearlist('sDeliverId');
  }
  return true;
}
