evaluateDetail.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="page-evaluate">
  3. <!-- 头部商品信息 -->
  4. <view class="card">
  5. <view class="goods-list">
  6. <view v-if="order.isPackage!=1" v-for="(item,index) in items" :key="index" class="item">
  7. <view class="img-box">
  8. <image :src="JSON.parse(item.jsonInfo).image" mode="aspectFill"></image>
  9. </view>
  10. <view class="info-box">
  11. <view>
  12. <view class="name-box ellipsis2">
  13. <view v-if="item.isPrescribe==1" class="tag">处方药</view>{{JSON.parse(item.jsonInfo).productName}}
  14. </view>
  15. <view class="spec ellipsis2">{{JSON.parse(item.jsonInfo).sku}}</view>
  16. </view>
  17. <view class="price-num">
  18. <view class="price">
  19. <text class="unit">¥</text>
  20. <text class="num">{{JSON.parse(item.jsonInfo).price.toFixed(2)}}</text>
  21. </view>
  22. <view class="num">x{{JSON.parse(item.jsonInfo).num}}</view>
  23. </view>
  24. </view>
  25. </view>
  26. <view v-if="order.isPackage==1&&order.packageJson!=null" class="item" >
  27. <view class="img-box">
  28. <image :src="JSON.parse(order.packageJson).imgUrl" mode="aspectFill"></image>
  29. </view>
  30. <view class="info-box">
  31. <view>
  32. <view class="name-box ellipsis2">
  33. <view class="tag">套餐</view>{{JSON.parse(order.packageJson).title}}
  34. </view>
  35. <view class="spec ellipsis2">{{JSON.parse(order.packageJson).descs}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="card">
  42. <!-- 表单区 -->
  43. <u-form ref="form" :model="form" :rules="rules" label-width="140rpx" errorType="toast">
  44. <!-- 1. 商品打分 -->
  45. <u-form-item label="商品打分" prop="rating">
  46. <u-rate v-model="form.rating" :count="5" active-icon="star-fill" inactive-icon="star" size="24"></u-rate>
  47. </u-form-item>
  48. <!-- 2. 评价内容 -->
  49. <u-form-item label="评价内容" prop="content">
  50. <u-textarea v-model="form.content" placeholder="请分享您的使用感受~" maxlength="200" height="160"
  51. count></u-textarea>
  52. </u-form-item>
  53. <!-- 3. 上传图片 -->
  54. <u-form-item label="上传图片">
  55. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  56. :maxCount="6" :previewFullImage="true"></u-upload>
  57. </u-form-item>
  58. <!-- 4. 是否匿名 -->
  59. <u-form-item label="匿名评价">
  60. <view><checkbox :checked="form.isAnonymous" @click="handleAnonymous()" style="transform: scale(0.7);" /></view>
  61. </u-form-item>
  62. </u-form>
  63. </view>
  64. <!-- 5. 提交按钮 -->
  65. <view class="u-p-30">
  66. <u-button type="primary" shape="circle" @click="submit">提交评价</u-button>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import {getMyStoreOrderById,addOrderComment} from '@/api/myStoreOrder.js'
  72. export default {
  73. data() {
  74. return {
  75. form: {
  76. rating: 5, // 默认 5 星
  77. content: '',
  78. isAnonymous: false
  79. },
  80. fileList1: [], // 上传组件回显列表
  81. rules: {
  82. rating: [{
  83. type: 'number',
  84. min: 1,
  85. required: true,
  86. message: '请打分',
  87. trigger: 'change'
  88. }],
  89. content: [{
  90. required: true,
  91. message: '请输入评价',
  92. trigger: ['change','blur']
  93. },
  94. {
  95. min: 5,
  96. message: '至少 5 个字',
  97. trigger: ['change','blur']
  98. }
  99. ]
  100. },
  101. orderId: '',
  102. order:{},
  103. items:[],
  104. }
  105. },
  106. onLoad(option) {
  107. this.orderId = option.orderId
  108. this.getMyStoreOrderById()
  109. },
  110. onReady() {
  111. this.$refs.form.setRules(this.rules)
  112. },
  113. methods: {
  114. handleAnonymous() {
  115. this.form.isAnonymous = !this.form.isAnonymous;
  116. },
  117. // 选择图片后回调
  118. async afterRead(event) {
  119. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  120. let lists = [].concat(event.file)
  121. let fileListLen = this[`fileList${event.name}`].length
  122. lists.map((item) => {
  123. this[`fileList${event.name}`].push({
  124. ...item,
  125. status: 'uploading',
  126. message: '上传中'
  127. })
  128. })
  129. for (let i = 0; i < lists.length; i++) {
  130. const result = await this.uploadFilePromise(lists[i].url)
  131. let item = this[`fileList${event.name}`][fileListLen]
  132. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  133. status: 'success',
  134. message: '',
  135. url: result
  136. }))
  137. fileListLen++
  138. }
  139. },
  140. uploadFilePromise(url) {
  141. return new Promise((resolve, reject) => {
  142. let a = uni.uploadFile({
  143. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  144. filePath: url,
  145. name: 'file',
  146. formData: {
  147. user: 'test'
  148. },
  149. success: (res) => {
  150. setTimeout(() => {
  151. console.log(JSON.parse(res.data).url)
  152. resolve(JSON.parse(res.data).url)
  153. }, 1000)
  154. }
  155. });
  156. })
  157. },
  158. // 删除图片
  159. deletePic(event) {
  160. this[`fileList${event.name}`].splice(event.index, 1)
  161. },
  162. // 提交
  163. submit() {
  164. this.$refs.form.validate().then(res => {
  165. if(res) {
  166. const imgUrls = this.fileList1.map(item => item.url).join(',')
  167. const params = {
  168. orderId: this.orderId,
  169. rating: this.form.rating,
  170. content: this.form.content.trim(),
  171. imageUrl: imgUrls,
  172. isAnonymous: this.form.isAnonymous ? 1 : 0,
  173. isShow: 1,
  174. isDel: 0,
  175. nickName: uni.getStorageSync('nickName'),
  176. userId: uni.getStorageSync('userId'),
  177. }
  178. uni.showLoading({
  179. title: '提交中'
  180. })
  181. addOrderComment(params).then(res=>{
  182. uni.hideLoading()
  183. if(res.code == 200) {
  184. uni.showToast({
  185. title: '评价成功',
  186. icon: 'success'
  187. })
  188. uni.$emit('refreshOrder')
  189. setTimeout(() => uni.navigateBack(), 800)
  190. } else {
  191. uni.showToast({
  192. title: res.msg,
  193. icon: 'success'
  194. })
  195. }
  196. })
  197. }
  198. })
  199. },
  200. getMyStoreOrderById(){
  201. var data={orderId:this.orderId};
  202. getMyStoreOrderById(data).then(res => {
  203. if(res.code==200){
  204. this.order=res.order;
  205. this.items=res.items;
  206. }else{
  207. uni.showToast({
  208. icon:'none',
  209. title: "请求失败",
  210. });
  211. }
  212. });
  213. },
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. .page-evaluate {
  219. padding: 24rpx;
  220. }
  221. .card {
  222. background: #fff;
  223. padding: 24rpx;
  224. border-radius: 16rpx;
  225. margin-bottom: 20rpx;
  226. }
  227. .goods-list{
  228. padding: 0 30upx;
  229. background-color: #FFFFFF;
  230. border-radius: 16upx;
  231. .item{
  232. padding: 30upx 0;
  233. border-bottom: 1px solid #EDEEEF;
  234. display: flex;
  235. align-items: center;
  236. .img-box{
  237. width: 160upx;
  238. height: 160upx;
  239. margin-right: 30upx;
  240. image{
  241. width: 100%;
  242. height: 100%;
  243. }
  244. }
  245. .info-box{
  246. width: calc(100% - 190upx);
  247. height: 160upx;
  248. display: flex;
  249. flex-direction: column;
  250. justify-content: space-between;
  251. .name-box{
  252. font-size: 28upx;
  253. font-family: PingFang SC;
  254. font-weight: 500;
  255. color: #111111;
  256. line-height: 40upx;
  257. .tag{
  258. display: inline-block;
  259. padding: 0 6upx;
  260. height: 30upx;
  261. background: linear-gradient(90deg, #2BC7B9 0%, #2BC7A4 100%);
  262. border-radius: 4upx;
  263. margin-right: 10upx;
  264. font-size: 22upx;
  265. font-family: PingFang SC;
  266. font-weight: bold;
  267. color: #FFFFFF;
  268. line-height: 30upx;
  269. float: left;
  270. margin-top: 7upx;
  271. }
  272. }
  273. .spec{
  274. margin-top: 18upx;
  275. font-size: 24upx;
  276. font-family: PingFang SC;
  277. font-weight: 500;
  278. color: #999999;
  279. line-height: 1;
  280. }
  281. .price-num{
  282. display: flex;
  283. align-items: center;
  284. justify-content: space-between;
  285. .price{
  286. display: flex;
  287. align-items: flex-end;
  288. .unit{
  289. font-size: 24upx;
  290. font-family: PingFang SC;
  291. font-weight: 500;
  292. color: #111111;
  293. line-height: 1.2;
  294. margin-right: 4upx;
  295. }
  296. .num{
  297. font-size: 32upx;
  298. font-family: PingFang SC;
  299. font-weight: 500;
  300. color: #111111;
  301. line-height: 1;
  302. }
  303. }
  304. .num{
  305. font-size: 24upx;
  306. font-family: PingFang SC;
  307. font-weight: 500;
  308. color: #999999;
  309. line-height: 1;
  310. }
  311. }
  312. }
  313. }
  314. .sub-total{
  315. height: 88upx;
  316. display: flex;
  317. align-items: center;
  318. justify-content: flex-end;
  319. .discount{
  320. font-size: 24upx;
  321. font-family: PingFang SC;
  322. font-weight: 500;
  323. color: #999999;
  324. line-height: 1;
  325. margin-right: 30upx;
  326. }
  327. .label{
  328. font-size: 24upx;
  329. font-family: PingFang SC;
  330. font-weight: 500;
  331. color: #999999;
  332. }
  333. .price{
  334. display: flex;
  335. align-items: flex-end;
  336. .unit{
  337. font-size: 24upx;
  338. font-family: PingFang SC;
  339. font-weight: 500;
  340. color: #FF6633;
  341. line-height: 1.2;
  342. margin-right: 4upx;
  343. }
  344. .num{
  345. font-size: 32upx;
  346. font-family: PingFang SC;
  347. font-weight: bold;
  348. color: #FF6633;
  349. line-height: 1;
  350. }
  351. }
  352. }
  353. }
  354. </style>