import React, { PureComponent } from "react"; import { connect } from "dva"; import { routerRedux } from "dva/router"; import { Icon, Checkbox, Select, Input, DatePicker, Popover, Button, notification, message, Layout, Row, Col, Affix, Popconfirm, Spin, Tag, Modal } from "antd"; import moment from "moment"; import styles from "./index.less"; import OrderGoodsList from "@/components/OrderGoodsList/index.js"; import TreeListModal from "@/components/SelectDialog/TreeList/index"; import InvoiceDialog from "@/components/InvoiceDialog/index"; import { getCustomer, getDefaultCurrency } from "@/utils/request.js"; import FormPayforDialog from "@/components/PayforDialog/index"; import { setItemsDefaultData, getMaxOccupyMny, matchCustomerCast, ifSupplierIsOrg, translateItemBomFromItem } from "./orderTools"; import { getGoodAndPalettePriceConAPI,saveGoodsOptsResultAPI, getOptByIdAPI } from "../../../services/api"; const { Header, Content } = Layout; // 获取默认币种 const currency = { id: getDefaultCurrency().id || "", currencySign: getDefaultCurrency().currencySign || "¥", currencyPriceScale: getDefaultCurrency().currencyPriceScale || 2, currencyAmountScale: getDefaultCurrency().currencyAmountScale || 2 }; const ifOptional = true; const ifStrucManage = true; class OrderEidt extends PureComponent { constructor(props) { super(props); this.customerId = getCustomer().id; this.customerRankCode = getCustomer().customerRankCode; this.ifPromotion = false; // 是否重新询促销 this.ifOccupy = false; // 是否重新询费用 this.ifCredit = false; // 是否重新询信用 this.ifFillBom = false; // 是否重新补充BOM信息 // this.promotionStyle = ""; // 促销维度 this.giftItems = []; this.state = { ref: {}, addressData: [], // 收货地址 invoiceInfoData: [], // 发票 btnTxt: "展开地址", iconType: "down", isShow: false, // 控制地址收起展开 totalWeight: 0, // 总质量 totalVolume: 0, // 总体积 totalNum: 0, // 总数量 totalDealAmount: 0, // 订单成交金额 totalAmount: 0, // 商品总金额(订单原金额) promAmount: 0, // 促销金额 supplierId: "", // 供应商 transportModeId: "", // 运输方式 settleModeId: "", // 结算方式 underPaymentModeId: "", // 支付方式 underPaymentModeCode: "", underPaymentModeName: "", // 支付方式name remark: "", // 订单备注 deliveryDate: Date.now(), // 期望收货日期 offsetAmount: 0, // 费用冲抵金额 haveChecked: false, // 购物车下单,暂存订单编辑用到该参数 supplierDisabled: false, // 供应商不可编辑,默认false srcOrderId: "", // 来源单据(原单主键) srcOrderCode: "", // 来源单据编号 castTypeId: "", // 客户费用单类型主键(货补兑付) saleModel: "01", // 销售模式 // 根据供货方是否组织,判断是否一级经销商,默认为一级经销商 ifCashOrder: false, // 是否 货补兑付订单(一级渠道商才能使用货补) ifOneSupplier: true, // 是否一级渠道商 ifEditOrder: false, // 是否是订单编辑 loading: false, // 提交、暂存 goodsLoading: false, // 商品行 occupyMnyTopLimit: {}, payNeedData: {}, modalResultVisible: false, ifSubmit: false, isSubBut: false, actionType: "", isDisabled: false, optValShow: false, optSearchVal: "", optValSelectId: "", optVal: { baseGoodsOptValue: "", baseGoodsOptId: "", ext05: "", ext04: "", price: "" } , currRow: -1, goodsAttrVals: [] }; } componentWillMount() { const { dispatch, location } = this.props; // 获取购物车商品(购物车下单) const cartData = location["cartData"]; // 获取订单主键(订单编辑) const orderId = location[`orderId`]; // 复制 const query = location[`query`]; // 货补兑付 const cashOrderData = location[`cashOrderData`]; dispatch({ type: "orderEdit/getSupplierData", payload: null }) .finally(() => { const { supplierData } = this.props; const { supplierId, saleModel } = this.state; if (supplierId) { // // 匹配账期 // dispatch({ // type: "orderEdit/getAccountPeriodInfo", // payload: { // saleOrg: supplierId, // 销售组织 // customer: this.customerId, // 客户 // saleModel: saleModel // } // }); // 判断供应商是否为组织 const isOrg = ifSupplierIsOrg(supplierId, supplierData); // 供应商是组织时,只设置ifOneSupplier为true,适配货补 if (isOrg) { this.setState({ ifOneSupplier: true }); } else { this.setState({ ifOneSupplier: false }); } } }); dispatch({ type: "orderEdit/getAddressData", payload: null }) .finally(() => { const { addressData, orderEditData } = this.props; // console.log("==="); // console.log(orderEditData); // console.log(addressData); if (orderEditData && orderEditData.reqOrderReceiveAddress && orderEditData.reqOrderReceiveAddress.receiveAddressId && addressData) { addressData.forEach(item => { item.isSelected = "0"; }); (addressData.find(item => item.id == orderEditData.reqOrderReceiveAddress.receiveAddressId) || {}).isSelected = "1"; this.setState({ addressData: addressData }); } }); dispatch({ type: "orderEdit/getLogisticsData", payload: null }); dispatch({ type: "orderEdit/getSettlementData", payload: null }); dispatch({ type: "orderEdit/getPayforMainData", payload: null }); // 获取项目 dispatch({ type: "orderEdit/getProjectData", payload: { search_EQ_isEnable: 1 } }); dispatch({ type: "orderEdit/getInvoiceInfoData", payload: null }) .finally(() => { const { invoiceInfoData, orderEditData } = this.props; if (orderEditData && orderEditData.reqOrderInvoice && orderEditData.reqOrderInvoice.invoiceId && invoiceInfoData ) { invoiceInfoData.forEach(item => { item.isDefault = "0"; }); ( invoiceInfoData.find( item => item.id == orderEditData.reqOrderInvoice.invoiceId ) || {} ).isDefault = "1"; this.setState({ invoiceInfoData: invoiceInfoData }); } }); // 防止有历史数据,先清空订单商品,促销等相关信息 dispatch({ type: "orderEdit/orderEditData", orderEditData: null }); dispatch({ type: "orderEdit/orderCartData", orderCartData: [] }); dispatch({ type: "orderEdit/occupyMnyTopLimits", occupyMnyTopLimits: null }); dispatch({ type: "orderEdit/orderCredit", orderCredit: {} }); dispatch({ type: "orderEdit/promotionInfoData", promotionInfoData: null }); // 复制订单 if (query && query.orderId) { dispatch({ type: "orderEdit/getOrderEditDataForCopy", payload: { id: query.orderId } }); this.setState({ srcOrderId: query.orderId, srcOrderCode: query.orderCode, haveChecked: true }); } // 订单编辑 (例如:订单暂存编辑、驳回编辑) if (orderId) { dispatch({ type: "orderEdit/getOrderEditData", payload: { id: orderId } }); this.setState({ ifEditOrder: true, haveChecked: true }); } // 购物车下单 if (cartData) { dispatch({ type: "orderEdit/orderCartData", orderCartData: setItemsDefaultData(cartData.cartlist, false) }); this.setState({ supplierId: cartData.saleOrgId || cartData.supplierId, ifOneSupplier: cartData.isPrimaryChannel == 1 ? true : false, supplierDisabled: true, goodsLoading: cartData.isPrimaryChannel == 1 ? true : false, haveChecked: true }); } // 货补兑付下单 todo... if (cashOrderData) { dispatch({ type: "orderEdit/orderCartData", orderCartData: setItemsDefaultData(cashOrderData.reqOrderItems, true) }); this.setState({ castTypeId: cashOrderData.castTypeId, supplierId: cashOrderData.saleOrgId, ifOneSupplier: true, // 一级经销商才能使用货补 saleModel: "03", supplierDisabled: true, haveChecked: false, ifCashOrder: true }); } } componentWillReceiveProps(nextProps) { const { dispatch, orderCartData, occupyMnyTopLimits } = nextProps; const { ifCashOrder, ifOneSupplier } = this.state; // 非货补订单重新询促销,先清空费用冲抵、促销、赠品信息 if (this.ifPromotion && !ifCashOrder) { // 清空促销,赠品信息 dispatch({ type: "orderEdit/promotionInfoData", promotionInfoData: null }); this.giftItems = []; this.setState({ goodsLoading: true }); // 如为一级经销商,则需重新匹配费用 if (ifOneSupplier) { // 重新询促销,代表商品行信息发生改变,此时,重新匹配费用 const occupyMnyTopLimit = matchCustomerCast(orderCartData, occupyMnyTopLimits); this.setState({ offsetAmount: 0, occupyMnyTopLimit: occupyMnyTopLimit || {} }); } } if ("promotionInfoData" in nextProps) { const promotionInfoData = nextProps.promotionInfoData; if (promotionInfoData && promotionInfoData.reqOrderItems) { dispatch({ type: "orderEdit/orderCartData", orderCartData: promotionInfoData.reqOrderItems }); } } if ("addressData" in nextProps) { const addressData = nextProps.addressData; this.setState({ addressData: addressData }); } if ("invoiceInfoData" in nextProps) { const invoiceInfoData = nextProps.invoiceInfoData; this.setState({ invoiceInfoData: invoiceInfoData }); } if ("orderCartData" in nextProps) { const orderCartData = nextProps.orderCartData; if (orderCartData && orderCartData.length > 0) { if (this.state.haveChecked) { // 查询促销信息 this.ifPromotion = true; // 重新补充Bom信息 this.ifFillBom = true; // 非货补下单且为一级渠道商下单,重新询费用 if (!this.state.ifCashOrder && this.state.ifOneSupplier) { // 查询费用 this.ifOccupy = true; } this.setState({ haveChecked: false }); } } } if ("orderEditData" in nextProps) { const orderEditData = nextProps.orderEditData; if (orderEditData && orderEditData.id) { if (this.state.haveChecked) { // todo... this.setState({ supplierDisabled: (orderEditData.saleOrgId || orderEditData.supplierId) ? true : false, supplierId: orderEditData.saleOrgId || orderEditData.supplierId, // 供应商(一级渠道商为组织、非一级渠道商为上级客户) ifOneSupplier: orderEditData.saleOrgId ? true : false, transportModeId: orderEditData.transportModeId, // 运输方式 settleModeId: orderEditData.settleModeId, // 结算方式 underPaymentModeId: orderEditData.underPaymentModeId, // 支付方式 underPaymentModeCode: orderEditData.underPaymentModeCode, // 支付方式 underPaymentModeName: orderEditData.underPaymentModeName, remark: orderEditData.remark, // 订单备注 deliveryDate: Date.now() // 期望收货日期 }); // todo... if (orderEditData.reqOrderItems.length > 0) { dispatch({ type: "orderEdit/orderCartData", orderCartData: orderEditData.reqOrderItems }); const { addressData, invoiceInfoData } = nextProps; if ( orderEditData.reqOrderReceiveAddress && orderEditData.reqOrderReceiveAddress.receiveAddressId ) { addressData.forEach(item => { item.isSelected = "0"; }); ( addressData.find( item => item.id == orderEditData.reqOrderReceiveAddress.receiveAddressId ) || {} ).isSelected = "1"; } if ( orderEditData.reqOrderInvoice && orderEditData.reqOrderInvoice.invoiceId ) { invoiceInfoData.forEach(item => { item.isDefault = "0"; }); ( invoiceInfoData.find( item => item.id == orderEditData.reqOrderInvoice.invoiceId ) || {} ).isDefault = "1"; } } } } } // 订单暂存、提交返回结果 todo... if ("resultOrder" in nextProps) { const resultOrder = nextProps.resultOrder; if (!resultOrder) return null; if (resultOrder.id) { let msg = "订单提交成功"; if (resultOrder.orderStatusCode == "01") { msg = "订单暂存成功"; if (this.state.underPaymentModeName == "在线支付" && this.state.isSubBut) { const currencyName = JSON.parse(localStorage["_A_P_currency"]).name; const payBillDatalist = { id: resultOrder.id }; this.state.payNeedData = { total_amount: resultOrder.totalDealAmount, out_trade_no: resultOrder.orderCode, paymentModeName: resultOrder.paymentModeName, currencyName: currencyName, payBillData: payBillDatalist }; dispatch({ type: "paymentNotice/orderPayBillSet", orderPayBillSet: this.state.payNeedData }); this.props.dispatch({ type: "global/orderListVisible", payload: true }); } else { setTimeout(() => { dispatch(routerRedux.push("/buyer/orderList")); }, 2000); } } else { // 删除购物车相关商品 this.removeShopCart(); } notification.success({ message: msg, description: `订单号为${resultOrder.orderCode},2秒后跳转到订单列表页`, duration: 2 }); if (resultOrder.orderStatusCode == "01" && this.state.underPaymentModeName == "在线支付") { console.log("去支付"); } else { setTimeout(() => { dispatch(routerRedux.push("/buyer/orderList")); }, 2000); } dispatch({ type: "orderEdit/resultOrder", resultOrder: null }); } else { const { ifSubmit } = this.state; if (!ifSubmit) return; let msg = "订单提交失败"; if (resultOrder.orderStatusCode == "01") { msg = "订单暂存失败"; } if (resultOrder.message) { msg = `${msg}:${resultOrder.message}`; } notification.error({ message: msg, duration: 3 }); dispatch({ type: "orderEdit/resultOrder", resultOrder: null }); } } } componentDidUpdate() { const { orderCartData, dispatch, occupyMnyTopLimits } = this.props; const { supplierId, ifCashOrder, saleModel, ifOneSupplier } = this.state; // orderCartData.forEach(item => { // console.log(`=================================${item.dealAmount}`); // return item; // }); // 非货补订单询促销 if (!ifCashOrder && this.ifPromotion) { // 匹配促销信息 dispatch({ type: "orderEdit/getPromotionInfo", payload: { saleOrgId: supplierId, // 销售组织 customerId: this.customerId, // 客户 // isPrimaryChannel: ifOneSupplier ? 1 : 0, // 是否一级渠道商 orderType: "reqOrder", reqOrderItems: orderCartData // 商品行信息 } }) .finally(() => { this.setState({ goodsLoading: false }); // 非货补下单且为一级渠道商下单,检测信用 if (!this.state.ifCashOrder && this.state.ifOneSupplier) { this.checkCreditHandle(); } // 重新补充BOM信息 if (this.ifFillBom) { this.LinkGoodsBomInfo(); } // this.LinkGoodsBomInfo(); }); this.giftItems = []; this.ifPromotion = false; } // 非货补下单且为一级渠道商下单,匹配费用,检测信用 if (!ifCashOrder && ifOneSupplier) { if (this.ifOccupy) { // 匹配费用 dispatch({ type: "orderEdit/getOccupyMnyTopLimit", payload: { saleOrgId: supplierId, // 销售组织 customerId: this.customerId // 客户 } }) .finally(() => { const occupyMnyTopLimit = matchCustomerCast(orderCartData, this.props.occupyMnyTopLimits); this.setState({ occupyMnyTopLimit: occupyMnyTopLimit || {} }); }); this.ifOccupy = false; } if (this.ifCredit) { this.checkCreditHandle(); this.ifCredit = false; } } } // 设为默认地址 setDefaultHandle(index) { let { addressData } = this.state; addressData = Array.isArray(addressData) ? addressData : Object.values(addressData); // 设置默认收获地址 this.props.dispatch({ type: "orderEdit/setDefaultAddress", payload: { customer: this.customerId, // 客户id id: addressData[index].id // 收获地址id } }) .finally((res) => { res.forEach(item => { if (!!item.isDefault) item.isSelected = "1"; else item.isSelected = "0"; }); /* if (res) { addressData.forEach(item => { item.isDefault = "0"; item.isSelected = "0"; }); addressData[index].isDefault = "1"; addressData[index].isSelected = "1"; } */ this.setState({ addressData: Object.assign({}, res) }); }); /* addressData.forEach(item => { item.isDefault = "0"; item.isSelected = "0"; }); addressData[index].isDefault = "1"; addressData[index].isSelected = "1"; this.setState({ addressData: Object.assign({}, addressData) }); */ } // 结算方式改变 settlementChange(value) { this.setState({ settleModeId: value }); } // 支付方式 payforMainChange(value) { const { payforMainData } = this.props; let payModl = "", code = ""; for (var i = 0; i < payforMainData.length; i++) { if (payforMainData[i].id == value) { payModl = payforMainData[i].name; code = payforMainData[i].code; } } this.setState({ underPaymentModeId: value, underPaymentModeCode: code, underPaymentModeName: payModl }); } checkCreditHandle() { // const { orderCartData, dispatch } = this.props; // const { supplierId, saleModel } = this.state; // if (supplierId && orderCartData && Array.isArray(orderCartData)) { // // 信用检测 // dispatch({ // type: "orderEdit/orderCreditChecker", // payload: { // saleOrgId: supplierId, // 销售组织 // customerId: this.customerId, // 客户 // saleModel: saleModel, // reqOrderItems: orderCartData // 商品行信息 // } // }); // } } // 联查BOM信息 LinkGoodsBomInfo() { const { dispatch, orderCartData } = this.props; dispatch({ type: "orderEdit/getItemBomInfo", payload: { reqOrderItems: orderCartData // 商品行信息 } }); this.ifFillBom = false; } // 删除购物车商品 removeShopCart() { const { orderCartData, cartListData, dispatch } = this.props; if (!cartListData || !Array.isArray(cartListData)) return; if (!orderCartData || !Array.isArray(orderCartData)) return; const { supplierId } = this.state; const cartIds = []; for (let i = 0; i < cartListData.length; i++) { const saleOrgId = cartListData[i].saleOrgId || cartListData[i].supplierId; if (saleOrgId == supplierId) { const newCartlistData = cartListData[i].cartlist; if (newCartlistData && newCartlistData.length > 0) { orderCartData.forEach(orderItem => { const cart = newCartlistData.find(item => item.goodsId == orderItem.goodsId); if (cart && cart.id) { cartIds.push(cart.id); } }); } } } if (cartIds && cartIds.length > 0) { const cartId = cartIds.join(","); dispatch({ type: "cartList/deleteCartListData", payload: { id: cartId } }); } } selectAddressHandle(index) { let { addressData } = this.state; addressData = Array.isArray(addressData) ? addressData : Object.values(addressData); addressData.forEach(item => { item.isSelected = "0"; }); addressData[index].isSelected = "1"; this.setState({ addressData: Object.assign({}, addressData) }); } promotionChangeHandle(style) { const { orderCartData, dispatch, promotionInfoData } = this.props; const mutualRelationShip = promotionInfoData.mutualRelationShip; const { supplierId, ifCashOrder, ifOneSupplier } = this.state; if (!ifCashOrder) { dispatch({ type: "orderEdit/getPromotionInfo", payload: { saleOrgId: supplierId, // 销售组织 customerId: this.customerId, // 客户 isPrimaryChannel: ifOneSupplier ? 1 : 0, // 是否一级渠道商 promotionStyle: style, reqOrderItems: orderCartData // 商品行信息 } }) .finally(() => { const { dispatch, promotionInfoData } = this.props; const newPromotionInfoData = Object.assign({}, promotionInfoData); newPromotionInfoData.giftProms = promotionInfoData.giftProms; newPromotionInfoData.orderPriceProm = promotionInfoData.orderPriceProm; newPromotionInfoData.reqOrderItems = promotionInfoData.reqOrderItems; newPromotionInfoData.mutualRelationShip = mutualRelationShip; dispatch({ type: "orderEdit/promotionInfoData", promotionInfoData: newPromotionInfoData }); }); this.giftItems = []; } } async onOptClick(goods, index) { const attrs = await getOptByIdAPI({id: goods.goodsId, groupId: "", colourCode:""}); this.setState({ currRow: index, optValShow: true, goodsAttrVals: attrs[0].goodsAttrVals }) } selectColor(optValSelectId) { this.setState({ optValSelectId }); } async confirmColor(color) { const { dispatch, orderCartData, supplierData } = this.props; let goodsDetail = {...orderCartData[this.state.currRow]} let existRow = orderCartData.findIndex((item,index) => item.ext05 == color.attrValId && item.goodsId == color.goodsId && index != this.state.currRow) if (existRow >= 0) { message.info("所选颜色商品已存在,请重新选择!"); return } const params = { organizationId: supplierData[0].id, customerId: getCustomer().id, goodsId: goodsDetail.goodsId, orderTypeId: '01', paletteId: color.attrValId, shopId: '' } const result = await getGoodAndPalettePriceConAPI(params) if (result.length) { const optParams = [{ goodsOptDtos: [{ goodsId: goodsDetail.goodsId, goodsOptVals: [color], optResult: color.custDocGroupName+ ":" + color.attrValName, uniqueKey: goodsDetail.goodsId }] }] const opt = await saveGoodsOptsResultAPI(optParams); const price = result[0].price const priceAndMny = { promPrice : price, basePrice : price, dealPrice : price, salePrice : price, ext09 : price, ext10 : price * goodsDetail.orderNum, amount : price * goodsDetail.orderNum, dealAmount : goodsDetail.amount, baseGoodsOptId : opt[0].goodsOptDtos[0].id, baseGoodsOptValue : color.custDocGroupName+ ":" + color.attrValName, ext05 : color.attrValCode } let newItem = Object.assign({},goodsDetail,priceAndMny) orderCartData.splice(this.state.currRow,1,newItem) dispatch({ type: "orderEdit/orderCartData", orderCartData: [...orderCartData] }) } } // 备注改变 remarkChange(e) { this.setState({ remark: e.target.value }); } // 收货日期改变 dateChange(date, datestring) { this.setState({ deliveryDate: datestring }); } // 物流方式改变 logisticsChange(value) { this.setState({ transportModeId: value }); } // 供应商改变 supplierChange(value) { const { dispatch, supplierData } = this.props; const { supplierId, saleModel } = this.state; // 匹配账期 // dispatch({ // type: "orderEdit/getAccountPeriodInfo", // payload: { // saleOrg: value, // 销售组织 // customer: this.customerId, // 客户 // saleModel: saleModel // } // }); // 判断供应上是否为组织 const isOrg = ifSupplierIsOrg(value, supplierData); // 供应商是组织时,只设置ifOneSupplier为true,适配货补 if (isOrg) { this.setState({ supplierId: value, ifOneSupplier: true }); this.ifOccupy = true; } else { this.setState({ supplierId: value, ifOneSupplier: false }); } dispatch({ type: "orderEdit/orderCartData", orderCartData: [] }); // 促销 dispatch({ type: "orderEdit/promotionInfoData", promotionInfoData: null }); this.giftItems = []; // 信用检测 dispatch({ type: "orderEdit/orderCredit", orderCredit: {} }); // 清空促销 dispatch({ type: "orderEdit/occupyMnyTopLimits", occupyMnyTopLimits: null }); } // 票扣改变时 custfeeChange(e) { e.preventDefault(); const value = e.target.value; const reg = /^-?(0|[1-9][0-9]*)(\.[0-9]*)?$/; if (value.length == 0) { this.setState({ offsetAmount: value }); } else { if (value.length > 1 && value.indexOf("0") == 0 && value.indexOf(".") != 1) { this.setState({ offsetAmount: parseFloat(value) }); } else { if (value && reg.test(value)) { this.setState({ offsetAmount: value }); } else { message.info("请输入有效金额!"); } } } } // 票扣输入框失去焦点时 custfeeBlur() { const { totalAmount, promAmount, offsetAmount, occupyMnyTopLimit } = this.state; const max = getMaxOccupyMny( occupyMnyTopLimit, totalAmount, totalAmount - promAmount ); let value = +offsetAmount; if (value > max) { value = max; message.info("您录入的费用冲抵金额不能超出本次最高可冲抵金额!"); } if (value < 0) { value = 0; } value = +(value.toFixed(currency.currencyAmountScale)); this.setState({ offsetAmount: value, totalDealAmount: totalAmount - promAmount - value }); this.ifCredit = true; } // 获取商品信息 goodsInfoChange(value) { const { totalDealAmount, promAmount, occupyMnyTopLimit } = this.state; const offsetAmount = +this.state.offsetAmount; /** * 促销金额 = 商品总金额-商品促销后总金额 * 订单金额 = 商品促销后总金额 - 冲抵金额 */ this.setState({ totalAmount: value.newTotalAmount, promAmount: value.newTotalAmount - value.newTotalDealAmount, totalDealAmount: value.newTotalDealAmount - offsetAmount, totalWeight: value.newAllWeight, totalVolume: value.newAllVolume, totalNum: value.newTotalNum }); } // 展开收起地址 showAddressClick() { this.setState({ btnTxt: this.state.btnTxt == "展开地址" ? "收起地址" : "展开地址", iconType: this.state.iconType == "down" ? "up" : "down", isShow: !this.state.isShow }); } // 取消 cancelHandle() { const { dispatch } = this.props; const { ifCashOrder, ifOneSupplier } = this.state; // 如果是货补兑付订单,则点击取消返回货补兑付列表页 if (ifCashOrder && ifOneSupplier) { dispatch(routerRedux.push("/buyer/goodsSupplyList")); } else { dispatch(routerRedux.push("/buyer/orderList")); } } // 暂存 saveTempHandle(isSubmit) { const { dispatch } = this.props; const postData = this.packageOrderData(); const warnInfo = this.validOrderData(postData); if (warnInfo) { message.warning(warnInfo); return false; } this.setState({ loading: true, ifSubmit: true, isSubBut: false }); dispatch({ type: "orderEdit/saveTempOrder", payload: postData }) .finally(() => { this.setState({ loading: false, isDisabled: true }); }); } // 提交 okHandle() { const { dispatch, orderCredit, payforMainData, accountPeriodInfo } = this.props; const { ifCashOrder, castTypeId, ifOneSupplier, underPaymentModeId } = this.state; let postData = this.packageOrderData(); // 提交订单时,如有买赠或整单降价,则补充相应信息 postData = this.fillOrderPriceCutAndGiftRows(postData); // 补充BOM信息 postData = this.fillGoodsBomInfo(postData); let warnInfo = this.validOrderData(postData); // 货补兑付时,补充客户费用单主键 todo... if (ifCashOrder && ifOneSupplier) { if (!castTypeId) { warnInfo += "未获取到客户费用单主键,请重新下单! "; } postData.saleModel = "03"; // 货补下单时,销售模式为03 postData.offsetAmount = postData.totalDealAmount; postData.totalAmount = 0; postData.totalDealAmount = 0; postData.costTypeId = castTypeId; postData.reqOrderItems.forEach(item => { if (item.isGift != 1) { item.offsetAmount = item.dealAmount; } }); } if (warnInfo) { message.warning(warnInfo); return false; } this.setState({ loading: true, ifSubmit: true }); if (this.state.underPaymentModeName == "在线支付") { // this.saveTempHandle(true); this.setState({ isSubBut: true }); dispatch({ type: "orderEdit/saveTempOrder", payload: postData }) .finally(() => { this.setState({ loading: false }); }); return; } if (orderCredit && orderCredit.validMessage) { message.info(orderCredit.validMessage); } // totalDealAmount: 0, // 订单成交金额 // totalAmount: 0, // 商品总金额(订单原金额) // if (parseFloat(orderCredit) + parseFloat(postData.totalDealAmount) < parseFloat(postData.totalAmount)) { // message.info("信用不足!"); // } // if (!accountPeriodInfo || !accountPeriodInfo.name) { // message.info("未匹配到账期"); // } dispatch({ type: "orderEdit/submitOrder", payload: postData }).finally((data) => { this.setState({ loading: false }); }); } // 补充整单降价、赠品行信息 fillOrderPriceCutAndGiftRows(postData) { const giftItems = this.giftItems; const { promotionInfoData } = this.props; // 如有整单降价,则在表头上补充整单降价促销信息 if (promotionInfoData && promotionInfoData.orderPriceProm) { const orderPriceProm = promotionInfoData.orderPriceProm; postData.reqOrderPromRels = [ { activityId: orderPriceProm.activityId, ruleId: orderPriceProm.ruleId, description: orderPriceProm.description, promWay: 2, // 1 买赠 2 降价 isWhole: 1 // 1 整单 } ]; } if (giftItems && giftItems.length > 0) { const giftRows = []; giftItems.forEach(giftProm => { const giftDtos = giftProm.giftDtos; if (giftDtos && giftDtos.length > 0) { giftDtos.forEach(gift => { // 封装赠品行信息 const translate = { id: null, isGift: 1, basePrice: 0, salePrice: 0, promPrice: 0, dealPrice: 0, ext09:0, ext10:0, amount: 0, // 金额 promAmount: 0, // 均摊到行上的整单降价促销金额 dealAmount: 0, // 成交金额 offsetAmount: 0, // 均摊到行上的费用冲抵金额 reqOrderPromRels: [ { ruleId: giftProm.ruleId, ruleCode: giftProm.ruleCode, ruleName: giftProm.ruleName, activityId: giftProm.activityId, activityCode: giftProm.activityCode, activityName: giftProm.activityName, giftId: gift.giftId, description: giftProm.description, combineType: giftProm.combineType, // 组合类型 1 固定组合 goodCombineNum: giftProm.goodCombineNum, // 固定组合类商品基准数量 promWay: 1, // 1 买赠 2 降价 isWhole: 0 } ] }; const newGift = Object.assign({}, gift, translate); giftRows.push(newGift); }); } }); // 如果赠品行不为空,则补充到订单表体行 if (giftRows.length > 0) { const reqOrderItems = postData.reqOrderItems; const newReqOrderItems = reqOrderItems.concat(giftRows); postData.reqOrderItems = newReqOrderItems; } } return postData; } // 补充BOM信息 fillGoodsBomInfo(postData) { const reqOrderItems = postData.reqOrderItems; const reqOrderItemBoms = translateItemBomFromItem(reqOrderItems); postData.reqOrderItems = reqOrderItems; postData.reqOrderItemBoms = reqOrderItemBoms; return postData; } // 校验订单数据 validOrderData(postData) { if (!postData) return "订单信息有误,请重新下单!"; let msg = ""; if (!this.state.supplierId) { msg += "供应商不能为空!"; } if (!this.state.underPaymentModeId) { msg += "请输入支付方式!"; } // if (!postData.transportModeId) { // msg += "运输方式不能为空!"; // } // if (!postData.settleModeId) { // msg += "结算方式不能为空!"; // } if (!postData.deliveryDate) { msg += "期望到货日期不能为空!"; } if ( !postData.reqOrderReceiveAddress || !postData.reqOrderReceiveAddress.receiveAddressId ) { msg += "收货地址信息不能为空!"; } if (!postData.reqOrderInvoice || !postData.reqOrderInvoice.invoiceId) { msg += "发票信息不能为空!"; } if (!postData.reqOrderItems || postData.reqOrderItems.length < 1) { msg += "商品信息不能为空!"; } // postData.reqOrderItems.forEach((item, index) => { // if (!item.salePrice || !item.stock || parseFloat(item.salePrice) <= 0 || parseFloat(item.stock) <= 0) { // msg += `第${index + 1}行商品【${item.goodsDisplayName}】无价格或无库存,不可下单,请修改!`; // } // }); return msg; } // 封装订单信息 packageOrderData() { const { orderCartData, location, orderEditData } = this.props; const { id, supplierId, transportModeId, settleModeId, underPaymentModeId, underPaymentModeCode, remark, deliveryDate, invoiceInfoData, totalAmount, totalDealAmount, offsetAmount, totalWeight, totalVolume, srcOrderId, srcOrderCode, totalNum, ifEditOrder, saleModel, ifOneSupplier } = this.state; // 默认地址 let addressData = this.state.addressData; addressData = Array.isArray(addressData) ? addressData : Object.values(addressData); const addressDefault = addressData.find(item => item.isSelected == "1") || {}; // 默认发票 const invoiceInfoDefault = invoiceInfoData.find( item => item.isDefault == "1" ) || {}; // todo... orderCartData.forEach(item => { item.reqOrderId = null; item.id = null; if (item.reqOrderPromRels) { item.reqOrderPromRels.forEach(promRel => { promRel.isWhole = 0; }); } }); const postData = { // todo... id: ifEditOrder ? orderEditData.id : "", orderCode: ifEditOrder ? orderEditData.orderCode : "", customerId: this.customerId, saleOrgId: ifOneSupplier ? supplierId : "", // 销售组织 (一级经销商) supplierId: ifOneSupplier ? "" : supplierId, // 供应商(非一级经销商) saleModel: "01", // 销售模式(正向时默认01:正向销售) transportModeId: transportModeId, // 运输方式 settleModeId: settleModeId, // 结算方式 underPaymentModeId: underPaymentModeCode, // 支付方式 deliveryDate: deliveryDate, // 期望收货日期 totalNum: "", // 总数量 currency: currency.id, // 币种 currencySign: currency.currencySign, // 币符 currencyPriceScale: currency.currencyPriceScale, // 币种单价精度 currencyAmountScale: currency.currencyAmountScale, // 币种金额精度 totalAmount: totalAmount, // 原金额 totalDealAmount: totalDealAmount, // 成交金额 totalWeight: totalWeight, // 总重量 totoalVolume: totalVolume, // 总体积 totalNum: totalNum, // 总数量 reqOrderSource: "01", // 门户 srcOrderId: srcOrderId, srcOrderCode: srcOrderCode, remark: remark, // 订单备注 offsetAmount: offsetAmount, // 费用冲抵金额 reqOrderReceiveAddress: { reqOrderId: id, receiveAddressId: addressDefault.id, // 收货地址id receiver: addressDefault.receiver, // 收货人 receiverTel: addressDefault.receiverTel, // 电话 receiverPhone: addressDefault.receiverPhone, // 手机 countryId: addressDefault.countryId, receiverProvince: addressDefault.receiverProvince, // 省 receiverProvinceId: addressDefault.receiveAddressId, receiverCity: addressDefault.receiverCity, // 市 receiverCityId: addressDefault.receiverCityId, receiverCounty: addressDefault.receiverCounty, // 县 receiverCountyId: addressDefault.receiverCountyId, receiverTown: addressDefault.receiverTown, // 镇 receiverTownId: addressDefault.receiverTownId, receiverAddress: addressDefault.receiverAddress, // 详细地址 receiverZipcode: addressDefault.receiverZipcode, // 邮编 isDefault: addressDefault.isDefault // 是否默认地址 }, reqOrderInvoice: { reqOrderId: id, invoiceId: invoiceInfoDefault.id, // 发票id invoiceType: invoiceInfoDefault.invoiceType, // 发票类型 invoiceContent: invoiceInfoDefault.invoiceContent, // 开票项目 invoiceTitle: invoiceInfoDefault.invoiceTitle, // 发票抬头 invoiceTaxId: invoiceInfoDefault.invoiceTaxId, // 纳税人识别码 invoiceBank: invoiceInfoDefault.invoiceBank, // 开户银行 invoiceAccount: invoiceInfoDefault.invoiceAccount, // 开户账户 invoiceSubBank: invoiceInfoDefault.invoiceSubBank // 支行 }, reqOrderItems: orderCartData }; return Object.assign({}, postData); } // showCustfeeDialog() { // this.props.dispatch({ // type: "global/custfeeVisible", // payload: true // }); // } showInvoiceDialog() { this.props.dispatch({ type: "global/invoiceVisible", payload: true }); } showModal() { const { supplierId } = this.state; if (!supplierId) { message.info("请先选择供应商!"); return false; } this.props.dispatch({ type: "global/treeListVisible", payload: true }); } addGoodsInfo(treeListSelectedRows) { const { orderCartData, dispatch } = this.props; let newOrderCartData = []; if (typeof orderCartData == "object") { newOrderCartData = orderCartData.concat([]); } // 判断添加的商品是否重复 todo... treeListSelectedRows.forEach(addRow => { let repeat = false; const conversionRate = parseFloat(addRow.conversionRate || "1"); newOrderCartData.forEach(item => { // 重复,则累加订货数量、主数量 if (item.goodsId == addRow.id && item.ext05 == addRow.ext05) { item.orderNum += 1; item.mainNum += conversionRate; repeat = true; } }); if (!repeat) { const newAddRow = Object.assign({}, addRow); newAddRow.orderNum = 1; newAddRow.mainNum = conversionRate; const newAddRows = setItemsDefaultData([newAddRow], true); newOrderCartData = newOrderCartData.concat(newAddRows); } }); dispatch({ type: "orderEdit/orderCartData", orderCartData: newOrderCartData }); // 匹配促销信息 this.ifPromotion = true; // 重新补充BOM信息 this.ifFillBom = true; } // setModalResultVisible = (modalResultVisible) => { // this.setState({ modalResultVisible }); // } render() { const { btnTxt, iconType, isShow, totalAmount, totalDealAmount, promAmount, totalWeight, totalVolume, invoiceInfoData, supplierId, transportModeId, settleModeId, underPaymentModeId, underPaymentModeCode, underPaymentModeName, supplierDisabled, ifCashOrder, occupyMnyTopLimit, ifOneSupplier, modalResultVisible, actionType } = this.state; const { logisticsData, settlementData, payforMainData, orderCartData, orderCredit, supplierData, promotionInfoData, accountPeriodInfo } = this.props; if (payforMainData && payforMainData.length && this.state.underPaymentModeId == "") { for (var i = 0; i < payforMainData.length; i++) { if (payforMainData[i].code == "GoodsFirst") { this.setState({ underPaymentModeId: payforMainData[i].id }); } } } const currOrderMaxOccMny = getMaxOccupyMny( occupyMnyTopLimit, totalAmount, totalAmount - promAmount ); let addressData = this.state.addressData; addressData = Array.isArray(addressData) ? addressData : Object.values(addressData); // 收货地址 const addressHtml = () => { if (!addressData) return null; const htmlArr = []; let defaultHtml; for (let i = 0; i < addressData.length; i++) { const index = i; if (!addressData[i].receiverPhone) addressData[i].receiverPhone = ""; if (addressData[i].isSelected == 1) { defaultHtml = (
  • {addressData[i].receiver}
    {addressData[i].receiverProvince}{" "} {addressData[i].receiverCity}{" "} {addressData[i].receiverCounty}{" "} {addressData[i].receiverTown} {addressData[i].receiverAddress} {addressData[i].receiverPhone ? addressData[i].receiverPhone.substr(0, 3) + "****" + addressData[i].receiverPhone.substring(7, 11) : ""} 默认地址 设为默认
  • ); } else { const html = (
  • {addressData[i].receiver}
    {addressData[i].receiverProvince}{" "} {addressData[i].receiverCity}{" "} {addressData[i].receiverCounty}{" "} {addressData[i].receiverTown} {addressData[i].receiverAddress} {addressData[i].receiverPhone ? addressData[i].receiverPhone.substr(0, 3) + "****" + addressData[i].receiverPhone.substring(7, 11) : ""} 默认地址 设为默认
  • ); htmlArr.push(html); } } htmlArr.unshift(defaultHtml); return htmlArr; }; // 拼接下拉框选项 const selectOptionHtml = listData => { if (!listData || listData.length < 1) return null; const optionHtmls = listData.map(item => ( {item.name} )); return optionHtmls; }; // 发票信息 const invoiceInfoHtml = () => { if (!invoiceInfoData) return null; const invoiceInfo = invoiceInfoData.find(item => item.isDefault == 1); let html; if (!invoiceInfo) { html = ( 纳税人识别号: 开户行: 账号: 选择 ); } else { html = ( {invoiceInfo.invoiceType} {invoiceInfo.invoiceTitle} 纳税人识别号: {invoiceInfo.invoiceTaxId} 开户行: {invoiceInfo.invoiceBank} 账号: {invoiceInfo.invoiceAccount} 选择 ); } return html; }; // 信用查询 const content = () => { if (!orderCredit) return null; const creditData = orderCredit.creditData; if (!creditData || creditData.length < 1) { return (
    未匹配到信用
    ); } return (
    本单信用满足情况
    {creditData.map(item => { return ( {item.productLineName} 信用余额: {parseFloat(item.creditBalance || 0).toFixed(currency.currencyAmountScale)} 本单产品线金额: {parseFloat(item.thisProdLineAmount || 0) .toFixed(currency.currencyAmountScale)} ); })}
    ); }; const disabledDate = current => { return current && current.valueOf() <= Date.now() - 86400000; }; return (
    {/* */}
    {supplierDisabled ? "供应商" : "请选择供应商"}
    {/* 订单信息 */}
    {/* 收货地址 */}

    收货人信息

      {addressHtml()}
    {btnTxt}
    {/* 收货地址-- 结束 */} {/* 物流结算方式 */}

    物流结算

    运输方式
    {/*
    结算方式
    支付方式
    账期 {accountPeriodInfo ? accountPeriodInfo.name : ""}
    */}
    {/* 物流结算方式 */} {/* 发票信息 */}

    发票信息

    {invoiceInfoHtml()}
    {/* 发票信息--end */} {/* 期望到货日期 */}

    备注

    {/* */}
    {/* 期望到货日期--end */}
    {/* 订单信息--结束 */} {/* 商品 */} { this.ifPromotion = value; }} setGiftItems={items => { this.giftItems = items; }} {...this.props} ref={c => { this.orderGoodsList = c; }} /> {/* 商品--end */} {/* 订单底部信息 */}
    总重量: {totalWeight.toFixed(2)}千克
    商品金额: ¥{totalAmount.toFixed(2)}
    总体积: {totalVolume.toFixed(2)}
    {/*
    费用冲抵: (本次最高冲抵: ¥{parseFloat(currOrderMaxOccMny || "0") .toFixed(currency.currencyAmountScale)} 费用总余额: ¥{parseFloat((occupyMnyTopLimit || {}).supplyMaxOccupyMny || "0") .toFixed(currency.currencyAmountScale)}
    */}
    促销金额: ¥{promAmount.toFixed(2)}
    促销金额: ¥{promAmount.toFixed(2)}
    商品金额: ¥{totalAmount.toFixed(2)}
    订单总金额: ¥{ifCashOrder && ifOneSupplier ? "0.00" : totalDealAmount.toFixed(2)}
    {/*
    促销金额: ¥{promAmount.toFixed(currency.currencyAmountScale)}
    */} {/*
    总体积: {totalVolume.toFixed(4)}
    */} {/*
    促销金额: ¥{promAmount.toFixed(currency.currencyAmountScale)}
    */} {/* 信用查询 */}
    {/* 订单底部信息--end */} (this.state.ref.treeListModal = ref)} title="请选择商品" supplierId={this.state.supplierId} treeUrl="/buyer/goods-category/tree" listUrl="/b2b/goods/find-by-customer" saleModel="01" onConfirm={this.addGoodsInfo.bind(this)} />
    { this.setState({optValShow: false}) }} onOk={async () => { if (this.state.optValSelectId) { const colorSelc = this.state.goodsAttrVals ? this.state.goodsAttrVals.find(item => item.attrValId == this.state.optValSelectId) : null const optVal = Object.assign({},this.state.optVal,colorSelc,{baseGoodsOptValue: `${colorSelc.custDocGroupName}->${colorSelc.attrValName}`}) this.setState({ optVal , optValShow: false, goodsAttrVals: [] }) this.confirmColor(optVal) } else { message.warning("请选择颜色") } }} width="1000px" maskClosable={false} >
    { this.setState({optSearchVal: e.target.value}) }} onSearch={(e) => { this.setState({optSearchVal: e}) }} onPressEnter={(e) => { this.setState({optSearchVal: e.target.value}) }} />
    { this.state.goodsAttrVals ? this.state.goodsAttrVals.filter(item => !this.state.optSearchVal || item.attrValName.indexOf(this.state.optSearchVal) >= 0).map((item,index) => { // return {item.attrValName} return {this.selectColor(item.attrValId)}}>{item.attrValName} }) : "" }
    ); } } export default connect(state => ({ supplierData: state.orderEdit.supplierData, addressData: state.orderEdit.addressData, logisticsData: state.orderEdit.logisticsData, settlementData: state.orderEdit.settlementData, payforMainData: state.orderEdit.payforMainData, invoiceInfoData: state.orderEdit.invoiceInfoData, orderCartData: state.orderEdit.orderCartData, resultOrder: state.orderEdit.resultOrder, // orderCustfeeData: state.orderEdit.orderCustfeeData, promotionInfoData: state.orderEdit.promotionInfoData, occupyMnyTopLimits: state.orderEdit.occupyMnyTopLimits, orderCredit: state.orderEdit.orderCredit, orderEditData: state.orderEdit.orderEditData, cartListData: state.cartList.cartListData, projectData: state.orderEdit.projectData, orderPayBillSet: state.paymentNotice.orderPayBillSet, accountPeriodInfo: state.orderEdit.accountPeriodInfo // treeListSelectedRows: state.global.selectedRows }))(OrderEidt);