appraise.vue 5.2 KB

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