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

90 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-12-28 10:58:37 +00:00
const app = getApp();
Page({
data: {
data_list_loding_status: 1,
data_list_loding_msg: '处理错误',
2018-12-28 10:58:37 +00:00
form_submit_loading: false,
},
onLoad() {},
onShow() {
my.setNavigationBar({title: app.data.common_pages_title.answer_form});
this.init();
},
// 初始化
init() {
2019-06-28 08:18:04 +00:00
var user = app.get_user_info(this, "init");
2018-12-28 10:58:37 +00:00
if (user != false) {
// 用户未绑定用户则转到登录页面
2019-06-28 08:18:04 +00:00
if (app.user_is_need_login(user)) {
2018-12-28 10:58:37 +00:00
my.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-28 10:58:37 +00:00
}
},
/**
* 表单提交
*/
formSubmit(e)
{
// 数据验证
var validation = [
{fields: 'name', msg: '请填写联系人'},
{fields: 'tel', msg: '请填写联系电话'},
{fields: 'content', msg: '请填写内容'}
];
if(app.fields_check(e.detail.value, validation))
{
my.showLoading({content: '提交中...'});
this.setData({form_submit_loading: true});
// 网络请求
2019-06-28 09:34:30 +00:00
my.request({
2019-01-03 10:44:57 +00:00
url: app.get_request_url('add', 'answer'),
2018-12-28 10:58:37 +00:00
method: 'POST',
data: e.detail.value,
dataType: 'json',
2019-06-28 09:34:30 +00:00
headers: { 'content-type': 'application/x-www-form-urlencoded' },
2018-12-28 10:58:37 +00:00
success: (res) => {
my.hideLoading();
if(res.data.code == 0)
{
2019-10-08 08:20:08 +00:00
app.showToast(res.data.msg, 'success');
2018-12-28 10:58:37 +00:00
setTimeout(function()
{
my.redirectTo({
url: "/pages/user-answer-list/user-answer-list"
});
}, 2000);
} else {
this.setData({form_submit_loading: false});
2019-11-27 10:06:58 +00:00
if (app.is_login_check(res.data)) {
app.showToast(res.data.msg);
2019-11-28 06:19:07 +00:00
} else {
app.showToast('提交失败,请重试!');
2019-11-27 10:06:58 +00:00
}
2018-12-28 10:58:37 +00:00
}
},
fail: () => {
my.hideLoading();
this.setData({form_submit_loading: false});
2019-10-08 08:20:08 +00:00
app.showToast('服务器请求出错');
2018-12-28 10:58:37 +00:00
}
});
}
},
});