Authored by 郝肖肖

'普通结算页'

... ... @@ -41,5 +41,47 @@ export default {
method: 'app.Buynow.submit'
}, params)
});
},
/**
* [1、普通结算Payment]
* @param {[type]} params [{}]
* @return {[type]} [{}]
*/
shoppingPayment(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.payment'
}, params)
});
},
/**
* [2、普通结算Compute]
* @param {[type]} params [{}]
* @return {[type]} [{}]
*/
shoppingCompute(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.compute'
}, params)
});
},
/**
* [3、普通结算Submit]
* @param {[type]} params [{}]
* @return {[type]} [{}]
*/
shoppingSubmit(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.submit'
}, params)
});
}
};
... ...
... ... @@ -11,10 +11,10 @@ const PAYMENT = { // 支付类型
TYPE: 1,
};
const ORDER_TYPE = { // 结算订单类型
BUYNOW: 'buynow'
BUYNOW: 'buynow',
ORDINARY: 'ordinary'
};
const router = global.router;
const app = getApp();
let yas;
... ... @@ -27,8 +27,11 @@ function formatPaymentData(data, yasInfo) {
deliveryWayList: data.delivery_way || [],
deliveryTimeList: data.delivery_time || [],
promotionList: data.shopping_cart_data.promotion_formula_list,
paymentAmount: data.shopping_cart_data.last_order_amount
paymentAmount: data.shopping_cart_data.last_order_amount,
isJit: false,
package_title_detail: ''
};
let supplierId = 0;
yasInfo = yasInfo || {};
... ... @@ -41,9 +44,99 @@ function formatPaymentData(data, yasInfo) {
yasInfo.skus && yasInfo.skus.push(value.product_sku);
yasInfo.pids && yasInfo.pids.push(value.product_id);
if (!info.isJit && value.is_jit === 'Y') {
supplierId = value.supplier_id;
info.isJit = true;
}
return value;
});
(data.shopping_cart_data && data.shopping_cart_data.package_list || []).some(item => {
info.package_title_detail = item.title || '';
return item === supplierId;
});
let selectWay,
selectTime;
if (info.deliveryWayList.length) {
info.deliveryWayList.map(value => {
if (value.default === 'Y') {
value.checked = true;
selectWay = value;
}
});
if (!selectWay) {
selectWay = info.deliveryWayList[0];
info.deliveryWayList[0].checked = true;
}
info.deliveryWayId = selectWay.delivery_way_id;
info.deliveryWayText = `${selectWay.delivery_way_name}:运费¥${selectWay.delivery_way_cost}`;
}
if (info.deliveryTimeList.length) {
info.deliveryTimeList.map(value => {
if (value.default === 'Y') {
value.checked = true;
selectTime = value;
}
});
if (!selectTime) {
selectTime = info.deliveryTimeList[0];
info.deliveryTimeList[0].checked = true;
}
info.deliveryTimeId = selectTime.delivery_time_id;
info.deliveryTimeText = selectTime.delivery_time_string || '';
}
return info;
}
// 普通结算-数据格式化
function formatShoppingPaymentData(data, yasInfo) {
data = data || {};
let info = {
choosedAddress: data.delivery_address || '',
goodsList: data.goods_list || [],
deliveryWayList: data.delivery_way || [],
deliveryTimeList: data.delivery_time || [],
promotionList: data.shopping_cart_data.promotion_formula_list,
paymentAmount: data.shopping_cart_data.last_order_amount,
isJit: false,
package_title_detail: ''
};
let supplierId = 0;
yasInfo = yasInfo || {};
info.goodsList.map(value => {
if (value.goods_type === 'gift' || value.goods_type === 'price_gift') {
value.sales_price = value.last_price;
}
yasInfo.skns && yasInfo.skns.push(value.product_skn);
yasInfo.skus && yasInfo.skus.push(value.product_sku);
yasInfo.pids && yasInfo.pids.push(value.product_id);
if (!info.isJit && value.is_jit === 'Y') {
supplierId = value.supplier_id;
info.isJit = true;
}
return value;
});
(data.shopping_cart_data && data.shopping_cart_data.package_list || []).some(item => {
info.package_title_detail = item.title || '';
return item === supplierId;
});
let selectWay,
selectTime;
... ... @@ -99,7 +192,10 @@ Page({
invoiceNeedStatus: false,
promotionList: [],
paymentAmount: ''
paymentAmount: '',
isJit: false,
package_title_detail: ''
},
onLoad(options) {
this.orderData = options;
... ... @@ -108,11 +204,69 @@ Page({
skus: [],
pids: []
};
this.loadEnsurePayment({buyNumber: this.orderData.buyNumber, productSku: this.orderData.productSku});
// 立即购买
if (this.orderData.productSku) {
this.loadEnsurePayment({buyNumber: this.orderData.buyNumber, productSku: this.orderData.productSku});
} else {
this.loadShoppingPayment(options);
}
yas = new Yas(app);
yas.pageOpenReport();
},
_showModal(message) {
return wx.showModal({
content: message || '网络异常,请稍后重试',
showCancel: false,
confirmText: '好的',
});
},
// 普通购买
loadShoppingPayment(options) {
this.orderType = ORDER_TYPE.ORDINARY;
return ensureModel.shoppingPayment({
cart_type: options.cartType || 'ordinary',
yoho_coin_mode: 0
}).then(res => {
if (res.code !== 200) {
return this._showModal(res.message);
}
let data = formatShoppingPaymentData(res.data, this.yasInfo);
this.setData(data);
}).catch(() => {
this._showModal();
});
},
shoppingCompute(data) {
if (typeof data === 'object') {
Object.assign(this.orderData, data);
}
return ensureModel.shoppingCompute({
cart_type: 'ordinary',
payment_type: 1, // 支付方式,1 在线支付 2 货到付款
delivery_way: this.orderData.deliveryWayId, // 快递方式,1 普通 2 加急
use_yoho_coin: 0, // 使用的yoho币金额,单位元1:00
use_red_envelopes: 0, // 使用的红包,单位元
coupon_code: '', // 优惠券code,多个用","分割
promotion_code: '', // 优惠码code
gift_card_code: '', // 礼品卡code
}).then(res => {
if (res.code === 200) {
let comp = res.data || {};
this.setData({
promotionList: comp.promotion_formula_list,
paymentAmount: comp.last_order_amount
});
}
});
},
loadEnsurePayment(options) {
if (options.productSku) {
this.orderType = ORDER_TYPE.BUYNOW;
... ... @@ -171,7 +325,6 @@ Page({
this.setData({
promotionList: comp.promotion_formula_list,
paymentAmount: comp.last_order_amount
});
}
});
... ... @@ -184,7 +337,7 @@ Page({
});
},
chooseAddress() {
router.go('address', {
global.router.go('address', {
type: 'select',
id: this.data.choosedAddress.address_id
});
... ... @@ -193,7 +346,7 @@ Page({
this.setData({choosedAddress: address});
},
enterAddress() {
router.go('address', {type: 'add'});
global.router.go('address', {type: 'add'});
},
chooseWechatAddress() {
wechatAddressUtil.choose(res => {
... ... @@ -224,7 +377,12 @@ Page({
});
}
this.buynowCompute({deliveryWayId: id});
if (this.orderData.productSku) {
this.buynowCompute({deliveryWayId: id});
} else {
this.shoppingCompute({deliveryWayId: id});
}
this.setData({
deliveryWayText: name,
deliveryWayEditStatus: false,
... ... @@ -280,8 +438,7 @@ Page({
console.log('invoice info setStorageSync error');
}
router.go('cartInvoice', {skey: skey});
global.router.go('cartInvoice', {skey: skey});
},
changeInvoiceCallback(invoice) {
if (!invoice.invoiceCompany && !invoice.invoiceTitle) {
... ... @@ -299,6 +456,7 @@ Page({
this.buynowOrderSubmit();
} else {
// 普通购物车下单
this.shoppingSubmit();
}
},
buynowOrderSubmit() {
... ... @@ -363,7 +521,6 @@ Page({
ORDER_TYPE: 102 // 101购物车下单,102立即购买下单
});
// 上报formID
commonModel.addWechatFormId({
order_code: data.order_code,
... ... @@ -384,5 +541,87 @@ Page({
}).catch(() => {
this.orderSubmiting = false;
});
},
shoppingSubmit() {
if (this.orderSubmiting) {
return;
}
let param = {
payment_id: PAYMENT.ID,
payment_type: PAYMENT.TYPE,
use_red_envelopes: 0, // 使用的红包,单位元
use_yoho_coin: 0, // 使用的yoho币金额,单位元
coupon_code: '', // 优惠券code,多个用","分割
is_print_price: 'N', // string 否 "Y" "N" 是否打印
is_continue_buy: 'N', // string 否 "N" "Y" 是否继续结算
gift_card_code: '', // 礼品卡code
qhy_union: JSON.stringify({client_id: app.getUnionType()})
};
if (this.orderData.deliveryWayId) {
param.delivery_way = this.orderData.deliveryWayId;
}
if (this.orderData.deliveryTimeId) {
param.delivery_time = this.orderData.deliveryTimeId;
}
if (this.data.choosedAddress && this.data.choosedAddress.address_id) {
param.address_id = this.data.choosedAddress.address_id;
} else {
return this.showToast('请选择收件地址');
}
if (this.data.invoiceNeedStatus) {
let invoiceInfo = this.data.invoiceInfo;
Object.assign(param, {
invoices_title: invoiceInfo.invoiceTitleShow,
invoices_type: invoiceInfo.invoiceType,
invoice_content: invoiceInfo.invoiceContent,
buyerTaxNumber: invoiceInfo.taxNumber,
invoice_payable_type: invoiceInfo.invoiceCompany ? 2 : 1,
receiverMobile: invoiceInfo.receiver
});
}
if (+param.invoices_type === 2 && !param.receiverMobile) {
return this.showToast('请填写电子发票接收手机号');
}
this.orderSubmiting = true;
return ensureModel.shoppingSubmit(param).then(res => {
this.orderSubmiting = false;
if (res.code !== 200) {
return this._showModal(res.message);
}
let data = res.data;
// yas上报
yas.report('YB_SC_ORD', {
ORD_NUM: data.order_code + '',
PRD_SKN: this.yasInfo.skns.join(','),
RPD_SKU: this.yasInfo.skus.join(','),
PRD_ID: this.yasInfo.pids.join(','),
ORDER_TYPE: 101 // 101购物车下单,102立即购买下单
});
// 上报formID
commonModel.addWechatFormId({
order_code: data.order_code,
openId: app.getOpenID(),
miniapp_type: app.getMiniappType(),
formId: this.formId
});
data.needJump = true;
wechatPay(data);
}).catch(() => {
this.orderSubmiting = false;
});
}
});
... ...
... ... @@ -5,6 +5,10 @@
<address-card address="{{choosedAddress}}" bind:chooseAddress="chooseAddress" bind:addAddressByLocal="enterAddress" bind:addAddressByWechat="chooseWechatAddress"></address-card>
</view>
<view class="split-line"></view>
<view class="tip" wx:if="{{isJit && package_title_detail}}">
<text class="tip-text">{{package_title_detail}}</text>
</view>
<view class="split-line"></view>
<view class="goods-list">
<block wx:if="{{goodsList.length}}">
<order-item wx:for="{{goodsList}}" wx:key="unique" item="{{item}}" index="{{index}}"></order-item>
... ... @@ -21,7 +25,7 @@
</view>
</view>
<view wx:if="{{deliveryWayEditStatus}}" class="edit-wrap delivery-way-wrap">
<view wx:for="{{deliveryWayList}}" wx:key="{{index}}" class="edit-item delivery-way-item" data-id="{{item.delivery_way_id}}" data-name="{{item.delivery_way_name}}:运费¥{{item.delivery_way_cost}}" bindtap="changeDeliveryWay">
<view wx:for="{{deliveryWayList}}" wx:key="{{index}}" class="edit-item delivery-way-item" data-id="{{item.delivery_way_id}}" data-name="{{item.delivery_way_name}}:运费¥{{item.delivery_way_cost}}" bindtap="changeDeliveryWay" wx:if="{{item.is_support === 'Y'}}">
<text class="left-name">{{item.delivery_way_name}}: 运费¥{{item.delivery_way_cost}}</text>
<text class="iconfont {{item.checked ? 'icon-round-checked' : 'icon-round'}}"></text>
</view>
... ...
page { /* stylelint-disable-line */
/* stylelint-disable-next-line */
page {
background-color: #f0f0f0;
}
... ... @@ -24,6 +25,22 @@ page { /* stylelint-disable-line */
height: 20rpx;
}
.container .tip {
width: 100%;
height: 60rpx;
background-color: white;
display: flex;
align-items: center;
}
.container .tip .tip-text {
color: #444;
font-size: 30rpx;
background-color: white;
text-overflow: ellipsis;
margin-left: 5%;
}
.goods-list {
padding-left: 30rpx;
background-color: #fff;
... ...