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

178 lines
3.5 KiB
JavaScript

// pages/replyQuestions/replyQuestions.js
var app = getApp()
var miucms = require('../../utils/miucms.js');
var config = {};
Page({
/**
* 页面的初始数据
*/
data: {
questions: [],
can_submit: false,
status: '',
avatar: '',
show_custom: false,
show_fast_reply: false,
uniqid: 'm1Oeq5PvPnnr',
token: '',
messageid: '',
XiaoappHKid: '',
islandlord: false,
lastmessageid: 0,
page: {},
pagemessageid: 0,
count: 0,
data: [],
impression: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
this.get_config()
that.setData({
uniqid: options.uniqid
})
wx.getStorage({
key: 'questions_info',
success: function(res) {
console.log(res)
that.setData({
XiaoappHKid: res.data.XiaoappHKid,
info: res.data.info,
questions: res.data.questions,
token: res.data.token
})
// wx.removeStorage({
// key: 'questions_info',
// })
},
})
},
get_config() {
var that = this;
if (app.globalData.config.lists) {
config = app.globalData.config;
that.setData({
user: app.globalData.user,
status: app.globalData.status
})
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
input: function (e) {
let that = this;
var i = e.currentTarget.dataset.i;
this.data.questions[i].answer = e.detail.value;
let can_submit = true;
for (let i = 0; i < this.data.questions.length; i++) {
if (this.data.questions[i].answer.trim().length == 0) {
can_submit = false;
break;
}
}
this.setData({
questions: that.data.questions,
can_submit: can_submit
})
},
submit: function () {
var that = this;
if (!this.data.can_submit) {
return false
}
// 提交
wx.showLoading({
title: '提交中',
})
wx.request({
url: app.globalData.config.message.launch,
data: {
session: wx.getStorageSync('session'),
token: that.data.token,
uniqid: that.data.uniqid,
do_submit: 1,
XiaoappHKid: that.data.XiaoappHKid,
questions: that.data.questions
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: app.globalData.header,
success: function (res) {
var data = app.return_data(res);
if (data.extraparam && data.extraparam.mode == 'chat') {
// 直接聊天
wx.redirectTo({
url: '/pages/chartroom/chartroom?uniqid=' + data.talk.uniqid,
})
}
},
fail: function (res) {
wx.showModal({
content: res,
})
},
complete: function (res) {
wx.hideLoading()
that.setData({
can_submit: false
})
}
})
},
})