appraise.vue 9.0 KB

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