appraise.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <mobile-frame>
  3. <view class="info">
  4. <view class="one">
  5. <view class="one_1">
  6. <text>评论商品</text>
  7. </view>
  8. <view class="one_2">
  9. <view class="list" v-for="(item,index) in goodsList" :key="index">
  10. <view class="list_1">
  11. <image class="image"
  12. :src="item.goods.file&&item.goods.file.length>0?item.goods.file[0].url:''" mode="">
  13. </image>
  14. </view>
  15. <view class="list_2">
  16. <view class="name">
  17. {{item.goods_name}}
  18. </view>
  19. <view class="other_1">
  20. <text>规格:</text>
  21. <text>{{item.name}}</text>
  22. </view>
  23. <view class="other_1">
  24. <text>金额:</text>
  25. <text
  26. class="money">¥{{info.type=='0'?item.price||item.sell_money:item.group_config.money}}</text>
  27. </view>
  28. <view class="other_1">
  29. <text>数量:</text>
  30. <text>×{{item.buy_num}}</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="two">
  37. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  38. <uni-forms-item label="评论商品" name="goods">
  39. <picker class="picker" mode="selector" :range="goodsList" @change="goodsChange"
  40. range-key="goods_name">
  41. <view>{{form.goods_name||'请选择评论商品'}}</view>
  42. </picker>
  43. </uni-forms-item>
  44. <uni-forms-item label="评论内容" name="content">
  45. <uni-easyinput maxlength=-1 type="textarea" v-model="form.content" placeholder="请输入评论内容" />
  46. </uni-forms-item>
  47. <uni-forms-item label="上传评论图片" name="file" v-if="readonly==false">
  48. <upload :list="file" name="file" :count="6" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  49. </uni-forms-item>
  50. <uni-forms-item label="商品评分" name="goods_score">
  51. <uni-rate :readonly="readonly" size="18" v-model="form.goods_score" />
  52. </uni-forms-item>
  53. <uni-forms-item label="发货评分" name="transport_score">
  54. <uni-rate :readonly="readonly" size="18" v-model="form.transport_score" />
  55. </uni-forms-item>
  56. <uni-forms-item label="店铺评分" name="shop_score">
  57. <uni-rate :readonly="readonly" size="18" v-model="form.shop_score" />
  58. </uni-forms-item>
  59. </uni-forms>
  60. <view class="btn">
  61. <button type="primary" @click="onSubmit('form')" size="small">提交</button>
  62. </view>
  63. </view>
  64. </view>
  65. </mobile-frame>
  66. </template>
  67. <script>
  68. import moment from 'moment';
  69. import upload from '@/components/upload/index.vue';
  70. export default {
  71. components: {
  72. upload
  73. },
  74. data() {
  75. return {
  76. id: '',
  77. // 追加
  78. rate_id: '',
  79. user: {},
  80. form: {},
  81. info: {},
  82. file: [],
  83. // 商品
  84. goodsList: [],
  85. rules: {
  86. content: {
  87. rules: [{
  88. required: true,
  89. errorMessage: '请输入评论内容',
  90. }]
  91. },
  92. grade: {
  93. rules: [{
  94. required: true,
  95. errorMessage: '请输入评论等级',
  96. }]
  97. },
  98. goods: {
  99. rules: [{
  100. required: true,
  101. errorMessage: '请选择评论商品',
  102. }]
  103. },
  104. },
  105. readonly: false,
  106. };
  107. },
  108. onLoad: function(e) {
  109. const that = this;
  110. that.$set(that, `id`, e.id || '');
  111. // 监听用户是否登录
  112. that.watchLogin();
  113. },
  114. methods: {
  115. // 监听用户是否登录
  116. watchLogin() {
  117. const that = this;
  118. uni.getStorage({
  119. key: 'token',
  120. success: function(res) {
  121. let user = that.$jwt(res.data);
  122. if (user) that.$set(that, `user`, user);
  123. that.search();
  124. },
  125. fail: function(err) {
  126. uni.navigateTo({
  127. url: `/pages/login/index`
  128. })
  129. }
  130. });
  131. },
  132. // 查询列表
  133. async search() {
  134. const that = this;
  135. let user = that.user;
  136. let res;
  137. if (that.id) {
  138. res = await that.$api(`/orderDetail/${that.id}`);
  139. if (res.errcode == '0') {
  140. that.$set(that, `info`, res.data.order);
  141. for (let val of res.data.goods) val.goods_name = val.goods.name
  142. that.$set(that, `goodsList`, res.data.goods);
  143. uni.hideLoading();
  144. }
  145. }
  146. },
  147. async goodsChange(e) {
  148. const that = this;
  149. let data = that.goodsList[e.detail.value];
  150. if (data) that.$set(that, `goodsList`, [data])
  151. if (data.rate) {
  152. that.$set(that, `rate_id`, data.rate);
  153. let res = await that.$api(`/goodsRate/${data.rate}`);
  154. if (res.errcode == '0') {
  155. that.$set(that, `form`, res.data);
  156. that.$set(that.form, `goods_name`, data.goods_name);
  157. that.$set(that, `readonly`, true)
  158. }
  159. } else {
  160. that.$set(that.form, `goods`, data.goods._id);
  161. that.$set(that.form, `goods_name`, data.goods_name);
  162. that.$set(that.form, `goodsSpec`, data._id);
  163. }
  164. },
  165. // 图片上传
  166. uplSuc(e) {
  167. const that = this;
  168. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  169. },
  170. // 图片删除
  171. uplDel(e) {
  172. const that = this;
  173. let data = that[e.name];
  174. let arr = data.filter((i, index) => index != e.data.index);
  175. that.$set(that, `${e.name}`, arr)
  176. },
  177. // 提交保存
  178. async onSubmit(ref) {
  179. const that = this;
  180. that.$refs[ref].validate().then(async params => {
  181. if (that.rate_id) {
  182. let reply = that.form;
  183. let obj = {
  184. file: that.file,
  185. content: params.content,
  186. time: moment().format('YYYY-MM-DD HH:mm:ss')
  187. }
  188. reply.reply.push(obj)
  189. const arr = await that.$api(`/goodsRate/${that.rate_id}`, 'POST', reply)
  190. if (arr.errcode == '0') {
  191. uni.showToast({
  192. title: `追加成功`,
  193. icon: 'success',
  194. });
  195. uni.navigateBack({
  196. detail: 1
  197. })
  198. } else {
  199. uni.showToast({
  200. title: arr.errmsg,
  201. icon: 'none',
  202. })
  203. }
  204. } else {
  205. let reply = [{
  206. file: that.file,
  207. content: params.content,
  208. time: moment().format('YYYY-MM-DD HH:mm:ss')
  209. }];
  210. params.orderDetail = that.id
  211. params.reply = reply;
  212. params.customer = that.user?._id;
  213. params.shop = that.info?.goods[0]?.shop;
  214. params.goodsSpec = that.form.goodsSpec;
  215. const arr = await that.$api(`/goodsRate`, 'POST', params);
  216. if (arr.errcode == '0') {
  217. uni.showToast({
  218. title: `评论成功`,
  219. icon: 'success',
  220. });
  221. uni.navigateBack({
  222. detail: 1
  223. })
  224. } else {
  225. uni.showToast({
  226. title: arr.errmsg,
  227. icon: 'none',
  228. })
  229. }
  230. }
  231. })
  232. }
  233. }
  234. }
  235. </script>
  236. <style lang="scss">
  237. .info {
  238. display: flex;
  239. flex-direction: column;
  240. width: 100vw;
  241. height: 100vh;
  242. .one {
  243. margin: 2vw;
  244. border: 1px solid #f1f1f1;
  245. border-radius: 5px;
  246. padding: 2vw;
  247. .one_1 {
  248. margin: 0 0 2vw 0;
  249. text {
  250. font-size: 16px;
  251. font-weight: bold;
  252. }
  253. }
  254. .one_2 {
  255. .list {
  256. display: flex;
  257. background-color: #f1f1f1;
  258. padding: 2vw;
  259. margin: 0 0 2vw 0;
  260. border-radius: 5px;
  261. .list_1 {
  262. width: 22vw;
  263. height: 22vw;
  264. border-radius: 5px;
  265. .image {
  266. width: 100%;
  267. height: 100%;
  268. border-radius: 5px;
  269. }
  270. }
  271. .list_2 {
  272. width: 63vw;
  273. padding: 0 0 0 2vw;
  274. .name {
  275. font-size: 16px;
  276. font-weight: bold;
  277. margin: 0 0 0.5vw 0;
  278. }
  279. .other_1 {
  280. .money {
  281. color: #ff0000 !important;
  282. }
  283. text {
  284. font-size: 13px;
  285. color: #858585;
  286. }
  287. text:last-child {
  288. color: #000000;
  289. }
  290. }
  291. }
  292. }
  293. .list:last-child {
  294. margin: 0;
  295. }
  296. }
  297. }
  298. .two {
  299. padding: 2vw;
  300. .picker {
  301. width: 100%;
  302. border: 1px solid #3333;
  303. border-radius: 5px;
  304. padding: 2vw;
  305. }
  306. .uni-input {
  307. border: #f1f1ff 1px solid;
  308. padding: 2vw 2vw;
  309. border-radius: 1vw;
  310. }
  311. .btn {
  312. text-align: center;
  313. button {
  314. margin: 0 2vw 2vw 2vw;
  315. background-color: var(--ff0Color);
  316. color: var(--fffColor);
  317. }
  318. .name {
  319. color: var(--f85Color);
  320. font-size: var(--font14Size);
  321. }
  322. }
  323. }
  324. }
  325. .uni-forms-item {
  326. margin-bottom: 6vw !important;
  327. display: flex;
  328. flex-direction: row;
  329. }
  330. .uni-forms-item__content {
  331. display: flex;
  332. align-items: center;
  333. }
  334. </style>