myfeedback_duihuan.js 3.5 KB
    const app = getApp()

    Page({
        data: {
            datalist: '',
            goodsInfo: {},
            count: 1,
            remark:''
        },


        onLoad: function (options) {
            this.setData({
                id: options.id
            })
            this.setData({
                goodsInfo: wx.getStorageSync('goodsInfo')
            })
        },
        onReady: function () {

        },
        onShow: function () {
            let that = this;
            let tempAdress = wx.getStorageSync('tempAdress');
            if (tempAdress) {
                this.setData({
                    datalist: tempAdress
                })
            } else {
                that.getaddress()
            }

        },

        getchooseaddress() {
            wx.navigateTo({
                url: '/pages/myaddress/myaddress',
            })

        },
        // 地址
        getaddress() {
            let that = this;
            let url = '/index/second/getDefaultAddress';
            let head = {
                'XX-Token': wx.getStorageSync('token')
            }
            app.post(url, {}, head).then((res) => {
                console.log(res)


                that.setData({
                    datalist: res
                })


            }).catch((err) => {

            })
        },


        // 兑换
        getdatalist() {
            let that = this;
            let url = '/index/second/commitOrder';
            let head = {
                'XX-Token': wx.getStorageSync('token')
            }
            if(that.data.datalist==null){
                wx.showToast({
                  title: '请选择收货地址',
                  icon:'none'
                })
                return;
            }
            app.post(url, {
                good_id: that.data.goodsInfo.id,
                num: that.data.count,
                address_id: that.data.datalist.id,
                remark:that.data.remark
            }, head).then((res) => {
                console.log(res)
                wx.showToast({
                    title: '兑换成功',
                })
                setTimeout(function () {
                    wx.navigateTo({
                      url: '/pages/myfeedback/myfeedback_list/myfeedback_list'
                    })
                  }, 1000)



            }).catch((err) => {

            })
        },
        bindNum(e) {
            let type = e.currentTarget.dataset.type;
            // console.log(type)
            // console.log(e)
            type == 'minus' ?
                this.setData({
                    count: this.data.count == 1 ? 1 : this.data.count-1
                }) :
                this.setData({
                    count: this.data.count + 1
                })
        },
        // 备注
        bindremark(e) {
            // console.log(e.detail.value)
            this.setData({
                remark:e.detail.value
            })
        },

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

        },

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

        },

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

        },

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

        },

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

        }
    })