Authored by zhangxiaoru

suggest

@@ -11,9 +11,6 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model @@ -11,9 +11,6 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model
11 11
12 const favorite = (req, res) => { 12 const favorite = (req, res) => {
13 13
14 - // favoriteModel.getfavoriteData(uid, page, limit).then((result) => {  
15 -  
16 - // }).catch(next);  
17 res.render('favorite', { 14 res.render('favorite', {
18 module: 'home', 15 module: 'home',
19 page: 'favorite', 16 page: 'favorite',
@@ -13,6 +13,7 @@ const _ = require('lodash'); @@ -13,6 +13,7 @@ const _ = require('lodash');
13 const myCurrency = (req, res, next) => { 13 const myCurrency = (req, res, next) => {
14 let uid = req.user.uid || 8039759; 14 let uid = req.user.uid || 8039759;
15 let contentCode = '05afedf76886d732573f10f7451a1703'; 15 let contentCode = '05afedf76886d732573f10f7451a1703';
  16 +
16 // let gender = req.query.gender || '3,3'; 17 // let gender = req.query.gender || '3,3';
17 18
18 myCurrencyModel.myCurrency(uid, contentCode).then(result => { 19 myCurrencyModel.myCurrency(uid, contentCode).then(result => {
  1 +/**
  2 +* 个人中心意见反馈
  3 +* @author: zxr<xiaoru.zhang@yoho.cn>
  4 +* @date: 2016/09/01
  5 +*/
  6 +
  7 +'use strict';
  8 +
  9 +const suggestModel = require('../models/suggest');
  10 +const headerModel = require('../../../doraemon/models/header'); // 头部model
  11 +const _ = require('lodash');
  12 +
  13 +const suggestData = (req, res, next) => {
  14 + let udid = req.sessionID || 'yoho';
  15 + let page = req.query.page || 1;
  16 + let limit = 10;
  17 +
  18 + suggestModel.suggestData(udid, page, limit).then((result) => {
  19 +
  20 + res.render('suggest', {
  21 + module: 'home',
  22 + page: 'suggest',
  23 + pageHeader: _.assign(headerModel.setNav({
  24 + navTitle: '有货币'
  25 + }), {
  26 + navBtn: false
  27 + }),
  28 + title: '意见反馈',
  29 + pageFooter: true,
  30 + suggestContent: result
  31 + });
  32 + }).catch(next);
  33 +};
  34 +
  35 +const upAndDown = (req, res, next) => {
  36 + let uid = req.user.uid || 8039759;
  37 + let udid = req.sessionID || 'yoho';
  38 + let reliable = req.body.reliable || 1;
  39 + let suggestId = req.body.suggest_id;
  40 +
  41 + suggestModel.upAndDown(uid, udid, reliable, suggestId).then((result) => {
  42 +
  43 + res.json(result);
  44 + }).catch(next);
  45 +};
  46 +
  47 +const suggestSub = (req, res) => {
  48 + res.render('suggest-sub', {
  49 + module: 'home',
  50 + page: 'suggest',
  51 + pageHeader: _.assign(headerModel.setNav({
  52 + navTitle: '反馈问题'
  53 + }), {
  54 + navBtn: false,
  55 + suggestSub: true
  56 + }),
  57 + title: '反馈问题',
  58 + pageFooter: true
  59 + });
  60 +};
  61 +
  62 +const saveSuggest = (req, res, next) => {
  63 + let uid = req.user.uid || 8039759;
  64 + let content = req.body.content;
  65 + let image = req.body.image;
  66 + let suggestType = req.body.suggest_type || 2;
  67 +
  68 + suggestModel.saveSuggest(uid, content, image, suggestType).then((result) => {
  69 +
  70 + res.json(result);
  71 + }).catch(next);
  72 +};
  73 +
  74 +// const suggestimgUpload = (req, res, next) => {
  75 +
  76 +// suggestModel.suggestimgUpload('fileData').then((result) => {
  77 +
  78 +// res.json(result);
  79 +// }).catch(next);
  80 +// };
  81 +
  82 +module.exports = {
  83 + suggestData,
  84 + upAndDown,
  85 + suggestSub,
  86 + saveSuggest
  87 + // suggestimgUpload
  88 +};
@@ -28,6 +28,6 @@ exports.getHelpDetail = (code) => { @@ -28,6 +28,6 @@ exports.getHelpDetail = (code) => {
28 code: code, 28 code: code,
29 }).then(result => { 29 }).then(result => {
30 return result.replace(/^<!DOCTYPE.*<body>/g, ''). 30 return result.replace(/^<!DOCTYPE.*<body>/g, '').
31 - replace(/<\/body>.*<\/html>/g, ''); 31 + replace(/<\/body>.*<\/html>/g, '');
32 }); 32 });
33 }; 33 };
@@ -15,7 +15,7 @@ const yohoCoin = (uid) => { @@ -15,7 +15,7 @@ const yohoCoin = (uid) => {
15 if (result && result.code === 200) { 15 if (result && result.code === 200) {
16 return camelCase(result.data); 16 return camelCase(result.data);
17 } else { 17 } else {
18 - logger.error('youho币总数 cood 不是 200'); 18 + logger.error('youhocoin cood 不是 200');
19 } 19 }
20 }); 20 });
21 }; 21 };
@@ -79,7 +79,7 @@ const currencyDetail = (uid, page, limit) => { @@ -79,7 +79,7 @@ const currencyDetail = (uid, page, limit) => {
79 } 79 }
80 80
81 } else { 81 } else {
82 - logger.error('youho币列表 cood 不是 200'); 82 + logger.error('youholist cood 不是 200');
83 } 83 }
84 84
85 }); 85 });
  1 +/**
  2 +* 个人中心意见反馈
  3 +* @author: zxr<xiaoru.zhang@yoho.cn>
  4 +* @date: 2016/09/01
  5 +*/
  6 +
  7 +'use strict';
  8 +
  9 +const logger = global.yoho.logger;
  10 +const api = global.yoho.API;
  11 +const serviceAPI = global.yoho.ServiceAPI;
  12 +const camelCase = global.yoho.camelCase;
  13 +const _ = require('lodash');
  14 +const config = global.yoho.config;
  15 +const helpers = global.yoho.helpers;
  16 +
  17 +const suggestData = (udid, page, limit) => {
  18 +
  19 + return serviceAPI.get('suggest/api/v1/suggest/getList', {
  20 + udid: udid,
  21 + page: page,
  22 + limit: limit
  23 + }).then((result) => {
  24 + //console.log(result)
  25 + if(result && result.code === 200) {
  26 + _.forEach(result.data.list, function(data) {
  27 +
  28 + data = _.assign(data, {
  29 + good: data.is_reliable === 1,
  30 + bad: data.is_reliable === 2,
  31 + none: data.is_reliable === 0
  32 + })
  33 + })
  34 +
  35 + return camelCase(result.data.list)
  36 + } else {
  37 + logger.error('收藏商品 cood 不是 200');
  38 + }
  39 + });
  40 +};
  41 +
  42 +const upAndDown = (uid, udid, reliable, suggestId) => {
  43 +
  44 + return serviceAPI.get('suggest/api/v1/suggest/is_reliable', {
  45 + uid: uid,
  46 + udid: udid,
  47 + is_reliable: reliable,
  48 + suggest_id: suggestId
  49 + });
  50 +};
  51 +
  52 +//提交
  53 +const saveSuggest = (uid, content, image, suggestType) => {
  54 +
  55 + let per = {
  56 + uid: uid,
  57 + content: content,
  58 + suggest_type: suggestType
  59 + };
  60 +
  61 + if (image !== null) {
  62 + per.image = image;
  63 + }
  64 +
  65 + return serviceAPI.get('suggest/api/v1/suggest/saveSuggest', per);
  66 +}
  67 +
  68 +//图片上传
  69 +// const suggestimgUpload = (name) => {
  70 +
  71 +
  72 +// };
  73 +
  74 +
  75 +module.exports = {
  76 + suggestData,
  77 + upAndDown,
  78 + saveSuggest
  79 + // suggestimgUpload
  80 +};
