2023-04-17 16:14:18 +08:00

173 lines
3.1 KiB
JavaScript

// pages/setFastrReply/setFastrReply.js
var app = getApp()
var config = {};
var miucms = require('../../utils/miucms.js');
Page({
/**
* 页面的初始数据
*/
data: {
message:[],
loading:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.getStorage({
key:'message',
success: function (res) {
that.setData({
message: res.data
})
if (res.data.length == 0) {
that.setData({
message: ['']
})
}
},
})
this.get_config()
},
get_config() {
var that = this;
if (app.globalData.config.lists) {
config = app.globalData.config;
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
// onShareAppMessage: function () {
// },
del_item:function(e){
var i = e.currentTarget.dataset.i;
console.log(i)
let that = this;
that.data.message.splice(i,1);
this.setData({
message: that.data.message
})
},
input:function(e){
var i = e.currentTarget.dataset.i;
let that = this;
that.data.message[i] = e.detail.value;
this.setData({
message: that.data.message
})
},
add_item:function(){
let that = this;
that.data.message.push('');
this.setData({
message: that.data.message
})
},
cle: function () {
wx.navigateBack({
delta: 1, // 回退前 delta(默认为1) 页面
})
},
submit:function(){
let that = this;
// 避免重复提交
if(that.data.loading){
return false
}
that.setData({
loading: true
})
wx.showLoading({
title: '提交中',
})
wx.request({
url: config.message.customreply,
data: {
session: wx.getStorageSync('session'),
do_submit:1,
message:that.data.message
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: app.globalData.header,
success: function (res) {
wx.setStorage({
key: 'message',
data: that.data.message,
success: function (res) {
wx.navigateBack({
delta: 1,
})
}
})
},
fail: function (res) {
wx.hideLoading()
wx.showModal({
title: '提示',
content: 'res',
})
},
complete: function () {
wx.hideLoading()
that.setData({
loading: false
})
}
})
}
})