appraise.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <mobile-frame>
  3. <view class="info">
  4. <view class="one">
  5. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  6. <uni-forms-item label="评论内容" name="content">
  7. <uni-easyinput type="textarea" v-model="form.content" placeholder="请输入评论内容" />
  8. </uni-forms-item>
  9. <uni-forms-item label="上传评论图片" name="file">
  10. <upload :list="file" name="file" :count="6" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  11. </uni-forms-item>
  12. <uni-forms-item label="商品评分" name="goods_score">
  13. <uni-rate size="18" v-model="form.goods_score" />
  14. </uni-forms-item>
  15. <uni-forms-item label="发货评分" name="transport_score">
  16. <uni-rate size="18" v-model="form.transport_score" />
  17. </uni-forms-item>
  18. <uni-forms-item label="店铺评分" name="shop_score">
  19. <uni-rate size="18" v-model="form.shop_score" />
  20. </uni-forms-item>
  21. </uni-forms>
  22. <view class="btn">
  23. <button type="primary" @click="onSubmit('form')" size="small">提交</button>
  24. </view>
  25. </view>
  26. </view>
  27. </mobile-frame>
  28. </template>
  29. <script>
  30. import moment from 'moment';
  31. import upload from '@/components/upload/index.vue';
  32. export default {
  33. components: {
  34. upload
  35. },
  36. data() {
  37. return {
  38. id: '',
  39. user: {},
  40. form: {},
  41. info: {},
  42. file: [],
  43. rules: {
  44. content: {
  45. rules: [{
  46. required: true,
  47. errorMessage: '请输入评论内容',
  48. }]
  49. },
  50. grade: {
  51. rules: [{
  52. required: true,
  53. errorMessage: '请输入评论等级',
  54. }]
  55. }
  56. },
  57. };
  58. },
  59. onLoad: function(e) {
  60. const that = this;
  61. that.$set(that, `id`, e.id || '');
  62. // 监听用户是否登录
  63. that.watchLogin();
  64. },
  65. methods: {
  66. // 图片上传
  67. uplSuc(e) {
  68. const that = this;
  69. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  70. },
  71. // 图片删除
  72. uplDel(e) {
  73. const that = this;
  74. let data = that[e.name];
  75. let arr = data.filter((i, index) => index != e.data.index);
  76. that.$set(that, `${e.name}`, arr)
  77. },
  78. // 提交保存
  79. async onSubmit(ref) {
  80. const that = this;
  81. that.$refs[ref].validate().then(async params => {
  82. let reply = [{
  83. file: that.file,
  84. content: params.content,
  85. time: moment().format('YYYY-MM-DD HH:mm:ss')
  86. }];
  87. params.reply = reply;
  88. params.customer = that.user?._id;
  89. params.shop = that.info?.goods[0]?.shop;
  90. params.goods = that.info?.goods[0]?.goods[0]?.goods?._id;
  91. params.goodsSpec = that.info?.goods[0]?.goods[0]?._id;
  92. const arr = await that.$api(`/goodsRate`, 'POST', params);
  93. if (arr.errcode == '0') {
  94. uni.showToast({
  95. title: `评论成功`,
  96. icon: 'success',
  97. });
  98. uni.navigateBack({
  99. detail: 1
  100. })
  101. } else {
  102. uni.showToast({
  103. title: arr.errmsg,
  104. icon: 'none',
  105. })
  106. }
  107. })
  108. },
  109. // 监听用户是否登录
  110. watchLogin() {
  111. const that = this;
  112. uni.getStorage({
  113. key: 'token',
  114. success: function(res) {
  115. let user = that.$jwt(res.data);
  116. if (user) that.$set(that, `user`, user);
  117. that.search();
  118. },
  119. fail: function(err) {
  120. uni.navigateTo({
  121. url: `/pages/login/index`
  122. })
  123. }
  124. });
  125. },
  126. // 查询列表
  127. async search() {
  128. const that = this;
  129. let user = that.user;
  130. if (that.id) {
  131. let res = await that.$api(`/orderDetail/${that.id}`);
  132. if (res.errcode == '0') {
  133. that.$set(that, `info`, res.data.order);
  134. uni.hideLoading();
  135. }
  136. }
  137. },
  138. }
  139. }
  140. </script>
  141. <style lang="scss">
  142. .info {
  143. display: flex;
  144. flex-direction: column;
  145. width: 100vw;
  146. height: 100vh;
  147. .one {
  148. padding: 2vw;
  149. .uni-input {
  150. border: #f1f1ff 1px solid;
  151. padding: 2vw 2vw;
  152. border-radius: 1vw;
  153. }
  154. .btn {
  155. text-align: center;
  156. button {
  157. margin: 0 2vw 2vw 2vw;
  158. background-color: var(--ff0Color);
  159. color: var(--fffColor);
  160. }
  161. .name {
  162. color: var(--f85Color);
  163. font-size: var(--font14Size);
  164. }
  165. }
  166. }
  167. }
  168. .uni-forms-item {
  169. margin-bottom: 6vw !important;
  170. display: flex;
  171. flex-direction: row;
  172. }
  173. .uni-forms-item__content {
  174. display: flex;
  175. align-items: center;
  176. }
  177. </style>