write-comments.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class="write-comments">
  3. <div class="content">
  4. <div class="crumbs">
  5. <nuxt-link to="/user-center" class="item-a">{{$t('comments.personalCenter')}}</nuxt-link>
  6. <span class="arrow">></span>
  7. <span class="item-span" v-if="isComm == 0">{{$t('comments.postComment')}}</span>
  8. <span class="item-span" v-if="isComm == 1">{{$t('comments.commentDetails')}}</span>
  9. </div>
  10. <div class="comments-con">
  11. <!-- 待评价 -->
  12. <div v-if="orderItemProds.length > 0">
  13. <div class="comments-box" v-for="(item,index) in orderItemProds" :key="index">
  14. <div class="goods-msg">
  15. <div class="img">
  16. <img v-if="item.pic" :src="item.pic" alt @error="handlePicError"/>
  17. <img v-else src="~/assets/img/def.png" alt />
  18. </div>
  19. <a
  20. class="name"
  21. href="javascript:void(0);"
  22. @click="toProdDetail(item.prodId)"
  23. >{{item.prodName}}</a>
  24. <div v-if="item.skuName" class="sku">{{$t('comments.specification')}}: {{item.skuName}}</div>
  25. <div class="order-number">
  26. {{$t('comments.orderNumber')}}:
  27. <a
  28. href="javascript:void(0);"
  29. @click="toOrderDetail(item.orderNumber)"
  30. class="number"
  31. >{{item.orderNumber}}</a>
  32. </div>
  33. <div class="deal-time">
  34. {{$t('comments.transactionTime')}}:
  35. <span class="number">{{item.payTime}}</span>
  36. </div>
  37. </div>
  38. <div class="operation">
  39. <div class="item" aria-disabled="true">
  40. <div class="tit">{{$t('comments.productRating')}}</div>
  41. <!-- 评分星级: -->
  42. <div class="star-box">
  43. <!-- <span class="text">商品评分</span> -->
  44. <span class="stars">
  45. <i
  46. :class="[item.score > 0?'star':'star-gray']"
  47. @click="prodComm(1,item.orderItemId)"
  48. ></i>
  49. <i
  50. :class="[item.score > 1?'star':'star-gray']"
  51. @click="prodComm(2,item.orderItemId)"
  52. ></i>
  53. <i
  54. :class="[item.score > 2?'star':'star-gray']"
  55. @click="prodComm(3,item.orderItemId)"
  56. ></i>
  57. <i
  58. :class="[item.score > 3?'star':'star-gray']"
  59. @click="prodComm(4,item.orderItemId)"
  60. ></i>
  61. <i
  62. :class="[item.score > 4?'star':'star-gray']"
  63. @click="prodComm(5,item.orderItemId)"
  64. ></i>
  65. </span>
  66. </div>
  67. <!-- <div class="star-box">
  68. <span class="text">店铺服务</span>
  69. <span class="stars">
  70. <i :class="[storeCommNum > 0?'star':'star-gray']" @click="storeComm(1)"></i>
  71. <i :class="[storeCommNum > 1?'star':'star-gray']" @click="storeComm(2)"></i>
  72. <i :class="[storeCommNum > 2?'star':'star-gray']" @click="storeComm(3)"></i>
  73. <i :class="[storeCommNum > 3?'star':'star-gray']" @click="storeComm(4)"></i>
  74. <i :class="[storeCommNum > 4?'star':'star-gray']" @click="storeComm(5)"></i>
  75. </span>
  76. </div>
  77. <div class="star-box">
  78. <span class="text">物流服务</span>
  79. <span class="stars">
  80. <i :class="[logCommNum > 0?'star':'star-gray']" @click="logComm(1)"></i>
  81. <i :class="[logCommNum > 1?'star':'star-gray']" @click="logComm(2)"></i>
  82. <i :class="[logCommNum > 2?'star':'star-gray']" @click="logComm(3)"></i>
  83. <i :class="[logCommNum > 3?'star':'star-gray']" @click="logComm(4)"></i>
  84. <i :class="[logCommNum > 4?'star':'star-gray']" @click="logComm(5)"></i>
  85. </span>
  86. </div>-->
  87. </div>
  88. <!-- <div class="item">
  89. <div class="tit">大众评价</div>
  90. <div class="comments">
  91. <div class="c-item active">产品质量很好</div>
  92. <div class="c-item">细节做工很棒</div>
  93. <div class="c-item">快递运输快</div>
  94. <div class="c-item">卖家服务很好</div>
  95. <div class="c-item">价格很便宜</div>
  96. </div>
  97. </div>-->
  98. <div class="item">
  99. <div class="tit">{{$t('comments.specificDescription')}}</div>
  100. <div class="des-box">
  101. <textarea
  102. v-model="item.content"
  103. class="des"
  104. maxlength="150"
  105. :placeholder="$t('comments.provideYourComments')"
  106. ></textarea>
  107. <div class="des-tip">{{$t('comments.enterUpTo150Characters')}}</div>
  108. </div>
  109. </div>
  110. <div class="item">
  111. <div class="tit">{{$t('comments.uploadImages')}}</div>
  112. <div class="img-box">
  113. <mul-pic-upload v-model="item.imgs" :limit="9" />
  114. <div class="img-des">( {{$t('comments.uploadUpTo9Photos')}} )</div>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <!-- /待评价 -->
  121. <!-- 已评价 -->
  122. <div class="comments-box" v-if="isComm == 1">
  123. <div class="goods-msg">
  124. <div class="img">
  125. <img v-if="orderItem.pic" :src="orderItem.pic" alt @error="handlePicError"/>
  126. <img v-else src="~/assets/img/def.png" alt />
  127. </div>
  128. <a
  129. class="name"
  130. href="javascript:void(0);"
  131. @click="toProdDetail(orderItem.prodId)"
  132. >{{orderItem.prodName}}</a>
  133. <div v-if="orderItem.skuName" class="sku">{{$t('comments.specification')}}: {{orderItem.skuName}}</div>
  134. <div class="order-number">
  135. {{$t('comments.orderNumber')}}:
  136. <a
  137. href="javascript:void(0);"
  138. @click="toOrderDetail(orderItem.orderNumber)"
  139. class="number"
  140. >{{orderItem.orderNumber}}</a>
  141. </div>
  142. <div class="deal-time">
  143. {{$t('comments.transactionTime')}}:
  144. <span class="number">{{orderItem.recTime}}</span>
  145. </div>
  146. </div>
  147. <div class="operation">
  148. <div class="item" aria-disabled="true">
  149. <div class="tit">{{$t('comments.productRating')}}</div>
  150. <!-- 评分星级: -->
  151. <div class="star-box">
  152. <span class="stars">
  153. <i :class="[prodCommNum > 0?'star':'star-gray']" @click="prodComm(1)"></i>
  154. <i :class="[prodCommNum > 1?'star':'star-gray']" @click="prodComm(2)"></i>
  155. <i :class="[prodCommNum > 2?'star':'star-gray']" @click="prodComm(3)"></i>
  156. <i :class="[prodCommNum > 3?'star':'star-gray']" @click="prodComm(4)"></i>
  157. <i :class="[prodCommNum > 4?'star':'star-gray']" @click="prodComm(5)"></i>
  158. </span>
  159. </div>
  160. </div>
  161. <div class="item" style="margin-top: -15px;">
  162. <div class="tit">{{$t('comments.specificDescription')}}</div>
  163. <div class="des-content">
  164. <span>{{content}}</span>
  165. </div>
  166. </div>
  167. <div class="item">
  168. <div class="tit">{{$t('comments.commentsOnPictures')}}</div>
  169. <div class="img-box" v-if="pics.length">
  170. <div class="file-img" v-for="(item, index) in pics" :key="index">
  171. <img :src="item" alt />
  172. </div>
  173. </div>
  174. <div class="des-content" style="color: #999;" v-if="!pics.length">{{$t('comments.none')}}</div>
  175. </div>
  176. </div>
  177. </div>
  178. <!-- /已评价 -->
  179. <div class="btn-box">
  180. <a href="javascript:void(0);" v-if="isComm == 0" @click="submitComm()" class="btn">{{$t('comments.postComment')}}</a>
  181. <div class="agree-box" v-if="isComm == 0" @click="checkAgree">
  182. <input
  183. type="checkbox"
  184. :class="['checkbox',isAnonymous?'checked': 'default']"
  185. class="checkbox default"
  186. />
  187. <span class="text">{{$t('comments.anonymousOrNot')}}</span>
  188. </div>
  189. <a href="javascript:void(0);" v-if="isComm == 1" @click="cancel()" class="btn back">{{$t('comments.backToList')}}</a>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. </template>
  195. <script>
  196. import MulPicUpload from '~/components/mul-pic-upload'
  197. export default {
  198. data () {
  199. return {
  200. orderItemId: 0,
  201. orderItem: {},
  202. prodCommNum: 0,
  203. storeCommNum: 0,
  204. logCommNum: 0,
  205. pics: [],
  206. imgs: '',
  207. content: '',
  208. isAnonymous: false,
  209. isComm: this.$route.query.isComm,
  210. orderNumber: this.$route.query.orderNumber, //订单号
  211. orderItemProds: [], //订单商品信息
  212. submitCommCount: 0 // 已经提交了的评价数
  213. }
  214. },
  215. created () {
  216. this.orderItemId = this.$route.query.orderItemId || 0
  217. // this.getOrderItem(this.orderItemId)
  218. },
  219. mounted () {
  220. this.isComm = this.$route.query.isComm
  221. this.orderItemId = this.$route.query.orderItemId || 0
  222. // this.getUserInfo()
  223. if (this.isComm == 0) {
  224. this.getOrderItems(this.orderNumber)
  225. } else if (this.isComm == 1) {
  226. this.getOrderItem(this.orderItemId)
  227. this.getComm(this.orderItemId)
  228. } else {
  229. this.isComm = 0
  230. }
  231. },
  232. components: {
  233. MulPicUpload
  234. },
  235. methods: {
  236. /**
  237. * 加载默认图片
  238. */
  239. handlePicError(e){
  240. e.target.src=require('@/assets/img/def.png')
  241. },
  242. /**
  243. * 改变商品评分
  244. */
  245. prodComm (num, orderItemId) {
  246. if (this.isComm == 1) {
  247. return
  248. }
  249. this.orderItemProds.forEach(orderItem => {
  250. if (orderItemId == orderItem.orderItemId) {
  251. orderItem.score = num
  252. }
  253. })
  254. },
  255. /**
  256. * 改变店铺评分
  257. */
  258. storeComm (num) {
  259. if (this.isComm == 1) {
  260. return
  261. }
  262. this.storeCommNum = num
  263. },
  264. /**
  265. * 改变物流评分
  266. */
  267. logComm (num) {
  268. if (this.isComm == 1) {
  269. return
  270. }
  271. this.logCommNum = num
  272. },
  273. /**
  274. * 获取商品评价
  275. */
  276. getComm (orderItemId) {
  277. this.$axios.get('/p/prodComm/getProdComment', {
  278. params: {
  279. orderItemId: orderItemId
  280. }
  281. })
  282. .then(({ data }) => {
  283. this.content = data.content
  284. this.prodCommNum = data.score
  285. if (data.pics) {
  286. this.pics = data.pics.split(",")
  287. }
  288. })
  289. },
  290. /**
  291. * 获取多个商品详情
  292. */
  293. getOrderItems (orderNumber) {
  294. this.$axios.get('/p/myOrder/getOrderItems', {
  295. params: {
  296. orderNumber: orderNumber
  297. }
  298. }).then(({ data }) => {
  299. console.log(data);
  300. for (var i = 0; i < data.length; i++) {
  301. data[i].images = [];
  302. data[i].content = "";
  303. data[i].score = 5;
  304. data[i].evaluate = 0;
  305. }
  306. this.orderItemProds = data
  307. })
  308. },
  309. /**
  310. * 获取单个商品详情
  311. */
  312. getOrderItem (orderItemId) {
  313. this.$axios.get('/p/myOrder/getOrderItem', {
  314. params: {
  315. orderItemId: orderItemId
  316. }
  317. }).then(({ data }) => {
  318. console.log(data);
  319. this.orderItem = data
  320. })
  321. },
  322. /**
  323. * 提交评论
  324. */
  325. submitComm () {
  326. var allFill = true;
  327. for (var i = 0; i < this.orderItemProds.length; i++) {
  328. var cont = this.orderItemProds[i].content.trim();
  329. if (cont == "") {
  330. this.$message({
  331. message: this.$t('comments.evaluationCannotBeEmpty'),
  332. type: 'warning',
  333. duration: 1000,
  334. })
  335. allFill = false;
  336. break;
  337. }
  338. }
  339. if (allFill) {
  340. for (var i = 0; i < this.orderItemProds.length; i++) {
  341. let prodComm = {
  342. orderItemId: this.orderItemProds[i].orderItemId,
  343. score: this.orderItemProds[i].score,
  344. content: this.orderItemProds[i].content,
  345. isAnonymous: this.isAnonymous ? 1 : 0,
  346. evaluate: this.orderItemProds[i].score == 3 ? 1 : this.orderItemProds[i].score < 3 ? 2 : 0,
  347. prodId: this.orderItemProds.prodId,
  348. pics: this.orderItemProds[i].imgs,
  349. }
  350. this.$axios.post('/p/prodComm', prodComm)
  351. .then(({ data }) => {
  352. this.submitCommCount += 1
  353. if (this.submitCommCount == this.orderItemProds.length) {
  354. this.$message({
  355. message: this.$t('comments.submitCommentSuccessfully'),
  356. type: 'success',
  357. duration: 1000,
  358. onClose: () => {
  359. this.$router.push({ path: '/user-center/uc-comments' })
  360. }
  361. })
  362. }
  363. })
  364. }
  365. }
  366. },
  367. /**
  368. * 跳转订单详情
  369. */
  370. toOrderDetail (orderNumber) {
  371. this.$router.push({ path: '/order-detail', query: { orderNumber: orderNumber } })
  372. },
  373. /**
  374. * 跳转店铺页
  375. */
  376. // toOrderDetail (shopId) {
  377. // this.$router.push({ path: '/shopIndex?pn=', query: { shopId: shopId } })
  378. // },
  379. /**
  380. * 是否匿名
  381. */
  382. checkAgree () {
  383. this.isAnonymous = !this.isAnonymous
  384. },
  385. /**
  386. * 跳转到商品详情页
  387. */
  388. toProdDetail (prodId) {
  389. this.$router.push({ path: '/detail/' + prodId })
  390. },
  391. /**
  392. * 返回
  393. */
  394. cancel () {
  395. this.$router.push({ path: '/user-center/uc-comments', query: { isComm: 1 } })
  396. },
  397. }
  398. }
  399. </script>
  400. <style scoped src='~/assets/css/write-comments.css'></style>
  401. <style>
  402. .write-comments .el-upload--picture-card {
  403. background-color: #fff;
  404. border: 1px solid #eee;
  405. border-radius: 0;
  406. width: 112px;
  407. height: 112px;
  408. line-height: 112px;
  409. margin: 0 0 15px 15px;
  410. }
  411. .write-comments .el-upload--picture-card:hover {
  412. border-color: #eee;
  413. }
  414. .write-comments .el-upload--picture-card i {
  415. margin-top: -35px;
  416. font-size: 20px;
  417. color: #999;
  418. }
  419. .write-comments .el-upload-list--picture-card .el-upload-list__item {
  420. border: 1px solid #eee;
  421. border-radius: 0;
  422. width: 112px;
  423. height: 112px;
  424. margin: 0 0 15px 15px;
  425. }
  426. .write-comments .el-icon-plus{
  427. width:20px;
  428. height:20px;
  429. }
  430. </style>