Authored by 梁志锋

我要咨询页面提交功能实现 code review by zhaobiao

/**
* 我要咨询提交页面
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/12/01
*/
var $ = require('jquery'),
tip = require('../../plugin/tip'),
loading = require('../../plugin/loading');
var $consultForm = $('.consult-form'),
$submit = $('#submit'),
$content = $('#content'),
$footer = $('#yoho-footer'),
$navTitle = $('.nav-title'),
navTitle = $navTitle.html(),
productId = $('#product_id').val(),
isSubmiting;
$submit.on('touchend', function() {
$content.blur();
$consultForm.submit();
return false;
}).on('touchstart', function() {
$(this).addClass('highlight');
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});
$content.on('focus', function() {
if ($content.val() === '请输入咨询内容') {
$content.val('');
}
}).on('blur', function() {
if ($content.val() === '') {
$content.val('请输入咨询内容');
}
});
// 提交表单请求
$consultForm.on('submit', function() {
var content;
if (isSubmiting) {
return false;
}
// 简单的表单校验
content = $content.val();
if (!content || content === '请输入咨询内容') {
tip.show('咨询内容不能为空');
return false;
}
isSubmiting = true;
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/product/detail/consultsubmit',
data: {
product_id: productId,
content: content
}
}).then(function(res) {
if ($.type(res) !== 'object') {
res = {};
}
if (res.code !== 200) {
tip.show(res.message || '网络出了点问题~');
isSubmiting = false;
loading.hideLoadingMask();
} else {
window.history.go(-1);
}
}).fail(function() {
tip.show('网络出了点问题~');
isSubmiting = false;
});
return false;
});
... ...
... ... @@ -9,10 +9,9 @@ var $ = require('jquery'),
Hammer = require('yoho.hammer'),
tip = require('../../plugin/tip');
var likeHammer = new Hammer(document.getElementById('likeBtn'));
var addToCartHammer = new Hammer(document.getElementById('addtoCart'));
var productId = $('#productId').val();
var likeHammer = new Hammer(document.getElementById('likeBtn')),
addToCartHammer = new Hammer(document.getElementById('addtoCart')),
productId = $('#productId').val();
likeHammer.on('tap', function(e) {
var opt,
... ...
... ... @@ -8,4 +8,5 @@ require('./newsale/newarrival');
require('./newsale/discount');
require('./list');
require('./detail/detail');
require('./detail/desc');
\ No newline at end of file
require('./detail/loadmore');
require('./detail/consultform');
\ No newline at end of file
... ...