submit-controller.js
5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* 校验控制器
*/
define(
"check/submit-controller",
[
'mk7/controller',
'mk7/url',
'mk7/utils',
'mk7/modals',
'mk7/jweixin'
],
function (ctrl, url, utils, modals, jweixin) {
var ctrl = new ctrl();
var $$ = Dom7;
var t7 = Template7;
var uuid = "";
ctrl.run = function () {
var me = this;
uuid = me.params.uuid;
me.setPageTitle("验证标签");
jweixin.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: window.$site.appid, // 必填,公众号的唯一标识
timestamp: window.$site.timestamp, // 必填,生成签名的时间戳
nonceStr: window.$site.noncestr, // 必填,生成签名的随机串
signature: window.$site.signature,// 必填,签名,见附录1
jsApiList: ['chooseImage','previewImage','uploadImage', 'getLocalImgData']
});
me.render();
};
ctrl.bindEvents = function () {
var me = this;
$$(".scan-image").click(function () {
me.uploadImg($$(this));
});
$$(".scan-button").click(function () {
var uploadFile = $$(".scan-image").attr("data");
if (utils.isEmpty(uploadFile)) {
utils.toast({content:"请拍照文件上传后再试!"});
return false;
}
var thiz = $$(this);
$$.ajax({
method : "POST",
url: url.to('check/default/check-actived'),
data : {upload_file: uploadFile, uuid: uuid},
dataType : "json",
beforeSend : function(){
me.showIndicator();
thiz.html("验证中…");
},
success : function(res){
try {
if(res.success) {
if (res.code == 1) {
window.location.href = url.to('check#success/' + uuid);
} else {
utils.toast({content: res.message, closeDelay:3000});
}
} else {
window.location.href = url.to('check#error/' + uuid);
}
} catch(ex) {
utils.toast({content:'校验失败,请重拍图片再试!', closeDelay:3000});
}
},
error : function(res){
utils.toast({content:"校验失败,请重拍图片再试!"});
thiz.html("提交验证");
},
complete : function(res){
me.hideIndicator();
thiz.html("提交验证");
},
});
});
};
ctrl.uploadImg=function(uploadParent) {
var me = this;
jweixin.ready(function () {
//每次只传一张图片
jweixin.chooseImage({
count: 1,
sizeType: ['compressed'],//'original',
sourceType: ['album', 'camera'], // 'album', 'camera'
success: function (res) {
if (res.localIds.length > 0) {
me.upload(res.localIds, uploadParent);
}
}
});
});
};
ctrl.upload = function (localIds, uploadParent) {
var me = this;
if (localIds[0] == undefined) {
return '';
}
jweixin.uploadImage({
localId: localIds[0],
isShowProgressTips: 1, // 默认为1,显示进度提示
success: function (res) {
$$.ajax({
method : "POST",
url: url.to('check/default/update-serviceid'),
data : {service_id:res.serverId, uuid: uuid},
dataType : "json",
beforeSend : function(){
me.showIndicator();
},
success : function(res){
try {
if(res.success) {
var imgUrl = res.img_path;
uploadParent.attr("data", imgUrl);
uploadParent.attr("src", res.show_path);
} else {
utils.toast({content:res.message, closeDelay:3000});
}
} catch(ex) {
utils.toast({content:'图片上传失败!', closeDelay:3000});
me.hideIndicator();
}
},
error : function(res){
utils.toast({content:"图片上传失败!"});
me.hideIndicator();
},
complete : function(res){
me.hideIndicator();
},
});
},
fail: function (res) {
me.app.alert(JSON.stringify(res));
}
});
};
return ctrl;
}
);