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

    /**
     * 页面的初始数据
     */
    data: {
        detail:null,
        invite_name:''
    },
    id:null,
  tpls:TP.tpls(),
    /**
     * 生命周期函数--监听页面加载
     */
    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(getCurrentPages().length==1);
    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return this.shareSetting();
    },
    getDetail(fouce=false){
        App.Reserve.Detail({
            openid: getApp().openid,
            rid: this.id
        },fouce).then(res => {
          let reserev=RS.reserve(res.data)
            this.setData({
                detail:this.formatDatail(reserev)
            })
        })
    },
    formatDatail(detail){
        detail.rdateStr=util.unixtoTime(detail.ddate,'MM月DD日 WW HH:II');
        // 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;
                    detail.remindtime=item.remind_date;
                    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){
            let userInfo=util.cache('userInfo');
            if(userInfo){
              userInfo=JSON.stringify({
                openid: getApp().openid,
                avatar: userInfo.avatarUrl,
                nickname: userInfo.nickName,
                gender: userInfo.gender
              })
            }
            App.Reserve.SetRelaSuccess({
                rid:this.id,
                openid:getApp().openid,
                is_agree:1,
                userinfo:userInfo
            }).then(res=>{
              App.Reserve.Detail({
                openid: getApp().openid,
                rid: this.id
              },'clear')
                wx.navigateTo({
                    //id={{detail.id}}&rdate={{detail.rdate}}
                    url:'remind?id='+this.id+'&ddate='+this.data.detail.ddate,
                });
            })
        }else{
            // wx.navigateTo({
            //     url:'invite?id='+this.id,
            // });
        }
    },
    reserveCancel(){
      let userInfo = util.cache('userInfo');
      if (userInfo) {
        userInfo = JSON.stringify({
          openid: getApp().openid,
          avatar: userInfo.avatarUrl,
          nickname: userInfo.nickName,
          gender: userInfo.gender
        })
      }
      App.Reserve.SetRelaSuccess({
        rid: this.id,
        openid: getApp().openid,
        cancel: 'cancel',
        is_agree: 0,
        userinfo: userInfo
      }).then(res => {
        this.getDetail(true);
      })
    },
    shareSetting(){
        console.log('this.topicVal',this.topicVal)
        if(this.topicVal && this.data.detail.openid==getApp().openid){
            App.Reserve.SetTopicFromShare({
                rid:this.id,
                topic:this.topicVal
            })
        }
        let nickname="";
        try{
            nickname=util.cache('userInfo').nickName;
        }catch(e){}
        return {
            //title: (nickname||'')+'给你发了一个邀请,点击查看',
            title: this.tpls[0].shareTitle,
            path: '/pages/customer/index?id='+this.id+'&fromid='+getApp().openid+'&invite_name='+nickname+'&hasInvitation=1&tplid=1',
            imageUrl:this.tpls[0].shareImage,
        }
    }
})