evaluate.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view>
  3. <view class="content" v-for="item in orderDetail.goods">
  4. <view class="goods-title">
  5. <image class="goods-img" :src="item.goods_image" mode="scaleToFill" />
  6. <view class="title"> {{ item.goods_name }} </view>
  7. </view>
  8. <view class="rate">
  9. <view class="_label"> 商品评价 </view>
  10. <u-rate :count="count" v-model="value" size="22"></u-rate>
  11. </view>
  12. <u-upload
  13. :fileList="fileList1"
  14. @afterRead="afterRead"
  15. @delete="deletePic"
  16. name="1"
  17. multiple
  18. :maxCount="10"
  19. accept="all"
  20. >
  21. <view class="upload-photo">
  22. <u-icon name="camera" size="26"></u-icon>
  23. <text>添加图片/视频</text>
  24. </view>
  25. </u-upload>
  26. <view class="_text">
  27. <u--textarea
  28. border="none"
  29. v-model="value1"
  30. height="150"
  31. placeholder="展开说说对商品的想法"
  32. ></u--textarea>
  33. </view>
  34. </view>
  35. <button class="btn-1" @click="submit">提交评价</button>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. count: 5,
  43. value: 5,
  44. value1: "",
  45. fileList1: [],
  46. status: "",
  47. orderDetail: {},
  48. };
  49. },
  50. onLoad(options) {
  51. this.status = options.orderId;
  52. this.getDetail();
  53. },
  54. methods: {
  55. //提交评价
  56. submit() {
  57. let imgList = [];
  58. this.fileList1.map((item) => {
  59. imgList.push(item.thumb);
  60. });
  61. uni.$u.http
  62. .post(`/api/order/comment`, {
  63. order_goods_id: this.orderDetail.goods[0].id,
  64. content: this.value1,
  65. score: this.value,
  66. image: imgList.join(","),
  67. video: "",
  68. })
  69. .then((res) => {
  70. uni.showToast({
  71. title: "评价成功",
  72. icon: "none",
  73. });
  74. let timer = setTimeout(() => {
  75. uni.navigateBack({
  76. delta: 1,
  77. });
  78. clearTimeout(timer);
  79. }, 1000);
  80. });
  81. },
  82. // 删除图片
  83. deletePic(event) {
  84. this[`fileList${event.name}`].splice(event.index, 1);
  85. },
  86. // 新增图片
  87. async afterRead(event) {
  88. console.log(event);
  89. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  90. let lists = [].concat(event.file);
  91. let fileListLen = this[`fileList${event.name}`].length;
  92. lists.map((item) => {
  93. this[`fileList${event.name}`].push({
  94. ...item,
  95. // status: "uploading",
  96. // message: "上传中",
  97. });
  98. });
  99. for (let i = 0; i < lists.length; i++) {
  100. const result = await this.uploadFilePromise(lists[i].url);
  101. let item = this[`fileList${event.name}`][fileListLen];
  102. this[`fileList${event.name}`].splice(
  103. fileListLen,
  104. 1,
  105. Object.assign(item, {
  106. status: "success",
  107. message: "",
  108. url: result,
  109. })
  110. );
  111. fileListLen++;
  112. }
  113. },
  114. uploadFilePromise(url) {
  115. return new Promise((resolve, reject) => {
  116. let a = uni.uploadFile({
  117. url: `${uni.$u.http.config.baseURL}/api/upload/images`, // 仅为示例,非真实的接口地址
  118. filePath: url,
  119. name: "file",
  120. formData: {
  121. user: "test",
  122. },
  123. success: (res) => {
  124. setTimeout(() => {
  125. resolve(res.data.data);
  126. }, 1000);
  127. },
  128. });
  129. });
  130. },
  131. getDetail() {
  132. uni.$u.http.get(`/api/order/read?id=${this.status}`).then((res) => {
  133. this.orderDetail = res;
  134. });
  135. },
  136. },
  137. mounted() {
  138. uni.setNavigationBarTitle({
  139. title: "评价",
  140. });
  141. },
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. .content {
  146. background-color: #fff;
  147. padding: 40rpx 24rpx;
  148. .goods-title {
  149. display: flex;
  150. justify-content: flex-start;
  151. align-items: center;
  152. .goods-img {
  153. width: 52rpx;
  154. height: 52rpx;
  155. border-radius: 6rpx;
  156. }
  157. .title {
  158. font-size: 24rpx;
  159. color: rgba(51, 51, 51, 0.5);
  160. margin-left: 20rpx;
  161. }
  162. }
  163. .rate {
  164. display: flex;
  165. align-items: center;
  166. margin-bottom: 20rpx;
  167. ._label {
  168. font-size: 32rpx;
  169. font-weight: 600;
  170. margin-right: 22rpx;
  171. }
  172. }
  173. ._text {
  174. margin-top: 32rpx;
  175. padding-top: 26rpx;
  176. border-top: 2rpx solid rgba(151, 151, 151, 0.1);
  177. }
  178. .upload-photo {
  179. width: 180rpx;
  180. height: 180rpx;
  181. border: 2rpx dashed #979797;
  182. border-radius: 8rpx;
  183. display: flex;
  184. align-items: center;
  185. flex-direction: column;
  186. justify-content: center;
  187. font-size: 24rpx;
  188. color: rgba(34, 34, 34, 0.8);
  189. }
  190. ::v-deep .u-textarea {
  191. background-color: #fff;
  192. }
  193. }
  194. .btn-1 {
  195. background-color: #f83224;
  196. color: #fff;
  197. border-radius: 40rpx;
  198. height: 80rpx;
  199. line-height: 80rpx;
  200. width: 90%;
  201. margin: 0 auto;
  202. margin-top: 70rpx;
  203. font-size: 32rpx;
  204. }
  205. </style>