appraise.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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?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.navigateTo({
  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. if (val.customer && val.customer.phone) {
  143. val.customer.phone = val.customer.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  144. }
  145. }
  146. that.$set(that, `list`, list)
  147. that.$set(that, `total`, res.total)
  148. that.$set(that.btnlist[0], `total`, res.total)
  149. let one = list.filter(item => item.goods_score == 5);
  150. that.$set(that, `one`, one)
  151. that.$set(that.btnlist[1], `total`, one.length);
  152. let two = list.filter(item => item.goods_score < 5 && item.goods_score > 2)
  153. that.$set(that, `two`, two)
  154. that.$set(that.btnlist[2], `total`, two.length);
  155. let thr = list.filter(item => item.goods_score <= 2)
  156. that.$set(that, `thr`, thr)
  157. that.$set(that.btnlist[3], `total`, thr.length);
  158. } else {
  159. uni.showToast({
  160. title: res.errmsg,
  161. });
  162. }
  163. },
  164. async confirm(e) {
  165. const that = this;
  166. if (e) {
  167. let reply = that.reply
  168. let obj = {
  169. content: e,
  170. time: moment().format('YYYY-MM-DD HH:mm:ss')
  171. }
  172. reply.reply.push(obj)
  173. const arr = await that.$api(`/goodsRate/${that.reply._id}`, 'POST', reply)
  174. if (arr.errcode == '0') {
  175. uni.showToast({
  176. title: `回复成功`,
  177. icon: 'success',
  178. });
  179. that.$set(that, `reply`, {});
  180. } else {
  181. uni.showToast({
  182. title: arr.errmsg,
  183. icon: 'none',
  184. })
  185. }
  186. } else {
  187. that.$set(that, `reply`, {});
  188. }
  189. },
  190. // 回复
  191. toReply(e, index) {
  192. const that = this;
  193. that.$set(that, `reply`, e);
  194. that.$set(that.reply, `index`, index);
  195. },
  196. // 放大
  197. toLarge(e, index) {
  198. let url = e.reply[0].file.map(item => item.url)
  199. uni.previewImage({
  200. current: index,
  201. urls: url
  202. })
  203. },
  204. // 选择
  205. toSelect(e) {
  206. const that = this;
  207. that.$set(that, `code`, e.code);
  208. if (e.code == '0') {
  209. that.search()
  210. } else if (e.code == '1') {
  211. that.$set(that, `list`, that.one);
  212. } else if (e.code == '2') {
  213. that.$set(that, `list`, that.two);
  214. } else {
  215. that.$set(that, `list`, that.thr);
  216. }
  217. },
  218. }
  219. }
  220. </script>
  221. <style lang="scss">
  222. .main {
  223. display: flex;
  224. flex-direction: column;
  225. width: 100vw;
  226. height: 100vh;
  227. background-color: var(--f1Color);
  228. .one {
  229. margin: 0 0 2vw 0;
  230. .one_1 {
  231. display: flex;
  232. justify-content: space-around;
  233. background-color: var(--mainColor);
  234. margin: 0 0 0.5vw 0;
  235. padding: 2vw;
  236. .text1 {
  237. width: 65vw;
  238. font-size: var(--font16Szie);
  239. }
  240. .text2 {
  241. font-size: var(--font16Szie);
  242. color: var(--f85Color);
  243. text {
  244. margin: 0 0 0 1vw;
  245. color: var(--ff0Color);
  246. }
  247. }
  248. }
  249. .one_2 {
  250. display: flex;
  251. justify-content: space-around;
  252. padding: 2vw;
  253. background-color: var(--mainColor);
  254. }
  255. }
  256. .two {
  257. position: relative;
  258. flex-grow: 1;
  259. .list {
  260. display: flex;
  261. justify-content: space-around;
  262. align-items: flex-start;
  263. background-color: var(--mainColor);
  264. margin: 0 0 2vw 0;
  265. padding: 2vw;
  266. .image {
  267. width: 10vw;
  268. height: 10vw;
  269. border-radius: 10vw;
  270. }
  271. .iconfont {
  272. font-size: 30px;
  273. }
  274. .list_1 {
  275. flex-grow: 1;
  276. width: 85vw;
  277. margin: 0 0 0 2vw;
  278. font-size: var(--font14Size);
  279. .other {
  280. display: flex;
  281. justify-content: space-between;
  282. text:last-child {
  283. font-size: var(--font12Size);
  284. color: var(--f85Color);
  285. }
  286. }
  287. .other1 {
  288. margin: 1vw 0 0 0;
  289. word-break: break-all;
  290. word-wrap: break-word;
  291. }
  292. .flie {
  293. display: flex;
  294. flex-wrap: wrap;
  295. margin: 1vw 0;
  296. .images {
  297. width: 20vw;
  298. height: 20vw;
  299. margin: 0 1vw 0 0;
  300. }
  301. }
  302. .other2 {
  303. font-size: var(--font12Size);
  304. color: var(--f85Color);
  305. margin: 2vw 0 0 0;
  306. .other2_1 {
  307. display: flex;
  308. justify-content: space-between;
  309. }
  310. .reply {
  311. display: flex;
  312. flex-direction: column;
  313. width: 70vw;
  314. word-wrap: break-word;
  315. word-break: break-all;
  316. }
  317. .reply_2 {
  318. display: flex;
  319. flex-direction: column;
  320. word-wrap: break-word;
  321. word-break: break-all;
  322. }
  323. }
  324. }
  325. }
  326. }
  327. }
  328. .scroll-view {
  329. position: absolute;
  330. top: 0;
  331. left: 0;
  332. right: 0;
  333. bottom: 0;
  334. .list-scroll-view {
  335. display: flex;
  336. flex-direction: column;
  337. }
  338. }
  339. </style>