Page({

    /**
     * 页面的初始数据
     */
    data: {
        order   : null,
        title   : [],
        imgs    : null,
        titleVal: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        wx.showLoading({
            title: '加载中...',
            mask : true
        })
        wx.$api.refund.refundPreposition(options.id).then(res => {
            let { title, order } = res.data;
            this.setData({
                title,
                order,
                titleVal: title[0]
            })
            wx.hideLoading()
        })
    },
    /**
     * 选择退货理由
     */
    onRadio(e){
        this.setData({
            titleVal: e.detail.value
        })
    },
    /**
     * 选择图片上传
     */
    onUpd(){
        wx.chooseMedia({
            count	    : 1, 
            mediaType   : ['image'],
            success	    : path => {
                wx.$api.file.uploadImg(path.tempFiles[0].tempFilePath, {}).then(res => {
                    this.setData({
                        imgs: res
                    })
                })
            }
        })
    },
    /**
     * 提交申请
     */
    onSubmit(){
        let data = {
            title       : this.data.titleVal,
            pictures    : this.data.imgs != null ? this.data.imgs.path : ''
        }
        wx.showLoading({
            title: '加载中...',
            mask : true
        })
        wx.$api.refund.submitRefund(this.data.order.order_no, data).then(res => {
            wx.hideLoading()
            wx.showModal({
                title       : '提示',
                content     : res.data,
                showCancel  : false,
                confirmColor: '#da2b54',
                success     : modalRes => {
                    if(modalRes.confirm){
                        wx.navigateBack()
                    }
                    wx.hideLoading()
                }
            })
        }).catch(err => {})
    }
})