金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

350 lines
9.0 KiB

  1. <template>
  2. <!--<import src="../../../component/rater/rater.wxml"></import>-->
  3. <view id="order-comment">
  4. <view class="order-items">
  5. <view class="order-item" v-for="(item, index) in orderData.items" :key="index">
  6. <view class="order-info mx-1px-bottom">
  7. <view class="image">
  8. <image :src="item.item_meta.image"></image>
  9. </view>
  10. <view class="texts">
  11. <view class="name">{{item.item_name}}</view>
  12. <view class="spec">{{item.item_meta.specs_text}}</view>
  13. <view class="content">
  14. <view class="item_start">
  15. <uni-rate size="18" active-color="red" value="5" @change="changeStar"></uni-rate>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="comment-content mx-1px-bottom">
  21. <view class="content">
  22. <textarea @input="changeEvaluate" :data-index="index" :value="item.comment" placeholder="请输入您对该商品的想法"></textarea>
  23. <view class="number">还可以输入{{500 - length}}</view>
  24. </view>
  25. </view>
  26. <view class="uploading-box">
  27. <view class="img-item uploading-item" v-for="(itemVal,idx) in item.upload_images" :key="idx">
  28. <view class="img">
  29. <image mode="widthFix" :src="itemVal"></image>
  30. </view>
  31. <span class="delete" :data-index="index" :data-idx="idx" :data-images="item.upload_images" @tap="deleteImg($event,item.upload_images)">
  32. x
  33. </span>
  34. </view>
  35. <view class="uploading uploading-item" @tap="upload" v-if="item.upload_images.length<5" :data-index="index">
  36. <view class="uploading-input">
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="submit" :disabled="disabled" @tap="submit">提交评价</view>
  43. </view>
  44. </template>
  45. <script>
  46. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  47. import uniRate from "@/components/score/uni-rate/uni-rate.vue"
  48. export default {
  49. data() {
  50. return {
  51. orderData:'',
  52. minLength: 5,
  53. disabled: true,
  54. order_no: '',
  55. length: '',
  56. star:5
  57. };
  58. },
  59. components:{
  60. uniRate
  61. },
  62. onLoad(e) {
  63. console.log(e);
  64. var no = e.no;
  65. this.initOrderComment(no);
  66. this.setData({
  67. order_no: no
  68. });
  69. },
  70. methods: {
  71. upload(e) {
  72. var index = e.currentTarget.dataset.index;
  73. var that = this;
  74. wx.chooseImage({
  75. count: 1,
  76. // 默认9
  77. success: function (res) {
  78. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  79. var tempFilePaths = res.tempFilePaths;
  80. var token = that.$cookieStorage.get('user_token');
  81. /* that.$http.uploadFile({
  82. header: {
  83. 'content-type': 'multipart/form-data',
  84. Authorization: token
  85. },
  86. api: 'api/users/upload/avatar',
  87. //仅为示例,非真实的接口地址
  88. filePath: tempFilePaths[0],
  89. name: 'avatar_file'
  90. }).then(res => {
  91. var result = JSON.parse(res.data);
  92. var arr = that.orderData.items[index].upload_images;
  93. arr.push(result.data.url);
  94. var uploadData = `orderData.items[${index}]`;
  95. that.orderData.items[index].upload_images=arr;
  96. }); */
  97. uni.uploadFile({
  98. header: {
  99. Authorization: token
  100. },
  101. url: config.GLOBAL.baseUrl + 'api/users/upload/avatar',
  102. filePath: tempFilePaths[0],
  103. fileType: 'image',
  104. name: 'avatar_file',
  105. success: res => {
  106. var result = JSON.parse(res.data);
  107. var arr = that.orderData.items[index].upload_images;
  108. arr.push(result.data.url);
  109. var uploadData = `orderData.items[${index}]`;
  110. that.orderData.items[index].upload_images=arr;
  111. }
  112. })
  113. }
  114. });
  115. },
  116. changeEvaluate(e) {
  117. var len = e.detail.value;
  118. var index = e.currentTarget.dataset.index;
  119. if (e.detail.value.length > 500) {
  120. wx.showModal({
  121. title: '提示',
  122. content: '超出字数限制'
  123. });
  124. len = len.slice(0, 500);
  125. }
  126. // this.setData({
  127. // [`orderData.items[${index}].comment`]: len,
  128. // length: e.detail.value.length
  129. // });
  130. this.length=e.detail.value.length;
  131. this.orderData.items[index].comment=len;
  132. },
  133. deleteImg(e,images) {
  134. var index = e.currentTarget.dataset.index;
  135. var idx = e.currentTarget.dataset.idx;
  136. // #ifndef H5
  137. // #endif
  138. // #ifdef H5
  139. images = images
  140. // #endif
  141. images.splice(idx, 1);
  142. // this.setData({
  143. // [`orderData.items[${index}].upload_images`]: images
  144. // });
  145. this.orderData.items[index].upload_images=images;
  146. },
  147. allowComment() {
  148. if (this.orderData.items && this.orderData.items.length) {
  149. for (let item of this.orderData.items) {
  150. if (item.comment.length < this.minLength) return false;
  151. }
  152. return true;
  153. } else {
  154. return false;
  155. }
  156. },
  157. submit() {
  158. if (this.allowComment()) {
  159. var no = this.order_no;
  160. var comments = [];
  161. var data = this.orderData.items;
  162. var rater = this.star;
  163. data.forEach((item,index) => {
  164. comments.push({
  165. order_no: no,
  166. order_item_id: item.id,
  167. contents: item.comment,
  168. point: rater,
  169. images:item.upload_images
  170. })
  171. });
  172. this.postSubmit(comments);
  173. } else {
  174. wx.showModal({
  175. content: "请填写完成",
  176. showCancel: false
  177. });
  178. }
  179. },
  180. changeStar(e){
  181. this.star=e.value;
  182. },
  183. postSubmit(comments) {
  184. wx.showLoading({
  185. title: "加载中",
  186. mask: true
  187. });
  188. var data = {};
  189. comments.forEach((comment, index) => {
  190. data[index] = comment;
  191. });
  192. this.$http.post({
  193. api: 'api/shopping/order/review',
  194. header: {
  195. Authorization: this.$cookieStorage.get('user_token')
  196. },
  197. data: data
  198. }).then(res => {
  199. if (res.statusCode == 200) {
  200. res = res.data;
  201. if (res.status
  202. && comments.length
  203. ) {
  204. console.log(23423423);
  205. wx.showModal({
  206. content: '评价成功',
  207. showCancel: false,
  208. success: res => {
  209. if (res.confirm || !res.cancel && !res.confirm) {
  210. wx.redirectTo({
  211. url: '/pages/order/comment/comment'
  212. });
  213. }
  214. }
  215. });
  216. } else {
  217. wx.showModal({
  218. content: res.message || "请求失败",
  219. showCancel: false
  220. });
  221. }
  222. wx.hideLoading();
  223. } else {
  224. wx.showModal({
  225. content: "请求失败",
  226. showCancel: false
  227. });
  228. wx.hideLoading();
  229. }
  230. });
  231. },
  232. initOrderComment(id) {
  233. wx.showLoading({
  234. title: "加载中",
  235. mask: true
  236. });
  237. this.$http.get({
  238. api: 'api/order/' + id,
  239. header: {
  240. Authorization: this.$cookieStorage.get('user_token')
  241. }
  242. }).then(res => {
  243. if (res.statusCode == 200) {
  244. res = res.data;
  245. if (res.status) {
  246. // var start = Rater;
  247. var data = res.data;
  248. data.items.forEach((v, index) => {
  249. /* start.init(index, {
  250. value: 5
  251. })*/
  252. v.score = '';
  253. v.comment = '';
  254. v.upload_images = [];
  255. });
  256. this.setData({
  257. orderData: data
  258. });
  259. } else {
  260. wx.showModal({
  261. content: res.message || "请求失败",
  262. showCancel: false
  263. });
  264. }
  265. wx.hideLoading();
  266. } else {
  267. wx.showModal({
  268. content: "请求失败",
  269. showCancel: false
  270. });
  271. wx.hideLoading();
  272. }
  273. });
  274. },
  275. setData: function (obj) {
  276. let that = this;
  277. let keys = [];
  278. let val, data;
  279. Object.keys(obj).forEach(function (key) {
  280. keys = key.split('.');
  281. val = obj[key];
  282. data = that.$data;
  283. keys.forEach(function (key2, index) {
  284. if (index + 1 == keys.length) {
  285. that.$set(data, key2, val);
  286. } else {
  287. if (!data[key2]) {
  288. that.$set(data, key2, {});
  289. }
  290. }
  291. data = data[key2];
  292. });
  293. });
  294. }
  295. },
  296. computed: {},
  297. watch: {}
  298. };
  299. </script>
  300. <style rel="stylesheet/less" lang="less">
  301. @import "evaluate";
  302. </style>