commentPost.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <view class="container">
  3. <view class="post-comment">
  4. <view class="goods">
  5. <view class="img">
  6. <image :src="orderGoods.picUrl"></image>
  7. </view>
  8. <view class="info">
  9. <view class="t">
  10. <text class="name">{{ orderGoods.goodsName }} x{{ orderGoods.number }}</text>
  11. </view>
  12. <view class="attr">{{ orderGoods.goodsSpecificationValues }}</view>
  13. </view>
  14. </view>
  15. <view class="rater">
  16. <text class="rater-title">评分</text>
  17. <block v-for="(item, index) in stars" :key="index">
  18. <van-icon name="star" @tap.native="selectRater($event, { star: item })" color="#ab956d" :data-star="item" v-if="item < star" />
  19. <van-icon name="star-o" @tap.native="selectRater($event, { star: item })" :data-star="item" v-else />
  20. </block>
  21. <text class="rater-desc">{{ starText }}</text>
  22. </view>
  23. <view class="input-box">
  24. <textarea class="content" :focus="true" @input="bindInputValue" maxlength="140" placeholder="留言经过筛选后,对所有人可见" />
  25. <text class="count">{{ 140 - content.length }}</text>
  26. </view>
  27. <view class="weui-uploader">
  28. <view class="weui-uploader__hd">
  29. <view class="weui-uploader__title">图片上传</view>
  30. <view class="weui-uploader__info">{{ picUrls.length }}/{{ files.length }}</view>
  31. </view>
  32. <view class="weui-uploader__bd">
  33. <view class="weui-uploader__files" id="uploaderFiles">
  34. <block v-for="(item, index) in files" :key="index">
  35. <view class="weui-uploader__file" @tap="previewImage" :id="item">
  36. <image class="weui-uploader__img" :src="item" mode="aspectFill" />
  37. </view>
  38. <!-- <view class="weui-uploader__file weui-uploader__file_status" bindtap="previewImage" id="{{item}}">
  39. <image class="weui-uploader__img" src="{{item}}" mode="aspectFill" />
  40. <view class="weui-uploader__file-content">50%</view>
  41. </view> -->
  42. </block>
  43. <view class="weui-uploader__input-box">
  44. <view class="weui-uploader__input" @tap="chooseImage"></view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="btns">
  50. <view class="close" @tap="onClose">取消</view>
  51. <view class="post" @tap="onPost">发表</view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. // 上传组件 基于https://github.com/Tencent/weui-wxss/tree/master/src/example/uploader
  58. var app = getApp();
  59. var util = require('../../../utils/util.js');
  60. var api = require('../../../config/api.js');
  61. export default {
  62. data() {
  63. return {
  64. orderId: 0,
  65. type: 0,
  66. valueId: 0,
  67. orderGoods: {
  68. picUrl: '',
  69. goodsName: '',
  70. number: '',
  71. goodsSpecificationValues: ''
  72. },
  73. content: '',
  74. stars: [0, 1, 2, 3, 4],
  75. star: 5,
  76. starText: '十分满意',
  77. hasPicture: false,
  78. picUrls: [],
  79. files: []
  80. };
  81. },
  82. onLoad: function (options) {
  83. var that = this;
  84. that.setData({
  85. orderId: options.orderId,
  86. type: options.type,
  87. valueId: options.valueId
  88. });
  89. this.getOrderGoods();
  90. },
  91. onReady: function () {},
  92. onShow: function () {
  93. // 页面显示
  94. },
  95. onHide: function () {
  96. // 页面隐藏
  97. },
  98. onUnload: function () {
  99. // 页面关闭
  100. },
  101. methods: {
  102. chooseImage: function (e) {
  103. if (this.files.length >= 5) {
  104. util.showErrorToast('只能上传五张图片');
  105. return false;
  106. }
  107. var that = this;
  108. uni.chooseImage({
  109. count: 1,
  110. sizeType: ['original', 'compressed'],
  111. sourceType: ['album', 'camera'],
  112. success: function (res) {
  113. that.setData({
  114. files: that.files.concat(res.tempFilePaths)
  115. });
  116. that.upload(res);
  117. }
  118. });
  119. },
  120. upload: function (res) {
  121. var that = this;
  122. const uploadTask = uni.uploadFile({
  123. url: api.StorageUpload,
  124. filePath: res.tempFilePaths[0],
  125. name: 'file',
  126. success: function (res) {
  127. var _res = JSON.parse(res.data);
  128. if (_res.errno === 0) {
  129. var url = _res.data.url;
  130. that.picUrls.push(url);
  131. that.setData({
  132. hasPicture: true,
  133. picUrls: that.picUrls
  134. });
  135. }
  136. },
  137. fail: function (e) {
  138. uni.showModal({
  139. title: '错误',
  140. content: '上传失败',
  141. showCancel: false
  142. });
  143. }
  144. });
  145. uploadTask.onProgressUpdate((res) => {
  146. console.log('上传进度', res.progress);
  147. console.log('已经上传的数据长度', res.totalBytesSent);
  148. console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend);
  149. });
  150. },
  151. previewImage: function (e) {
  152. uni.previewImage({
  153. current: e.currentTarget.id,
  154. // 当前显示图片的http链接
  155. urls: this.files // 需要预览的图片http链接列表
  156. });
  157. },
  158. selectRater: function (e, _dataset) {
  159. /* ---处理dataset begin--- */
  160. this.handleDataset(e, _dataset);
  161. /* ---处理dataset end--- */
  162. var star = e.currentTarget.dataset.star + 1;
  163. var starText;
  164. if (star == 1) {
  165. starText = '很差';
  166. } else if (star == 2) {
  167. starText = '不太满意';
  168. } else if (star == 3) {
  169. starText = '满意';
  170. } else if (star == 4) {
  171. starText = '比较满意';
  172. } else {
  173. starText = '十分满意';
  174. }
  175. this.setData({
  176. star: star,
  177. starText: starText
  178. });
  179. },
  180. getOrderGoods: function () {
  181. let that = this;
  182. util.request(api.OrderGoods, {
  183. orderId: that.orderId,
  184. goodsId: that.valueId
  185. }).then(function (res) {
  186. if (res.errno === 0) {
  187. that.setData({
  188. orderGoods: res.data
  189. });
  190. }
  191. });
  192. },
  193. onClose: function () {
  194. uni.navigateBack();
  195. },
  196. onPost: function () {
  197. let that = this;
  198. if (!this.content) {
  199. util.showErrorToast('请填写评论');
  200. return false;
  201. }
  202. util.request(
  203. api.OrderComment,
  204. {
  205. orderGoodsId: that.orderGoods.id,
  206. content: that.content,
  207. star: that.star,
  208. hasPicture: that.hasPicture,
  209. picUrls: that.picUrls,
  210. order_id: that.orderId
  211. },
  212. 'POST'
  213. ).then(function (res) {
  214. if (res.errno === 0) {
  215. uni.showToast({
  216. title: '评论成功',
  217. complete: function () {
  218. uni.switchTab({
  219. url: '/pages/ucenter/index/index'
  220. });
  221. }
  222. });
  223. } else {
  224. uni.showToast({
  225. title: res.errmsg,
  226. icon: 'none'
  227. });
  228. }
  229. //console.log(res);
  230. });
  231. },
  232. bindInputValue(event) {
  233. let value = event.detail.value;
  234. //判断是否超过140个字符
  235. if (value && value.length > 140) {
  236. return false;
  237. }
  238. this.setData({
  239. content: event.detail.value
  240. });
  241. }
  242. }
  243. };
  244. </script>
  245. <style>
  246. page,
  247. .container {
  248. height: 100%;
  249. background: #f4f4f4;
  250. }
  251. .post-comment {
  252. width: 750rpx;
  253. height: auto;
  254. overflow: hidden;
  255. padding: 30rpx;
  256. background: #fff;
  257. }
  258. .post-comment .goods {
  259. display: flex;
  260. align-items: center;
  261. height: 199rpx;
  262. margin-left: 31.25rpx;
  263. }
  264. .post-comment .goods .img {
  265. height: 145.83rpx;
  266. width: 145.83rpx;
  267. background: #f4f4f4;
  268. }
  269. .post-comment .goods .img image {
  270. height: 145.83rpx;
  271. width: 145.83rpx;
  272. }
  273. .post-comment .goods .info {
  274. height: 145.83rpx;
  275. flex: 1;
  276. padding-left: 20rpx;
  277. }
  278. .post-comment .goods .name {
  279. margin-top: 30rpx;
  280. display: block;
  281. height: 44rpx;
  282. line-height: 44rpx;
  283. color: #333;
  284. font-size: 30rpx;
  285. }
  286. .post-comment .goods .number {
  287. display: block;
  288. height: 37rpx;
  289. line-height: 37rpx;
  290. color: #666;
  291. font-size: 25rpx;
  292. }
  293. .post-comment .goods .status {
  294. width: 105rpx;
  295. color: #b4282d;
  296. font-size: 25rpx;
  297. }
  298. .post-comment .rater {
  299. display: flex;
  300. flex-direction: row;
  301. height: 55rpx;
  302. }
  303. .post-comment .rater .rater-title {
  304. font-size: 29rpx;
  305. padding-right: 10rpx;
  306. }
  307. .post-comment .rater image {
  308. padding-left: 5rpx;
  309. height: 50rpx;
  310. width: 50rpx;
  311. }
  312. .post-comment .rater .rater-desc {
  313. font-size: 29rpx;
  314. padding-left: 10rpx;
  315. }
  316. .post-comment .input-box {
  317. height: 337.5rpx;
  318. width: 690rpx;
  319. position: relative;
  320. background: #fff;
  321. }
  322. .post-comment .input-box .content {
  323. position: absolute;
  324. top: 0;
  325. left: 0;
  326. display: block;
  327. background: #fff;
  328. font-size: 29rpx;
  329. border: 5px solid #f4f4f4;
  330. height: 300rpx;
  331. width: 650rpx;
  332. padding: 20rpx;
  333. }
  334. .post-comment .input-box .count {
  335. position: absolute;
  336. bottom: 20rpx;
  337. right: 20rpx;
  338. display: block;
  339. height: 30rpx;
  340. width: 50rpx;
  341. font-size: 29rpx;
  342. color: #999;
  343. }
  344. .post-comment .btns {
  345. height: 108rpx;
  346. }
  347. .post-comment .close {
  348. float: left;
  349. height: 108rpx;
  350. line-height: 108rpx;
  351. text-align: left;
  352. color: #666;
  353. padding: 0 30rpx;
  354. }
  355. .post-comment .post {
  356. float: right;
  357. height: 108rpx;
  358. line-height: 108rpx;
  359. text-align: right;
  360. padding: 0 30rpx;
  361. }
  362. .weui-uploader {
  363. margin-top: 50rpx;
  364. }
  365. .weui-uploader__hd {
  366. display: -webkit-box;
  367. display: -webkit-flex;
  368. display: flex;
  369. padding-bottom: 10px;
  370. -webkit-box-align: center;
  371. -webkit-align-items: center;
  372. align-items: center;
  373. }
  374. .weui-uploader__title {
  375. -webkit-box-flex: 1;
  376. -webkit-flex: 1;
  377. flex: 1;
  378. }
  379. .weui-uploader__info {
  380. color: #b2b2b2;
  381. }
  382. .weui-uploader__bd {
  383. margin-bottom: -4px;
  384. margin-right: -9px;
  385. overflow: hidden;
  386. }
  387. .weui-uploader__file {
  388. float: left;
  389. margin-right: 9px;
  390. margin-bottom: 9px;
  391. }
  392. .weui-uploader__img {
  393. display: block;
  394. width: 79px;
  395. height: 79px;
  396. }
  397. .weui-uploader__file_status {
  398. position: relative;
  399. }
  400. .weui-uploader__file_status:before {
  401. content: ' ';
  402. position: absolute;
  403. top: 0;
  404. right: 0;
  405. bottom: 0;
  406. left: 0;
  407. background-color: rgba(0, 0, 0, 0.5);
  408. }
  409. .weui-uploader__file-content {
  410. position: absolute;
  411. top: 50%;
  412. left: 50%;
  413. -webkit-transform: translate(-50%, -50%);
  414. transform: translate(-50%, -50%);
  415. color: #fff;
  416. }
  417. .weui-uploader__input-box {
  418. float: left;
  419. position: relative;
  420. margin-right: 9px;
  421. margin-bottom: 9px;
  422. width: 77px;
  423. height: 77px;
  424. border: 1px solid #d9d9d9;
  425. }
  426. .weui-uploader__input-box:after,
  427. .weui-uploader__input-box:before {
  428. content: ' ';
  429. position: absolute;
  430. top: 50%;
  431. left: 50%;
  432. -webkit-transform: translate(-50%, -50%);
  433. transform: translate(-50%, -50%);
  434. background-color: #d9d9d9;
  435. }
  436. .weui-uploader__input-box:before {
  437. width: 2px;
  438. height: 39.5px;
  439. }
  440. .weui-uploader__input-box:after {
  441. width: 39.5px;
  442. height: 2px;
  443. }
  444. .weui-uploader__input-box:active {
  445. border-color: #999;
  446. }
  447. .weui-uploader__input-box:active:after,
  448. .weui-uploader__input-box:active:before {
  449. background-color: #999;
  450. }
  451. .weui-uploader__input {
  452. position: absolute;
  453. z-index: 1;
  454. top: 0;
  455. left: 0;
  456. width: 100%;
  457. height: 100%;
  458. opacity: 0;
  459. }
  460. </style>