statements.js 6.22 KB
import api from '../../common/api.js';
import {formatImageUrl} from '../../utils/util';
import {parseComputeData} from '../../utils/statementsUtil';
import { aliPay } from '../../utils/payUtil';

const FROM_PRODUCT_DETAIL = "productdetail";
const FROM_SHOPPING_CART = "shopcart"

Page({
    data: {
        // payment: {},
        isDisplaydeliveryWay: false,
        isShowAddNewAddress: false,
        invoicesItem: {
            id: "invoices",
            title: "发票",
            subtitle: "",
            isChecked: false,
            isShowHelp: false,
        },
        submitparam: {
            address_id: 'nIwE1fqIniAyb+HmGedV4g==',//送货地址id
            coupon_code: '',//优惠券code,多个用","分割
            delivery_time: 0,//寄送时间类型
            delivery_way: 1,//发货方式(1:普通, 2顺丰)
            payment_id:15,//支付id 默认支付宝
            payment_type:1,//支付方式,1 在线支付 2 货到付款
            receiverMobile:'15950485925',
            sale_channel:1,
            use_red_envelopes: 0,//使用的红包,单位元
            use_red_package: 0,//使用的红包,单位元
            use_yoho_coin: 0,//使用的yoho币金额,单位元

            // method: 'app.Buynow.submit',
            // product_sku:'474098',
            // sku_type: 'I',
            // buy_number: 1,
            uid: '600033236',
            // invoice_content: 12,
            // invoices_title: '个人',
            // invoices_type: 2,
            // buyerTaxNumber: '',
        }

    },
    onLoad: function (option) {
        if(option && option.fromPage){
            let fromPage = option.fromPage;
            this.data.fromPage = fromPage;
            if(fromPage === FROM_PRODUCT_DETAIL){
                this.data.submitparam.method = "app.Buynow.submit";
                this.data.submitparam.sku_type = "I";
                this.data.submitparam.buy_number = 1;
                // this.data.submitparam.product_sku="474098";
            }else if(fromPage === FROM_SHOPPING_CART ){
                this.data.submitparam.method = "app.Shopping.submit";
                this.data.submitparam.cart_type = "ordinary";
                this.data.submitparam.is_continue_buy = "N";
                this.data.submitparam.is_print_price = "N";
            }
        }
        let pages = getCurrentPages();
        let length =pages.length;
        let payment = {};
        if(length > 1){
            let lastPageData = pages[length - 2].data;
            this.setData({
                lastPageData,
            });
        }
        
        this.fechPaymentInfo();
    },
    onShow: function () {},
    fechPaymentInfo: function () {
        let that = this;
        let param = {
            buy_number:1,
            is_support_apple_pay:'N',
            method:'app.Buynow.enhancedPayment',
            open_red_package:true,
            product_sku:'1029813',
            sku_type:'I',
            uid:'600033236',
            yoho_coin_mode:0
        }
        api.get({data: param})
            .then(json=>{
            if(json && json.code == 200){
                let data =  json.data;
                if(data){
                    let resultData = parseComputeData(data,75,100);
                    let addressInfo = data.delivery_address;
                    if(addressInfo){
                        let addressId = resultData.delivery_address.address_id
                        that.data.submitparam.address_id = addressId;
                        that.data.isShowAddNewAddress = false;
                    }else {
                        that.data.isShowAddNewAddress = true;
                    }
                    if(that.data.fromPage === FROM_PRODUCT_DETAIL){
                        let productInfo = data.goods_list[0];
                        if(productInfo){
                            let productSku = productInfo.product_sku;
                            that.data.submitparam.product_sku = productSku;
                        }
                    }
                    
                    that.setData({
                        data:resultData,
                    })
                }
                
            }
        })
        

    },
    fechCompute: function (refreshParam) {
        let that = this;
        let goods_list = that.data.data.goods_list;
        let goodsInfo = that.data.data.goods_list[0];
        let params = {
            buy_number:goodsInfo.buy_number,
            cart_type:"ordinary",
            // coupon_code:
            // delivery_way:2,
            method:"app.Buynow.compute",
            open_red_package:false,
            payment_type:1,
            product_sku:goodsInfo.product_sku,
            sku_type:"I",
            uid:'600033236',
            yoho_coin_mode:0
        }
        let assignData = Object.assign(refreshParam, params);
        api.get({data: assignData})
            .then(json=>{
            if(json && json.code == 200){
                let data =  json.data;
                let resultData = parseComputeData(data,75,100);
                // data.delivery_way = this.parseDelivery(data.delivery_way);
                let oldData = that.data.data;
                let result = Object.assign(oldData, data);
                that.setData({
                    data:result,
                })
            }
        })
    },
    refreshCompute: function (e) {
        let selectParam = e.detail.params;
        this.fechCompute(selectParam);
    },
    onChangeSwitch: function (e) {
        let isChecked = e.detail.isChecked;
        this.data.invoicesItem.isChecked = isChecked;
    },
    addNewAddress: function () {
        //新增收货地址,跳转到新增页面
    },
    navigateToInvoice: function () {
        tt.navigateTo({
            url: 'pages/invoice/invoceDetail',
            success (res) {
                console.log(`${res}`);
            },
            fail (res) {
                console.log(`navigateTo调用失败`);
            }
        });
    },
    submit: function () {
        debugger
        let params = this.data.submitparam;
        api.get({data: params})
            .then(json=>{
            if(json && json.code == 200){
                let data =  json.data;
                aliPay(data);
                
            }
        })
    }
})