success_new.js 6.73 KB
// pack-cookbook/pages/success_new.js
import App from '../../utils/api';
import util from '../../utils/util';
Page({
    /**
     * 页面的初始数据
     */
    data: {
        cookbooklist: [],
        sellerName: '',
        sellerid: '',
        probablyPrice: '',
        vipProbablyPrice:'',
        discount: '',
        stringifyUse: '',
        priceInfo: '',
        scoreInfo: '',
        notes: '',
        marketing: {},
        recharge_data: {},
        coupon_data: {},
        dataStr: Date.now() * 1 / 1000,
        rid:'',
        oid:'',
        sellerDate:'',
        region:'',
        tableNum:'',
        soltName:'',
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        let obj = JSON.parse(wx.getStorageSync('cookbookObj'));
        let cookbooklist = JSON.parse(wx.getStorageSync('cookbooklist'));
        this.formatCookList(cookbooklist);
        this.setData({
            sellerName: obj.sellerName,
            sellerid: obj.sellerid,
            notes: obj.notes,
            rid:obj.rid,
            oid:obj.oid,
            sellerDate: obj.sellerDate,
            region: obj.region,
            tableNum: obj.tableNum,
            soltName:obj.soltName
        })
        console.log('obj',obj);
        this.getSellerTemplateConfFun()
    },
    formatCookList(cookbooklist){
        let probablyPrice = 0;
        let vipProbablyPrice = 0;
        let noData = false;
        cookbooklist.forEach(items => {
            items.is_show = false
            items.normsLen=0
            items.cookbooklist[0].forEach(item => {
                item.arr=[];//arr 点菜的菜品列表
                if (item.norms && item.norms.length>0) {
                    item.norms.forEach(i => {
                        let obj={
                            name:item.name,
                            practice:i.practice,
                            unit:i.unit,
                            price:i.price,
                            quantum:i.quantum,
                        }
                        item.arr.push(obj)
                        let price = i.quantum * 1 * (i.price * 1);
                        let vipPrice = i.quantum * 1 * (i.member_price * 1);
                        probablyPrice += price;
                        vipProbablyPrice += vipPrice;
                    })
                    noData = true
                    items.is_show = true;//展示不展示
                    items.normsLen+=item.arr.length;//菜品数量
                }
            })
        })
        // wx.setStorageSync('cookbooklist', JSON.stringify(this.data.cookbooklist))
        this.setData({
            cookbooklist,
            probablyPrice,
            vipProbablyPrice,
            noData
        })
    },
    // 菜品更换
    continueOrdering(){
        wx.reLaunch({
          url: `/pack-cookbook/pages/index_new?rid=${this.data.rid}&sid=${this.data.sellerid}&oid=${this.data.oid}&sellerName=${this.data.sellerName}&identity=1`,
        })
    },
    // 点击了解更多会员优惠政策
    gotoFavourableList(){
        let url=util.http_build_query({
            sellerName:this.data.sellerName,
            sellerid:this.data.sellerid,
            oid:this.data.oid,
            types:'2',
        },'/pack-cookbook/pages/favourableList')
        console.log(url);
        wx.navigateTo({
          url
        })
    },
    getSellerTemplateConfFun(sid) {
        console.log(sid, 'sidsidsidsid');
        App.Seller.GetSellerTemplateConf({
            sid: this.data.sellerid
        }).then(res => {
            let data = res.data
            let marketing, coupon_data, priceInfo, scoreInfo, recharge_list, stringifyUse;
            marketing = data.marketing ? JSON.parse(data.marketing) : '';
            console.log('marketing', marketing);
            if (marketing.coupon_data) {
                coupon_data = marketing.coupon_data;
                stringifyUse = JSON.stringify(marketing.coupon_data.use)
            }
            console.log('coupon_data', coupon_data);
            console.log('stringifyUse', stringifyUse);
            if (marketing.is_recharge == '1' && marketing.recharge_data) {
                let recharge_data = marketing.recharge_data
                recharge_list = marketing.recharge_data.recharge_list
                if (recharge_list.is_price == '1') priceInfo = '会员充值满' + recharge_data.recharge_money + '元赠送' + recharge_list.price + '元余额';
                if (recharge_list.is_score == '1') scoreInfo = '会员充值满' + recharge_data.recharge_money + '元赠送' + recharge_list.score + '积分';
                console.log('scoreInfo', scoreInfo);
                console.log('priceInfo', priceInfo);
                this.setData({
                    recharge_data: marketing.recharge_data
                })
                console.log('recharge_data', recharge_data);
            }
            this.setData({
                coupon_data,
                stringifyUse
            })
            // is_cash 代金券  is_discount折扣券  is_dish菜品券 只有代金券有几折显示
            if (marketing.is_coupon == '1' && coupon_data && (!coupon_data.use.is_cash || coupon_data.use.is_cash == '1')) {
                let cash = coupon_data.use.cash;
                let price = coupon_data.price * 1;
                let discount = ((price / cash) * 10).toFixed(2);
                this.setData({
                    discount
                })
            }
            this.setData({
                marketing,
                priceInfo,
                scoreInfo
            })
        }).catch(res => {
            console.log('GetSellerTemplateConf请求失败');
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        let options={
            sid:this.data.sellerid,
            rid:this.data.rid,
            oid:this.data.oid,
            identity:'1',
            hasOnlyShow:'1'
        };
        return {
        title:'菜品已点好,快来看看都点了什么~',
        path:util.http_build_query(options,'/pack-cookbook/pages/success_new'),
        imageUrl:'http://nosqn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148571.jpg',
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },
})