<!--pages/addOrder/addOrder.wxml-->
<view class="view-page">
<!-- 卖家信息部分 -->
<view class="view-box">
<van-cell border="{{ false }}" title="卖家信息" />
<van-field label="名称" readonly model:value="{{ SellerInfo.eiName }}" placeholder="买家公司" border="{{ false }}"/>
<van-field label="营业执照号" readonly model:value="{{ SellerInfo.eiLicenseNo }}" placeholder="营业执照号" border="{{ false }}"/>
<van-field label="联系人" readonly model:value="{{ SellerInfo.eiContact }}" placeholder="联系人" border="{{ false }}"/>
<van-field label="联系电话" readonly model:value="{{ SellerInfo.eiAdminMobile }}" placeholder="联系电话" border="{{ false }}"/>
<van-field label="联系地址" readonly autosize type="textarea"
model:value="{{SellerInfo.eiProvinceName}} {{SellerInfo.eiCityName}} {{SellerInfo.eiAreaName}} {{SellerInfo.eiAddress}}"
placeholder="联系地址" border="{{ false }}"
/>
</view>
<!-- 买家信息部分 -->
<view class="view-box">
<!-- value="请添加地址" bind:click="clickBuyerFun" -->
<van-cell border="{{ false }}" title="配送信息" />
<van-field
label="配送方式"
left-icon="setting-o"
center
>
<van-radio-group slot="input" value="{{ radioVak }}" bind:change="onChange" direction="horizontal">
<van-radio name="10">送货</van-radio>
<van-radio name="20">自提</van-radio>
</van-radio-group>
</van-field>
<van-field label="{{labName}}" readonly model:value="{{ SendTimeVal }}" placeholder="请选择" border="{{ false }}" left-icon="clock-o" right-icon="arrow" bind:click-input="clickTimeFun" bind:click-icon="clickTimeFun" />
<van-cell
wx:if="{{radioVak=='10'}}"
bind:click="clickBuyerFun"
center
is-link
border="{{ false }}"
icon="location-o"
title="{{customerObjPersonName}} {{customerObjPhone}}"
size="large"
label="{{customerAddress}} "
/>
<!-- customerObjProvince -->
<van-cell
wx:if="{{radioVak=='20'}}"
center
is-link
border="{{ false }}"
icon="location-o"
title="{{SellerInfo.eiContact}} {{SellerInfo.eiAdminMobile}}"
size="large"
label="{{SellerInfo.eiProvinceName}} {{SellerInfo.eiCityName}} {{SellerInfo.eiAreaName}} {{SellerInfo.eiAddress}}"
/>
</view>
<view class="view-box goods-box">
<van-cell border="{{ false }}" title="商品信息" value="{{editVal}}" bind:click="clickGoChose" is-link />
<view class=" pad-box">
<view class="selgoods-list" wx:for="{{OrdersGoods}}" wx:for-item="item" data-each="{{item}}" wx:key="key" >
<view class="view-goods">
<view class="goods-left">
<van-image width="80" height="80" src="{{item.piImageUrl}}" />
</view>
<view class="goods-right">
<view class="img-name">{{item.piProductName}}</view>
<view class="prod-des">{{item.ProductDes}}</view>
<view class="one-line">
<view class="unit-text"></view>
<view class="unit-price">
<!-- <view class="unit-Mul">×</view> -->
<van-stepper
min=""
value="{{ item.SelNum }}"
data-item-index="{{index}}"
bind:blur="ChangeNum"
plus-class="plusnone"
input-width="50px"
minus-class="minusnone"
/>
<view class="price-text">{{item.piSpec}}</view>
</view>
</view>
<!-- <view class="item-subotal">小计:¥{{item.subTotal}}</view> -->
</view>
</view>
<view class="goods-del">
<!-- <van-field value="{{ item.itemRemarks }}" bind:change="markChange" data-value="itemRemarks" ></van-field> -->
<van-field value="{{ item.itemRemarks }}" placeholder="可以输入商品备注" bind:change="markChange" data-item-index="{{index}}"/>
<van-button plain bind:click="DelItem" size="mini" data-item-index="{{index}}" type="warning">删除</van-button>
</view>
</view>
</view>
</view>
<view class="goods-total">
<!-- <view class="goods-count">
<view class="total-text">商品总价</view>
<view class="total-text">¥{{TotalPriceVal}}</view>
</view> -->
<van-field model:value="{{ orderRemarks }}" placeholder="订单备注"/>
</view>
<!-- 配送时间弹出 -->
<van-popup
custom-class="popup-main"
round
custom-style="height: 50%;"
position="bottom"
show="{{ showTime }}"
bind:close="TimeClose"
>
<van-datetime-picker
type="date"
value="{{ vanDateTimeVal }}"
min-date="{{ minDate }}"
formatter="{{ formatter }}"
bind:confirm="timeConfirm"
bind:cancel="TimeClose"
/>
</van-popup>
<van-toast id="van-toast" />
<van-dialog id="van-dialog" />
</view>
<van-goods-action>
<van-goods-action-button text="返回" type="warning" bind:click="SubmitBack" />
<van-goods-action-button text="提交" color="#fa550f" bind:click="SubmitAddOrders" />
</van-goods-action>
// pages/addOrder/addOrder.js
import {requestAddOrder, requestDetailOrder,requestEditOrder} from '../../http/orderListApi'
import { getLocalUserInfo } from '../../unit/userInfo'
import Toast from '@vant/weapp/toast/toast';
import { centToYuan,yuanToCent } from '../../unit/priceUtil'
import { requestAddressList } from '../../http/addressApi'
import { goodsGroup, } from '../../http/goodsApi'
import Dialog from '@vant/weapp/dialog/dialog';
function FindPrice(item){
if(item.agreementUnitPrice){
return centToYuan(item.agreementUnitPrice);
}else if(item.customerUnitPrice){
return centToYuan(item.customerUnitPrice);
}else{
return centToYuan(item.latestSaleUnitPrice);
}
}
var dayjs = require('dayjs')
Page({
/**
* 页面的初始数据
*/
data: {
editVal:"",
isEdit:false,
SelfPickName:"",
SelfPickContact:"",
SelfPickAddress:"",
SellerInfo:{},
orderRemarks:"",
CustomerPopup:false,
CustomerData:[],
customerObjBusinessName:"",
customerObjPersonName:"",
customerAddress:"",
customerObjPhone:"",
customerObjProvince:"",
customerObjCity:"",
customerObjDistrict:"",
customerObjAddress:"",
orderSupplierId:"",
customerObjCode:"",
vanDateTimeVal: new Date().getTime(),
SendTimeVal:dayjs(new Date().getTime()).format('YYYY-MM-DD'),
OrdersGoods:[],
TotalPriceVal:0,
DetailOrderID:"",
radioVak:"10",
showTime:false,
labName:"配送日期",
formatter(type, value) {
if (type === 'year') {
return `${value}年`;
}
if (type === 'month') {
return `${value}月`;
}
return value;
},
minDate: new Date().getTime(),
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let that =this;
console.log(options)
if(JSON.stringify(options) == "{}"){
}else{
let detailInfo=JSON.parse(decodeURIComponent(options.detInfo));
console.log(detailInfo)
if(detailInfo.editStatus==true){
console.log("这是编辑")
if(detailInfo.basicInfo){
this.getDetails(detailInfo.basicInfo.ordId)
}else{
this.getDetails(detailInfo.ordId)
}
}else{
console.log("这是新增")
let newGoods= detailInfo.FromChoseGoods.map((item) => {
return {
...item,
standardPrice:FindPrice(item),
subTotal:Number((item.standardPrice) * item.SelNum).toFixed(2),
ProductDes:item.piSpec+'、'+item.piNetContent+item.piNetContentUnit+'/'+item.piSpec,
itemRemarks:""
};
});
this.setData({
SellerInfo:detailInfo.basicInfo,
OrdersGoods:newGoods,
orderSupplierId:detailInfo.basicInfo.eiId
})
// setTimeout(function () {
// that.RefreshGoods(that.data.SendTimeVal)
// },500);
this.totalPriceFun()
}
}
setTimeout(function () {
that.getAddressDataFun()
},500);
},
getDetails(DelItem){
requestDetailOrder(DelItem).then((res) => {
let resultData = res.data;
this.setData({
editVal:"选择商品",
isEdit:true,
orderSupplierId:resultData.ordSupplierId,
SellerInfo:{
eiName:resultData.ordSupplierName,
ordSupplierId:resultData.ordSupplierId,
eiLicenseNo:resultData.supplierEnterpriseInfo.eiLicenseNo,
eiContact:resultData.supplierEnterpriseInfo.eiContact,
eiAdminMobile:resultData.supplierEnterpriseInfo.eiAdminMobile,
eiContact:resultData.supplierEnterpriseInfo.eiContact,
eiProvinceName:resultData.supplierEnterpriseInfo.eiProvinceName,
eiCityName:resultData.supplierEnterpriseInfo.eiCityName,
eiAreaName:resultData.supplierEnterpriseInfo.eiAreaName,
eiAddress:resultData.supplierEnterpriseInfo.eiAddress,
},
DetailOrderID:resultData.ordId,
SendTimeVal:resultData.ordSupplyDate,
radioVak:resultData.orderSupplyType+"",
OrdersGoods:resultData.details.map((item) => {
return {
...item,
unitName:item.productUnit,
SelNum:item.productNum,
standardPrice:centToYuan(item.supplyPrice),
subTotal:(centToYuan(item.supplyPrice) * item.productNum).toFixed(2),
piImageUrl:item.productImage,
piSpec:item.productSpec,
piId:item.productId,
piProductName:item.productName,
ProductDes:item.productSpec+'、'+item.productNetContent+item.productNetContentUnit+'/'+item.productSpec
};
}),
})
this.detCustomerInfo(resultData)
console.log(this.data.OrdersGoods)
// this.RefreshGoods(this.data.SendTimeVal)
this.totalPriceFun()
})
},
clickGoChose(){
if(this.data.isEdit== false){
return
}
const newData = JSON.stringify(
{
basicInfo:{...this.data.SellerInfo,SendTimeVal:this.data.SendTimeVal},
SeledGoods:this.data.OrdersGoods,
editChose:true
}
);
wx.navigateTo({ url: `/pages/ChoseGoods/ChoseGoods?detInfo=`+ encodeURIComponent(newData) });
console.log("去选择商品")
},
detCustomerInfo(resultData){
console.log(resultData)
if(resultData.orderSupplyType==10){ //送货
this.setData({
customerObjPersonName:resultData.ordContactName,
customerObjPhone:resultData.ordContactPhone,
customerAddress:resultData.ordSupplyAddress,
})
}else{ //自提
this.setData({
SelfPickName:this.data.SupplierInfo.eiContact,
SelfPickContact:this.data.SupplierInfo.eiAdminMobile,
SelfPickAddress:this.data.SupplierInfo.eiProvinceName+
this.data.SupplierInfo.eiCityName+
this.data.SupplierInfo.eiAreaName+
this.data.SupplierInfo.eiProductionAddress,
})
}
},
onChange(event) {
console.log(event.detail)
if(event.detail=='20'){
this.setData({
labName:'自提时间',
});
}else{
this.setData({
labName:'配送日期',
});
}
this.setData({
radioVak: event.detail,
});
},
getAddressDataFun(){
var that =this;
requestAddressList().then((res) => {
var DefaultAddress={}
if(res.data.length>0){
res.data.map((item) => {
if(item.eaIsdefault==1){
DefaultAddress= item
}
});
this.setData({
customerObjPersonName:DefaultAddress.eaContact,
customerObjPhone:DefaultAddress.eaMobile,
customerObjProvince:DefaultAddress.eaProvinceName==null?"":DefaultAddress.eaProvinceName,
customerObjCity:DefaultAddress.eaCityName==null?"":DefaultAddress.eaCityName,
customerObjDistrict:DefaultAddress.eaAreaName==null?"":DefaultAddress.eaAreaName,
customerObjAddress:DefaultAddress.eaAddress==null?"":DefaultAddress.eaAddress,
})
this.setData({
customerAddress:this.data.customerObjProvince+this.data.customerObjCity+this.data.customerObjDistrict+this.data.customerObjAddress
})
}
setTimeout(function () {
that.RefreshGoods(that.data.SendTimeVal)
},10);
})
},
changeGoods(goodsList){
let OldGoods= this.data.OrdersGoods;
let NewGoods= goodsList;
function FindGoods(itemID,HasDataList){
let findData = HasDataList.find(x => x.productId == itemID.piId);
return findData
}
var BuildGoodsData=[]
function changePrice(item){
if(item.customerUnitPrice==null){
return centToYuan(item.latestSaleUnitPrice)
}else{
return centToYuan(item.customerUnitPrice)
}
}
NewGoods.map((item)=>{
if(FindGoods(item,OldGoods)){
BuildGoodsData.push(FindGoods(item,OldGoods))
}else{
BuildGoodsData.push(
{
...item,
productNum:item.SelNum,
productSpec:item.piSpec,
productName:item.piProductName,
productImage:item.piImageUrl,
productSpec:item.piSpec,
productId:item.piId,
supplyPrice:item.customerUnitPrice==null? centToYuan(item.latestSaleUnitPrice):centToYuan(item.customerUnitPrice),
subTotal:(changePrice(item) * item.SelNum).toFixed(2),
}
)
}
})
this.setData({
OrdersGoods:BuildGoodsData,
});
this.totalPriceFun()
},
clickTimeFun(){
this.setData({
showTime:true,
})
},
TimeClose(){
this.setData({
showTime:false,
})
},
RefreshGoods(supplyTime){
let postData={
enterpriseId:this.data.orderSupplierId,
supplyDate:supplyTime
}
goodsGroup(postData).then((res) => {
let newGoodsData =[]
res.data.map((item) => {
if(item.products){
item.products.map((each)=>{
newGoodsData.push(each)
})
}
});
function FindItem(itemVal,moreList){
let findData = moreList.find(x => x.piId == itemVal.piId);
return FindPrice(findData)
}
let newList = this.data.OrdersGoods.map((item)=>{
return {
...item,
standardPrice:FindItem(item,newGoodsData),
subTotal:((FindItem(item,newGoodsData)) * item.SelNum).toFixed(2),
};
})
console.log(newList)
this.setData({
OrdersGoods:newList
})
this.totalPriceFun();
})
},
// 时间确定zzzz
timeConfirm(val) {
let TimeVal = dayjs(val.detail).format('YYYY-MM-DD');
this.setData({
SendTimeVal:TimeVal,
showTime:false,
})
this.RefreshGoods(TimeVal)
},
changeDefaultAddress(itemObj){
console.log(itemObj)
this.setData({
customerObjPersonName:itemObj.eaContact,
customerObjPhone:itemObj.eaMobile,
customerObjProvince:itemObj.eaProvinceName==null?"":itemObj.eaProvinceName,
customerObjCity:itemObj.eaCityName==null?"":itemObj.eaCityName,
customerObjDistrict:itemObj.eaAreaName==null?"":itemObj.eaAreaName,
customerObjAddress:itemObj.eaAddress==null?"":itemObj.eaAddress,
})
this.setData({
customerAddress:this.data.customerObjProvince+this.data.customerObjCity+this.data.customerObjDistrict+this.data.customerObjAddress
})
},
clickBuyerFun(){
wx.navigateTo({ url: `/pages/Addresslist/Addresslist` });
return
},
markChange(event) {
let indexNum = event.currentTarget.dataset.itemIndex;
this.data.OrdersGoods[indexNum].itemRemarks = event.detail;
this.setData({
OrdersGoods:this.data.OrdersGoods,
})
// console.log(e.currentTarget.dataset.value)
},
ChangeNum(event){
var that =this;
let indexNum = event.currentTarget.dataset.itemIndex;
this.data.OrdersGoods[indexNum].SelNum = event.detail.value;
this.data.OrdersGoods[indexNum].subTotal = (this.data.OrdersGoods[indexNum].standardPrice * this.data.OrdersGoods[indexNum].SelNum).toFixed(2);
that.setData({
OrdersGoods:that.data.OrdersGoods,
})
that.totalPriceFun();
},
DelItem(event){
let indexNum = event.currentTarget.dataset.itemIndex;
let that =this;
Dialog.confirm({
title: '提示',
message: '确定删除此商品吗',
})
.then(() => {
that.delEachOrder(indexNum)
})
.catch(() => {
// on cancel
});
},
delEachOrder(indexNum){
this.data.OrdersGoods.splice(indexNum, 1);
this.setData({
OrdersGoods:this.data.OrdersGoods,
})
console.log(indexNum)
this.totalPriceFun()
},
totalPriceFun () {
console.log(this.data.OrdersGoods)
var sum1 = 0;
for (var i in this.data.OrdersGoods) {
sum1 += this.data.OrdersGoods[i].standardPrice * this.data.OrdersGoods[i].SelNum;
}
this.setData({
TotalPriceVal:sum1.toFixed(2),
});
},
onReady() {
},
loadCustomerFun(){
},
SubmitAddOrders(){
if(this.data.SendTimeVal==""){
wx.showToast({
icon: 'none',
title: "配送日期不可为空",
})
return
}
console.log(this.data.OrdersGoods)
console.log(this.data.SellerInfo)
let SupplierData= this.data.SellerInfo;
let SupplierInfo={
ordSupplierId:this.data.orderSupplierId,
ordSupplierName:SupplierData.eiName,
}
console.log(getLocalUserInfo().current)
let EnterpriseData= getLocalUserInfo().current;
let EnterpriseInfo={
enterpriseId:EnterpriseData.enterpriseInfo.eiId,
enterpriseName:EnterpriseData.enterpriseInfo.eiName,
}
let BuyerInfo={};
if(this.data.radioVak=='10'){
BuyerInfo={
ordContactName:this.data.customerObjPersonName,
ordContactPhone:this.data.customerObjPhone,
ordSupplyDate:this.data.SendTimeVal,
ordSupplyAddress:this.data.customerAddress,
}
}else{
BuyerInfo={
ordContactName:this.data.SellerInfo.eiContact,
ordContactPhone:this.data.SellerInfo.eiAdminMobile,
ordSupplyDate:this.data.SendTimeVal,
ordSupplyAddress:this.data.SellerInfo.eiProvinceName+
this.data.SellerInfo.eiCityName+
this.data.SellerInfo.eiAreaName+
this.data.SellerInfo.eiAddress,
}
}
console.log(this.data.OrdersGoods)
for (var i = 0; i < this.data.OrdersGoods.length; i++) {
if(!this.data.OrdersGoods[i].SelNum || this.data.OrdersGoods[i].SelNum == 0){
wx.showToast({
icon: 'none',
title: "商品数量必须大于0",
})
return;
}
}
let postOrders= this.data.OrdersGoods.map((item) => {
return {
productNum:item.SelNum,
productId:item.piId,
dtlRemark:item.itemRemarks,
supplyPrice:yuanToCent(item.standardPrice),
};
});
let postdata={
...SupplierInfo,
...EnterpriseInfo,
...BuyerInfo,
details:postOrders,
orderSupplyType:this.data.radioVak,
ordRemark:this.data.orderRemarks
}
console.log(postdata)
console.log("新增")
if(this.data.DetailOrderID){
console.log({...postdata,ordId:this.data.DetailOrderID})
requestEditOrder({...postdata,ordId:this.data.DetailOrderID}).then((res) => {
Toast.success('编辑成功');
setTimeout(function () {
wx.navigateBack({ delta: 1 });
}, 1000);
})
}else{
requestAddOrder(postdata,).then((res) => {
Toast.success('新增成功');
setTimeout(function () {
const newData = JSON.stringify({
ordSupplierId:res.data.ordSupplierId
});
wx.redirectTo({url: '/pages/successful/successful?succeedInfo='+ encodeURIComponent(newData),});
}, 1000);
})
}
},
SubmitBack() {
wx.navigateBack({ delta: 1 });
},
onShow() {
this.loadCustomerFun()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
网友评论