wx_upload.htm 覆盖source/plugin/tom_tchuodong/template/- <script>
- var picnum = {};
- <!--{loop $bmnumArr $k $i}-->
- picnum[$i] = {};
- <!--{loop $attrpicList $key $val}-->
- picnum[{$i}][{$val['id']}] = 0;
- <!--{/loop}-->
- <!--{/loop}-->
-
- var oldWindowHeight = $(window).height();
- function photoupload(attr_id,num,numberid){
- wx.ready(function () {
- var picnums = picnum[numberid][attr_id];
-
- var newWindowHeight = $(window).height();
- if(newWindowHeight < (oldWindowHeight - 100)){
- return false;
- }
- var photo_num = num - picnums;
- if(photo_num == 0){
- tusi("{lang tom_tchuodong:over_photo}");
- return false;
- }else if(photo_num > 9){
- photo_num = 9;
- }
- wx.chooseImage({
- count: photo_num,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- var length = res.localIds.length;
- if(length > 0){
- loading('{lang tom_tchuodong:uploading}');
- uploadImg(res);
- }
- }
- });
- function uploadImg(res){
- var i = 0, length = res.localIds.length;
- if(length > 0){
- function upload(){
- wx.uploadImage({
- localId: res.localIds[i],
- isShowProgressTips: 0,
- success: function (res) {
- var serverId = res.serverId;
- downloadServer(serverId);
- i++;
- if(i < length){
- upload();
- }else{
- loading(false);
- }
- },
- fail:function(res){
- loading(false);
- tusi('{lang tom_tchuodong:wx_upload_error}');
- }
- });
- }
- upload();
- }
- }
- function downloadServer(serverId){
- $.ajax({
- type:'POST',
- url:'{$wxUploadUrl}',
- data:{serverId:serverId},
- dataType:'json',
- success:function(data){
- if(data.status == 200){
- $("#photolist_"+attr_id+'_'+numberid).append('<li class="li_'+li_i+'"><section class="img"><img src="'+data.picurl+'" /><input type="hidden" name="photo_'+attr_id+'_'+numberid+'[]" value="'+data.picurl+'"/></section><div class=" close pic-delete-btn pointer" onclick="picremove('+li_i+','+attr_id+','+numberid+');"> X </div></li>');
- li_i ++;
- picnum[numberid][attr_id]++;
- }else if(data.status == 301){
- <!--{if $test == 1}-->
- alert(data.content);
- <!--{/if}-->
- tusi('{lang tom_tchuodong:wx_upload_error_301}');
- return false;
- }else if(data.status == 302){
- tusi('{lang tom_tchuodong:wx_upload_error_302}');
- return false;
- }else{
- tusi('error');
- return false;
- }
- },
- error:function(){
- loading(false);
- tusi('{lang tom_tchuodong:wx_upload_error_1}');
- }
- })
- }
- });
- }
-
- wx.ready(function () {
-
- $(document).on('click', '#filedata2', function(){
-
- var newWindowHeight = $(window).height();
- if(newWindowHeight < (oldWindowHeight - 100)){
- return false;
- }
-
- wx.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- var length = res.localIds.length;
- if(length > 0){
- loading('{lang tom_tcshop:uploading}');
- uploadImg(res, 2);
- }
- }
- });
- })
-
- $(document).on('click', '#filedata3', function(){
- var count = $("#photolist").find("li").length;
-
- var newWindowHeight = $(window).height();
- if(newWindowHeight < (oldWindowHeight - 100)){
- return false;
- }
-
- var photo_num = max_photo_num - count;
- if(photo_num == 0){
- tusi("{lang tom_tchuodong:fabu_max_photo_num}"+max_photo_num+"{lang tom_tchuodong:bm_zhang}");exit;
- return false;
- }else if(photo_num > 9){
- photo_num = 9;
- }
- wx.chooseImage({
- count: photo_num,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- var length = res.localIds.length;
- if(length > 0){
- loading('{lang tom_tcshop:uploading}');
- uploadImg(res, 3);
- }
- }
- });
- })
-
- $(document).on('click', '#filedata4', function(){
-
- var newWindowHeight = $(window).height();
- if(newWindowHeight < (oldWindowHeight - 100)){
- return false;
- }
-
- wx.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- var length = res.localIds.length;
- if(length > 0){
- loading('{lang tom_tcshop:uploading}');
- uploadImg(res, 4);
- }
- }
- });
- })
-
- function uploadImg(res, type){
- var i = 0, length = res.localIds.length;
- if(length > 0){
- function upload(){
- wx.uploadImage({
- localId: res.localIds[i],
- isShowProgressTips: 0,
- success: function (res) {
- var serverId = res.serverId;
- downloadServer(serverId, type);
- i++;
- if(i < length){
- upload();
- }else{
- loading(false);
- }
- },
- fail:function(res){
- loading(false);
- tusi('{lang tom_tcshop:wx_upload_error}');
- }
- });
- }
- upload();
- }
- }
-
- function downloadServer(serverId, type){
- var type = type;
- $.ajax({
- type:'POST',
- url:'{$wxUploadUrl2}',
- data:{serverId:serverId},
- dataType:'json',
- success:function(data){
- if(data.status == 200){
- if(type == 2){
- $("#picurl").html('<li><section class="img"><img src="'+data.picurl+'" /><input type="hidden" name="picurl" value="'+data.picurl+'"/></section></li>');
- picurl_count++;
- }else if(type == 3){
- $("#photolist").append('<li class="li_'+li_i+'"><section class="img"><img src="'+data.picurl+'" /><input type="hidden" name="photo_'+li_i+'" value="'+data.picurl+'"/></div><div class=" close pic-delete-btn pointer" onclick="picremove('+li_i+');"> X </div></li>');
- li_i++;
- photo_count++;
- }else if(type == 4){
- $("#toppic").html('<li><section class="img"><img src="'+data.picurl+'" /><input type="hidden" name="toppic" value="'+data.picurl+'"/></section></li>');
- toppic_count++;
- }
- }else if(data.status == 301){
- <!--{if $test == 1}-->
- alert(data.content);
- <!--{/if}-->
- tusi('{lang tom_tcshop:wx_upload_error_301}');
- return false;
- }else if(data.status == 302){
- <!--{if $test == 1}-->
- alert(data.type);
- <!--{/if}-->
- tusi('{lang tom_tcshop:wx_upload_error_302}');
- return false;
- }else{
- tusi('error');
- return false;
- }
- },
- error:function(){
- loading(false);
- tusi('{lang tom_tcshop:wx_upload_error_1}');
- }
- })
- }
- });
- </script>
复制代码
|