// pages/home/xyc/wdyw/wdyw.js
const app = getApp();//新建页面时 默认引入
const req = app.xzjlReq();//初始化一个的request() 实例
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showDelDialog:false,
        detail:{},
        visible:false,
        shareVisible:false, //分享弹层
        rrs:[{"lastModifiedDate":"2023-03-29T14:49:58.000+08:00","createdAt":"2023-03-14T15:44:16.000+08:00","id":1,"userid":1,"link":"http://www.baidu.com","img":"http://oss.wish.ydxxkj.top/resource/24130a65-ec5e-4c48-86d1-e964859f8532-1680072583657.jpg","content":"我希望明年去富士山下的樱花.","status":"processing","deadline":"2024-04-16"},{"lastModifiedDate":"2023-03-29T14:49:58.000+08:00","createdAt":"2023-03-14T15:44:16.000+08:00","id":1,"userid":1,"link":"http://www.baidu.com","img":"http://oss.wish.ydxxkj.top/resource/24130a65-ec5e-4c48-86d1-e964859f8532-1680072583657.jpg","content":"我希望明年去富士山下的樱花.","status":"completed","deadline":"2024-04-16"},{"lastModifiedDate":"2023-03-29T14:49:58.000+08:00","createdAt":"2023-03-14T15:44:16.000+08:00","id":1,"userid":1,"link":"http://www.baidu.com","img":"http://oss.wish.ydxxkj.top/resource/24130a65-ec5e-4c48-86d1-e964859f8532-1680072583657.jpg","content":"我希望明年去富士山下的樱花.","status":"expired","deadline":"2024-04-16"}],
        wishes:[]
    },
    // 分享微信
    shareWx(){
        console.log('分享微信')
    },
    showShare(){
        this.setData({
            shareVisible:!this.data.shareVisible
        })
    },
    go2DelDialog(){
        this.setData({showDelDialog:true})
    },
    closeDelDialog(){
        this.setData({showDelDialog:false})
    },
    confirmDelDialog(e){
        console.log(e.target.dataset.del)
        console.log('确定删除')
        console.log(this.data.detail.id)
        /**确定删除愿望 */
        this.setData({showDelDialog:false})
        req.deleteRequest('/api/user/curt/wish/'+this.data.detail.id,{}).then((res)=>{
            console.log(res)
            if(res.data.code==200){
                wx.showToast({
                    title:'愿望删除成功',
                    icon: 'none',
                    duration: 1000
                })
                this.getMyWish()
                this.setData({
                    visible: false
                })
            }
           }).catch((err)=>{
            console.log(err);
        })
    },
    doFinishWish(e){/**愿望已达成 */
        console.log(e.target.dataset.del)
        console.log('愿望达成')
        console.log(this.data.detail.id)
        /**确定删除愿望 */
        this.setData({showDelDialog:false})
        req.patchRequest('/api/user/curt/wish/'+this.data.detail.id+"/completed",{}).then((res)=>{
            console.log(res)
            if(res.data.code==200){
                wx.showToast({
                    title:'愿望达成成功',
                    icon: 'none',
                    duration: 1000
                })
            }else{
                wx.showToast({
                    title:res.data.msg,
                    icon: 'none',
                    duration: 1000
                })
            }
           }).catch((err)=>{
            console.log(err);
        })
    },
    go2WishDetail(e){/**查看愿望详情 */
        this.setData({visible:true,detail:e.currentTarget.dataset.wish})
        this.setData({detail:e.currentTarget.dataset.wish})
    },
    onVisibleChange(e) {
        this.setData({
          visible: e.detail.visible,
        });
      },
      changeVisible(){
          this.setData({visible:false})
      },
    go2Reback(){
        wx.navigateBack({ changed: true });
    },
    getMyWish(){
        req.getRequest('/api/user/curt/wish',{}).then((res)=>{
            console.log(res,'11111111')
            if(res.data.code==200){
                this.setData({wishes:res.data.data.records})
            }
           }).catch((err)=>{
            console.log(err);
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getMyWish()
    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

    onShareTimeline(){
    }
})