detail_customer.js 3.34 KB
// pages/customer/detail_owner.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({

    /**
     * 页面的初始数据
     */
    data: {
        detail:null,
        invite_name:''
    },
    id:null,
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.id=options.id;
        let invite_names=wx.getStorageSync('invite_names') ||{};
        let invite_name=invite_names[options.id];
        if(invite_name){
            this.setData({
                invite_name:invite_name
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getDetail();
    },

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

    },

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

    },

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

    },
    getDetail(fouce=false){
        App.Reserve.Detail({
            openid: getApp().openid,
            rid: this.id
        },fouce).then(res => {
            this.setData({
                detail:this.formatDatail(res.data)
            })
        })
    },
    formatDatail(detail){
        detail.rdateStr=util.unixtoTime(detail.rdate,'MM月DD日 WW HH:II');
        detail.tableFirst=detail.tables[0].name;
        if(detail.tables.length>1){
            detail.tableSubInfo='等'+(detail.tables.length)+'个'
                +(detail.tables[0].tid==2?'包间':'');
        }
        // if(!detail.cusman){
        //     detail.cusman='vking';
        //     detail.cusman_phone='15877556369';
        //     detail.cusman_account='wx:vking';
        // }
        detail.hasCanSuccess=false;
        if(detail.customers.length>0){
            let openid=getApp().openid;
            detail.customers.forEach(item=>{
                if(openid==item.openid){
                    detail.hasCanSuccess=true;
                    return true;
                }
            })
        }
        return detail;
    },
    showManager(){
        if(this.data.detail.cusman_phone || this.data.detail.cusman_account){
            this.selectComponent('#manager').show();
        }

    },
    lookLocation:function(){
        wx.openLocation({
            latitude:Number(this.data.detail.seller.lat),
            longitude:Number(this.data.detail.seller.long),
            scale:17,
            address:this.data.detail.seller.map_address,
            success:function (res) {
                console.log(res)
            }
        })
    },
    userinfo(){
        if(!this.data.detail.hasCanSuccess){
            App.Reserve.SetRelaSuccess({
                rid:this.id,
                openid:getApp().openid
            }).then(res=>{
                this.getDetail(true);
            })
        }else{
            wx.navigateTo({
                url:'invite?id='+this.id,
            });
        }
    },
    reserveCancel(){
        App.Reserve.SetRelaSuccess({
            rid:this.id,
            openid:getApp().openid,
            cancel:'cancel'
        }).then(res=>{
            this.getDetail(true);
        })
    }
})