@@ -19,6 +19,7 @@ const orderDetailController = require(`${cRoot}/orderDetail`); @@ -19,6 +19,7 @@ const orderDetailController = require(`${cRoot}/orderDetail`);
19 const currencyController = require(`${cRoot}/myCurrency`); 19 const currencyController = require(`${cRoot}/myCurrency`);
20 const coupons = require(`${cRoot}/coupons`); 20 const coupons = require(`${cRoot}/coupons`);
21 const help = require(`${cRoot}/help`); 21 const help = require(`${cRoot}/help`);
  22 +const suggest = require(`${cRoot}/suggest`);
22 23
23 // const myDetail = require(`${cRoot}/myDetail); 24 // const myDetail = require(`${cRoot}/myDetail);
24 25
@@ -75,4 +76,11 @@ router.post('/couponData', coupons.couponData); @@ -75,4 +76,11 @@ router.post('/couponData', coupons.couponData);
75 router.get('/help', help.index); 76 router.get('/help', help.index);
76 router.get('/helpDetail', help.helpDetail); 77 router.get('/helpDetail', help.helpDetail);
77 78
78 -module.exports = router;  
  79 +//意见反馈
  80 +router.get('/suggest', suggest.suggestData);
  81 +router.post('/upAndDown', suggest.upAndDown);
  82 +router.get('/suggestSub', suggest.suggestSub);
  83 +router.post('/savesuggest', suggest.saveSuggest);
  84 +// router.post('/suggestimgUpload', suggestimgUpload);
  85 +
  86 +module.exports = router;
