appraise.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 v-if="!rate_id" label="商品评分" name="goods_score">
  13. <uni-rate size="18" v-model="form.goods_score" />
  14. </uni-forms-item>
  15. <uni-forms-item v-if="!rate_id" label="发货评分" name="transport_score">
  16. <uni-rate size="18" v-model="form.transport_score" />
  17. </uni-forms-item>
  18. <uni-forms-item v-if="!rate_id" 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. // 追加
  40. rate_id: '',
  41. user: {},
  42. form: {},
  43. info: {},
  44. file: [],
  45. rules: {
  46. content: {
  47. rules: [{
  48. required: true,
  49. errorMessage: '请输入评论内容',
  50. }]
  51. },
  52. grade: {
  53. rules: [{
  54. required: true,
  55. errorMessage: '请输入评论等级',
  56. }]
  57. }
  58. },
  59. };
  60. },
  61. onLoad: function(e) {
  62. const that = this;
  63. that.$set(that, `id`, e.id || '');
  64. that.$set(that, `rate_id`, e.rate_id || '');
  65. // 监听用户是否登录
  66. that.watchLogin();
  67. },
  68. methods: {
  69. // 图片上传
  70. uplSuc(e) {
  71. const that = this;
  72. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  73. },
  74. // 图片删除
  75. uplDel(e) {
  76. const that = this;
  77. let data = that[e.name];
  78. let arr = data.filter((i, index) => index != e.data.index);
  79. that.$set(that, `${e.name}`, arr)
  80. },
  81. // 提交保存
  82. async onSubmit(ref) {
  83. const that = this;
  84. that.$refs[ref].validate().then(async params => {
  85. if (that.rate_id) {
  86. let res = await that.$api(`/goodsRate/${that.rate_id}`);
  87. if (res.errcode == '0') {
  88. let reply = res.data;
  89. let obj = {
  90. file: that.file,
  91. content: params.content,
  92. time: moment().format('YYYY-MM-DD HH:mm:ss')
  93. }
  94. reply.reply.push(obj)
  95. const arr = await that.$api(`/goodsRate/${that.rate_id}`, 'POST', reply)
  96. if (arr.errcode == '0') {
  97. uni.showToast({
  98. title: `追加成功`,
  99. icon: 'success',
  100. });
  101. uni.navigateBack({
  102. detail: 1
  103. })
  104. } else {
  105. uni.showToast({
  106. title: arr.errmsg,
  107. icon: 'none',
  108. })
  109. }
  110. }
  111. } else {
  112. let reply = [{
  113. file: that.file,
  114. content: params.content,
  115. time: moment().format('YYYY-MM-DD HH:mm:ss')
  116. }];
  117. params.orderDetail = that.id
  118. params.reply = reply;
  119. params.customer = that.user?._id;
  120. params.shop = that.info?.goods[0]?.shop;
  121. params.goods = that.info?.goods[0]?.goods[0]?.goods?._id;
  122. params.goodsSpec = that.info?.goods[0]?.goods[0]?._id;
  123. const arr = await that.$api(`/goodsRate`, 'POST', params);
  124. if (arr.errcode == '0') {
  125. uni.showToast({
  126. title: `评论成功`,
  127. icon: 'success',
  128. });
  129. uni.navigateBack({
  130. detail: 1
  131. })
  132. } else {
  133. uni.showToast({
  134. title: arr.errmsg,
  135. icon: 'none',
  136. })
  137. }
  138. }
  139. })
  140. },
  141. // 监听用户是否登录
  142. watchLogin() {
  143. const that = this;
  144. uni.getStorage({
  145. key: 'token',
  146. success: function(res) {
  147. let user = that.$jwt(res.data);
  148. if (user) that.$set(that, `user`, user);
  149. that.search();
  150. },
  151. fail: function(err) {
  152. uni.navigateTo({
  153. url: `/pages/login/index`
  154. })
  155. }
  156. });
  157. },
  158. // 查询列表
  159. async search() {
  160. const that = this;
  161. let user = that.user;
  162. if (that.id) {
  163. let res = await that.$api(`/orderDetail/${that.id}`);
  164. if (res.errcode == '0') {
  165. that.$set(that, `info`, res.data.order);
  166. uni.hideLoading();
  167. }
  168. }
  169. },
  170. }
  171. }
  172. </script>
  173. <style lang="scss">
  174. .info {
  175. display: flex;
  176. flex-direction: column;
  177. width: 100vw;
  178. height: 100vh;
  179. .one {
  180. padding: 2vw;
  181. .uni-input {
  182. border: #f1f1ff 1px solid;
  183. padding: 2vw 2vw;
  184. border-radius: 1vw;
  185. }
  186. .btn {
  187. text-align: center;
  188. button {
  189. margin: 0 2vw 2vw 2vw;
  190. background-color: var(--ff0Color);
  191. color: var(--fffColor);
  192. }
  193. .name {
  194. color: var(--f85Color);
  195. font-size: var(--font14Size);
  196. }
  197. }
  198. }
  199. }
  200. .uni-forms-item {
  201. margin-bottom: 6vw !important;
  202. display: flex;
  203. flex-direction: row;
  204. }
  205. .uni-forms-item__content {
  206. display: flex;
  207. align-items: center;
  208. }
  209. </style>