appraise.vue 8.2 KB

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