appraise.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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" :src="item.customer.icon&&item.customer.icon.length>0?item.customer.icon[0].url:''" mode="">
  20. </image>
  21. <text v-else class="iconfont icon-top"></text>
  22. <view class="list_1">
  23. <view class="other">
  24. <text>{{item.customer.phone}}</text>
  25. <text>{{item.reply[0].time||'暂无'}}</text>
  26. </view>
  27. <view class="flie">
  28. <view v-for="(tag, indexs) in item.reply[0].file" :key="indexs">
  29. <image @click="toLarge(item,indexs)" class="images" :src="tag.url" mode="">
  30. </image>
  31. </view>
  32. </view>
  33. <view class="stars">
  34. <uni-rate size="18" :readonly="true" :value="item.goods_score" />
  35. </view>
  36. <view class="other1"><text>{{item.reply[0].content||'暂无'}}</text></view>
  37. <view class="other2">规格:{{item.goodsSpec.name}}</view>
  38. <view class="other2" v-for="(itm, indexx) in item.reply" :key="indexx">
  39. <view class="other2_1">
  40. <view :class="[item.customer._id!=user._id?'reply_2':'reply']">
  41. <text>用户评论:{{itm.content||'暂无'}}</text>
  42. <text v-if="itm.reply">商家回复:{{itm.reply||'暂无'}}</text>
  43. </view>
  44. <view v-if="item.customer._id==user._id" @tap="toReply(item,indexx)">回复</view>
  45. </view>
  46. <uni-easyinput v-if="reply.reply&&reply.customer._id==user._id&&reply._id==item._id&&reply.index==indexx" class="input" maxlength=-1 type="textarea" @change="confirm" placeholder="评论" />
  47. </view>
  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: 10,
  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. // 监听用户是否登录
  106. watchLogin() {
  107. const that = this;
  108. uni.getStorage({
  109. key: 'token',
  110. success: function(res) {
  111. let user = that.$jwt(res.data);
  112. that.$set(that, `user`, user);
  113. that.search()
  114. },
  115. fail: function(err) {
  116. uni.reLaunch({
  117. url: `/pages/login/index`
  118. })
  119. }
  120. })
  121. },
  122. // 查询列表
  123. async search() {
  124. const that = this;
  125. let user = that.user;
  126. let res;
  127. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  128. id: that.id
  129. });
  130. if (res.errcode == '0') {
  131. that.$set(that, `info`, res.data)
  132. }
  133. let info = {
  134. goods: that.id
  135. }
  136. res = await that.$api(`/goodsRate`, `GET`, {
  137. ...info,
  138. })
  139. if (res.errcode == '0') {
  140. let list = res.data;
  141. for (let val of list) {
  142. val.customer.phone = val.customer.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  143. }
  144. that.$set(that, `list`, list)
  145. that.$set(that, `total`, res.total)
  146. that.$set(that.btnlist[0], `total`, res.total)
  147. let one = list.filter(item => item.goods_score == 5);
  148. that.$set(that, `one`, one)
  149. that.$set(that.btnlist[1], `total`, one.length);
  150. let two = list.filter(item => item.goods_score < 5 && item.goods_score > 2)
  151. that.$set(that, `two`, two)
  152. that.$set(that.btnlist[2], `total`, two.length);
  153. let thr = list.filter(item => item.goods_score <= 2)
  154. that.$set(that, `thr`, thr)
  155. that.$set(that.btnlist[3], `total`, thr.length);
  156. } else {
  157. uni.showToast({
  158. title: res.errmsg,
  159. });
  160. }
  161. },
  162. async confirm(e) {
  163. const that = this;
  164. if (e) {
  165. let reply = that.reply
  166. let obj = {
  167. content: e,
  168. time: moment().format('YYYY-MM-DD HH:mm:ss')
  169. }
  170. reply.reply.push(obj)
  171. const arr = await that.$api(`/goodsRate/${that.reply._id}`, 'POST', reply)
  172. if (arr.errcode == '0') {
  173. uni.showToast({
  174. title: `回复成功`,
  175. icon: 'success',
  176. });
  177. that.$set(that, `reply`, {});
  178. } else {
  179. uni.showToast({
  180. title: arr.errmsg,
  181. icon: 'none',
  182. })
  183. }
  184. } else {
  185. that.$set(that, `reply`, {});
  186. }
  187. },
  188. // 回复
  189. toReply(e, index) {
  190. const that = this;
  191. that.$set(that, `reply`, e);
  192. that.$set(that.reply, `index`, index);
  193. },
  194. // 放大
  195. toLarge(e, index) {
  196. let url = e.reply[0].file.map(item => item.url)
  197. uni.previewImage({
  198. current: index,
  199. urls: url
  200. })
  201. },
  202. // 选择
  203. toSelect(e) {
  204. const that = this;
  205. that.$set(that, `code`, e.code);
  206. if (e.code == '0') {
  207. that.search()
  208. } else if (e.code == '1') {
  209. that.$set(that, `list`, that.one);
  210. } else if (e.code == '2') {
  211. that.$set(that, `list`, that.two);
  212. } else {
  213. that.$set(that, `list`, that.thr);
  214. }
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss">
  220. .main {
  221. display: flex;
  222. flex-direction: column;
  223. width: 100vw;
  224. height: 100vh;
  225. background-color: var(--f1Color);
  226. .one {
  227. margin: 0 0 2vw 0;
  228. .one_1 {
  229. display: flex;
  230. justify-content: space-around;
  231. background-color: var(--mainColor);
  232. margin: 0 0 0.5vw 0;
  233. padding: 2vw;
  234. .text1 {
  235. width: 65vw;
  236. font-size: var(--font16Szie);
  237. }
  238. .text2 {
  239. font-size: var(--font16Szie);
  240. color: var(--f85Color);
  241. text {
  242. margin: 0 0 0 1vw;
  243. color: var(--ff0Color);
  244. }
  245. }
  246. }
  247. .one_2 {
  248. display: flex;
  249. justify-content: space-around;
  250. padding: 2vw;
  251. background-color: var(--mainColor);
  252. }
  253. }
  254. .two {
  255. position: relative;
  256. flex-grow: 1;
  257. .list {
  258. display: flex;
  259. justify-content: space-around;
  260. align-items: flex-start;
  261. background-color: var(--mainColor);
  262. margin: 0 0 2vw 0;
  263. padding: 2vw;
  264. .image {
  265. width: 10vw;
  266. height: 10vw;
  267. border-radius: 10vw;
  268. }
  269. .iconfont {
  270. font-size: 30px;
  271. }
  272. .list_1 {
  273. flex-grow: 1;
  274. width: 85vw;
  275. margin: 0 0 0 2vw;
  276. font-size: var(--font14Size);
  277. .other {
  278. display: flex;
  279. justify-content: space-between;
  280. text:last-child {
  281. font-size: var(--font12Size);
  282. color: var(--f85Color);
  283. }
  284. }
  285. .other1 {
  286. margin: 1vw 0 0 0;
  287. word-break: break-all;
  288. word-wrap: break-word;
  289. }
  290. .flie {
  291. display: flex;
  292. flex-wrap: wrap;
  293. margin: 1vw 0;
  294. .images {
  295. width: 20vw;
  296. height: 20vw;
  297. margin: 0 1vw 0 0;
  298. }
  299. }
  300. .other2 {
  301. font-size: var(--font12Size);
  302. color: var(--f85Color);
  303. margin: 2vw 0 0 0;
  304. .other2_1 {
  305. display: flex;
  306. justify-content: space-between;
  307. }
  308. .reply {
  309. display: flex;
  310. flex-direction: column;
  311. width: 70vw;
  312. word-wrap: break-word;
  313. word-break: break-all;
  314. }
  315. .reply_2 {
  316. display: flex;
  317. flex-direction: column;
  318. word-wrap: break-word;
  319. word-break: break-all;
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. .scroll-view {
  327. position: absolute;
  328. top: 0;
  329. left: 0;
  330. right: 0;
  331. bottom: 0;
  332. .list-scroll-view {
  333. display: flex;
  334. flex-direction: column;
  335. }
  336. }
  337. </style>