appraise.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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">
  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. code: ''
  97. };
  98. },
  99. onLoad: function(e) {
  100. const that = this;
  101. that.$set(that, `id`, e.id || '');
  102. that.watchLogin()
  103. },
  104. methods: {
  105. async confirm(e) {
  106. const that = this;
  107. let reply = that.reply
  108. let obj = {
  109. content: e.detail.value,
  110. time: moment().format('YYYY-MM-DD HH:mm:ss')
  111. }
  112. reply.reply.push(obj)
  113. const arr = await that.$api(`/goodsRate/${that.reply._id}`, 'POST', reply)
  114. if (arr.errcode == '0') {
  115. uni.showToast({
  116. title: `回复成功`,
  117. icon: 'success',
  118. });
  119. that.$set(that, `reply`, {});
  120. } else {
  121. uni.showToast({
  122. title: arr.errmsg,
  123. icon: 'none',
  124. })
  125. }
  126. },
  127. // 回复
  128. toReply(e) {
  129. const that = this;
  130. that.$set(that, `reply`, e);
  131. },
  132. // 放大
  133. toLarge(e, index) {
  134. let url = e.reply[0].file.map(item => item.url)
  135. uni.previewImage({
  136. current: index,
  137. urls: url
  138. })
  139. },
  140. // 选择
  141. toSelect(e) {
  142. const that = this;
  143. that.$set(that, `code`, e.code);
  144. if (e.code == '0') {
  145. // that.clearPage();
  146. that.search()
  147. } else if (e.code == '1') {
  148. that.$set(that, `list`, that.one);
  149. } else if (e.code == '2') {
  150. that.$set(that, `list`, that.two);
  151. } else {
  152. that.$set(that, `list`, that.thr);
  153. }
  154. },
  155. // 监听用户是否登录
  156. watchLogin() {
  157. const that = this;
  158. uni.getStorage({
  159. key: 'token',
  160. success: function(res) {
  161. let user = that.$jwt(res.data);
  162. that.$set(that, `user`, user);
  163. that.search()
  164. },
  165. fail: function(err) {
  166. uni.reLaunch({
  167. url: `/pages/login/index`
  168. })
  169. }
  170. })
  171. },
  172. // 查询列表
  173. async search() {
  174. const that = this;
  175. let user = that.user;
  176. let res;
  177. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  178. id: that.id
  179. });
  180. if (res.errcode == '0') {
  181. that.$set(that, `info`, res.data)
  182. }
  183. let info = {
  184. // skip: that.skip,
  185. // limit: that.limit,
  186. goods: that.id
  187. }
  188. res = await that.$api(`/goodsRate`, `GET`, {
  189. ...info,
  190. })
  191. if (res.errcode == '0') {
  192. // let list = [...that.list, ...res.data]
  193. let list = res.data;
  194. for (let val of list) {
  195. val.customer.phone = val.customer.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  196. }
  197. that.$set(that, `list`, list)
  198. that.$set(that, `total`, res.total)
  199. that.$set(that.btnlist[0], `total`, res.total)
  200. let one = list.filter(item => item.goods_score == 5);
  201. that.$set(that, `one`, one)
  202. that.$set(that.btnlist[1], `total`, one.length);
  203. let two = list.filter(item => item.goods_score < 5 && item.goods_score > 2)
  204. that.$set(that, `two`, two)
  205. that.$set(that.btnlist[2], `total`, two.length);
  206. let thr = list.filter(item => item.goods_score <= 2)
  207. that.$set(that, `thr`, thr)
  208. that.$set(that.btnlist[3], `total`, thr.length);
  209. } else {
  210. uni.showToast({
  211. title: res.errmsg,
  212. });
  213. }
  214. },
  215. // 分页
  216. toPage(e) {
  217. const that = this;
  218. let list = that.list;
  219. let limit = that.limit;
  220. if (that.total > list.length) {
  221. uni.showLoading({
  222. title: '加载中',
  223. mask: true
  224. })
  225. let page = that.page + 1;
  226. that.$set(that, `page`, page)
  227. let skip = page * limit;
  228. that.$set(that, `skip`, skip)
  229. that.search();
  230. uni.hideLoading();
  231. } else uni.showToast({
  232. title: '没有更多数据了',
  233. icon: 'none'
  234. });
  235. },
  236. // 清空列表
  237. clearPage() {
  238. const that = this;
  239. that.$set(that, `list`, [])
  240. that.$set(that, `skip`, 0)
  241. that.$set(that, `limit`, 6)
  242. that.$set(that, `page`, 0)
  243. }
  244. }
  245. }
  246. </script>
  247. <style lang="scss">
  248. .main {
  249. display: flex;
  250. flex-direction: column;
  251. width: 100vw;
  252. height: 100vh;
  253. background-color: var(--f1Color);
  254. .one {
  255. margin: 0 0 2vw 0;
  256. .one_1 {
  257. display: flex;
  258. justify-content: space-around;
  259. background-color: var(--mainColor);
  260. margin: 0 0 0.5vw 0;
  261. padding: 2vw;
  262. .text1 {
  263. width: 65vw;
  264. font-size: var(--font16Szie);
  265. }
  266. .text2 {
  267. font-size: var(--font16Szie);
  268. color: var(--f85Color);
  269. text {
  270. margin: 0 0 0 1vw;
  271. color: var(--ff0Color);
  272. }
  273. }
  274. }
  275. .one_2 {
  276. display: flex;
  277. justify-content: space-around;
  278. padding: 2vw;
  279. background-color: var(--mainColor);
  280. }
  281. }
  282. .two {
  283. position: relative;
  284. flex-grow: 1;
  285. .list {
  286. display: flex;
  287. justify-content: space-around;
  288. align-items: flex-start;
  289. background-color: var(--mainColor);
  290. margin: 0 0 2vw 0;
  291. padding: 4vw;
  292. .image {
  293. width: 10vw;
  294. height: 10vw;
  295. border-radius: 10vw;
  296. }
  297. .iconfont {
  298. font-size: 30px;
  299. }
  300. .list_1 {
  301. flex-grow: 1;
  302. margin: 0 0 0 2vw;
  303. font-size: var(--font14Size);
  304. .other {
  305. display: flex;
  306. justify-content: space-between;
  307. text:last-child {
  308. font-size: var(--font12Size);
  309. color: var(--f85Color);
  310. }
  311. }
  312. .other1 {
  313. margin: 1vw 0 0 0;
  314. }
  315. .flie {
  316. display: flex;
  317. flex-wrap: wrap;
  318. margin: 1vw 0;
  319. .images {
  320. width: 20vw;
  321. height: 20vw;
  322. margin: 0 1vw 0 0;
  323. }
  324. }
  325. .other2 {
  326. display: flex;
  327. justify-content: space-between;
  328. font-size: var(--font12Size);
  329. color: var(--f85Color);
  330. margin: 2vw 0 0 0;
  331. .reply {
  332. display: flex;
  333. flex-direction: column;
  334. width: 70vw;
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. .scroll-view {
  342. position: absolute;
  343. top: 0;
  344. left: 0;
  345. right: 0;
  346. bottom: 0;
  347. .list-scroll-view {
  348. display: flex;
  349. flex-direction: column;
  350. }
  351. }
  352. </style>