|
|
1
|
+/**
|
|
|
2
|
+ * 我要咨询提交页面
|
|
|
3
|
+ * @author: liangzhifeng<zhifeng.liang@yoho.cn>
|
|
|
4
|
+ * @date: 2015/12/01
|
|
|
5
|
+ */
|
|
|
6
|
+var $ = require('jquery'),
|
|
|
7
|
+ tip = require('../../plugin/tip'),
|
|
|
8
|
+ loading = require('../../plugin/loading');
|
|
|
9
|
+
|
|
|
10
|
+var $consultForm = $('.consult-form'),
|
|
|
11
|
+ $submit = $('#submit'),
|
|
|
12
|
+ $content = $('#content'),
|
|
|
13
|
+ $footer = $('#yoho-footer'),
|
|
|
14
|
+ $navTitle = $('.nav-title'),
|
|
|
15
|
+ navTitle = $navTitle.html(),
|
|
|
16
|
+ productId = $('#product_id').val(),
|
|
|
17
|
+ isSubmiting;
|
|
|
18
|
+
|
|
|
19
|
+$submit.on('touchend', function() {
|
|
|
20
|
+ $content.blur();
|
|
|
21
|
+ $consultForm.submit();
|
|
|
22
|
+ return false;
|
|
|
23
|
+}).on('touchstart', function() {
|
|
|
24
|
+ $(this).addClass('highlight');
|
|
|
25
|
+}).on('touchend touchcancel', function() {
|
|
|
26
|
+ $(this).removeClass('highlight');
|
|
|
27
|
+});
|
|
|
28
|
+
|
|
|
29
|
+$content.on('focus', function() {
|
|
|
30
|
+ if ($content.val() === '请输入咨询内容') {
|
|
|
31
|
+ $content.val('');
|
|
|
32
|
+ }
|
|
|
33
|
+}).on('blur', function() {
|
|
|
34
|
+ if ($content.val() === '') {
|
|
|
35
|
+ $content.val('请输入咨询内容');
|
|
|
36
|
+ }
|
|
|
37
|
+});
|
|
|
38
|
+
|
|
|
39
|
+// 提交表单请求
|
|
|
40
|
+$consultForm.on('submit', function() {
|
|
|
41
|
+ var content;
|
|
|
42
|
+ if (isSubmiting) {
|
|
|
43
|
+ return false;
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
|
46
|
+ // 简单的表单校验
|
|
|
47
|
+ content = $content.val();
|
|
|
48
|
+ if (!content || content === '请输入咨询内容') {
|
|
|
49
|
+ tip.show('咨询内容不能为空');
|
|
|
50
|
+ return false;
|
|
|
51
|
+ }
|
|
|
52
|
+
|
|
|
53
|
+ isSubmiting = true;
|
|
|
54
|
+ loading.showLoadingMask();
|
|
|
55
|
+ $.ajax({
|
|
|
56
|
+ method: 'POST',
|
|
|
57
|
+ url: '/product/detail/consultsubmit',
|
|
|
58
|
+ data: {
|
|
|
59
|
+ product_id: productId,
|
|
|
60
|
+ content: content
|
|
|
61
|
+ }
|
|
|
62
|
+ }).then(function(res) {
|
|
|
63
|
+ if ($.type(res) !== 'object') {
|
|
|
64
|
+ res = {};
|
|
|
65
|
+ }
|
|
|
66
|
+ if (res.code !== 200) {
|
|
|
67
|
+ tip.show(res.message || '网络出了点问题~');
|
|
|
68
|
+ isSubmiting = false;
|
|
|
69
|
+ loading.hideLoadingMask();
|
|
|
70
|
+ } else {
|
|
|
71
|
+ window.history.go(-1);
|
|
|
72
|
+ }
|
|
|
73
|
+ }).fail(function() {
|
|
|
74
|
+ tip.show('网络出了点问题~');
|
|
|
75
|
+ isSubmiting = false;
|
|
|
76
|
+ });
|
|
|
77
|
+ return false;
|
|
|
78
|
+}); |