evaluate.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <el-form class="ns-evalute" v-loading="loading">
  3. <div class="ns-eva-li" v-for="(item, index) in goodsList" :key="index">
  4. <!-- 商品信息 -->
  5. <div class="ns-eva-good">
  6. <el-image fit="scale-down" :src="$img(item.sku_image, { size: 'mid' })" @error="imageError(index)"
  7. @click="toGoodsDetail(item.sku_id)"></el-image>
  8. <p class="ns-eva-good-name" :title="item.sku_name" @click="toGoodsDetail(item.sku_id)">{{ item.sku_name }}</p>
  9. <p>¥{{ item.price }}</p>
  10. </div>
  11. <!-- 评价表单 -->
  12. <div class="ns-eva-form">
  13. <div class="block" v-if="!isEvaluate">
  14. <span class="demonstration">描述相符:</span>
  15. <el-rate v-model="goodsEvalList[index].scores" @change="setStar(index)"></el-rate>
  16. <div class="level">
  17. <i class="iconfont" :class="
  18. goodsEvalList[index].explain_type == '1'
  19. ? 'iconhaoping1 ns-text-color'
  20. : goodsEvalList[index].explain_type == '2'
  21. ? 'iconzhongchaping ns-text-color'
  22. : goodsEvalList[index].explain_type == '3'
  23. ? 'iconzhongchaping'
  24. : ''
  25. "></i>
  26. <span>
  27. {{
  28. goodsEvalList[index].explain_type == '1'
  29. ? '好评'
  30. : goodsEvalList[index].explain_type == '2'
  31. ? '中评'
  32. : goodsEvalList[index].explain_type == '3'
  33. ? '差评'
  34. : ''
  35. }}
  36. </span>
  37. </div>
  38. </div>
  39. <div class="ns-textarea">
  40. <el-input v-if="!isEvaluate" type="textarea" :rows="5" placeholder="请在此处输入您的评价"
  41. v-model="goodsEvalList[index].content" maxlength="200" show-word-limit></el-input>
  42. <el-input v-else type="textarea" :rows="5" placeholder="请在此处输入您的追评"
  43. v-model="goodsEvalList[index].again_content" maxlength="200" show-word-limit></el-input>
  44. </div>
  45. <div class="upload-wrap">
  46. <el-upload ref="upload" :class="{ ishide: hide[index] }" :action="uploadActionUrl" :data="uploadData"
  47. list-type="picture-card" :on-success="
  48. (file, fileList) => {
  49. return handleSuccess(file, fileList, index);
  50. }
  51. " :on-preview="handlePictureCardPreview" :on-remove="
  52. (file, fileList) => {
  53. return handleRemove(file, fileList, index);
  54. }
  55. " :on-exceed="handleExceed" multiple drag limit="6">
  56. <i class="el-icon-plus"></i>
  57. <!-- <i class="el-icon-upload"></i> -->
  58. <!-- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  59. <div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过500kb</div> -->
  60. </el-upload>
  61. <el-dialog :visible.sync="dialogVisible"><img width="100%" :src="dialogImageUrl" alt="" /></el-dialog>
  62. <div class="tips">共6张,还能上传{{ imgList[index].length ? 6 - imgList[index].length : 6 }}张</div>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="save-btn-wrap"><el-button @click="save" type="primary">提交</el-button></div>
  67. </el-form>
  68. </template>
  69. <script>
  70. import {
  71. mapGetters
  72. } from 'vuex';
  73. import {
  74. orderInfo,
  75. save,
  76. uploadImg
  77. } from '@/api/order/order';
  78. import Config from '@/plugins/config';
  79. export default {
  80. name: 'evaluate',
  81. components: {},
  82. data: () => {
  83. return {
  84. loading: true,
  85. value1: 5,
  86. memberName: '',
  87. memberNeadimg: '',
  88. orderId: null,
  89. orderNo: '',
  90. isAnonymous: 0, //是否匿名发布 1.匿名,0.公开
  91. goodsList: [], //订单列表
  92. goodsEvalList: [], //评价列表
  93. imgList: [],
  94. isEvaluate: 0, //判断是否为追评
  95. flag: false, //防止重复点击
  96. siteName: '', // 店铺名称
  97. shop_deliverycredit: 5, // 配送服务分值
  98. shop_desccredit: 5, // 描述相符分值
  99. shop_servicecredit: 5, // 服务态度分值
  100. uploadActionUrl: Config.baseUrl + '/api/upload/evaluateimg',
  101. uploadData: {
  102. app_type: "pc",
  103. app_type_name: "PC"
  104. },
  105. dialogImageUrl: '',
  106. dialogVisible: false,
  107. hide: []
  108. };
  109. },
  110. created() {
  111. this.orderId = this.$route.query.order_id;
  112. this.getUserInfo();
  113. if (this.orderId) {
  114. this.getOrderInfo();
  115. }
  116. },
  117. computed: {
  118. ...mapGetters(['defaultGoodsImage'])
  119. },
  120. layout: 'member',
  121. methods: {
  122. handleSuccess(file, fileList, index) {
  123. let arr = this.imgList[index];
  124. arr = arr.concat(file.data.pic_path);
  125. this.imgList[index] = [];
  126. this.$set(this.imgList, index, arr);
  127. if (this.isEvaluate) {
  128. this.goodsEvalList[index].again_images = this.imgList[index].toString();
  129. } else {
  130. this.goodsEvalList[index].images = this.imgList[index].toString();
  131. }
  132. if (this.imgList[index].length >= 6) {
  133. this.hide[index] = true;
  134. }
  135. },
  136. handleRemove(file, fileList, index) {
  137. let i = this.$util.inArray(file.response.data.pic_path, this.imgList[index]);
  138. this.imgList[index].splice(i, 1);
  139. if (this.isEvaluate) {
  140. this.goodsEvalList[index].again_images = this.imgList[index].toString();
  141. } else {
  142. this.goodsEvalList[index].images = this.imgList[index].toString();
  143. }
  144. if (this.imgList[index].length < 6) {
  145. this.hide[index] = false;
  146. }
  147. },
  148. handleExceed(file, fileList) {
  149. // 图片数量大于6
  150. this.$message.warning('上传图片最大数量为6张');
  151. },
  152. handlePictureCardPreview(file) {
  153. // 点开大图
  154. this.dialogImageUrl = file.url;
  155. this.dialogVisible = true;
  156. },
  157. //获取用户信息
  158. getUserInfo() {
  159. this.$store
  160. .dispatch('member/member_detail', {
  161. refresh: 1
  162. })
  163. .then(res => {
  164. this.memberName = res.data.nickname;
  165. this.memberNeadimg = res.data.headimg;
  166. })
  167. .catch(err => {
  168. this.$message.error(err.message);
  169. });
  170. },
  171. //获取订单信息
  172. getOrderInfo() {
  173. //获取订单信息
  174. orderInfo({
  175. order_id: this.orderId
  176. })
  177. .then(res => {
  178. if (res.code == 0) {
  179. this.isEvaluate = res.data.evaluate_status;
  180. this.orderNo = res.data.list[0].order_no;
  181. this.goodsList = res.data.list;
  182. this.siteName = res.data.list[0].site_name;
  183. if (this.isEvaluate) {
  184. for (let i = 0; i < res.data.list.length; i++) {
  185. let array = [];
  186. this.imgList.push(array);
  187. this.hide.push(false);
  188. this.goodsEvalList.push({
  189. order_goods_id: res.data.list[i].order_goods_id,
  190. goods_id: res.data.list[i].goods_id,
  191. sku_id: res.data.list[i].sku_id,
  192. again_content: '',
  193. again_images: '',
  194. site_id: res.data.list[i].site_id
  195. });
  196. }
  197. } else {
  198. for (let i = 0; i < res.data.list.length; i++) {
  199. let array = [];
  200. this.imgList.push(array);
  201. this.goodsEvalList.push({
  202. content: '', // 评价内容
  203. images: '', //图片数组
  204. scores: 5, // 评分
  205. explain_type: 1, // 评价类型
  206. order_goods_id: res.data.list[i].order_goods_id,
  207. goods_id: res.data.list[i].goods_id,
  208. sku_id: res.data.list[i].sku_id,
  209. sku_name: res.data.list[i].sku_name,
  210. sku_price: res.data.list[i].price,
  211. sku_image: res.data.list[i].sku_image,
  212. site_id: res.data.list[i].site_id
  213. });
  214. }
  215. }
  216. }
  217. this.loading = false;
  218. })
  219. .catch(err => {
  220. this.$message.error(err.message);
  221. this.$router.push('/member/order_list');
  222. this.loading = false;
  223. });
  224. },
  225. //监听评分变化
  226. setStar(index) {
  227. if (this.goodsEvalList[index].scores >= 4) {
  228. this.goodsEvalList[index].explain_type = 1;
  229. } else if (1 < this.goodsEvalList[index].scores && this.goodsEvalList[index].scores < 4) {
  230. this.goodsEvalList[index].explain_type = 2;
  231. } else {
  232. this.goodsEvalList[index].explain_type = 3;
  233. }
  234. },
  235. imageError(index) {
  236. this.goodsList[index].sku_image = this.defaultGoodsImage;
  237. },
  238. /**
  239. * 提交
  240. */
  241. save() {
  242. for (let i = 0; i < this.goodsEvalList.length; i++) {
  243. if (this.isEvaluate) {
  244. if (!this.goodsEvalList[i].again_content.trim().length) {
  245. this.$message({
  246. message: '商品的评价不能为空哦',
  247. type: 'warning'
  248. });
  249. return;
  250. }
  251. } else {
  252. if (!this.goodsEvalList[i].content.trim().length) {
  253. this.$message({
  254. message: '商品的评价不能为空哦',
  255. type: 'warning'
  256. });
  257. return;
  258. }
  259. }
  260. }
  261. let goodsEvaluate = JSON.stringify(this.goodsEvalList);
  262. let data = {
  263. order_id: this.orderId,
  264. goods_evaluate: goodsEvaluate,
  265. isEvaluate: this.isEvaluate
  266. };
  267. if (!this.isEvaluate) {
  268. data.order_no = this.orderNo;
  269. data.member_name = this.memberName;
  270. data.member_headimg = this.memberNeadimg;
  271. data.is_anonymous = this.isAnonymous;
  272. }
  273. if (this.flag) return;
  274. this.flag = true;
  275. save(data)
  276. .then(res => {
  277. if (res.code == 0) {
  278. this.$message({
  279. message: '评价成功',
  280. type: 'success',
  281. duration: 2000,
  282. onClose: () => {
  283. this.$router.push({
  284. path: '/member/order_list'
  285. });
  286. }
  287. });
  288. } else {
  289. this.$message({
  290. message: res.message,
  291. type: 'warning'
  292. });
  293. this.flag = false;
  294. }
  295. })
  296. .catch(err => {
  297. this.$message.error(err.message);
  298. this.flag = false;
  299. });
  300. },
  301. /**
  302. * 跳转到商品详情
  303. */
  304. toGoodsDetail(id) {
  305. this.$util.pushToTab('sku-' + id);
  306. }
  307. }
  308. };
  309. </script>
  310. <style lang="scss" scoped>
  311. .ns-evalute {
  312. margin: 20px 0;
  313. background: #ffffff;
  314. padding: 30px;
  315. border-radius: 5px;
  316. .ns-eva-li {
  317. display: flex;
  318. padding: 20px 0;
  319. border-bottom: 1px solid #eeeeee;
  320. .ns-eva-good {
  321. width: 30%;
  322. text-align: center;
  323. .el-image {
  324. width: 125px;
  325. height: 125px;
  326. cursor: pointer;
  327. }
  328. .ns-eva-good-name {
  329. width: 250px;
  330. margin: 0 auto;
  331. overflow: hidden;
  332. text-overflow: ellipsis;
  333. display: -webkit-box;
  334. -webkit-line-clamp: 2;
  335. -webkit-box-orient: vertical;
  336. cursor: pointer;
  337. }
  338. }
  339. }
  340. .ns-eva-form {
  341. width: 70%;
  342. .ns-textarea {
  343. position: relative;
  344. }
  345. .upload-wrap {
  346. .tips {
  347. margin-top: 10px;
  348. }
  349. }
  350. .level {
  351. display: inline-block;
  352. margin-left: 50px;
  353. i {
  354. margin-right: 5px;
  355. vertical-align: top;
  356. }
  357. }
  358. .el-textarea {
  359. margin: 10px 0;
  360. }
  361. }
  362. .el-rate {
  363. display: inline-block;
  364. vertical-align: middle;
  365. }
  366. .save-btn-wrap {
  367. text-align: center;
  368. margin-top: 20px;
  369. }
  370. .el-dialog {
  371. img {
  372. width: auto;
  373. margin: 0 auto;
  374. }
  375. }
  376. }
  377. </style>
  378. <style lang="scss">
  379. .ns-evalute {
  380. .el-upload--picture-card {
  381. border: none;
  382. }
  383. .el-upload--picture-card,
  384. .el-upload-list--picture-card .el-upload-list__item {
  385. width: 70px;
  386. height: 70px;
  387. line-height: 80px;
  388. position: relative;
  389. }
  390. .el-upload-list--picture-card .el-upload-list__item-thumbnail {
  391. width: 100%;
  392. height: auto;
  393. position: absolute;
  394. top: 50%;
  395. transform: translateY(-50%);
  396. }
  397. .el-upload-list__item.is-success .el-upload-list__item-status-label {
  398. display: none;
  399. }
  400. .ishide .el-upload--picture-card {
  401. display: none;
  402. }
  403. .upload-wrap .el-upload-dragger {
  404. width: 70px;
  405. height: 70px;
  406. }
  407. .el-dialog {
  408. .el-dialog__body {
  409. text-align: center;
  410. }
  411. }
  412. }
  413. </style>