appraise.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1">
  6. <view class="text1">{{info.goods.name}}{{info.specs[0].name}}</view>
  7. <view class="text2">好评率 <text>{{info.rate||100}}%</text></view>
  8. </view>
  9. <view class="one_2">
  10. <view class="one_2_1" v-for="(item,index) in btnlist" :key="index" @tap="toSelect(item)">
  11. <text>{{item.name}}</text><text>({{item.total||0}})</text>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="two">
  16. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  17. <view class="list-scroll-view">
  18. <view class="list" v-for="(item, index) in list" :key="index">
  19. <image v-if="item.customer.icon&&item.customer.icon.length>0" class="image"
  20. :src="item.customer.icon&&item.customer.icon.length>0?item.customer.icon[0].url:''"
  21. mode="">
  22. </image>
  23. <text v-else class="iconfont icon-top"></text>
  24. <view class="list_1">
  25. <view class="other">
  26. <text>{{item.customer.phone}}</text>
  27. <text>{{item.reply[0].time||'暂无'}}</text>
  28. </view>
  29. <view class="flie">
  30. <view v-for="(tag, indexs) in item.reply[0].file" :key="indexs">
  31. <image @click="toLarge(item,indexs)" class="images" :src="tag.url" mode="">
  32. </image>
  33. </view>
  34. </view>
  35. <view class="stars">
  36. <uni-rate size="18" :readonly="true" :value="item.goods_score" />
  37. </view>
  38. <view class="other1">{{item.reply[0].content||'暂无'}}</view>
  39. <view class="other2">规格:{{item.goodsSpec.name}}</view>
  40. <view class="other2" v-for="(itm, indexx) in item.reply" :key="indexx">
  41. <view class="reply">
  42. <text>用户评论:{{itm.content||'暂无'}}</text>
  43. <text v-if="itm.reply">商家回复:{{itm.reply||'暂无'}}</text>
  44. </view>
  45. <view @tap="toReply(item)">回复</view>
  46. </view>
  47. <input v-if="reply.reply" @confirm="confirm" class="input" placeholder="回复商家" />
  48. </view>
  49. </view>
  50. </view>
  51. </scroll-view>
  52. </view>
  53. </view>
  54. </mobile-frame>
  55. </template>
  56. <script>
  57. import moment from 'moment';
  58. export default {
  59. data() {
  60. return {
  61. id: '',
  62. user: {},
  63. btnlist: [{
  64. name: '全部好评',
  65. total: '0',
  66. code: '0'
  67. },
  68. {
  69. name: '好评',
  70. total: '0',
  71. code: '1'
  72. },
  73. {
  74. name: '中评',
  75. total: '0',
  76. code: '2'
  77. },
  78. {
  79. name: '差评',
  80. total: '0',
  81. code: '3'
  82. }
  83. ],
  84. info: {},
  85. list: [],
  86. total: 0,
  87. skip: 0,
  88. limit: 6,
  89. page: 0,
  90. one: [],
  91. two: [],
  92. thr: [],
  93. // 回复数据
  94. reply: {},
  95. };
  96. },
  97. onLoad: function(e) {
  98. const that = this;
  99. that.$set(that, `id`, e.id || '');
  100. that.watchLogin()
  101. },
  102. methods: {
  103. async confirm(e) {
  104. const that = this;
  105. let reply = that.reply
  106. let obj = {
  107. content: e.detail.value,
  108. time: moment().format('YYYY-MM-DD HH:mm:ss')
  109. }
  110. reply.reply.push(obj)
  111. const arr = await that.$api(`/goodsRate/${that.reply._id}`, 'POST', reply)
  112. if (arr.errcode == '0') {
  113. uni.showToast({
  114. title: `回复成功`,
  115. icon: 'success',
  116. });
  117. that.$set(that, `reply`, {});
  118. } else {
  119. uni.showToast({
  120. title: arr.errmsg,
  121. icon: 'none',
  122. })
  123. }
  124. },
  125. // 回复
  126. toReply(e) {
  127. const that = this;
  128. that.$set(that, `reply`, e);
  129. },
  130. // 放大
  131. toLarge(e, index) {
  132. let url = e.reply[0].file.map(item => item.url)
  133. uni.previewImage({
  134. current: index,
  135. urls: url
  136. })
  137. },
  138. // 选择
  139. toSelect(e) {
  140. const that = this;
  141. if (e.code == '0') {
  142. that.clearPage();
  143. that.search()
  144. } else if (e.code == '1') {
  145. that.$set(that, `list`, that.one);
  146. } else if (e.code == '2') {
  147. that.$set(that, `list`, that.two);
  148. } else {
  149. that.$set(that, `list`, that.thr);
  150. }
  151. },
  152. // 监听用户是否登录
  153. watchLogin() {
  154. const that = this;
  155. uni.getStorage({
  156. key: 'token',
  157. success: function(res) {
  158. let user = that.$jwt(res.data);
  159. that.$set(that, `user`, user);
  160. that.search()
  161. },
  162. fail: function(err) {
  163. uni.reLaunch({
  164. url: `/pages/login/index`
  165. })
  166. }
  167. })
  168. },
  169. // 查询列表
  170. async search() {
  171. const that = this;
  172. let user = that.user;
  173. let res;
  174. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  175. id: that.id
  176. });
  177. if (res.errcode == '0') {
  178. that.$set(that, `info`, res.data)
  179. }
  180. let info = {
  181. skip: that.skip,
  182. limit: that.limit,
  183. goods: that.id
  184. }
  185. res = await that.$api(`/goodsRate`, `GET`, {
  186. ...info,
  187. })
  188. if (res.errcode == '0') {
  189. let list = [...that.list, ...res.data]
  190. for (let val of list) {
  191. val.customer.phone = val.customer.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  192. }
  193. let one = list.filter(item => item.goods_score == 5);
  194. that.$set(that, `one`, one)
  195. that.$set(that.btnlist[1], `total`, one.length);
  196. let two = list.filter(item => item.goods_score < 5 && item.goods_score > 2)
  197. that.$set(that, `two`, two)
  198. that.$set(that.btnlist[2], `total`, two.length);
  199. let thr = list.filter(item => item.goods_score <= 2)
  200. that.$set(that, `thr`, thr)
  201. that.$set(that.btnlist[3], `total`, thr.length);
  202. that.$set(that, `list`, list)
  203. that.$set(that, `total`, res.total)
  204. that.$set(that.btnlist[0], `total`, res.total)
  205. } else {
  206. uni.showToast({
  207. title: res.errmsg,
  208. });
  209. }
  210. },
  211. // 分页
  212. toPage(e) {
  213. const that = this;
  214. let list = that.list;
  215. let limit = that.limit;
  216. if (that.total > list.length) {
  217. uni.showLoading({
  218. title: '加载中',
  219. mask: true
  220. })
  221. let page = that.page + 1;
  222. that.$set(that, `page`, page)
  223. let skip = page * limit;
  224. that.$set(that, `skip`, skip)
  225. that.search();
  226. uni.hideLoading();
  227. } else uni.showToast({
  228. title: '没有更多数据了',
  229. icon: 'none'
  230. });
  231. },
  232. // 清空列表
  233. clearPage() {
  234. const that = this;
  235. that.$set(that, `list`, [])
  236. that.$set(that, `skip`, 0)
  237. that.$set(that, `limit`, 6)
  238. that.$set(that, `page`, 0)
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="scss">
  244. .main {
  245. display: flex;
  246. flex-direction: column;
  247. width: 100vw;
  248. height: 100vh;
  249. background-color: var(--f1Color);
  250. .one {
  251. margin: 0 0 2vw 0;
  252. .one_1 {
  253. display: flex;
  254. justify-content: space-around;
  255. background-color: var(--mainColor);
  256. margin: 0 0 0.5vw 0;
  257. padding: 2vw;
  258. .text1 {
  259. width: 65vw;
  260. font-size: var(--font16Szie);
  261. }
  262. .text2 {
  263. font-size: var(--font16Szie);
  264. color: var(--f85Color);
  265. text {
  266. margin: 0 0 0 1vw;
  267. color: var(--ff0Color);
  268. }
  269. }
  270. }
  271. .one_2 {
  272. display: flex;
  273. justify-content: space-around;
  274. padding: 2vw;
  275. background-color: var(--mainColor);
  276. }
  277. }
  278. .two {
  279. position: relative;
  280. flex-grow: 1;
  281. .list {
  282. display: flex;
  283. justify-content: space-around;
  284. align-items: flex-start;
  285. background-color: var(--mainColor);
  286. margin: 0 0 2vw 0;
  287. padding: 4vw;
  288. .image {
  289. width: 10vw;
  290. height: 10vw;
  291. border-radius: 10vw;
  292. }
  293. .iconfont {
  294. font-size: 30px;
  295. }
  296. .list_1 {
  297. flex-grow: 1;
  298. margin: 0 0 0 2vw;
  299. font-size: var(--font14Size);
  300. .other {
  301. display: flex;
  302. justify-content: space-between;
  303. text:last-child {
  304. font-size: var(--font12Size);
  305. color: var(--f85Color);
  306. }
  307. }
  308. .other1 {
  309. margin: 1vw 0 0 0;
  310. }
  311. .flie {
  312. display: flex;
  313. flex-wrap: wrap;
  314. margin: 1vw 0;
  315. .images {
  316. width: 20vw;
  317. height: 20vw;
  318. margin: 0 1vw 0 0;
  319. }
  320. }
  321. .other2 {
  322. display: flex;
  323. justify-content: space-between;
  324. font-size: var(--font12Size);
  325. color: var(--f85Color);
  326. margin: 2vw 0 0 0;
  327. .reply {
  328. display: flex;
  329. flex-direction: column;
  330. width: 70vw;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. }
  337. .scroll-view {
  338. position: absolute;
  339. top: 0;
  340. left: 0;
  341. right: 0;
  342. bottom: 0;
  343. .list-scroll-view {
  344. display: flex;
  345. flex-direction: column;
  346. }
  347. }
  348. </style>