Showing
12 changed files
with
484 additions
and
233 deletions
apps/common/controllers/upload.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const request = require('request-promise'); | ||
4 | +const fs = require('fs'); | ||
5 | +const _ = require('lodash'); | ||
6 | + | ||
7 | +const utils = require('../models/utils'); | ||
8 | + | ||
9 | +const uploadImg = (req, res, next) => { | ||
10 | + let files = req.files && req.files.file || []; | ||
11 | + | ||
12 | + if (!_.isArray(files)) { | ||
13 | + files = [files]; | ||
14 | + } | ||
15 | + | ||
16 | + req.body.files = []; | ||
17 | + files.forEach(file => { | ||
18 | + req.body.files.push(fs.createReadStream(file.path)); | ||
19 | + req.body.files.push(file.name); | ||
20 | + }); | ||
21 | + | ||
22 | + request({ | ||
23 | + method: 'post', | ||
24 | + url: 'http://upload.static.yohobuy.com', | ||
25 | + formData: { | ||
26 | + fileData: req.body.files, | ||
27 | + project: req.body.bucket | ||
28 | + }, | ||
29 | + json: true | ||
30 | + }).then(function(result) { | ||
31 | + | ||
32 | + if (result && result.code === 200) { | ||
33 | + result.data = result.data || {}; | ||
34 | + result.data.images = _.map(_.get(result, 'data.imagesList'), (it) => { | ||
35 | + return utils.getUploadImgAbsoluteUrl(it, req.body.bucket); | ||
36 | + }); | ||
37 | + } | ||
38 | + | ||
39 | + res.json(result); | ||
40 | + }).catch(next); | ||
41 | +}; | ||
42 | + | ||
43 | +module.exports = { | ||
44 | + uploadImg | ||
45 | +}; |
apps/common/models/utils.js
0 → 100644
1 | +/** | ||
2 | + * common 相关 utils | ||
3 | + * @author: 刘传洋<chuanyang.liu@yoho.cn> | ||
4 | + * @date: 2016/10/31 | ||
5 | + */ | ||
6 | + | ||
7 | +/** | ||
8 | + * 01=["img10.static.yhbimg.com", "img11.static.yhbimg.com"], | ||
9 | + * 02=["img12.static.yhbimg.com", "img13.static.yhbimg.com"] | ||
10 | + * 03=["flv01.static.yhbimg.com", "flv01.static.yhbimg.com"] | ||
11 | + * @param url | ||
12 | + * @param bucket | ||
13 | + * @returns {*} | ||
14 | + */ | ||
15 | +'use strict'; | ||
16 | + | ||
17 | +const getUploadImgAbsoluteUrl = (url, bucket) => { | ||
18 | + | ||
19 | + if (!url) { | ||
20 | + return null; | ||
21 | + } | ||
22 | + | ||
23 | + let urlArr = url.split('/'), | ||
24 | + stag = urlArr[urlArr.length - 1].substr(0, 2), | ||
25 | + domain = `static.yhbimg.com/${bucket}`; | ||
26 | + | ||
27 | + url = domain + url; | ||
28 | + if (stag === '01') { | ||
29 | + return `//img11.${url}`; | ||
30 | + } else if (stag === '03') { | ||
31 | + return `//flv01.${url}`; | ||
32 | + } else { | ||
33 | + return `//img12.${url}`; | ||
34 | + } | ||
35 | +}; | ||
36 | + | ||
37 | +module.exports = { | ||
38 | + getUploadImgAbsoluteUrl | ||
39 | +}; |
@@ -9,8 +9,14 @@ | @@ -9,8 +9,14 @@ | ||
9 | const router = require('express').Router(); // eslint-disable-line | 9 | const router = require('express').Router(); // eslint-disable-line |
10 | const cRoot = './controllers'; | 10 | const cRoot = './controllers'; |
11 | 11 | ||
12 | +var multipart = require('connect-multiparty'); | ||
13 | +var multipartMiddleware = multipart(); | ||
14 | + | ||
12 | const rvCtrl = require(`${cRoot}/recent-view`); | 15 | const rvCtrl = require(`${cRoot}/recent-view`); |
16 | +const uploadCtrl = require(`${cRoot}/upload`); | ||
13 | 17 | ||
14 | router.get('/recentReview', rvCtrl.index); // 最近浏览 | 18 | router.get('/recentReview', rvCtrl.index); // 最近浏览 |
15 | 19 | ||
20 | +router.post('/upload/image', multipartMiddleware, uploadCtrl.uploadImg); | ||
21 | + | ||
16 | module.exports = router; | 22 | module.exports = router; |
@@ -19,8 +19,9 @@ exports.index = (req, res, next) => { | @@ -19,8 +19,9 @@ exports.index = (req, res, next) => { | ||
19 | // 转string值为bool值 | 19 | // 转string值为bool值 |
20 | isComment = isComment === 'Y'; | 20 | isComment = isComment === 'Y'; |
21 | 21 | ||
22 | + // uid = '20000318'; | ||
22 | // uid: 20000318 test1 | 23 | // uid: 20000318 test1 |
23 | - console.log('==> uid: ' + req.user.uid); | 24 | + // console.log('==> uid: ' + uid); |
24 | 25 | ||
25 | commentModel.getCommentList(uid, isComment, page) | 26 | commentModel.getCommentList(uid, isComment, page) |
26 | .then(data => { | 27 | .then(data => { |
@@ -30,36 +31,15 @@ exports.index = (req, res, next) => { | @@ -30,36 +31,15 @@ exports.index = (req, res, next) => { | ||
30 | }); | 31 | }); |
31 | 32 | ||
32 | res.render('comment', localData); | 33 | res.render('comment', localData); |
33 | - | ||
34 | - // res.render('comment', { | ||
35 | - // | ||
36 | - // }); | ||
37 | }) | 34 | }) |
38 | .catch(next); | 35 | .catch(next); |
39 | - | ||
40 | - /* res.render('comment', { | ||
41 | - comment: { | ||
42 | - orders: [{ | ||
43 | - orderTime: '2016-10-10', | ||
44 | - goods: [{ | ||
45 | - href: '', | ||
46 | - thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/08/05/06/016aeb5985c7e186b5c4e43e165311126d.jpg?imageMogr2/thumbnail/100x100/extent/100x100/background/d2hpdGU=/position/center/quality/70', | ||
47 | - name: '阿斯顿发到付', | ||
48 | - comments: [{ | ||
49 | - img: '//img12.static.yhbimg.com/article/2016/10/25/14/02fffad7f7caef65d7acb61a7334ece93a.jpg?imageView2/1/w/360/h/240' | ||
50 | - }, { | ||
51 | - img: 'http://img10.static.yhbimg.com/goodsimg/2015/08/05/06/016aeb5985c7e186b5c4e43e165311126d.jpg?imageMogr2/thumbnail/100x100/extent/100x100/background/d2hpdGU=/position/center/quality/70' | ||
52 | - }] | ||
53 | - }] | ||
54 | - }] | ||
55 | - } | ||
56 | - });*/ | ||
57 | }; | 36 | }; |
58 | 37 | ||
59 | exports.commentList4Order = (req, res, next) => { | 38 | exports.commentList4Order = (req, res, next) => { |
60 | let uid = req.user.uid; | 39 | let uid = req.user.uid; |
61 | let orderId = req.query.orderId; | 40 | let orderId = req.query.orderId; |
62 | 41 | ||
42 | + console.log(uid + '===' + orderId); | ||
63 | commentModel.getCommentList4Order(uid, orderId) | 43 | commentModel.getCommentList4Order(uid, orderId) |
64 | .then(data => { | 44 | .then(data => { |
65 | let result = _.merge({ | 45 | let result = _.merge({ |
@@ -86,9 +66,17 @@ exports.saveComment = (req, res, next) => { | @@ -86,9 +66,17 @@ exports.saveComment = (req, res, next) => { | ||
86 | content: req.body.content, | 66 | content: req.body.content, |
87 | goodsId: req.body.goodsId, | 67 | goodsId: req.body.goodsId, |
88 | orderId: req.body.orderId, | 68 | orderId: req.body.orderId, |
89 | - erpSkuId: req.body.erpSkuId | 69 | + erpSkuId: req.body.erpSkuId, |
70 | + anonymous: false, // 是否匿名评价 | ||
71 | + satisfied: Number(req.body.satisfied), | ||
72 | + url: req.body.url, | ||
73 | + size: req.body.size, | ||
74 | + height: req.body.height ? Number(req.body.height) : '', | ||
75 | + weight: req.body.weight ? Number(req.body.weight) : '' | ||
90 | }; | 76 | }; |
91 | 77 | ||
78 | +console.log(JSON.stringify(data)); | ||
79 | + | ||
92 | commentModel.saveShareOrder(data) | 80 | commentModel.saveShareOrder(data) |
93 | .then(result => { | 81 | .then(result => { |
94 | res.json(result); | 82 | res.json(result); |
@@ -59,7 +59,9 @@ exports.getCommentList = (uid, isComment, page, limit) => { | @@ -59,7 +59,9 @@ exports.getCommentList = (uid, isComment, page, limit) => { | ||
59 | productSkn: v.productSkn, | 59 | productSkn: v.productSkn, |
60 | productId: v.productId, | 60 | productId: v.productId, |
61 | goodsId: v.goodsId, | 61 | goodsId: v.goodsId, |
62 | - erpSkuId: v.erpSkuId | 62 | + erpSkuId: v.erpSkuId, |
63 | + orderId: value.orderId, | ||
64 | + orderCode: value.orderCode | ||
63 | }; | 65 | }; |
64 | 66 | ||
65 | if (isComment === v.hasOwnProperty('comment')) { | 67 | if (isComment === v.hasOwnProperty('comment')) { |
@@ -102,61 +104,57 @@ exports.getCommentList = (uid, isComment, page, limit) => { | @@ -102,61 +104,57 @@ exports.getCommentList = (uid, isComment, page, limit) => { | ||
102 | exports.getCommentList4Order = (uid, orderId) => { | 104 | exports.getCommentList4Order = (uid, orderId) => { |
103 | 105 | ||
104 | // limit = limit || 10; | 106 | // limit = limit || 10; |
107 | + // http://api.yoho.cn/?app_version=5.0.0&client_secret=e8098ddd3129372e8c93daea6600eda4&client_type=android&gender=1%2C3& | ||
108 | + // method=show.toShareOrderList& | ||
109 | + // orderCode=1617595089&os_version=android6.0.1%3AMI_MAX&screen_size=1080x1920&session_key= | ||
110 | + // 720e95e42f9c1edc5940f1d49c34b68e&uid=9963947&v=7&yh_channel=1 | ||
105 | 111 | ||
106 | const process = function*() { | 112 | const process = function*() { |
107 | 113 | ||
108 | let result = yield api.post('', { | 114 | let result = yield api.post('', { |
109 | - method: 'web.show.queryOrderProductCommentList', | 115 | + // method: 'web.show.queryOrderProductCommentList', |
116 | + method: 'show.toShareOrderList', | ||
110 | uid: uid, | 117 | uid: uid, |
111 | - orderId: orderId | 118 | + orderCode: orderId// , |
119 | + // orderId: orderId | ||
112 | }); | 120 | }); |
113 | 121 | ||
114 | - let isComment = true; | ||
115 | - | ||
116 | let commentList = { | 122 | let commentList = { |
117 | - isComment: isComment, | ||
118 | goodsNum: 0, | 123 | goodsNum: 0, |
119 | orders: [] | 124 | orders: [] |
120 | }; | 125 | }; |
121 | 126 | ||
122 | - // let pagerObj = {}; | ||
123 | - | ||
124 | - | ||
125 | // 接口返回成功, 处理数据 | 127 | // 接口返回成功, 处理数据 |
126 | if (result.code === 200 && !_.isEmpty(result.data)) { | 128 | if (result.code === 200 && !_.isEmpty(result.data)) { |
127 | - _.forEach(result.data, (value) => { | ||
128 | 129 | ||
129 | - let order = { | ||
130 | - orderNum: value.orderCode, | ||
131 | - orderTime: value.createTime, | ||
132 | - orderId: value.orderId, | ||
133 | - goods: [] | 130 | + let order = { |
131 | + // orderNum: value.orderCode, | ||
132 | + // orderTime: value.createTime, | ||
133 | + orderId: orderId, | ||
134 | + goods: [] | ||
135 | + }; | ||
136 | + | ||
137 | + _.forEach(result.data, (v) => { | ||
138 | + | ||
139 | + let cnAlphabet = v.cnAlphabet || ''; | ||
140 | + let good = { | ||
141 | + href: helpers.getUrlBySkc(v.productId, v.goodsId, cnAlphabet), | ||
142 | + thumb: imgUtils.getImageUrl(v.imageUrl, 100, 100), | ||
143 | + name: v.productName || '', | ||
144 | + productSkn: v.productSkn, | ||
145 | + productId: v.productId, | ||
146 | + goodsId: v.goodsId, | ||
147 | + erpSkuId: v.erpSkuId, | ||
148 | + orderCode: v.orderCode, | ||
149 | + orderId: v.orderId | ||
134 | }; | 150 | }; |
135 | 151 | ||
136 | - _.forEach(value.orderGoods, (v) => { | ||
137 | - let cnAlphabet = v.cnAlphabet || ''; | ||
138 | - let good = { | ||
139 | - href: helpers.getUrlBySkc(v.productId, v.goodsId, cnAlphabet), | ||
140 | - thumb: imgUtils.getImageUrl(v.imageUrl, 100, 100), | ||
141 | - name: v.productName || '', | ||
142 | - productSkn: v.productSkn, | ||
143 | - productId: v.productId, | ||
144 | - goodsId: v.goodsId, | ||
145 | - erpSkuId: v.erpSkuId | ||
146 | - }; | ||
147 | - | ||
148 | - if (isComment === v.hasOwnProperty('comment')) { | ||
149 | - if (isComment) { | ||
150 | - good.remark = v.comment; | ||
151 | - } | ||
152 | - order.goods.push(good); | ||
153 | - commentList.goodsNum++; | ||
154 | - } | ||
155 | - }); | ||
156 | - | ||
157 | - order.goods.length && commentList.orders.push(order); | 152 | + order.goods.push(good); |
153 | + commentList.goodsNum++; | ||
158 | }); | 154 | }); |
159 | 155 | ||
156 | + order.goods.length && commentList.orders.push(order); | ||
157 | + | ||
160 | // let total = commentList.orders.length; | 158 | // let total = commentList.orders.length; |
161 | 159 | ||
162 | 160 | ||
@@ -170,9 +168,9 @@ exports.getCommentList4Order = (uid, orderId) => { | @@ -170,9 +168,9 @@ exports.getCommentList4Order = (uid, orderId) => { | ||
170 | // //page: page | 168 | // //page: page |
171 | // }); | 169 | // }); |
172 | } else { | 170 | } else { |
173 | - commentList.empty = isComment ? NO_COMMENTED_GOODS : NO_UNCOMMENT_GOODS; // 空数据 提示文字 | 171 | + commentList.empty = NO_UNCOMMENT_GOODS; // 空数据 提示文字 |
174 | } | 172 | } |
175 | - | 173 | + console.log(JSON.stringify(commentList.orders.length)); |
176 | return { | 174 | return { |
177 | comment: commentList// , | 175 | comment: commentList// , |
178 | // pager: pagerObj | 176 | // pager: pagerObj |
@@ -126,7 +126,7 @@ router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode); | @@ -126,7 +126,7 @@ router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode); | ||
126 | // 我的评论 | 126 | // 我的评论 |
127 | router.get('/comment', [getCommonHeader, getHomeNav], commentController.index); | 127 | router.get('/comment', [getCommonHeader, getHomeNav], commentController.index); |
128 | router.post('/comment/saveComment', commentController.saveComment); | 128 | router.post('/comment/saveComment', commentController.saveComment); |
129 | -router.get('/comment/'); | 129 | +router.get('/comment/order', [getCommonHeader, getHomeNav], commentController.commentList4Order); |
130 | 130 | ||
131 | // 我的咨询 | 131 | // 我的咨询 |
132 | router.get('/consult', [getCommonHeader, getHomeNav], consultController.index); | 132 | router.get('/consult', [getCommonHeader, getHomeNav], consultController.index); |
@@ -52,32 +52,39 @@ | @@ -52,32 +52,39 @@ | ||
52 | <tr data-role="commentAddForm" class="m-hide"> | 52 | <tr data-role="commentAddForm" class="m-hide"> |
53 | <td colspan="3" class="comment-add"> | 53 | <td colspan="3" class="comment-add"> |
54 | <div class="arrow"><i></i><em></em></div> | 54 | <div class="arrow"><i></i><em></em></div> |
55 | + <input type="hidden" name="productSkn" value="{{productSkn}}" /> | ||
56 | + <input type="hidden" name="productId" value="{{productId}}" /> | ||
57 | + <input type="hidden" name="goodsId" value="{{goodsId}}" /> | ||
58 | + <input type="hidden" name="orderCode" value="{{orderCode}}" /> | ||
59 | + <input type="hidden" name="orderId" value="{{orderId}}" /> | ||
60 | + <input type="hidden" name="erpSkuId" value="{{erpSkuId}}" /> | ||
61 | + | ||
55 | <div class="row"> | 62 | <div class="row"> |
56 | <label class="fl-left"><i class="color-warn require-sign">*</i> 商品满意度:</label> | 63 | <label class="fl-left"><i class="color-warn require-sign">*</i> 商品满意度:</label> |
57 | - <span class="comment-star editable"> | ||
58 | - <span class="star-5"></span> | ||
59 | - <span class="star-4"></span> | ||
60 | - <span class="star-3"></span> | ||
61 | - <span class="star-2"></span> | ||
62 | - <span class="star-1"></span> | 64 | + <span class="comment-star editable"data-role="star"> |
65 | + <span class="star-5" data-star="5"></span> | ||
66 | + <span class="star-4" data-star="4"></span> | ||
67 | + <span class="star-3" data-star="3"></span> | ||
68 | + <span class="star-2" data-star="2"></span> | ||
69 | + <span class="star-1" data-star="1"></span> | ||
63 | </span> | 70 | </span> |
64 | </div> | 71 | </div> |
65 | <div class="row"> | 72 | <div class="row"> |
66 | - <span class="col btn-group"> | 73 | + <span class="col btn-group" data-role="size"> |
67 | <label><i class="color-warn require-sign">*</i> 尺码符合度:</label> | 74 | <label><i class="color-warn require-sign">*</i> 尺码符合度:</label> |
68 | - <a href="#" class="btn btn-outline">偏小</a> | ||
69 | - <a href="#" class="btn btn-outline">合身</a> | ||
70 | - <a href="#" class="btn btn-outline">偏大</a> | 75 | + <a href="javascript:void(0);" class="btn btn-outline" data-size="SMALL">偏小</a> |
76 | + <a href="javascript:void(0);" class="btn btn-outline" data-size="MIDDLE">合身</a> | ||
77 | + <a href="javascript:void(0);" class="btn btn-outline" data-size="BIG">偏大</a> | ||
71 | </span> | 78 | </span> |
72 | <span class="col"> | 79 | <span class="col"> |
73 | <label>身高:</label> | 80 | <label>身高:</label> |
74 | <span class="color-gray"> | 81 | <span class="color-gray"> |
75 | - <a href="#" class="btn btn-outline disabled">175</a> 厘米 | 82 | + <input class="btn btn-outline disabled s-input" name="height" value="" /> 厘米 |
76 | </span> | 83 | </span> |
77 | </span> | 84 | </span> |
78 | <span class="col"> | 85 | <span class="col"> |
79 | <label>体重:</label> | 86 | <label>体重:</label> |
80 | - <a href="#" class="btn btn-outline disabled">80</a> 公斤 | 87 | + <input class="btn btn-outline disabled s-input" name="weight" value="" /> 公斤 |
81 | </span> | 88 | </span> |
82 | </div> | 89 | </div> |
83 | <div class="row textarea" data-role="goodsCommentWrap"> | 90 | <div class="row textarea" data-role="goodsCommentWrap"> |
@@ -87,14 +94,15 @@ | @@ -87,14 +94,15 @@ | ||
87 | <div class="row img-list clearfix"> | 94 | <div class="row img-list clearfix"> |
88 | <div class="img-preview"> | 95 | <div class="img-preview"> |
89 | <img src="" /> | 96 | <img src="" /> |
90 | - <input type="file" id="upload-{{../orderId}}-{{goodsId}}" /> | 97 | + <input type="file" name="file" id="upload-{{../orderId}}-{{goodsId}}" /> |
98 | + <input type="hidden" name="imgUrl" /> | ||
91 | <i class="view">查看</i> | 99 | <i class="view">查看</i> |
92 | <i class="del">删除</i> | 100 | <i class="del">删除</i> |
93 | </div> | 101 | </div> |
94 | <span class="color-warn">最多上传1张图片</span> | 102 | <span class="color-warn">最多上传1张图片</span> |
95 | </div> | 103 | </div> |
96 | <div class="btns"> | 104 | <div class="btns"> |
97 | - <a href="#" class="btn btn-submit active radius">提交评价</a> | 105 | + <a href="javascript:void(0);" class="btn btn-submit active radius">提交评价</a> |
98 | <span class="color-warn">带*为必填选项</span> | 106 | <span class="color-warn">带*为必填选项</span> |
99 | </div> | 107 | </div> |
100 | </td> | 108 | </td> |
@@ -35,11 +35,12 @@ | @@ -35,11 +35,12 @@ | ||
35 | "body-parser": "^1.15.0", | 35 | "body-parser": "^1.15.0", |
36 | "captchapng": "0.0.1", | 36 | "captchapng": "0.0.1", |
37 | "connect-memcached": "^0.2.0", | 37 | "connect-memcached": "^0.2.0", |
38 | + "connect-multiparty": "^2.0.0", | ||
38 | "cookie-parser": "^1.4.3", | 39 | "cookie-parser": "^1.4.3", |
39 | "express": "^4.13.1", | 40 | "express": "^4.13.1", |
40 | - "handlebars": "^4.0.5", | ||
41 | "express-handlebars": "^3.0.0", | 41 | "express-handlebars": "^3.0.0", |
42 | "express-session": "^1.13.0", | 42 | "express-session": "^1.13.0", |
43 | + "handlebars": "^4.0.5", | ||
43 | "influxdb-winston": "^1.0.1", | 44 | "influxdb-winston": "^1.0.1", |
44 | "lodash": "^4.13.1", | 45 | "lodash": "^4.13.1", |
45 | "md5": "^2.1.0", | 46 | "md5": "^2.1.0", |
public/js/common/ajaxfileupload.js
0 → 100644
1 | +/* eslint-disable */ | ||
2 | +/** | ||
3 | + * Created by chuanyang.liu@yoho.cn on 2016/11/1 | ||
4 | + */ | ||
5 | + | ||
6 | +var $ = require('yoho-jquery'); | ||
7 | + | ||
8 | +jQuery.extend({ | ||
9 | + | ||
10 | + | ||
11 | + createUploadIframe: function(id, uri) | ||
12 | + { | ||
13 | + //create frame | ||
14 | + var frameId = 'jUploadFrame' + id; | ||
15 | + var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"'; | ||
16 | + if(window.ActiveXObject) | ||
17 | + { | ||
18 | + if(typeof uri== 'boolean'){ | ||
19 | + iframeHtml += ' src="' + 'javascript:false' + '"'; | ||
20 | + | ||
21 | + } | ||
22 | + else if(typeof uri== 'string'){ | ||
23 | + iframeHtml += ' src="' + uri + '"'; | ||
24 | + | ||
25 | + } | ||
26 | + } | ||
27 | + iframeHtml += ' />'; | ||
28 | + jQuery(iframeHtml).appendTo(document.body); | ||
29 | + | ||
30 | + return jQuery('#' + frameId).get(0); | ||
31 | + }, | ||
32 | + createUploadForm: function(id, fileElementId, data) | ||
33 | + { | ||
34 | + //create form | ||
35 | + var formId = 'jUploadForm' + id; | ||
36 | + var fileId = 'jUploadFile' + id; | ||
37 | + var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>'); | ||
38 | + if(data) | ||
39 | + { | ||
40 | + for(var i in data) | ||
41 | + { | ||
42 | + jQuery('<input type="hidden" /> ').attr('name', i).val(data[i]).appendTo(form); | ||
43 | + //jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form); | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + //var oldElement = jQuery('#' + fileElementId); | ||
48 | + if(jQuery.type(fileElementId) === 'string') { | ||
49 | + if(fileElementId.indexOf('#') != 0) { | ||
50 | + fileElementId = '#' + fileElementId; | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | + var oldElement = jQuery(fileElementId); | ||
55 | + var newElement = jQuery(oldElement).clone(); | ||
56 | + jQuery(oldElement).attr('id', fileId); | ||
57 | + jQuery(oldElement).before(newElement); | ||
58 | + jQuery(oldElement).appendTo(form); | ||
59 | + | ||
60 | + //set attributes | ||
61 | + jQuery(form).css('position', 'absolute'); | ||
62 | + jQuery(form).css('top', '-1200px'); | ||
63 | + jQuery(form).css('left', '-1200px'); | ||
64 | + jQuery(form).appendTo('body'); | ||
65 | + return form; | ||
66 | + }, | ||
67 | + | ||
68 | + handleError: function( s, xhr, status, e ) { | ||
69 | + // If a local callback was specified, fire it | ||
70 | + if ( s.error ) { | ||
71 | + s.error.call( s.context || s, xhr, status, e ); | ||
72 | + } | ||
73 | + | ||
74 | + // Fire the global callback | ||
75 | + if ( s.global ) { | ||
76 | + (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] ); | ||
77 | + } | ||
78 | + }, | ||
79 | + | ||
80 | + ajaxFileUpload: function(s) { | ||
81 | + // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout | ||
82 | + s = jQuery.extend({}, jQuery.ajaxSettings, s); | ||
83 | + var id = new Date().getTime() | ||
84 | + var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data)); | ||
85 | + var io = jQuery.createUploadIframe(id, s.secureuri); | ||
86 | + var frameId = 'jUploadFrame' + id; | ||
87 | + var formId = 'jUploadForm' + id; | ||
88 | + // Watch for a new set of requests | ||
89 | + if ( s.global && ! jQuery.active++ ) | ||
90 | + { | ||
91 | + jQuery.event.trigger( "ajaxStart" ); | ||
92 | + } | ||
93 | + var requestDone = false; | ||
94 | + // Create the request object | ||
95 | + var xml = {} | ||
96 | + if ( s.global ) | ||
97 | + jQuery.event.trigger("ajaxSend", [xml, s]); | ||
98 | + // Wait for a response to come back | ||
99 | + var uploadCallback = function(isTimeout) | ||
100 | + { | ||
101 | + var io = document.getElementById(frameId); | ||
102 | + try | ||
103 | + { | ||
104 | + if(io.contentWindow) | ||
105 | + { | ||
106 | + xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerText:null; | ||
107 | + xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; | ||
108 | + | ||
109 | + }else if(io.contentDocument) | ||
110 | + { | ||
111 | + xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerText:null; | ||
112 | + xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document; | ||
113 | + } | ||
114 | + }catch(e) | ||
115 | + { | ||
116 | + jQuery.handleError(s, xml, null, e); | ||
117 | + } | ||
118 | + if ( xml || isTimeout == "timeout") | ||
119 | + { | ||
120 | + requestDone = true; | ||
121 | + var status; | ||
122 | + try { | ||
123 | + status = isTimeout != "timeout" ? "success" : "error"; | ||
124 | + // Make sure that the request was successful or notmodified | ||
125 | + if ( status != "error" ) | ||
126 | + { | ||
127 | + // process the data (runs the xml through httpData regardless of callback) | ||
128 | + var data = jQuery.uploadHttpData( xml, s.dataType ); | ||
129 | + // If a local callback was specified, fire it and pass it the data | ||
130 | + if ( s.success ) | ||
131 | + s.success( data, status ); | ||
132 | + | ||
133 | + // Fire the global callback | ||
134 | + if( s.global ) | ||
135 | + jQuery.event.trigger( "ajaxSuccess", [xml, s] ); | ||
136 | + } else | ||
137 | + jQuery.handleError(s, xml, status); | ||
138 | + } catch(e) | ||
139 | + { | ||
140 | + status = "error"; | ||
141 | + jQuery.handleError(s, xml, status, e); | ||
142 | + } | ||
143 | + | ||
144 | + // The request was completed | ||
145 | + if( s.global ) | ||
146 | + jQuery.event.trigger( "ajaxComplete", [xml, s] ); | ||
147 | + | ||
148 | + // Handle the global AJAX counter | ||
149 | + if ( s.global && ! --jQuery.active ) | ||
150 | + jQuery.event.trigger( "ajaxStop" ); | ||
151 | + | ||
152 | + // Process result | ||
153 | + if ( s.complete ) | ||
154 | + s.complete(xml, status); | ||
155 | + | ||
156 | + jQuery(io).unbind() | ||
157 | + | ||
158 | + setTimeout(function() | ||
159 | + { try | ||
160 | + { | ||
161 | + jQuery(io).remove(); | ||
162 | + jQuery(form).remove(); | ||
163 | + | ||
164 | + } catch(e) | ||
165 | + { | ||
166 | + jQuery.handleError(s, xml, null, e); | ||
167 | + } | ||
168 | + | ||
169 | + }, 100) | ||
170 | + | ||
171 | + xml = null | ||
172 | + | ||
173 | + } | ||
174 | + } | ||
175 | + // Timeout checker | ||
176 | + if ( s.timeout > 0 ) | ||
177 | + { | ||
178 | + setTimeout(function(){ | ||
179 | + // Check to see if the request is still happening | ||
180 | + if( !requestDone ) uploadCallback( "timeout" ); | ||
181 | + }, s.timeout); | ||
182 | + } | ||
183 | + try | ||
184 | + { | ||
185 | + | ||
186 | + var form = jQuery('#' + formId); | ||
187 | + jQuery(form).attr('action', s.url); | ||
188 | + jQuery(form).attr('method', 'POST'); | ||
189 | + jQuery(form).attr('target', frameId); | ||
190 | + if(form.encoding) | ||
191 | + { | ||
192 | + jQuery(form).attr('encoding', 'multipart/form-data'); | ||
193 | + } | ||
194 | + else | ||
195 | + { | ||
196 | + jQuery(form).attr('enctype', 'multipart/form-data'); | ||
197 | + } | ||
198 | + jQuery(form).submit(); | ||
199 | + | ||
200 | + } catch(e) | ||
201 | + { | ||
202 | + jQuery.handleError(s, xml, null, e); | ||
203 | + } | ||
204 | + | ||
205 | + jQuery('#' + frameId).load(uploadCallback ); | ||
206 | + return {abort: function () {}}; | ||
207 | + | ||
208 | + }, | ||
209 | + | ||
210 | + uploadHttpData: function( r, type ) { | ||
211 | + var data = !type; | ||
212 | + data = type == "xml" || data ? r.responseXML : r.responseText; | ||
213 | + // If the type is "script", eval it in global context | ||
214 | + if ( type == "script" ) | ||
215 | + jQuery.globalEval( data ); | ||
216 | + // Get the JavaScript object, if JSON is used. | ||
217 | + if ( type == "json" ) | ||
218 | + data = JSON.parse(data); | ||
219 | + if( type == "string" ); | ||
220 | + // evaluate scripts within html | ||
221 | + if ( type == "html" ) | ||
222 | + jQuery("<div>").html(data).evalScripts(); | ||
223 | + | ||
224 | + return data; | ||
225 | + } | ||
226 | +}) | ||
227 | + |
1 | /** | 1 | /** |
2 | * 我的评论 | 2 | * 我的评论 |
3 | - * @author: yyqing<yanqing.yang@yoho.cn> | ||
4 | - * @date: 2016/3/1 | 3 | + * @author: liuchuanyang<chuanyang.liu@yoho.cn> |
4 | + * @date: 2016/10/28 | ||
5 | */ | 5 | */ |
6 | var $ = require('yoho-jquery'); | 6 | var $ = require('yoho-jquery'); |
7 | var ImgPreview = require('../common/img-preview'); | 7 | var ImgPreview = require('../common/img-preview'); |
8 | - | ||
9 | -var $comment = $('.comment-table'), | ||
10 | - $remarkBtn = $comment.find('.remark-btn'); | ||
11 | - | ||
12 | -var $dialog = $('#comment-dialog-widget'), | ||
13 | - $titleBar = $dialog.find('.dialog-titlebar'), | ||
14 | - $commentArea = $dialog.find('textarea'); | ||
15 | - | ||
16 | -var pageW = $(document).width(), | ||
17 | - pageH = $(document).height(), | ||
18 | - winH = $(window).height(), | ||
19 | - preview = new ImgPreview(); | ||
20 | - | ||
21 | -var dialog = { | ||
22 | - canmove: false, | ||
23 | - offset: {}, | ||
24 | - maxtop: 0, | ||
25 | - maxleft: 0 | ||
26 | - }, | ||
27 | - orderInfo = {}, | ||
28 | - $optDom; | ||
29 | - | ||
30 | - | ||
31 | -require('../plugins/jquery.qupload'); | ||
32 | - | ||
33 | -// 处理订单数据 | ||
34 | -$remarkBtn.each(function() { | ||
35 | - /* var $next = $(this).next(), | ||
36 | - data = $next.data(), | ||
37 | - key = data.orderid; | ||
38 | - | ||
39 | - orderInfo[key] = {}; | ||
40 | - orderInfo[key].productSkn = data.productskn; | ||
41 | - orderInfo[key].productId = data.productid; | ||
42 | - orderInfo[key].goodsId = data.goodsid; | ||
43 | - orderInfo[key].orderId = data.orderid; | ||
44 | - orderInfo[key].erpSkuId = data.erpskuid; | ||
45 | - | ||
46 | - $next.remove(); | ||
47 | - $(this).data('code', key);*/ | ||
48 | -}); | ||
49 | - | ||
50 | -$remarkBtn.click(function() { | ||
51 | - var scrollTop = $(document).scrollTop(); | ||
52 | - | ||
53 | - $optDom = $(this); | ||
54 | - $commentArea.val(''); | ||
55 | - $dialog.removeClass('hide').css({ | ||
56 | - top: scrollTop + (winH - $dialog.outerHeight()) / 2, | ||
57 | - left: (pageW - $dialog.outerWidth()) / 2 | ||
58 | - }); | ||
59 | -}); | ||
60 | - | ||
61 | -// 评论弹窗 | ||
62 | -$titleBar.bind('mousedown', function(e) { | ||
63 | - if ($(e.target).hasClass('dialog-close-btn')) { | ||
64 | - return; | ||
65 | - } | ||
66 | - | ||
67 | - dialog.canmove = true; | ||
68 | - dialog.offset = { | ||
69 | - x: e.offsetX, | ||
70 | - y: e.offsetY | 8 | +var preview = new ImgPreview(); |
9 | + | ||
10 | +require('../common/ajaxfileupload'); | ||
11 | + | ||
12 | +$('.comment-add').on('click', '.btn-submit', function() { | ||
13 | + | ||
14 | + var $f = $(this).closest('.comment-add'); | ||
15 | + var param = { | ||
16 | + productSkn: $f.find('input[name=productSkn]').val(), | ||
17 | + productId: $f.find('input[name=productId]').val(), | ||
18 | + goodsId: $f.find('input[name=goodsId]').val(), | ||
19 | + orderCode: $f.find('input[name=orderCode]').val(), | ||
20 | + orderId: $f.find('input[name=orderId]').val(), | ||
21 | + erpSkuId: $f.find('input[name=erpSkuId]').val(), | ||
22 | + content: $f.find('[name=goodsComment]').val(), | ||
23 | + url: $f.find('[name=imgUrl]').val(), | ||
24 | + | ||
25 | + height: $f.find('input[name=height]').val(), | ||
26 | + weight: $f.find('input[name=weight]').val(), | ||
27 | + satisfied: $f.find('[data-role="star"]').find('.active[data-star]').attr('data-star'), | ||
28 | + size: $f.find('[data-role="size"]').find('.active[data-size]').attr('data-size') | ||
71 | }; | 29 | }; |
72 | - dialog.maxtop = pageH - $dialog.outerHeight(); | ||
73 | - dialog.maxleft = pageW - $dialog.outerWidth(); | ||
74 | -}); | ||
75 | 30 | ||
76 | -$(document).mousemove(function(e) { | ||
77 | - var mtop, mleft; | 31 | + $.ajax({ |
32 | + type: 'POST', | ||
33 | + url: '/home/comment/saveComment', | ||
34 | + data: param | ||
35 | + }).then(function(jsonData) { | ||
78 | 36 | ||
79 | - if (!dialog.canmove) { | ||
80 | - return; | ||
81 | - } | 37 | + if (jsonData.code === 200) { |
38 | + //console.log(JSON.stringify(jsonData)); | ||
82 | 39 | ||
83 | - mtop = e.pageY - dialog.offset.y; | ||
84 | - mleft = e.pageX - dialog.offset.x; | ||
85 | - mtop = mtop < dialog.maxtop ? mtop : dialog.maxtop; | ||
86 | - mleft = mleft < dialog.maxleft ? mleft : dialog.maxleft; | ||
87 | - $dialog.css({ | ||
88 | - top: mtop > 0 ? mtop : 0, | ||
89 | - left: mleft > 0 ? mleft : 0 | 40 | + } else { |
41 | + alert(jsonData.message); | ||
42 | + } | ||
90 | }); | 43 | }); |
91 | -}).mouseup(function() { | ||
92 | - dialog.canmove = false; | ||
93 | }); | 44 | }); |
94 | 45 | ||
95 | -$('.img-preview').on('click', 'i.view', function() { | 46 | +// 图片预览 |
47 | +$('.img-preview').on('click', 'i.view', function(e) { | ||
96 | 48 | ||
97 | var url = $(this).closest('.img-preview').find('img').attr('src'); | 49 | var url = $(this).closest('.img-preview').find('img').attr('src'); |
98 | 50 | ||
51 | + e.stopPropagation(); | ||
99 | preview.preview(url); | 52 | preview.preview(url); |
100 | }); | 53 | }); |
101 | 54 | ||
102 | -$dialog.on('click', '.dialog-save-btn', function() { | ||
103 | - var remark = $.trim($commentArea.val()), | ||
104 | - param; | 55 | +// 图片删除 |
56 | +$('.img-preview').on('click', 'i.del', function(e) { | ||
105 | 57 | ||
106 | - if (remark === '') { | ||
107 | - alert('请添加评论内容'); | ||
108 | - return; | ||
109 | - } | ||
110 | - if ($optDom.length) { | ||
111 | - param = orderInfo[$optDom.data().code]; | ||
112 | - param.content = remark; | ||
113 | - | ||
114 | - $.ajax({ | ||
115 | - type: 'POST', | ||
116 | - url: '/home/comment/saveComment', | ||
117 | - data: param | ||
118 | - }).then(function(jsonData) { | ||
119 | - var $par = $optDom.parent(); | ||
120 | - | ||
121 | - if (jsonData.code === 200) { | ||
122 | - $par.prev().text(remark); | ||
123 | - $par.html('<span class="remarked">已评论!</span>'); | ||
124 | - $optDom.length = 0; | ||
125 | - $dialog.addClass('hide'); | ||
126 | - } else { | ||
127 | - alert(jsonData.message); | ||
128 | - } | ||
129 | - }); | ||
130 | - } | ||
131 | -}); | 58 | + var $p = $(this).closest('.img-preview'); |
132 | 59 | ||
133 | -$dialog.on('click', '.dialog-close-btn', function() { | ||
134 | - $optDom.length = 0; | ||
135 | - $dialog.addClass('hide'); | 60 | + e.stopPropagation(); |
61 | + $p.removeClass('selected'); | ||
62 | + $p.find('input[name=imgUrl]').val(''); | ||
63 | + $p.find('img').attr('src', ''); | ||
136 | }); | 64 | }); |
137 | 65 | ||
138 | -$('.comment-add input[type="file"]').each(function(i, it) { | ||
139 | - var $this = $(it), | ||
140 | - $par = $this.closest('.problem-description'); | ||
141 | - | ||
142 | - if (!window.location.origin) { | ||
143 | - window.location.origin = window.location.protocol + '//' + | ||
144 | - window.location.hostname + (window.location.port ? ':' + window.location.port : ''); | ||
145 | - } | ||
146 | - alert(window.location.origin); | ||
147 | - $this.qupload({ | ||
148 | - button_image_url: '', | ||
149 | - upload_url: window.location.origin + '/home/returns/imgUpload', | ||
150 | - file_post_name: 'fileData', | ||
151 | - button_text: '<span class="btn_upload_text">上传图片</span>', | ||
152 | - button_text_style: '.btn_upload_text{color: #ffffff;}', | ||
153 | - button_width: 60, | ||
154 | - button_height: 60, | ||
155 | - button_text_left_padding: 32, | ||
156 | - button_text_top_padding: 8, | ||
157 | - button_action: window.SWFUpload.BUTTON_ACTION.SELECT_FILE, | ||
158 | - file_size_limit: '10240', | ||
159 | - file_types: '*.jpg;*.jpeg;*.png;*.bmp', | ||
160 | - uploadSuccessed: function(data) { | ||
161 | - var $imgList = $par.find('li'), | ||
162 | - isShow = false, | ||
163 | - img, _html; | ||
164 | - | ||
165 | - img = JSON.parse(data).imgList[0]; | ||
166 | - _html = '<span class="btn-del" title="删除"></span>' + | ||
167 | - '<img src="' + img[0] + '" width="126" height="126">' + | ||
168 | - '<input type="hidden" name="imgs" value="' + img.imgRelUrl + '">'; | ||
169 | - $imgList.each(function() { | ||
170 | - if (!isShow && !$(this).find('img').length) { | ||
171 | - isShow = true; | ||
172 | - $(this).html(_html); | 66 | +// 图片上传 |
67 | +$('.comment-add').on('change', 'input[type=file]', function() { | ||
68 | + | ||
69 | + var $f = $(this); | ||
70 | + var $p = $f.closest('.img-preview'); | ||
71 | + | ||
72 | + if ($f.val()) { | ||
73 | + $.ajaxFileUpload({ | ||
74 | + url: '/common/upload/image', | ||
75 | + secureuri: false, | ||
76 | + fileElementId: $f, | ||
77 | + data: { | ||
78 | + bucket: 'sns' | ||
79 | + }, | ||
80 | + dataType: 'json', | ||
81 | + success: function(data /* , status */) { | ||
82 | + | ||
83 | + var url, relaUrl; | ||
84 | + | ||
85 | + if (data && data.code === 200 && data.data && data.data.images && data.data.images[0]) { | ||
86 | + url = data.data.images[0]; | ||
87 | + relaUrl = data.data.imagesList[0]; | ||
88 | + $p.find('img').attr('src', url); | ||
89 | + $p.find('input[name=imgUrl]').val(relaUrl); | ||
90 | + $p.addClass('selected'); | ||
173 | } | 91 | } |
174 | - }); | ||
175 | - } | ||
176 | - }); | 92 | + }, |
93 | + error: function() { /** data, status, e **/ | ||
94 | + alert('上传失败,请稍后再试!'); | ||
95 | + }, | ||
96 | + complete: function() { | ||
97 | + $f.clone().replaceAll($f); | ||
98 | + } | ||
99 | + }); | ||
100 | + } | ||
177 | }); | 101 | }); |
178 | 102 | ||
179 | // comment form | 103 | // comment form |
@@ -151,6 +151,9 @@ | @@ -151,6 +151,9 @@ | ||
151 | width:100%; | 151 | width:100%; |
152 | height:100%; | 152 | height:100%; |
153 | cursor: pointer; | 153 | cursor: pointer; |
154 | + position:absolute; | ||
155 | + left:0; | ||
156 | + top:0; | ||
154 | } | 157 | } |
155 | i{ | 158 | i{ |
156 | display:none; | 159 | display:none; |
@@ -160,6 +163,7 @@ | @@ -160,6 +163,7 @@ | ||
160 | text-align:center; | 163 | text-align:center; |
161 | color:#FFF; | 164 | color:#FFF; |
162 | background:rgba(0, 0, 0, .5); | 165 | background:rgba(0, 0, 0, .5); |
166 | + cursor: pointer; | ||
163 | 167 | ||
164 | &.view { | 168 | &.view { |
165 | left: 0; | 169 | left: 0; |
@@ -169,7 +173,9 @@ | @@ -169,7 +173,9 @@ | ||
169 | } | 173 | } |
170 | } | 174 | } |
171 | img { | 175 | img { |
172 | - max-width:100%; | 176 | + min-width:100%; |
177 | + max-width:200%; | ||
178 | + min-height:100%; | ||
173 | } | 179 | } |
174 | 180 | ||
175 | &.selected { | 181 | &.selected { |
@@ -223,6 +229,11 @@ | @@ -223,6 +229,11 @@ | ||
223 | } | 229 | } |
224 | } | 230 | } |
225 | } | 231 | } |
232 | + .s-input { | ||
233 | + width: 25px; | ||
234 | + padding-left: 5px; | ||
235 | + padding-right: 5px; | ||
236 | + } | ||
226 | .textarea{ | 237 | .textarea{ |
227 | position:relative; | 238 | position:relative; |
228 | > textarea{ | 239 | > textarea{ |
-
Please register or login to post a comment