Files
coupon/pages/refund/refund.js
2023-02-22 23:52:12 +08:00

456 lines
11 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//获取应用实例
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
dingdan_msg:false,
goods_id:'',
type:'',
fileListtwo: [],
reason:[],
id:'',
refund_remark:'',
voucher_img:'',
mengceng:false,
refund_box:false,
refund_id:'',
refund_ordertime:'',
charge_phone:'',
time:'',
timeData: {},
refund_name:'请选择',
goods_img:[],
list:[
{
text:'不喜欢/不想要',
},
{
text:'商品信息与描述不符'
},
{
text:'买多/买错/计划有变'
},
{
text:'更换其他项目、购买了其他项目'
},
{
text:'没有时间/个人原因'
},
{
text:'其他原因'
}
]
},
onChange(e) {
this.setData({
timeData: e.detail,
});
},
afterReadtwo(event) {
var that = this;
const { file } = event.detail;
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
url: app.buildUrl("/app/Goddesswechat/uploadImg"),
filePath: file.url,
name: 'file',
formData: {
uid:app.getCache('uid'),
token:app.getCache('token'),
file:file.url
},
success: (res)=> {
var resp = res.data;
var rstObj = JSON.parse(resp); //字符串转为对象
if(rstObj.erro==0){
app.console(rstObj.file_path+'cccccccc')
// 上传完成需要更新 fileList
const { fileListtwo = [] } = that.data;
fileListtwo.push({ ...file, url: rstObj.file_path ,name:rstObj.file_name});
that.setData({
fileListtwo,
voucher_img:rstObj.file_path
});
}else{
wx.showToast({ title: rstObj.msg, icon: 'none' });
return;
}
},
});
},
deletetwo(event){
app.console(event.detail.index+"================="+222),
this.data.fileListtwo.splice([event.detail.index],1)
this.setData({fileListtwo:this.data.fileListtwo});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options.type)
console.log(options.id)
//详情显示
if(options.type==2){
this.setData({
id:options.id,
type:2
})
this.refundOderInfor()
}
//退款编辑
if(options.type==3){
this.setData({
id:options.id,
type:3
})
this.refundOderInfor()
}
//退款驳回
if(options.type==1){
this.setData({
id:options.id,
type:1
})
this.refundOderInfor()
}
//待退款
if(options.type==4){
this.setData({
id:options.id,
type:4
})
this.refundOderInfor()
}
this.getRefundReason()
},
select(){
this.setData({
refund_box:true,
mengceng:true
})
},
mengceng(){
this.isok()
},
isok(){
this.setData({
refund_box:false,
mengceng:false
})
},
commit(){
wx.navigateTo({
url: '/pages/reforderdetail/reforderdetail?'+"type="+'3'+ '&id=' +this.data.id,
})
// var that = this;
// that.data.fileListtwo.forEach(item => {
// app.console('长度=item================'+item)
// const { goods_img = [] } = that.data;
// goods_img.push(item.url);
// that.setData({ goods_img });
// }),
// wx.request({
// url: app.buildUrl("/app/Goddesswechat/submitRefund"),
// header: app.getRequestHeader(),
// method:'POST',
// data: {
// version_number: app.globalData.version_number,
// uid:wx.getStorageSync('uid'),
// token:wx.getStorageSync('token'),
// id:this.data.id,
// refund_id:this.data.refund_id,
// refund_remark:this.data.refund_remark,
// voucher_img:that.data.goods_img,
// },
// success: function (res) {
// var resp = res.data;
// console.log(resp+"=================dddddddddddddddddddddddddddddddddddddddddddd")
// if(resp.erro==0){
// wx.showToast({ title: resp.msg, icon: 'none' });
// setTimeout(function () {
// //要延时执行的代码
// wx.switchTab({
// url: '/pages/order/order',
// });
// }, 2000) //延迟时间 这里是2秒
// }else{
// wx.showToast({ title: resp.msg, icon: 'none' });
// }
// }
// });
},
onClickLeft() {
wx.navigateBack()
},
//撤销退款申请
revoke(){
console.log(this.data.infro);
wx.request({
url: app.buildUrl("/app/Goddesswechat/cancelRefund"),
header: app.getRequestHeader(),
method:'POST',
data: {
version_number: app.globalData.version_number,
uid:wx.getStorageSync('uid'),
token:wx.getStorageSync('token'),
id:this.data.infro.order_id,
},
success: function (res) {
var resp = res.data;
if(resp.erro==0){
wx.showToast({ title: resp.msg, icon: 'none' });
setTimeout(function () {
//要延时执行的代码
wx.switchTab({
url: '/pages/order/order',
});
}, 2000) //延迟时间 这里是2秒
}else{
wx.showToast({ title: resp.msg, icon: 'none' });
}
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
// this.refundOderInfor();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
//退款订单详情
refundOderInfor: function () {
var that = this;
wx.request({
url: app.buildUrl("/app/Goddesswechat/refundOderInfor"),
header: app.getRequestHeader(),
method:'POST',
data: {
version_number: this.data.version_number,
uid:wx.getStorageSync('uid'),
token:wx.getStorageSync('token'),
id:this.data.id
},
success: function (res) {
var resp = res.data;
console.log(resp+"=================dddddddddddddddddddddddddddddddddddddddddddd")
console.log(resp.erro+"=================dddddddddddddddddddddddddddddddddddddddddddd")
if(resp.erro==0){
that.setData({
infro:resp.infro
});
}
}
});
},
callphone(){
wx.makePhoneCall({
phoneNumber: this.data.infro.charge_phone,
})
},
radioChange(e) {
console.log('radio发生change事件携带value值为', e.detail.value)
this.setData({
refund_id:e.detail.value
})
const reason = this.data.reason
for (let i = 0, len = reason.length; i < len; ++i) {
reason[i].checked = reason[i].value === e.detail.value
}
this.setData({
reason
})
this.data.reason.forEach(item => {
if(this.data.refund_id==item.id){
this.setData({ refund_name:item.reason });
}
})
console.log('radio发生change事件携带value值为', this.data.refund_name)
this.isok()
},
//后台设置的退款原因
getRefundReason: function () {
var that = this;
wx.request({
url: app.buildUrl("/app/Goddesswechat/getRefundReason"),
header: app.getRequestHeader(),
method:'POST',
data: {
version_number: app.globalData.version_number,
uid:wx.getStorageSync('uid'),
token:wx.getStorageSync('token'),
},
success: function (res) {
var resp = res.data;
console.log(resp+"=================dddddddddddddddddddddddddddddddddddddddddddd")
if(resp.erro==0){
that.setData({
reason:resp.reason
});
console.log(that.data.refund_id);
that.data.reason.forEach(item => {
if(that.data.refund_id==item.id){
that.setData({ refund_name:item.reason });
}
})
}
}
});
},
//退款订单信息
refundOderInfor: function () {
var that = this;
wx.request({
url: app.buildUrl("/app/Goddesswechat/refundOderInfor"),
header: app.getRequestHeader(),
method:'POST',
data: {
version_number: app.globalData.version_number,
uid:wx.getStorageSync('uid'),
token:wx.getStorageSync('token'),
id:this.data.id
},
success: function (res) {
console.log(res);
var resp = res.data;
if(resp.erro==0){
if(that.data.type==3){
that.setData({
infro:resp.infro,
});
}else{
that.setData({
infro:resp.infro,
refund:resp.refund,
refund_remark:resp.refund.refund_remark,
goods_img:resp.refund.voucher_img,
refund_id:resp.refund.refund_id,
refund_ordertime:resp.refund.time
});
}
console.log(that.data.refund_id);
// that.data.reason.forEach(item => {
// if(that.data.refund_id==item.id){
// that.setData({ refund_name:item.reason });
// console.log(this.refund);
// }
// })
if(that.data.goods_img.length>0){
that.data.goods_img.forEach(item => {
app.console('长度=item================'+item)
const { fileListtwo = [] } = that.data;
fileListtwo.push({ url: item });
that.setData({ fileListtwo });
})
that.setData({
goods_img:[]
})
}
//截止时间
if(that.data.refund_ordertime!=null){
var str2=that.data.refund_ordertime
app.console(str2+"=========555555========")
let currentt = formatTime(new Date(str2))
let t = currentt
let repTime = t.replace(/-/g, '/');
let timeTamp = Date.parse(repTime);
let time = timeTamp /1000
let now = new Date().getTime();
let diff = parseInt(now / 1000 - time);
if (diff < 24*60*60) {
app.console(diff+"=========等待商家处理时间内========")
that.setData({
time:(24*60*60-diff)*1000
})
} else {
app.console(diff+"=========等待商家处理代付款超时========")
}
}
}
}
});
},
})
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
module.exports = {
formatTime
}