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. watchLogin() {
  72. const that = this;
  73. uni.getStorage({
  74. key: 'token',
  75. success: function(res) {
  76. let user = that.$jwt(res.data);
  77. if (user) that.$set(that, `user`, user);
  78. that.search();
  79. },
  80. fail: function(err) {
  81. uni.navigateTo({
  82. url: `/pages/login/index`
  83. })
  84. }
  85. });
  86. },
  87. // 查询列表
  88. async search() {
  89. const that = this;
  90. let user = that.user;
  91. let res;
  92. if (that.id) {
  93. res = await that.$api(`/orderDetail/${that.id}`);
  94. if (res.errcode == '0') {
  95. that.$set(that, `info`, res.data.order);
  96. uni.hideLoading();
  97. }
  98. }
  99. if (that.rate_id) {
  100. res = await that.$api(`/goodsRate/${that.rate_id}`);
  101. if (res.errcode == '0') {
  102. that.$set(that, `form`, res.data);
  103. that.$set(that, `readonly`, true)
  104. }
  105. }
  106. },
  107. // 图片上传
  108. uplSuc(e) {
  109. const that = this;
  110. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  111. },
  112. // 图片删除
  113. uplDel(e) {
  114. const that = this;
  115. let data = that[e.name];
  116. let arr = data.filter((i, index) => index != e.data.index);
  117. that.$set(that, `${e.name}`, arr)
  118. },
  119. // 提交保存
  120. async onSubmit(ref) {
  121. const that = this;
  122. that.$refs[ref].validate().then(async params => {
  123. if (that.rate_id) {
  124. let reply = that.form;
  125. let obj = {
  126. file: that.file,
  127. content: params.content,
  128. time: moment().format('YYYY-MM-DD HH:mm:ss')
  129. }
  130. reply.reply.push(obj)
  131. const arr = await that.$api(`/goodsRate/${that.rate_id}`, 'POST', reply)
  132. if (arr.errcode == '0') {
  133. uni.showToast({
  134. title: `追加成功`,
  135. icon: 'success',
  136. });
  137. uni.navigateBack({
  138. detail: 1
  139. })
  140. } else {
  141. uni.showToast({
  142. title: arr.errmsg,
  143. icon: 'none',
  144. })
  145. }
  146. } else {
  147. let reply = [{
  148. file: that.file,
  149. content: params.content,
  150. time: moment().format('YYYY-MM-DD HH:mm:ss')
  151. }];
  152. params.orderDetail = that.id
  153. params.reply = reply;
  154. params.customer = that.user?._id;
  155. params.shop = that.info?.goods[0]?.shop;
  156. params.goods = that.info?.goods[0]?.goods[0]?.goods?._id;
  157. params.goodsSpec = that.info?.goods[0]?.goods[0]?._id;
  158. const arr = await that.$api(`/goodsRate`, 'POST', params);
  159. if (arr.errcode == '0') {
  160. uni.showToast({
  161. title: `评论成功`,
  162. icon: 'success',
  163. });
  164. uni.navigateBack({
  165. detail: 1
  166. })
  167. } else {
  168. uni.showToast({
  169. title: arr.errmsg,
  170. icon: 'none',
  171. })
  172. }
  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>