appraise.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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" v-if="status=='0'">
  9. <view v-for="(item,index) in goodsList" :key="index">
  10. <view class="set_name" v-if="item.is_set=='0'">
  11. <text class="set">套装</text> {{item.name}}
  12. </view>
  13. <view class="list" v-if="item.is_set=='0'" v-for="(tag,indexx) in item.goods" :key="indexx">
  14. <view class="list_1">
  15. <image class="image"
  16. :src="tag.goods.file&&tag.goods.file.length>0?tag.goods.file[0].url:''" mode="">
  17. </image>
  18. </view>
  19. <view class="list_2">
  20. <view class="name">
  21. {{tag.goods_name}}
  22. </view>
  23. <view class="other_1">
  24. <text>规格:</text>
  25. <text>{{tag.spec_name}}</text>
  26. </view>
  27. <view class="other_1">
  28. <text>数量:</text>
  29. <text>×{{tag.set_num}}</text>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="set" v-if="item.is_set=='0'">
  34. <view class="set_1">套装价:¥{{item.sell_money}}</view>
  35. <view class="set_2">数量:×{{item.buy_num}}</view>
  36. </view>
  37. <view class="list" v-else>
  38. <view class="list_1">
  39. <image class="image"
  40. :src="item.goods.file&&item.goods.file.length>0?item.goods.file[0].url:''" mode="">
  41. </image>
  42. </view>
  43. <view class="list_2">
  44. <view class="name">
  45. {{item.goods_name}}
  46. </view>
  47. <view class="other_1">
  48. <text>规格:</text>
  49. <text>{{item.name}}</text>
  50. </view>
  51. <view class="other_1">
  52. <text>金额:</text>
  53. <text
  54. class="money">¥{{info.type=='0'?item.price||item.sell_money:item.group_config.money}}</text>
  55. </view>
  56. <view class="other_1">
  57. <text>数量:</text>
  58. <text>×{{item.buy_num}}</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="two">
  66. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  67. <uni-forms-item label="评论商品" name="goods" v-if="status=='0'&&goodssList.length>0&&!form.set">
  68. <picker class="picker" mode="selector" :range="goodssList" @change="goodsChange"
  69. range-key="goods_name">
  70. <view>{{form.goods_name||'请选择评论商品'}}</view>
  71. </picker>
  72. </uni-forms-item>
  73. <uni-forms-item label="评论套装" name="set" v-if="status=='0'&&!form.goods_name&&setList.length>0">
  74. <picker class="picker" mode="selector" :range="setList" @change="setChange" range-key="name">
  75. <view>{{form.set_name||'请选择评论套装'}}</view>
  76. </picker>
  77. </uni-forms-item>
  78. <uni-forms-item label="评论套装商品" name="goods" v-if="status=='0'&&form.set">
  79. <picker class="picker" mode="selector" :range="setgoodsList" @change="setgoodsChange"
  80. range-key="goods_name">
  81. <view>{{form.goods_name||'请选择评论套装商品'}}</view>
  82. </picker>
  83. </uni-forms-item>
  84. <uni-forms-item label="评论内容" name="content">
  85. <uni-easyinput maxlength=-1 type="textarea" v-model="form.content" placeholder="请输入评论内容" />
  86. </uni-forms-item>
  87. <uni-forms-item label="上传评论图片" name="file" v-if="readonly==false">
  88. <upload :list="file" name="file" :count="6" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  89. </uni-forms-item>
  90. <uni-forms-item label="商品评分" name="goods_score">
  91. <uni-rate :readonly="readonly" size="18" v-model="form.goods_score" />
  92. </uni-forms-item>
  93. <uni-forms-item label="发货评分" name="transport_score">
  94. <uni-rate :readonly="readonly" size="18" v-model="form.transport_score" />
  95. </uni-forms-item>
  96. <uni-forms-item label="店铺评分" name="shop_score">
  97. <uni-rate :readonly="readonly" size="18" v-model="form.shop_score" />
  98. </uni-forms-item>
  99. </uni-forms>
  100. <view class="btn">
  101. <button type="primary" @click="onSubmit('form')" size="small">提交</button>
  102. </view>
  103. </view>
  104. </view>
  105. </mobile-frame>
  106. </template>
  107. <script>
  108. import moment from 'moment';
  109. import upload from '../components/upload/index.vue';
  110. export default {
  111. components: {
  112. upload
  113. },
  114. data() {
  115. return {
  116. id: '',
  117. status: '',
  118. // 追加
  119. rate_id: '',
  120. user: {},
  121. form: {},
  122. info: {},
  123. file: [],
  124. // 商品
  125. goodsList: [],
  126. rules: {
  127. content: {
  128. rules: [{
  129. required: true,
  130. errorMessage: '请输入评论内容',
  131. }]
  132. },
  133. grade: {
  134. rules: [{
  135. required: true,
  136. errorMessage: '请输入评论等级',
  137. }]
  138. },
  139. goods: {
  140. rules: [{
  141. required: true,
  142. errorMessage: '请选择评论商品',
  143. }]
  144. },
  145. },
  146. readonly: false,
  147. // 正常商品
  148. goodssList: [],
  149. // 套装
  150. setList: [],
  151. // 套装商品
  152. setgoodsList: [],
  153. };
  154. },
  155. onLoad: function(e) {
  156. const that = this;
  157. that.$set(that, `id`, e.id || '');
  158. that.$set(that, `status`, e.status || '');
  159. // 监听用户是否登录
  160. that.watchLogin();
  161. },
  162. methods: {
  163. // 监听用户是否登录
  164. watchLogin() {
  165. const that = this;
  166. uni.getStorage({
  167. key: 'token',
  168. success: function(res) {
  169. let user = that.$jwt(res.data);
  170. if (user) that.$set(that, `user`, user);
  171. that.search();
  172. },
  173. fail: function(err) {
  174. uni.navigateTo({
  175. url: `/pages/login/index`
  176. })
  177. }
  178. });
  179. },
  180. // 查询列表
  181. async search() {
  182. const that = this;
  183. let user = that.user;
  184. let res;
  185. if (that.id) {
  186. if (that.status == '0') {
  187. res = await that.$api(`/orderDetail/${that.id}`);
  188. if (res.errcode == '0') {
  189. that.$set(that, `info`, res.data.order);
  190. for (let val of res.data.goods) val.goods_name = val.goods.name
  191. that.$set(that, `goodsList`, res.data.goods);
  192. let goodssList = res.data.goods.filter(i => i.is_set != '0')
  193. that.$set(that, `goodssList`, goodssList)
  194. let setList = res.data.goods.filter(i => i.is_set == '0')
  195. that.$set(that, `setList`, setList)
  196. uni.hideLoading();
  197. }
  198. } else {
  199. res = await that.$api(`/groupOrder/${that.id}`, {}, 'group');
  200. if (res.errcode == '0') {
  201. if (res.data.rate) {
  202. that.$set(that, `rate_id`, res.data.rate);
  203. let arr = await that.$api(`/goodsRate/${res.data.rate}`);
  204. if (arrarr.errcode == '0') {
  205. that.$set(that, `form`, arr.data);
  206. that.$set(that.form, `goods_name`, res.data.goods.name);
  207. that.$set(that, `readonly`, true)
  208. }
  209. } else {
  210. that.$set(that.form, `goods`, res.data.goods._id);
  211. that.$set(that.form, `goods_name`, res.data.goods.name);
  212. that.$set(that.form, `goodsSpec`, res.goodsSpec.data._id);
  213. }
  214. uni.hideLoading();
  215. }
  216. }
  217. }
  218. },
  219. async goodsChange(e) {
  220. const that = this;
  221. let data = that.goodssList[e.detail.value];
  222. if (data) that.$set(that, `goodsList`, [data])
  223. if (data.rate) {
  224. that.$set(that, `rate_id`, data.rate);
  225. let res = await that.$api(`/goodsRate/${data.rate}`);
  226. if (res.errcode == '0') {
  227. that.$set(that, `form`, res.data);
  228. that.$set(that.form, `goods_name`, data.goods_name);
  229. that.$set(that, `readonly`, true)
  230. }
  231. } else {
  232. that.$set(that.form, `goods`, data.goods._id);
  233. that.$set(that.form, `goods_name`, data.goods_name);
  234. that.$set(that.form, `goodsSpec`, data._id);
  235. }
  236. },
  237. // 套装
  238. setChange(e) {
  239. const that = this;
  240. let data = that.setList[e.detail.value];
  241. if (data) {
  242. that.$set(that, `setgoodsList`, data.goods)
  243. that.$set(that, `goodsList`, [data])
  244. }
  245. that.$set(that.form, `set`, data._id);
  246. that.$set(that.form, `set_name`, data.name);
  247. },
  248. // 套装商品
  249. async setgoodsChange(e) {
  250. const that = this;
  251. let data = that.setgoodsList[e.detail.value];
  252. if (data.rate) {
  253. that.$set(that, `rate_id`, data.rate);
  254. let res = await that.$api(`/goodsRate/${data.rate}`);
  255. if (res.errcode == '0') {
  256. that.$set(that, `form`, res.data);
  257. that.$set(that.form, `goods_name`, data.goods_name);
  258. that.$set(that, `readonly`, true)
  259. }
  260. } else {
  261. that.$set(that.form, `goods`, data.goods._id);
  262. that.$set(that.form, `goods_name`, data.goods_name);
  263. that.$set(that.form, `goodsSpec`, data.spec._id);
  264. }
  265. },
  266. // 图片上传
  267. uplSuc(e) {
  268. const that = this;
  269. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  270. },
  271. // 图片删除
  272. uplDel(e) {
  273. const that = this;
  274. let data = that[e.name];
  275. let arr = data.filter((i, index) => index != e.data.index);
  276. that.$set(that, `${e.name}`, arr)
  277. },
  278. // 提交保存
  279. async onSubmit(ref) {
  280. const that = this;
  281. that.$refs[ref].validate().then(async params => {
  282. if (that.rate_id) {
  283. let reply = that.form;
  284. let obj = {
  285. file: that.file,
  286. content: params.content,
  287. time: moment().format('YYYY-MM-DD HH:mm:ss')
  288. }
  289. reply.reply.push(obj)
  290. const arr = await that.$api(`/goodsRate/${that.rate_id}`, 'POST', reply)
  291. if (arr.errcode == '0') {
  292. uni.showToast({
  293. title: `追加成功`,
  294. icon: 'success',
  295. });
  296. uni.navigateBack({
  297. detail: 1
  298. })
  299. } else {
  300. uni.showToast({
  301. title: arr.errmsg,
  302. icon: 'none',
  303. })
  304. }
  305. } else {
  306. let reply = [{
  307. file: that.file,
  308. content: params.content,
  309. time: moment().format('YYYY-MM-DD HH:mm:ss')
  310. }];
  311. if (that.form.set) params.set_id = that.form.set
  312. params.orderDetail = that.id
  313. params.reply = reply;
  314. params.customer = that.user?._id;
  315. params.shop = that.info?.goods[0]?.shop;
  316. params.goodsSpec = that.form.goodsSpec;
  317. const arr = await that.$api(`/goodsRate`, 'POST', params);
  318. if (arr.errcode == '0') {
  319. uni.showToast({
  320. title: `评论成功`,
  321. icon: 'success',
  322. });
  323. uni.navigateBack({
  324. detail: 1
  325. })
  326. } else {
  327. uni.showToast({
  328. title: arr.errmsg,
  329. icon: 'none',
  330. })
  331. }
  332. }
  333. })
  334. }
  335. }
  336. }
  337. </script>
  338. <style lang="scss">
  339. .info {
  340. display: flex;
  341. flex-direction: column;
  342. width: 100vw;
  343. height: 100vh;
  344. .one {
  345. margin: 2vw;
  346. border: 1px solid #f1f1f1;
  347. border-radius: 5px;
  348. padding: 2vw;
  349. .one_1 {
  350. margin: 0 0 2vw 0;
  351. text {
  352. font-size: 16px;
  353. font-weight: bold;
  354. }
  355. }
  356. .one_2 {
  357. .list {
  358. display: flex;
  359. background-color: #f1f1f1;
  360. padding: 2vw;
  361. margin: 0 0 2vw 0;
  362. border-radius: 5px;
  363. .list_1 {
  364. width: 22vw;
  365. height: 22vw;
  366. border-radius: 5px;
  367. .image {
  368. width: 100%;
  369. height: 100%;
  370. border-radius: 5px;
  371. }
  372. }
  373. .list_2 {
  374. width: 63vw;
  375. padding: 0 0 0 2vw;
  376. .name {
  377. font-size: 16px;
  378. font-weight: bold;
  379. margin: 0 0 0.5vw 0;
  380. }
  381. .other_1 {
  382. .money {
  383. color: var(--fFB1Color) !important;
  384. }
  385. text {
  386. font-size: 13px;
  387. color: #858585;
  388. }
  389. text:last-child {
  390. color: #000000;
  391. }
  392. }
  393. }
  394. }
  395. .list:last-child {
  396. margin: 0;
  397. }
  398. .set_name {
  399. display: flex;
  400. padding: 2vw 0;
  401. .set {
  402. margin: 0 1vw 0 0;
  403. font-size: 12px;
  404. border-radius: 5px;
  405. padding: 0 1vw;
  406. color: #ffffff;
  407. background-color: #FF6347;
  408. border: 1px solid #FFA500;
  409. }
  410. }
  411. .set {
  412. display: flex;
  413. justify-content: space-between;
  414. margin: 0 0 2vw 0;
  415. padding: 2vw 0;
  416. .set_1 {
  417. font-size: var(--font16Size);
  418. color: var(--f85Color);
  419. }
  420. text {
  421. padding: 0 1vw 0 0;
  422. font-size: var(--font20Szie);
  423. }
  424. }
  425. }
  426. }
  427. .two {
  428. padding: 2vw;
  429. .picker {
  430. width: 100%;
  431. border: 1px solid #3333;
  432. border-radius: 5px;
  433. padding: 2vw;
  434. }
  435. .uni-input {
  436. border: #f1f1ff 1px solid;
  437. padding: 2vw 2vw;
  438. border-radius: 1vw;
  439. }
  440. .btn {
  441. text-align: center;
  442. button {
  443. margin: 0 2vw 2vw 2vw;
  444. background-color: var(--fFB1Color);
  445. color: var(--fffColor);
  446. }
  447. .name {
  448. color: var(--f85Color);
  449. font-size: var(--font14Size);
  450. }
  451. }
  452. }
  453. }
  454. .uni-forms-item {
  455. margin-bottom: 6vw !important;
  456. display: flex;
  457. flex-direction: row;
  458. }
  459. .uni-forms-item__content {
  460. display: flex;
  461. align-items: center;
  462. }
  463. </style>