appraise.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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="goods">
  7. <picker class="picker" mode="selector" :range="goodsList" @change="goodsChange"
  8. range-key="goods_name">
  9. <view>{{form.goods_name||'请选择退款商品'}}</view>
  10. </picker>
  11. </uni-forms-item>
  12. <uni-forms-item label="评论内容" name="content">
  13. <uni-easyinput maxlength=-1 type="textarea" v-model="form.content" placeholder="请输入评论内容" />
  14. </uni-forms-item>
  15. <uni-forms-item label="上传评论图片" name="file">
  16. <upload :list="file" name="file" :count="6" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  17. </uni-forms-item>
  18. <uni-forms-item label="商品评分" name="goods_score">
  19. <uni-rate :readonly="readonly" size="18" v-model="form.goods_score" />
  20. </uni-forms-item>
  21. <uni-forms-item label="发货评分" name="transport_score">
  22. <uni-rate :readonly="readonly" size="18" v-model="form.transport_score" />
  23. </uni-forms-item>
  24. <uni-forms-item label="店铺评分" name="shop_score">
  25. <uni-rate :readonly="readonly" size="18" v-model="form.shop_score" />
  26. </uni-forms-item>
  27. </uni-forms>
  28. <view class="btn">
  29. <button type="primary" @click="onSubmit('form')" size="small">提交</button>
  30. </view>
  31. </view>
  32. </view>
  33. </mobile-frame>
  34. </template>
  35. <script>
  36. import moment from 'moment';
  37. import upload from '@/components/upload/index.vue';
  38. export default {
  39. components: {
  40. upload
  41. },
  42. data() {
  43. return {
  44. id: '',
  45. // 追加
  46. rate_id: '',
  47. user: {},
  48. form: {},
  49. info: {},
  50. file: [],
  51. // 商品
  52. goodsList: [],
  53. rules: {
  54. content: {
  55. rules: [{
  56. required: true,
  57. errorMessage: '请输入评论内容',
  58. }]
  59. },
  60. grade: {
  61. rules: [{
  62. required: true,
  63. errorMessage: '请输入评论等级',
  64. }]
  65. },
  66. goods: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '请选择评论商品',
  70. }]
  71. },
  72. },
  73. readonly: false,
  74. };
  75. },
  76. onLoad: function(e) {
  77. const that = this;
  78. that.$set(that, `id`, e.id || '');
  79. that.$set(that, `rate_id`, e.rate_id || '');
  80. // 监听用户是否登录
  81. that.watchLogin();
  82. },
  83. methods: {
  84. // 监听用户是否登录
  85. watchLogin() {
  86. const that = this;
  87. uni.getStorage({
  88. key: 'token',
  89. success: function(res) {
  90. let user = that.$jwt(res.data);
  91. if (user) that.$set(that, `user`, user);
  92. that.search();
  93. },
  94. fail: function(err) {
  95. uni.navigateTo({
  96. url: `/pages/login/index`
  97. })
  98. }
  99. });
  100. },
  101. // 查询列表
  102. async search() {
  103. const that = this;
  104. let user = that.user;
  105. let res;
  106. if (that.id) {
  107. res = await that.$api(`/orderDetail/${that.id}`);
  108. if (res.errcode == '0') {
  109. that.$set(that, `info`, res.data.order);
  110. for (let val of res.data.goods) val.goods_name = val.goods.name
  111. that.$set(that, `goodsList`, res.data.goods);
  112. uni.hideLoading();
  113. }
  114. }
  115. if (that.rate_id) {
  116. res = await that.$api(`/goodsRate/${that.rate_id}`);
  117. if (res.errcode == '0') {
  118. that.$set(that, `form`, res.data);
  119. that.$set(that, `readonly`, true)
  120. }
  121. }
  122. },
  123. goodsChange(e) {
  124. const that = this;
  125. let data = that.goodsList[e.detail.value];
  126. console.log(data);
  127. that.$set(that.form, `goods`, data.goods._id);
  128. that.$set(that.form, `goods_name`, data.goods_name);
  129. that.$set(that.form, `goodsSpec`, data._id);
  130. },
  131. // 图片上传
  132. uplSuc(e) {
  133. const that = this;
  134. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  135. },
  136. // 图片删除
  137. uplDel(e) {
  138. const that = this;
  139. let data = that[e.name];
  140. let arr = data.filter((i, index) => index != e.data.index);
  141. that.$set(that, `${e.name}`, arr)
  142. },
  143. // 提交保存
  144. async onSubmit(ref) {
  145. const that = this;
  146. that.$refs[ref].validate().then(async params => {
  147. if (that.rate_id) {
  148. let reply = that.form;
  149. let obj = {
  150. file: that.file,
  151. content: params.content,
  152. time: moment().format('YYYY-MM-DD HH:mm:ss')
  153. }
  154. reply.reply.push(obj)
  155. const arr = await that.$api(`/goodsRate/${that.rate_id}`, 'POST', reply)
  156. if (arr.errcode == '0') {
  157. uni.showToast({
  158. title: `追加成功`,
  159. icon: 'success',
  160. });
  161. uni.navigateBack({
  162. detail: 1
  163. })
  164. } else {
  165. uni.showToast({
  166. title: arr.errmsg,
  167. icon: 'none',
  168. })
  169. }
  170. } else {
  171. let reply = [{
  172. file: that.file,
  173. content: params.content,
  174. time: moment().format('YYYY-MM-DD HH:mm:ss')
  175. }];
  176. params.orderDetail = that.id
  177. params.reply = reply;
  178. params.customer = that.user?._id;
  179. params.shop = that.info?.goods[0]?.shop;
  180. const arr = await that.$api(`/goodsRate`, 'POST', params);
  181. if (arr.errcode == '0') {
  182. uni.showToast({
  183. title: `评论成功`,
  184. icon: 'success',
  185. });
  186. uni.navigateBack({
  187. detail: 1
  188. })
  189. } else {
  190. uni.showToast({
  191. title: arr.errmsg,
  192. icon: 'none',
  193. })
  194. }
  195. }
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss">
  202. .info {
  203. display: flex;
  204. flex-direction: column;
  205. width: 100vw;
  206. height: 100vh;
  207. .one {
  208. padding: 2vw;
  209. .picker {
  210. border: 1px solid #3333;
  211. border-radius: 5px;
  212. padding: 2vw;
  213. }
  214. .uni-input {
  215. border: #f1f1ff 1px solid;
  216. padding: 2vw 2vw;
  217. border-radius: 1vw;
  218. }
  219. .btn {
  220. text-align: center;
  221. button {
  222. margin: 0 2vw 2vw 2vw;
  223. background-color: var(--ff0Color);
  224. color: var(--fffColor);
  225. }
  226. .name {
  227. color: var(--f85Color);
  228. font-size: var(--font14Size);
  229. }
  230. }
  231. }
  232. }
  233. .uni-forms-item {
  234. margin-bottom: 6vw !important;
  235. display: flex;
  236. flex-direction: row;
  237. }
  238. .uni-forms-item__content {
  239. display: flex;
  240. align-items: center;
  241. }
  242. </style>