goods-comment.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view>
  3. <!-- 评分 -->
  4. <view v-if="goods_score != null" class="score-container oh padding-main">
  5. <view class="score fl tc">
  6. <view class="cr-base">综合评分</view>
  7. <view class="value cr-main">{{goods_score.avg || '0.0'}}</view>
  8. </view>
  9. <view class="progress fr tc border-radius-main">
  10. <block v-if="goods_score.avg > 0">
  11. <block v-for="(item, index) in goods_score.rating" :key="index">
  12. <view v-if="item.portion > 0" :class="'progress-bar ' + progress_class[index]" :style="'width: ' + item.portion + '%;'">{{item.name}}</view>
  13. </block>
  14. </block>
  15. <text v-else class="cr-gray">暂无评分</text>
  16. </view>
  17. </view>
  18. <!-- 列表 -->
  19. <scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="60">
  20. <view class="padding-horizontal-main goods-comment">
  21. <view v-for="(item, index) in data_list" :key="index" class="goods-comment-item padding-main border-radius-main bg-white spacing-mb">
  22. <view class="oh nav br-b padding-bottom-sm">
  23. <image class="avatar dis-block fl" :src="item.user.avatar || static_url+'default-user.png'" mode="aspectFit"></image>
  24. <view class="base-nav fr">
  25. <text class="va-m">{{item.user.user_name_view}}</text>
  26. <view class="dis-inline-block va-m margin-left-sm">
  27. <uni-rate :value="item.rating" :readonly="true" :is-fill="false" :size="14" />
  28. </view>
  29. <view class="fr">
  30. <text class="cr-grey">{{item.add_time_date}}</text>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="base-content oh padding-sm">
  35. <view class="content cr-base text-size-sm">{{item.content}}</view>
  36. <view v-if="(item.images || null) != null && item.images.length > 0" class="images oh margin-top-lg">
  37. <block v-for="(iv, ix) in item.images" :key="ix">
  38. <image class="br radius" @tap="comment_images_show_event" :data-index="index" :data-ix="ix" :src="iv" mode="aspectFit"></image>
  39. </block>
  40. </view>
  41. <view v-if="(item.msg || null) != null" class="spec cr-grey margin-top-lg">{{item.msg}}</view>
  42. <view v-if="item.is_reply == 1 && (item.reply || null) != null" class="reply br-t-dashed margin-top-lg padding-top-lg text-size-sm">
  43. <text class="cr-base">管理员回复:</text>
  44. <text class="reply-desc cr-main-pair">{{item.reply}}</text>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 提示信息 -->
  49. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  50. <!-- 结尾 -->
  51. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  52. </view>
  53. </scroll-view>
  54. </view>
  55. </template>
  56. <script>
  57. const app = getApp();
  58. import componentNoData from "../../components/no-data/no-data";
  59. import componentBottomLine from "../../components/bottom-line/bottom-line";
  60. var static_url = app.globalData.get_static_url('home');
  61. export default {
  62. data() {
  63. return {
  64. static_url: static_url,
  65. data_list_loding_status: 1,
  66. data_bottom_line_status: false,
  67. data_list: [],
  68. data_page_total: 0,
  69. data_page: 1,
  70. goods_score: null,
  71. params: null,
  72. progress_class: ['progress-bar-danger', 'progress-bar-warning', 'progress-bar-secondary', '', 'progress-bar-success'],
  73. };
  74. },
  75. components: {
  76. componentNoData,
  77. componentBottomLine
  78. },
  79. props: {},
  80. onLoad(params) {
  81. //params['goods_id']=9;
  82. this.setData({
  83. params: params
  84. });
  85. },
  86. onShow() {
  87. this.init();
  88. // 分享菜单处理
  89. app.globalData.page_share_handle();
  90. },
  91. // 下拉刷新
  92. onPullDownRefresh() {
  93. this.setData({
  94. data_page: 1
  95. });
  96. this.get_data_list(1);
  97. },
  98. methods: {
  99. // 初始化
  100. init() {
  101. // 获取数据
  102. this.get_goods_score();
  103. this.get_data_list();
  104. },
  105. // 获取商品评分
  106. get_goods_score() {
  107. uni.request({
  108. url: app.globalData.get_request_url("goodsscore", "goods"),
  109. method: 'POST',
  110. data: {
  111. goods_id: this.params.goods_id
  112. },
  113. dataType: 'json',
  114. success: res => {
  115. if (res.data.code == 0) {
  116. this.setData({
  117. goods_score: res.data.data || null
  118. });
  119. } else {
  120. if (res.data.code != -400) {
  121. app.globalData.showToast(res.data.msg);
  122. }
  123. }
  124. },
  125. fail: () => {
  126. app.globalData.showToast('服务器请求出错');
  127. }
  128. });
  129. },
  130. // 获取数据列表
  131. get_data_list(is_mandatory) {
  132. // 参数校验
  133. if ((this.params.goods_id || null) == null) {
  134. uni.stopPullDownRefresh();
  135. this.setData({
  136. data_bottom_line_status: false,
  137. data_list_loding_status: 2
  138. });
  139. } else {
  140. var self = this;
  141. // 分页是否还有数据
  142. if ((is_mandatory || 0) == 0) {
  143. if (this.data_bottom_line_status == true) {
  144. uni.stopPullDownRefresh();
  145. return false;
  146. }
  147. }
  148. uni.showLoading({
  149. title: '加载中...'
  150. });
  151. this.setData({
  152. data_list_loding_status: 1
  153. });
  154. uni.request({
  155. url: app.globalData.get_request_url("comments", "goods"),
  156. method: 'POST',
  157. data: {
  158. goods_id: this.params.goods_id,
  159. page: this.data_page
  160. },
  161. dataType: 'json',
  162. success: res => {
  163. uni.hideLoading();
  164. uni.stopPullDownRefresh();
  165. if (res.data.code == 0) {
  166. if (res.data.data.data.length > 0) {
  167. if (this.data_page <= 1) {
  168. var temp_data_list = res.data.data.data;
  169. } else {
  170. var temp_data_list = this.data_list || [];
  171. var temp_data = res.data.data.data;
  172. for (var i in temp_data) {
  173. temp_data_list.push(temp_data[i]);
  174. }
  175. }
  176. this.setData({
  177. data_list: temp_data_list,
  178. data_total: res.data.data.total,
  179. data_page_total: res.data.data.page_total,
  180. data_list_loding_status: 3,
  181. data_page: this.data_page + 1
  182. });
  183. // 是否还有数据
  184. this.setData({
  185. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  186. });
  187. } else {
  188. this.setData({
  189. data_list_loding_status: 0
  190. });
  191. if (this.data_page <= 1) {
  192. this.setData({
  193. data_list: [],
  194. data_bottom_line_status: false
  195. });
  196. }
  197. }
  198. } else {
  199. this.setData({
  200. data_list_loding_status: 0
  201. });
  202. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  203. app.globalData.showToast(res.data.msg);
  204. }
  205. }
  206. },
  207. fail: () => {
  208. uni.hideLoading();
  209. uni.stopPullDownRefresh();
  210. this.setData({
  211. data_list_loding_status: 2
  212. });
  213. app.globalData.showToast('服务器请求出错');
  214. }
  215. });
  216. }
  217. },
  218. // 滚动加载
  219. scroll_lower(e) {
  220. this.get_data_list();
  221. },
  222. // 评价图片预览
  223. comment_images_show_event(e) {
  224. var index = e.currentTarget.dataset.index;
  225. var ix = e.currentTarget.dataset.ix;
  226. uni.previewImage({
  227. current: this.data_list[index]['images'][ix],
  228. urls: this.data_list[index]['images']
  229. });
  230. }
  231. }
  232. };
  233. </script>
  234. <style>
  235. @import './goods-comment.css';
  236. </style>