createOpinion.js 6.84 KB
// pages/pinglun/createOpinion.js
import util from '../../utils/util';
import App from '../../utils/api'
import RS from '../../utils/reserveStatus'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        options: {},
        filesHttps: [],
        dateSmart:'',
        tablesText:'',
        detail:{},
        tableNum:'',
        cusdem:'',
        coupon:'',
        couponId:'',
        price:'',
        coupon:'',
        is_user_comments:'',
        showLoading:false,
    },
    text: '',
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if(options){
            this.setData({
                options
            })
            console.log('options', {
                ...options
            });
            this.getDetail()
        }
    },
	getDetail() {
		App.Reserve.Detail({
			openid: getApp().openid,
			rid: this.data.options.oid
		}).then(res => {
			let tablesText = '', //桌子信息
				tableNum =0;
			res.data.tables.forEach((t,i) => {
				tableNum+=t.table_pnum*1
				tablesText+=t.rname+t.name+(i==(res.data.tables.length-1)?'':'、');
			})
            let reserev = RS.reserve(res.data)
			let dateSmart
			if (res.data.type == 1) {
				dateSmart = util.unixtoTime(reserev.ddate, 'YYYY/MM/DD 星期WW')
				if (res.data.is_set_ddate == 1) {
					dateSmart += ' ' + util.unixtoTime(reserev.ddate, 'YYYY/MM/DD 星期WW')
				} else {
					dateSmart += ' ' + reserev.soltName
				}
			} else {
				dateSmart = util.unixtoTime(reserev.ddate, 'YYYY/MM/DD 星期WW HH:II')
            }
			this.setData({
                dateSmart,
                tablesText,
                is_user_comments:res.data.is_user_comments,
                tableNum:res.data.actual_pum?res.data.actual_pum:tableNum,
                cusdem:res.data.cusdem,
            })
			setTimeout(() => {
				this.getSellerTemplateConfFun(reserev.sid);
			}, 0);
		}).catch(res=>{
			console.log(res,'详情请求失败');
		})
	},
	getSellerTemplateConfFun(sid) {
		console.log('sidsidsidsid',sid);
		App.Seller.GetSellerTemplateConf({
			sid
		}).then(res => {
			let data=res.data
			let marketing,is_comments;
			marketing = util.determine(data.marketing);
			if(marketing){
                is_comments = marketing.is_comments?marketing.is_comments:'';
				marketing.coupon_data_comments=(is_comments=='1' && marketing.is_comments_coupon=='1')?util.determine(marketing.coupon_data_comments):'';
			}
            let coupon_data_comments=marketing.coupon_data_comments;//赠送优惠券的列表
            let coupon=(marketing && marketing.is_comments=='1' && marketing.is_comments_coupon=='1')?'1':'0';//评价赠送优惠券
            let couponId,price,use;
            if(coupon && coupon_data_comments && coupon_data_comments.length>0){
                let obj=coupon_data_comments[0];
                console.log('填写意见获取的券的信息',obj);
                couponId=obj.id;
                price=obj.price;
                use=JSON.stringify(obj.use)
            }
            this.setData({
                coupon:coupon || '',
                couponId:couponId || '',
                price:price || '',
                use:use || '',
            })
			this.setData({
				marketing,
			})
		}).catch(res=>{
			console.log('GetSellerTemplateConf请求失败');
		})
	},
    // 获取上传的图片或者视频
    tpupload(e) {
        this.setData({
            filesHttps: e.detail.filesHttps,
        })
    },
    textareaInput(e) {
        this.text = util.val(e).trim();
    },
    // 提交
    submit() {
        if (this.text == '') {
            return wx.showToast({
                icon: 'none',
                title: '请填写意见反馈!',
            })
        }
        if(this.data.is_user_comments){
            return wx.showToast({
                icon: 'none',
                title: '评价已提交!',
            })
        }
        this.setData({
            showLoading:true
        })
        let params = {
            sid: this.data.options.sellerid,
            rid: this.data.options.oid,
            author_openid: getApp().openid,
            enclosure: JSON.stringify(this.data.filesHttps),
            identity: 1,
            text: this.text,
            types: this.data.options.types, //types为1时  rid就是预订ID   types为2时   rid就是套餐ID  types为3时  rid就是卡券ID
            isnoshow: '1', //匿名评价 1 开 0 关
        }
        console.log({
            ...params
        });
        App.User.SetComment(params).then(res => {
            if (res.ret== 200 && res.data) {
                this.setData({
                    showLoading:false
                })
                let url = ''
                let options = this.data.options
                console.log('options',options);
                // 有券
                if (this.data.coupon == '1') {
                    url = util.http_build_query({
                        sellerName: options.sellerName,
                        coupon: this.data.coupon,
                        couponId: this.data.couponId,
                        price: this.data.price,
                        use: this.data.use,
                        oid: options.oid,
                        sellid: options.sellerid,
                    }, './opinionSuccess')
                } else { //没券
                    url = util.http_build_query({
                        sellerName: options.sellerName,
                        coupon: this.data.coupon, //1有券 2没有券
                        couponId: this.data.couponId || '',
                        sellid: options.sellerid,
                    }, './opinionSuccess')
                }
                wx.hideLoading()
                wx.redirectTo({
                    url
                })
            }else{
                this.setData({
                    showLoading:false
                })
                return wx.showToast({
                    icon: 'none',
                    title: res.msg,
                })
            }
        }).catch(e => {
            this.setData({
                showLoading:false
            })
            console.log('catch', e);
            wx.showToast({
                icon: 'none',
                title: e.msg,
            })
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

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

    },

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

    },

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

    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})