vr-shopxo-source/sourcecode/weixin/pages/answer-form/answer-form.js

91 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-12-29 10:39:25 +00:00
const app = getApp();
Page({
data: {
2020-07-19 14:40:12 +00:00
data_list_loding_status: 1,
data_list_loding_msg: '处理错误',
2018-12-29 10:39:25 +00:00
form_submit_loading: false,
},
onLoad() {},
onShow() {
2018-12-31 18:53:36 +00:00
wx.setNavigationBarTitle({title: app.data.common_pages_title.answer_form});
2018-12-29 10:39:25 +00:00
this.init();
},
// 初始化
init() {
2019-11-28 09:14:13 +00:00
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
}
2020-07-19 14:40:12 +00:00
// 开启表单
this.setData({data_list_loding_status: 0});
} else {
// 提示错误
this.setData({data_list_loding_status: 2, data_list_loding_msg: '用户未登录'});
2018-12-29 10:39:25 +00:00
}
},
/**
* 表单提交
*/
formSubmit(e)
{
// 数据验证
var validation = [
{fields: 'name', msg: '请填写联系人'},
{fields: 'tel', msg: '请填写联系电话'},
{fields: 'content', msg: '请填写内容'}
];
if(app.fields_check(e.detail.value, validation))
{
2019-01-05 13:37:48 +00:00
wx.showLoading({title: '提交中...'});
2018-12-29 10:39:25 +00:00
this.setData({form_submit_loading: true});
// 网络请求
wx.request({
2019-01-03 10:44:57 +00:00
url: app.get_request_url('add', 'answer'),
2018-12-29 10:39:25 +00:00
method: 'POST',
data: e.detail.value,
dataType: 'json',
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: (res) => {
wx.hideLoading();
if(res.data.code == 0)
{
2019-01-04 17:47:30 +00:00
app.showToast(res.data.msg, "success");
2018-12-29 10:39:25 +00:00
setTimeout(function()
{
wx.redirectTo({
url: "/pages/user-answer-list/user-answer-list"
});
}, 2000);
} else {
this.setData({form_submit_loading: false});
2019-11-26 08:19:24 +00:00
if (app.is_login_check(res.data)) {
app.showToast(res.data.msg);
2019-11-28 09:30:10 +00:00
} else {
app.showToast('提交失败,请重试!');
2019-11-26 08:19:24 +00:00
}
2018-12-29 10:39:25 +00:00
}
},
fail: () => {
wx.hideLoading();
this.setData({form_submit_loading: false});
2019-01-04 17:47:30 +00:00
app.showToast('服务器请求出错');
2018-12-29 10:39:25 +00:00
}
});
}
},
});