@@ -27,7 +27,6 @@ @@ -27,7 +27,6 @@
27 {{/ banner}} 27 {{/ banner}}
28 </div> 28 </div>
29 29
30 -  
31 {{> home/maybe-like}} 30 {{> home/maybe-like}}
32 31
33 </div> 32 </div>
  1 +<div class="yoho-suggest-sub-page yoho-page">
  2 + <div class="suggest-sub-form">
  3 + <textarea name="" id="suggest-textarea" placeholder="请输入意见反馈,我们会以消息形式回复您的建议或意见,改进产品体验,谢谢!"></textarea>
  4 + <div id="img-form" class="img-form">
  5 + <ul class="upload-img-list"></ul>
  6 + <span class="img-add">
  7 + <input id="upload-img" type="file" />
  8 + </span>
  9 + </div>
  10 + </div>
  11 +</div>
  1 +<div class="yoho-suggest-page yoho-page">
  2 + {{!-- {{# suggest}} --}}
  3 + <h2 class="suggest-header">
  4 + 为了更好的改进我们的服务,提升用户体验,<br />
  5 + 我们希望了解您的意见和建议
  6 + </h2>
  7 +
  8 + <div class="create-new-suggest tap-hightlight">
  9 + <a class="list-item" href="./suggestSub">
  10 + 反馈问题 (功能意见,界面意见)<span class="iconfont new-right">&#xe604;</span>
  11 + </a>
  12 + </div>
  13 +
  14 + <div class="suggest-content" id="suggest-content">
  15 + {{# suggestContent}}
  16 + <div class="suggest-item" data-id="{{id}}">
  17 + {{#if coverImage}}
  18 + <div class="suggest-item-img">
  19 + <img class="lazy" data-original="{{coverImage}}" alt=""/>
  20 + </div>
  21 + {{/if}}
  22 + <h2>{{filterContent}}</h2>
  23 + <p>{{replyContent}}</p>
  24 +
  25 + <div class="suggest-type suggest-good {{#good}}show{{/good}}">
  26 + <div class="active tap-hightlight">
  27 + <span class="iconfont">&#xe601;</span>
  28 + <span>靠谱,谢谢您的反馈</span>
  29 + </div>
  30 + </div>
  31 + <div class="suggest-type suggest-bad {{# bad}}show{{/ bad}}">
  32 + <div class="active tap-hightlight">
  33 + <span class="iconfont">&#xe601;</span>
  34 + <span>不靠谱,谢谢您的反馈</span>
  35 + </div>
  36 + </div>
  37 +
  38 + {{# none}}
  39 + <div class="suggest-type suggest-active show">
  40 + <div class="like-btn">
  41 + <span class="iconfont">&#xe601;</span>
  42 + <span>靠谱</span>
  43 + </div>
  44 + <div class="dislike-btn">
  45 + <span class="iconfont">&#xe601;</span>
  46 + <span>不靠谱</span>
  47 + </div>
  48 + </div>
  49 + {{/ none}}
  50 + </div>
  51 +
  52 + {{/ suggestContent}}
  53 + </div>
  54 + {{!-- {{/ suggest}} --}}
  55 +</div>
@@ -22,6 +22,9 @@ @@ -22,6 +22,9 @@
22 {{#navTitle}} 22 {{#navTitle}}
23 <p class="nav-title">{{.}}</p> 23 <p class="nav-title">{{.}}</p>
24 {{/navTitle}} 24 {{/navTitle}}
  25 + {{#suggestSub}}
  26 + <span class="nav-btn">提交</span>
  27 + {{/suggestSub}}
25 {{#saleNav}} 28 {{#saleNav}}
26 <span class="sale-nav nav-home"> 29 <span class="sale-nav nav-home">
27 {{channel}} <span class="iconfont">&#xe616;</span> 30 {{channel}} <span class="iconfont">&#xe616;</span>
@@ -28,7 +28,7 @@ var couponAJAX = function(statu, page) { @@ -28,7 +28,7 @@ var couponAJAX = function(statu, page) {
28 page: page 28 page: page
29 }, 29 },
30 success: function(data) { 30 success: function(data) {
31 - if(!data){ 31 + if (!data) {
32 AjaxFlag = 1; 32 AjaxFlag = 1;
33 window.rePosFooter(); 33 window.rePosFooter();
34 loading.hideLoadingMask(); 34 loading.hideLoadingMask();
  1 +/*
  2 +UploadiFive 1.2.2
  3 +Copyright (c) 2012 Reactive Apps, Ronnie Garcia
  4 +Released under the UploadiFive Standard License <http://www.uploadify.com/uploadifive-standard-license>
  5 +*/
  6 +
  7 +var jQuery = require('yoho-jquery');
  8 +
  9 +;(function($) {
  10 +
  11 + var methods = {
  12 +
  13 + init : function(options) {
  14 +
  15 + return this.each(function() {
  16 +
  17 + // Create a reference to the jQuery DOM object
  18 + var $this = $(this);
  19 + $this.data('uploadifive', {
  20 + inputs : {}, // The object that contains all the file inputs
  21 + inputCount : 0, // The total number of file inputs created
  22 + fileID : 0,
  23 + queue : {
  24 + count : 0, // Total number of files in the queue
  25 + selected : 0, // Number of files selected in the last select operation
  26 + replaced : 0, // Number of files replaced in the last select operation
  27 + errors : 0, // Number of files that returned an error in the last select operation
  28 + queued : 0, // Number of files added to the queue in the last select operation
  29 + cancelled : 0 // Total number of files that have been cancelled or removed from the queue
  30 + },
  31 + uploads : {
  32 + current : 0, // Number of files currently being uploaded
  33 + attempts : 0, // Number of file uploads attempted in the last upload operation
  34 + successful : 0, // Number of files successfully uploaded in the last upload operation
  35 + errors : 0, // Number of files returning errors in the last upload operation
  36 + count : 0 // Total number of files uploaded successfully
  37 + }
  38 + });
  39 + var $data = $this.data('uploadifive');
  40 +
  41 + // Set the default options
  42 + var settings = $data.settings = $.extend({
  43 + 'auto' : true, // Automatically upload a file when it's added to the queue
  44 + 'buttonClass' : false, // A class to add to the UploadiFive button
  45 + 'buttonText' : 'Select Files', // The text that appears on the UploadiFive button
  46 + 'checkScript' : false, // Path to the script that checks for existing file names
  47 + 'dnd' : true, // Allow drag and drop into the queue
  48 + 'dropTarget' : false, // Selector for the drop target
  49 + 'fileObjName' : 'Filedata', // The name of the file object to use in your server-side script
  50 + 'fileSizeLimit' : 0, // Maximum allowed size of files to upload
  51 + 'fileType' : false, // Type of files allowed (image, etc), separate with a pipe character |
  52 + 'formData' : {}, // Additional data to send to the upload script
  53 + 'height' : 30, // The height of the button
  54 + 'itemTemplate' : false, // The HTML markup for the item in the queue
  55 + 'method' : 'post', // The method to use when submitting the upload
  56 + 'multi' : true, // Set to true to allow multiple file selections
  57 + 'overrideEvents' : [], // An array of events to override
  58 + 'queueID' : false, // The ID of the file queue
  59 + 'queueSizeLimit' : 0, // The maximum number of files that can be in the queue
  60 + 'removeCompleted' : false, // Set to true to remove files that have completed uploading
  61 + 'simUploadLimit' : 0, // The maximum number of files to upload at once
  62 + 'truncateLength' : 0, // The length to truncate the file names to
  63 + 'uploadLimit' : 0, // The maximum number of files you can upload
  64 + 'uploadScript' : 'uploadifive.php', // The path to the upload script
  65 + 'width' : 100 // The width of the button
  66 +
  67 + /*
  68 + // Events
  69 + 'onAddQueueItem' : function(file) {}, // Triggered for each file that is added to the queue
  70 + 'onCancel' : function(file) {}, // Triggered when a file is cancelled or removed from the queue
  71 + 'onCheck' : function(file, exists) {}, // Triggered when the server is checked for an existing file
  72 + 'onClearQueue' : function(queue) {}, // Triggered during the clearQueue function
  73 + 'onDestroy' : function() {} // Triggered during the destroy function
  74 + 'onDrop' : function(files, numberOfFilesDropped) {}, // Triggered when files are dropped into the file queue
  75 + 'onError' : function(file, fileType, data) {}, // Triggered when an error occurs
  76 + 'onFallback' : function() {}, // Triggered if the HTML5 File API is not supported by the browser
  77 + 'onInit' : function() {}, // Triggered when UploadiFive if initialized
  78 + 'onQueueComplete' : function() {}, // Triggered once when an upload queue is done
  79 + 'onProgress' : function(file, event) {}, // Triggered during each progress update of an upload
  80 + 'onSelect' : function() {}, // Triggered once when files are selected from a dialog box
  81 + 'onUpload' : function(file) {}, // Triggered when an upload queue is started
  82 + 'onUploadComplete' : function(file, data) {}, // Triggered when a file is successfully uploaded
  83 + 'onUploadFile' : function(file) {}, // Triggered for each file being uploaded
  84 + */
  85 + }, options);
  86 +
  87 + // Calculate the file size limit
  88 + if (isNaN(settings.fileSizeLimit)) {
  89 + var fileSizeLimitBytes = parseInt(settings.fileSizeLimit) * 1.024
  90 + if (settings.fileSizeLimit.indexOf('KB') > -1) {
  91 + settings.fileSizeLimit = fileSizeLimitBytes * 1000;
  92 + } else if (settings.fileSizeLimit.indexOf('MB') > -1) {
  93 + settings.fileSizeLimit = fileSizeLimitBytes * 1000000;
  94 + } else if (settings.fileSizeLimit.indexOf('GB') > -1) {
  95 + settings.fileSizeLimit = fileSizeLimitBytes * 1000000000;
  96 + }
  97 + } else {
  98 + settings.fileSizeLimit = settings.fileSizeLimit * 1024;
  99 + }
  100 +
  101 + // Create a template for a file input
  102 + $data.inputTemplate = $('<input type="file">')
  103 + .css({
  104 + 'font-size' : settings.height + 'px',
  105 + 'opacity' : 0,
  106 + 'position' : 'absolute',
  107 + 'right' : '-3px',
  108 + 'top' : '-3px',
  109 + 'z-index' : 999
  110 + });
  111 +
  112 + // Create a new input
  113 + $data.createInput = function() {
  114 +
  115 + // Create a clone of the file input
  116 + var input = $data.inputTemplate.clone();
  117 + // Create a unique name for the input item
  118 + var inputName = input.name = 'input' + $data.inputCount++;
  119 + // Set the multiple attribute
  120 + if (settings.multi) {
  121 + input.attr('multiple', true);
  122 + }
  123 + // Set the accept attribute on the input
  124 + if (settings.fileType) {
  125 + input.attr('accept', settings.fileType);
  126 + }
  127 + // Set the onchange event for the input
  128 + input.bind('change', function() {
  129 + $data.queue.selected = 0;
  130 + $data.queue.replaced = 0;
  131 + $data.queue.errors = 0;
  132 + $data.queue.queued = 0;
  133 + // Add a queue item to the queue for each file
  134 + var limit = this.files.length;
  135 + $data.queue.selected = limit;
  136 + if (($data.queue.count + limit) > settings.queueSizeLimit && settings.queueSizeLimit !== 0) {
  137 + if ($.inArray('onError', settings.overrideEvents) < 0) {
  138 + alert('The maximum number of queue items has been reached (' + settings.queueSizeLimit + '). Please select fewer files.');
  139 + }
  140 + // Trigger the error event
  141 + if (typeof settings.onError === 'function') {
  142 + settings.onError.call($this, 'QUEUE_LIMIT_EXCEEDED');
  143 + }
  144 + } else {
  145 + for (var n = 0; n < limit; n++) {
  146 + file = this.files[n];
  147 + $data.addQueueItem(file);
  148 + }
  149 + $data.inputs[inputName] = this;
  150 + $data.createInput();
  151 + }
  152 + // Upload the file if auto-uploads are enabled
  153 + if (settings.auto) {
  154 + methods.upload.call($this);
  155 + }
  156 + // Trigger the select event
  157 + if (typeof settings.onSelect === 'function') {
  158 + settings.onSelect.call($this, $data.queue);
  159 + }
  160 + });
  161 + // Hide the existing current item and add the new one
  162 + if ($data.currentInput) {
  163 + $data.currentInput.hide();
  164 + }
  165 + $data.button.append(input);
  166 + $data.currentInput = input;
  167 + }
  168 +
  169 + // Remove an input
  170 + $data.destroyInput = function(key) {
  171 + $($data.inputs[key]).remove();
  172 + delete $data.inputs[key];
  173 + $data.inputCount--;
  174 + }
  175 +
  176 + // Drop a file into the queue
  177 + $data.drop = function(e) {
  178 + $data.queue.selected = 0;
  179 + $data.queue.replaced = 0;
  180 + $data.queue.errors = 0;
  181 + $data.queue.queued = 0;
  182 +
  183 + var fileData = e.dataTransfer;
  184 +
  185 + var inputName = fileData.name = 'input' + $data.inputCount++;
  186 + // Add a queue item to the queue for each file
  187 + var limit = fileData.files.length;
  188 + $data.queue.selected = limit;
  189 + if (($data.queue.count + limit) > settings.queueSizeLimit && settings.queueSizeLimit !== 0) {
  190 + // Check if the queueSizeLimit was reached
  191 + if ($.inArray('onError', settings.overrideEvents) < 0) {
  192 + alert('The maximum number of queue items has been reached (' + settings.queueSizeLimit + '). Please select fewer files.');
  193 + }
  194 + // Trigger the onError event
  195 + if (typeof settings.onError === 'function') {
  196 + settings.onError.call($this, 'QUEUE_LIMIT_EXCEEDED');
  197 + }
  198 + } else {
  199 + // Add a queue item for each file
  200 + for (var n = 0; n < limit; n++) {
  201 + file = fileData.files[n];
  202 + $data.addQueueItem(file);
  203 + }
  204 + // Save the data to the inputs object
  205 + $data.inputs[inputName] = fileData;
  206 + }
  207 +
  208 + // Upload the file if auto-uploads are enabled
  209 + if (settings.auto) {
  210 + methods.upload.call($this);
  211 + }
  212 +
  213 + // Trigger the onDrop event
  214 + if (typeof settings.onDrop === 'function') {
  215 + settings.onDrop.call($this, fileData.files, fileData.files.length);
  216 + }
  217 +
  218 + // Stop FireFox from opening the dropped file(s)
  219 + e.preventDefault();
  220 + e.stopPropagation();
  221 + }
  222 +
  223 + // Check if a filename exists in the queue
  224 + $data.fileExistsInQueue = function(file) {
  225 + for (var key in $data.inputs) {
  226 + input = $data.inputs[key];
  227 + limit = input.files.length;
  228 + for (var n = 0; n < limit; n++) {
  229 + existingFile = input.files[n];
  230 + // Check if the filename matches
  231 + if (existingFile.name == file.name && !existingFile.complete) {
  232 + return true;
  233 + }
  234 + }
  235 + }
  236 + return false;
  237 + }
  238 +
  239 + // Remove an existing file in the queue
  240 + $data.removeExistingFile = function(file) {
  241 + for (var key in $data.inputs) {
  242 + input = $data.inputs[key];
  243 + limit = input.files.length;
  244 + for (var n = 0; n < limit; n++) {
  245 + existingFile = input.files[n];
  246 + // Check if the filename matches
  247 + if (existingFile.name == file.name && !existingFile.complete) {
  248 + $data.queue.replaced++;
  249 + methods.cancel.call($this, existingFile, true);
  250 + }
  251 + }
  252 + }
  253 + }
  254 +
  255 + // Create the file item template
  256 + if (settings.itemTemplate == false) {
  257 + $data.queueItem = $('<div class="uploadifive-queue-item">\
  258 + <a class="close" href="#">X</a>\
  259 + <div><span class="filename"></span><span class="fileinfo"></span></div>\
  260 + <div class="progress">\
  261 + <div class="progress-bar"></div>\
  262 + </div>\
  263 + </div>');
  264 + } else {
  265 + $data.queueItem = $(settings.itemTemplate);
  266 + }
  267 +
  268 + // Add an item to the queue
  269 + $data.addQueueItem = function(file) {
  270 + if ($.inArray('onAddQueueItem', settings.overrideEvents) < 0) {
  271 + // Check if the filename already exists in the queue
  272 + $data.removeExistingFile(file);
  273 + // Create a clone of the queue item template
  274 + file.queueItem = $data.queueItem.clone();
  275 + // Add an ID to the queue item
  276 + file.queueItem.attr('id', settings.id + '-file-' + $data.fileID++);
  277 + // Bind the close event to the close button
  278 + file.queueItem.find('.close').bind('click', function() {
  279 + methods.cancel.call($this, file);
  280 + return false;
  281 + });
  282 + var fileName = file.name;
  283 + if (fileName.length > settings.truncateLength && settings.truncateLength != 0) {
  284 + fileName = fileName.substring(0, settings.truncateLength) + '...';
  285 + }
  286 + file.queueItem.find('.filename').html(fileName);
  287 + // Add a reference to the file
  288 + file.queueItem.data('file', file);
  289 + $data.queueEl.append(file.queueItem);
  290 + }
  291 + // Trigger the addQueueItem event
  292 + if (typeof settings.onAddQueueItem === 'function') {
  293 + settings.onAddQueueItem.call($this, file);
  294 + }
  295 + // Check the filesize
  296 + if (file.size > settings.fileSizeLimit && settings.fileSizeLimit != 0) {
  297 + $data.error('FILE_SIZE_LIMIT_EXCEEDED', file);
  298 + } else {
  299 + $data.queue.queued++;
  300 + $data.queue.count++;
  301 + }
  302 + }
  303 +
  304 + // Remove an item from the queue
  305 + $data.removeQueueItem = function(file, instant, delay) {
  306 + // Set the default delay
  307 + if (!delay) delay = 0;
  308 + var fadeTime = instant ? 0 : 500;
  309 + if (file.queueItem) {
  310 + if (file.queueItem.find('.fileinfo').html() != ' - Completed') {
  311 + file.queueItem.find('.fileinfo').html(' - Cancelled');
  312 + }
  313 + file.queueItem.find('.progress-bar').width(0);
  314 + file.queueItem.delay(delay).fadeOut(fadeTime, function() {
  315 + $(this).remove();
  316 + });
  317 + delete file.queueItem;
  318 + $data.queue.count--;
  319 + }
  320 + }
  321 +
  322 + // Count the number of files that need to be uploaded
  323 + $data.filesToUpload = function() {
  324 + var filesToUpload = 0;
  325 + for (var key in $data.inputs) {
  326 + input = $data.inputs[key];
  327 + limit = input.files.length;
  328 + for (var n = 0; n < limit; n++) {
  329 + file = input.files[n];
  330 + if (!file.skip && !file.complete) {
  331 + filesToUpload++;
  332 + }
  333 + }
  334 + }
  335 + return filesToUpload;
  336 + }
  337 +
  338 + // Check if a file exists
  339 + $data.checkExists = function(file) {
  340 + if ($.inArray('onCheck', settings.overrideEvents) < 0) {
  341 + // This request needs to be synchronous
  342 + $.ajaxSetup({
  343 + 'async' : false
  344 + });
  345 + // Send the filename to the check script
  346 + var checkData = $.extend(settings.formData, {filename: file.name});
  347 + $.post(settings.checkScript, checkData, function(fileExists) {
  348 + file.exists = parseInt(fileExists);
  349 + });
  350 + if (file.exists) {
  351 + if (!confirm('A file named ' + file.name + ' already exists in the upload folder.\nWould you like to replace it?')) {
  352 + // If not replacing the file, cancel the upload
  353 + methods.cancel.call($this, file);
  354 + return true;
  355 + }
  356 + }
  357 + }
  358 + // Trigger the check event
  359 + if (typeof settings.onCheck === 'function') {
  360 + settings.onCheck.call($this, file, file.exists);
  361 + }
  362 + return false;
  363 + }
  364 +
  365 + // Upload a single file
  366 + $data.uploadFile = function(file, uploadAll) {
  367 + if (!file.skip && !file.complete && !file.uploading) {
  368 + file.uploading = true;
  369 + $data.uploads.current++;
  370 + $data.uploads.attempted++;
  371 +
  372 + // Create a new AJAX request
  373 + xhr = file.xhr = new XMLHttpRequest();
  374 +
  375 + // Start the upload
  376 + // Use the faster FormData if it exists
  377 + if (typeof FormData === 'function' || typeof FormData === 'object') {
  378 +
  379 + // Create a new FormData object
  380 + var formData = new FormData();
  381 +
  382 + // Add the form data
  383 + formData.append(settings.fileObjName, file);
  384 +
  385 + // Add the rest of the formData
  386 + for (i in settings.formData) {
  387 + formData.append(i, settings.formData[i]);
  388 + }
  389 +
  390 + // Open the AJAX call
  391 + xhr.open(settings.method, settings.uploadScript, true);
  392 +
  393 + // On progress function
  394 + xhr.upload.addEventListener('progress', function(e) {
  395 + if (e.lengthComputable) {
  396 + $data.progress(e, file);
  397 + }
  398 + }, false);
  399 +
  400 + // On complete function
  401 + xhr.addEventListener('load', function(e) {
  402 + if (this.readyState == 4) {
  403 + file.uploading = false;
  404 + if (this.status == 200) {
  405 + if (file.xhr.responseText !== 'Invalid file type.') {
  406 + $data.uploadComplete(e, file, uploadAll);
  407 + } else {
  408 + $data.error(file.xhr.responseText, file, uploadAll);
  409 + }
  410 + } else if (this.status == 404) {
  411 + $data.error('404_FILE_NOT_FOUND', file, uploadAll);
  412 + } else if (this.status == 403) {
  413 + $data.error('403_FORBIDDEN', file, uploadAll);
  414 + } else {
  415 + $data.error('Unknown Error', file, uploadAll);
  416 + }
  417 + }
  418 + });
  419 +
  420 + // Send the form data (multipart/form-data)
  421 + xhr.send(formData);
  422 +
  423 + } else {
  424 +
  425 + // Send as binary
  426 + var reader = new FileReader();
  427 + reader.onload = function(e) {
  428 +
  429 + // Set some file builder variables
  430 + var boundary = '-------------------------' + (new Date).getTime(),
  431 + dashes = '--',
  432 + eol = '\r\n',
  433 + binFile = '';
  434 +
  435 + // Build an RFC2388 String
  436 + binFile += dashes + boundary + eol;
  437 + // Generate the headers
  438 + binFile += 'Content-Disposition: form-data; name="' + settings.fileObjName + '"';
  439 + if (file.name) {
  440 + binFile += '; filename="' + file.name + '"';
  441 + }
  442 + binFile += eol;
  443 + binFile += 'Content-Type: application/octet-stream' + eol + eol;
  444 + binFile += e.target.result + eol;
  445 +
  446 + for (key in settings.formData) {
  447 + binFile += dashes + boundary + eol;
  448 + binFile += 'Content-Disposition: form-data; name="' + key + '"' + eol + eol;
  449 + binFile += settings.formData[key] + eol;
  450 + }
  451 +
  452 + binFile += dashes + boundary + dashes + eol;
  453 +
  454 + // On progress function
  455 + xhr.upload.addEventListener('progress', function(e) {
  456 + $data.progress(e, file);
  457 + }, false);
  458 +
  459 + // On complete function
  460 + xhr.addEventListener('load', function(e) {
  461 + file.uploading = false;
  462 + var status = this.status;
  463 + if (status == 404) {
  464 + $data.error('404_FILE_NOT_FOUND', file, uploadAll);
  465 + } else {
  466 + if (file.xhr.responseText != 'Invalid file type.') {
  467 + $data.uploadComplete(e, file, uploadAll);
  468 + } else {
  469 + $data.error(file.xhr.responseText, file, uploadAll);
  470 + }
  471 + }
  472 + }, false);
  473 +
  474 + // Open the ajax request
  475 + var url = settings.uploadScript;
  476 + if (settings.method == 'get') {
  477 + var params = $(settings.formData).param();
  478 + url += params;
  479 + }
  480 + xhr.open(settings.method, settings.uploadScript, true);
  481 + xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
  482 +
  483 + // Trigger the uploadFile event
  484 + if (typeof settings.onUploadFile === 'function') {
  485 + settings.onUploadFile.call($this, file);
  486 + }
  487 +
  488 + // Send the file for upload
  489 + xhr.sendAsBinary(binFile);
  490 + }
  491 + reader.readAsBinaryString(file);
  492 +
  493 + }
  494 + }
  495 + }
  496 +
  497 + // Update a file upload's progress
  498 + $data.progress = function(e, file) {
  499 + if ($.inArray('onProgress', settings.overrideEvents) < 0) {
  500 + if (e.lengthComputable) {
  501 + var percent = Math.round((e.loaded / e.total) * 100);
  502 + }
  503 + file.queueItem.find('.fileinfo').html(' - ' + percent + '%');
  504 + file.queueItem.find('.progress-bar').css('width', percent + '%');
  505 + }
  506 + // Trigger the progress event
  507 + if (typeof settings.onProgress === 'function') {
  508 + settings.onProgress.call($this, file, e);
  509 + }
  510 + }
  511 +
  512 + // Trigger an error
  513 + $data.error = function(errorType, file, uploadAll) {
  514 + if ($.inArray('onError', settings.overrideEvents) < 0) {
  515 + // Get the error message
  516 + switch(errorType) {
  517 + case '404_FILE_NOT_FOUND':
  518 + errorMsg = '404 Error';
  519 + break;
  520 + case '403_FORBIDDEN':
  521 + errorMsg = '403 Forbidden';
  522 + break;
  523 + case 'FORBIDDEN_FILE_TYPE':
  524 + errorMsg = 'Forbidden File Type';
  525 + break;
  526 + case 'FILE_SIZE_LIMIT_EXCEEDED':
  527 + errorMsg = 'File Too Large';
  528 + break;
  529 + default:
  530 + errorMsg = 'Unknown Error';
  531 + break;
  532 + }
  533 +
  534 + // Add the error class to the queue item
  535 + file.queueItem.addClass('error')
  536 + // Output the error in the queue item
  537 + .find('.fileinfo').html(' - ' + errorMsg);
  538 + // Hide the
  539 + file.queueItem.find('.progress').remove();
  540 + }
  541 + // Trigger the error event
  542 + if (typeof settings.onError === 'function') {
  543 + settings.onError.call($this, errorType, file);
  544 + }
  545 + file.skip = true;
  546 + if (errorType == '404_FILE_NOT_FOUND') {
  547 + $data.uploads.errors++;
  548 + } else {
  549 + $data.queue.errors++;
  550 + }
  551 + if (uploadAll) {
  552 + methods.upload.call($this, null, true);
  553 + }
  554 + }
  555 +
  556 + // Trigger when a single file upload is complete
  557 + $data.uploadComplete = function(e, file, uploadAll) {
  558 + if ($.inArray('onUploadComplete', settings.overrideEvents) < 0) {
  559 + file.queueItem.find('.progress-bar').css('width', '100%');
  560 + file.queueItem.find('.fileinfo').html(' - Completed');
  561 + file.queueItem.find('.progress').slideUp(250);
  562 + file.queueItem.addClass('complete');
  563 + }
  564 + // Trigger the complete event
  565 + if (typeof settings.onUploadComplete === 'function') {
  566 + settings.onUploadComplete.call($this, file, file.xhr.responseText);
  567 + }
  568 + if (settings.removeCompleted) {
  569 + setTimeout(function() { methods.cancel.call($this, file); }, 3000);
  570 + }
  571 + file.complete = true;
  572 + $data.uploads.successful++;
  573 + $data.uploads.count++;
  574 + $data.uploads.current--;
  575 + delete file.xhr;
  576 + if (uploadAll) {
  577 + methods.upload.call($this, null, true);
  578 + }
  579 + }
  580 +
  581 + // Trigger when all the files are done uploading
  582 + $data.queueComplete = function() {
  583 + // Trigger the queueComplete event
  584 + if (typeof settings.onQueueComplete === 'function') {
  585 + settings.onQueueComplete.call($this, $data.uploads);
  586 + }
  587 + }
  588 +
  589 + // ----------------------
  590 + // Initialize UploadiFive
  591 + // ----------------------
  592 +
  593 + // Check if HTML5 is available
  594 + if (window.File && window.FileList && window.Blob && (window.FileReader || window.FormData)) {
  595 + // Assign an ID to the object
  596 + settings.id = 'uploadifive-' + $this.attr('id');
  597 +
  598 + // Wrap the file input in a div with overflow set to hidden
  599 + $data.button = $('<div id="' + settings.id + '" class="uploadifive-button">' + settings.buttonText + '</div>');
  600 + if (settings.buttonClass) $data.button.addClass(settings.buttonClass);
  601 +
  602 + // Style the button wrapper
  603 + $data.button.css({
  604 + 'height' : settings.height,
  605 + 'line-height' : settings.height + 'px',
  606 + 'overflow' : 'hidden',
  607 + 'position' : 'relative',
  608 + 'text-align' : 'center',
  609 + 'width' : settings.width
  610 + });
  611 +
  612 + // Insert the button above the file input
  613 + $this.before($data.button)
  614 + // Add the file input to the button
  615 + .appendTo($data.button)
  616 + // Modify the styles of the file input
  617 + .hide();
  618 +
  619 + // Create a new input
  620 + $data.createInput.call($this);
  621 +
  622 + // Create the queue container
  623 + if (!settings.queueID) {
  624 + settings.queueID = settings.id + '-queue';
  625 + $data.queueEl = $('<div id="' + settings.queueID + '" class="uploadifive-queue" />');
  626 + $data.button.after($data.queueEl);
  627 + } else {
  628 + $data.queueEl = $('#' + settings.queueID);
  629 + }
  630 +
  631 + // Add drag and drop functionality
  632 + if (settings.dnd) {
  633 + var $dropTarget = settings.dropTarget ? $(settings.dropTarget) : $data.queueEl.get(0);
  634 + $dropTarget.addEventListener('dragleave', function(e) {
  635 + // Stop FireFox from opening the dropped file(s)
  636 + e.preventDefault();
  637 + e.stopPropagation();
  638 + }, false);
  639 + $dropTarget.addEventListener('dragenter', function(e) {
  640 + // Stop FireFox from opening the dropped file(s)
  641 + e.preventDefault();
  642 + e.stopPropagation();
  643 + }, false);
  644 + $dropTarget.addEventListener('dragover', function(e) {
  645 + // Stop FireFox from opening the dropped file(s)
  646 + e.preventDefault();
  647 + e.stopPropagation();
  648 + }, false);
  649 + $dropTarget.addEventListener('drop', $data.drop, false);
  650 + }
  651 +
  652 + // Send as binary workaround for Chrome
  653 + if (!XMLHttpRequest.prototype.sendAsBinary) {
  654 + XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
  655 + function byteValue(x) {
  656 + return x.charCodeAt(0) & 0xff;
  657 + }
  658 + var ords = Array.prototype.map.call(datastr, byteValue);
  659 + var ui8a = new Uint8Array(ords);
  660 + this.send(ui8a.buffer);
  661 + }
  662 + }
  663 +
  664 + // Trigger the oninit event
  665 + if (typeof settings.onInit === 'function') {
  666 + settings.onInit.call($this);
  667 + }
  668 +
  669 + } else {
  670 +
  671 + // Trigger the fallback event
  672 + if (typeof settings.onFallback === 'function') {
  673 + settings.onFallback.call($this);
  674 + }
  675 + return false;
  676 +
  677 + }
  678 +
  679 + });
  680 +
  681 + },
  682 +
  683 +
  684 + // Write some data to the console
  685 + debug : function() {
  686 +
  687 + return this.each(function() {
  688 +
  689 + console.log($(this).data('uploadifive'));
  690 +
  691 + });
  692 +
  693 + },
  694 +
  695 + // Clear all the items from the queue
  696 + clearQueue : function() {
  697 +
  698 + this.each(function() {
  699 +
  700 + var $this = $(this),
  701 + $data = $this.data('uploadifive'),
  702 + settings = $data.settings;
  703 +
  704 + for (var key in $data.inputs) {
  705 + input = $data.inputs[key];
  706 + limit = input.files.length;
  707 + for (i = 0; i < limit; i++) {
  708 + file = input.files[i];
  709 + methods.cancel.call($this, file);
  710 + }
  711 + }
  712 + // Trigger the onClearQueue event
  713 + if (typeof settings.onClearQueue === 'function') {
  714 + settings.onClearQueue.call($this, $('#' + $data.settings.queueID));
  715 + }
  716 +
  717 + });
  718 +
  719 + },
  720 +
  721 + // Cancel a file upload in progress or remove a file from the queue
  722 + cancel : function(file, fast) {
  723 +
  724 + this.each(function() {
  725 +
  726 + var $this = $(this),
  727 + $data = $this.data('uploadifive'),
  728 + settings = $data.settings;
  729 +
  730 + // If user passed a queue item ID instead of file...
  731 + if (typeof file === 'string') {
  732 + if (!isNaN(file)) {
  733 + fileID = 'uploadifive-' + $(this).attr('id') + '-file-' + file;
  734 + }
  735 + file = $('#' + fileID).data('file');
  736 + }
  737 +
  738 + file.skip = true;
  739 + $data.filesCancelled++;
  740 + if (file.uploading) {
  741 + $data.uploads.current--;
  742 + file.uploading = false;
  743 + file.xhr.abort();
  744 + delete file.xhr;
  745 + methods.upload.call($this);
  746 + }
  747 + if ($.inArray('onCancel', settings.overrideEvents) < 0) {
  748 + $data.removeQueueItem(file, fast);
  749 + }
  750 +
  751 + // Trigger the cancel event
  752 + if (typeof settings.onCancel === 'function') {
  753 + settings.onCancel.call($this, file);
  754 + }
  755 +
  756 + });
  757 +
  758 + },
  759 +
  760 + // Upload the files in the queue
  761 + upload : function(file, keepVars) {
  762 +
  763 + this.each(function() {
  764 +
  765 + var $this = $(this),
  766 + $data = $this.data('uploadifive'),
  767 + settings = $data.settings;
  768 +
  769 + if (file) {
  770 +
  771 + $data.uploadFile.call($this, file);
  772 +
  773 + } else {
  774 +
  775 + // Check if the upload limit was reached
  776 + if (($data.uploads.count + $data.uploads.current) < settings.uploadLimit || settings.uploadLimit == 0) {
  777 + if (!keepVars) {
  778 + $data.uploads.attempted = 0;
  779 + $data.uploads.successsful = 0;
  780 + $data.uploads.errors = 0;
  781 + var filesToUpload = $data.filesToUpload();
  782 + // Trigger the onUpload event
  783 + if (typeof settings.onUpload === 'function') {
  784 + settings.onUpload.call($this, filesToUpload);
  785 + }
  786 + }
  787 +
  788 + // Loop through the files
  789 + $('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').each(function() {
  790 + _file = $(this).data('file');
  791 + // Check if the simUpload limit was reached
  792 + if (($data.uploads.current >= settings.simUploadLimit && settings.simUploadLimit !== 0) || ($data.uploads.current >= settings.uploadLimit && settings.uploadLimit !== 0) || ($data.uploads.count >= settings.uploadLimit && settings.uploadLimit !== 0)) {
  793 + return false;
  794 + }
  795 + if (settings.checkScript) {
  796 + // Let the loop know that we're already processing this file
  797 + _file.checking = true;
  798 + skipFile = $data.checkExists(_file);
  799 + _file.checking = false;
  800 + if (!skipFile) {
  801 + $data.uploadFile(_file, true);
  802 + }
  803 + } else {
  804 + $data.uploadFile(_file, true);
  805 + }
  806 + });
  807 + if ($('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').size() == 0) {
  808 + $data.queueComplete();
  809 + }
  810 + } else {
  811 + if ($data.uploads.current == 0) {
  812 + if ($.inArray('onError', settings.overrideEvents) < 0) {
  813 + if ($data.filesToUpload() > 0 && settings.uploadLimit != 0) {
  814 + alert('The maximum upload limit has been reached.');
  815 + }
  816 + }
  817 + // Trigger the onError event
  818 + if (typeof settings.onError === 'function') {
  819 + settings.onError.call($this, 'UPLOAD_LIMIT_EXCEEDED', $data.filesToUpload());
  820 + }
  821 + }
  822 + }
  823 +
  824 + }
  825 +
  826 + });
  827 +
  828 + },
  829 +
  830 + // Destroy an instance of UploadiFive
  831 + destroy : function() {
  832 +
  833 + this.each(function() {
  834 +
  835 + var $this = $(this),
  836 + $data = $this.data('uploadifive'),
  837 + settings = $data.settings;
  838 +
  839 + // Clear the queue
  840 + methods.clearQueue.call($this);
  841 + // Destroy the queue if it was created
  842 + if (!settings.queueID) $('#' + settings.queueID).remove();
  843 + // Remove extra inputs
  844 + $this.siblings('input').remove();
  845 + // Show the original file input
  846 + $this.show()
  847 + // Move the file input out of the button
  848 + .insertBefore($data.button);
  849 + // Delete the button
  850 + $data.button.remove();
  851 + // Trigger the destroy event
  852 + if (typeof settings.onDestroy === 'function') {
  853 + settings.onDestroy.call($this);
  854 + }
  855 +
  856 + });
  857 +
  858 + }
  859 +
  860 + }
  861 +
  862 + $.fn.upload = function(method) {
  863 +
  864 + if (methods[method]) {
  865 + return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  866 + } else if (typeof method === 'object' || !method) {
  867 + return methods.init.apply(this, arguments);
  868 + } else {
  869 + $.error('The method ' + method + ' does not exist in $.uploadify');
  870 + }
  871 +
  872 + }
  873 +
  874 +})(jQuery);
  1 +/**
  2 + * 个人中心--意见反馈
  3 + */
  4 +
  5 +var $ = require('yoho-jquery'),
  6 + Hammer = require('yoho-hammer'),
  7 + lazyLoad = require('yoho-jquery-lazyload'),
  8 + Handlebars = require('yoho-handlebars');
  9 +
  10 +var diaLog = require('../plugin/dialog');
  11 +
  12 +var $uploadImgList = $('.upload-img-list'),
  13 + headerNavHammer,
  14 + formHammer,
  15 + imgTpl,
  16 + imgTemplate,
  17 + $likeBtn = $('.suggest-item .like-btn'),
  18 + $disLikeBtn = $('.suggest-item .dislike-btn'),
  19 + $imgAdd = $('.img-add'),
  20 + imgStr = '',
  21 + uploadImgNum = 0;
  22 +
  23 +require('./jquery.upload');
  24 +
  25 +imgTpl = '{{# imgList}}' +
  26 + '<li>' +
  27 + '{{# imgUrl}}<img src="{{.}}" />' +
  28 + '<span class="upload-img-remove"></span>{{/ imgUrl}}' +
  29 + '</li>' +
  30 + '{{/ imgList}}';
  31 +
  32 +imgTemplate = Handlebars.compile(imgTpl);
  33 +
  34 +$('#upload-img').upload({
  35 + auto: true,
  36 + fileType: 'image/*',
  37 + uploadScript: '/home/suggestimgUpload',
  38 + fileObjName: 'fileData',
  39 + fileSizeLimit: 300,
  40 + height: '100%',
  41 + width: '100%',
  42 + multi: false,
  43 + onAddQueueItem: function(files) {
  44 +
  45 + //TODO
  46 + $uploadImgList.html(imgTemplate({
  47 + imgList: true
  48 + }));
  49 + },
  50 + onUploadComplete: function(file, data) {
  51 + $uploadImgList.html('');
  52 + imgStr = JSON.parse(data).imgList[0].imgRelUrl;
  53 + $uploadImgList.html(imgTemplate(JSON.parse(data)));
  54 + $imgAdd.hide();
  55 + uploadImgNum++;
  56 + }
  57 +});
  58 +
  59 +lazyLoad();
  60 +
  61 +headerNavHammer = new Hammer(document.getElementById('yoho-header'));
  62 +
  63 +headerNavHammer.on('tap', function(e) {
  64 + var suggestText = $('#suggest-textarea').val(),
  65 + textReg = /\S+/;
  66 +
  67 +
  68 + if ($(e.target).hasClass('nav-btn')) {
  69 +
  70 + if (!textReg.test(suggestText)) {
  71 + diaLog.showDialog({
  72 + autoHide: true,
  73 + dialogText: '意见不能为空'
  74 + });
  75 +
  76 + return;
  77 + }
  78 +
  79 + $.ajax({
  80 + method: 'post',
  81 + url: '/home/savesuggest',
  82 + data: {
  83 + content: suggestText,
  84 + image: imgStr
  85 + }
  86 + }).then(function(data) {
  87 + if (data.code === 200) {
  88 + diaLog.showDialog({
  89 + autoHide: true,
  90 + dialogText: '提交成功'
  91 + });
  92 + setTimeout(function() {
  93 + location.pathname = 'home/suggest';
  94 + }, 2000);
  95 + } else {
  96 + diaLog.showDialog({
  97 + autoHide: true,
  98 + dialogText: '提交失败~'
  99 + });
  100 + }
  101 + }).fail(function() {
  102 +
  103 + diaLog.showDialog({
  104 + autoHide: true,
  105 + dialogText: '网络错误~'
  106 + });
  107 + });
  108 + }
  109 +});
  110 +
  111 +if (document.getElementById('img-form') !== null) {
  112 + formHammer = new Hammer(document.getElementById('img-form'));
  113 +
  114 + formHammer.on('tap', function(e) {
  115 + if ($(e.target).hasClass('upload-img-remove')) {
  116 + $uploadImgList.html('');
  117 + imgStr = '';
  118 + uploadImgNum--;
  119 + setTimeout(function() {
  120 + $imgAdd.show();
  121 + }, 50);
  122 +
  123 + }
  124 + });
  125 +}
  126 +
  127 +// 点赞与取消点赞
  128 +$likeBtn.bind('click', function() {
  129 +
  130 + var id = $(this).closest('.suggest-item').attr('data-id'),
  131 + $that = $(this);
  132 +
  133 + $.ajax({
  134 + method: 'post',
  135 + url: '/home/upAndDown',
  136 + data: {
  137 + suggest_id: id,
  138 + reliable: 1
  139 + }
  140 + }).then(function(data) {
  141 + if (data.code === 200) {
  142 + $that.closest('.suggest-type').removeClass('show');
  143 + $that.closest('.suggest-item').find('.suggest-good').addClass('show');
  144 + }
  145 + }).fail(function(data) {
  146 +
  147 + //TODO
  148 +
  149 + diaLog.showDialog({
  150 + autoHide: true,
  151 + dialogText: '网络错误~'
  152 + });
  153 + });
  154 +});
  155 +
  156 +$disLikeBtn.bind('click', function() {
  157 +
  158 + var id = $(this).closest('.suggest-item').attr('data-id'),
  159 + $that = $(this);
  160 +
  161 + $.ajax({
  162 + method: 'post',
  163 + url: '/home/upAndDown',
  164 + data: {
  165 + suggest_id: id,
  166 + reliable: 2
  167 + }
  168 + }).then(function(data) {
  169 + if (data.code === 200) {
  170 + $that.closest('.suggest-type').removeClass('show');
  171 + $that.closest('.suggest-item').find('.suggest-bad').addClass('show');
  172 + }
  173 + }).fail(function(data) {
  174 +
  175 + //TODO
  176 +
  177 + diaLog.showDialog({
  178 + autoHide: true,
  179 + dialogText: '网络错误~'
  180 + });
  181 + });
  182 +});
@@ -131,6 +131,7 @@ @@ -131,6 +131,7 @@
131 border-top: 30px solid #f0f0f0; 131 border-top: 30px solid #f0f0f0;
132 border-bottom: 30px solid #f0f0f0; 132 border-bottom: 30px solid #f0f0f0;
133 position: relative; 133 position: relative;
  134 + height: 88px;
134 135
135 .list-item { 136 .list-item {
136 padding: 0 35px; 137 padding: 0 35px;