index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="detail mt20 bgfff">
  3. <view class="tab dflex">
  4. <view :class="'li ' + (currentTab == 0 ? 'active' : '')" data-current="0" @tap="tab">图文详情</view>
  5. <view :class="'li ' + (currentTab == 1 ? 'active' : '')" data-current="1" @tap="tab" v-if=""
  6. v-if="config.is_hide_product_parameter != 1">产品说明</view>
  7. <view :class="'li ' + (currentTab == 2 ? 'active' : '')" data-current="2" @tap="tab"
  8. v-if="isOpenComments == 1">买家评价</view>
  9. </view>
  10. <view :class="currentTab == 0 ? 'show' : 'hide'">
  11. <view class="tabcon details det-text">
  12. <!-- <rich-text :nodes="detail"></rich-text> -->
  13. <mp-html :content="detail" :lazy-load="true" @imgtap="choose"></mp-html>
  14. </view>
  15. <!-- <view class="tabcon details">
  16. <block v-for="(item, index) in imgs" :key="index">
  17. <image class="img" :src="item + '?x-oss-process=style/w750-auto'" mode="widthFix" @tap="chooseImg" :data-src="item"></image>
  18. </block>
  19. </view> -->
  20. <block v-if="diyNodes || diyImgs.length > 0">
  21. <view class="tabcon details">
  22. <rich-text :nodes="diyNodes" @tap="richImg"></rich-text>
  23. </view>
  24. <view class="tabcon details">
  25. <block v-for="(item, index) in diyImgs" :key="index">
  26. <image class="img" :src="item + '?x-oss-process=style/w750-auto'" mode="widthFix"
  27. @tap="chooseImg1" :data-src="item"></image>
  28. </block>
  29. </view>
  30. </block>
  31. </view>
  32. <view :class="[currentTab == 1? 'show' : 'hide','tabcon']">
  33. <view class="canshu" v-if="params.length > 0">
  34. <view v-for="(item, index) in params" :key="index" class="li dflex">
  35. <label class="label">{{item.name}}</label>
  36. <view class="view flex">{{item.value}}</view>
  37. </view>
  38. </view>
  39. <view class="nodata" v-else>
  40. <image :src="picUrlss+'empty.png'" mode="aspectFit"></image>
  41. <text>暂无记录~</text>
  42. </view>
  43. </view>
  44. <view :class="[currentTab == 2 ? 'show' : 'hide','tabcon']">
  45. <view class="fen dflex">
  46. <view class="zong"><text class="text">{{overallRating}}</text>综合评分</view>
  47. <view class="xing flex">
  48. <view class="ping dflex">
  49. <view class="view">服务态度</view>
  50. <image v-for="(item, index) in [1,2,3,4,5]" :key="index" class="image"
  51. :src="score.serviceAttitude >= item ? '/static/pages/images/star_h.png' : '/static/pages/images/star.png'">
  52. </image>
  53. <text class="text">{{score.serviceAttitude}}分</text>
  54. </view>
  55. <view class="ping dflex">
  56. <view class="view">商品评分</view>
  57. <image v-for="(item, index) in [1,2,3,4,5]" :key="index" class="image"
  58. :src="score.productRating >= item ? '/static/pages/images/star_h.png' : '/static/pages/images/star.png'">
  59. </image>
  60. <text class="text">{{score.productRating}}分</text>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="pltab dflex">
  65. <view :class="'li ' + (scoreTab == 0 ? 'active' : '')" @tap="scoreTabFun" data-current="0">
  66. 全部({{score.ratingAll}})</view>
  67. <view :class="'li ' + (scoreTab == 3 ? 'active' : '')" @tap="scoreTabFun" data-current="3">
  68. 好评({{score.ratingGood}})</view>
  69. <view :class="'li ' + (scoreTab == 2 ? 'active' : '')" @tap="scoreTabFun" data-current="2">
  70. 中评({{score.ratingMedium}})</view>
  71. <view :class="'li ' + (scoreTab == 1 ? 'active' : '')" @tap="scoreTabFun" data-current="1">
  72. 差评({{score.ratingBad}})</view>
  73. </view>
  74. <view class="plcon">
  75. <block v-if="scoreList.length > 0">
  76. <view v-for="(item, index) in scoreList" :key="index" class="li dflex">
  77. <image :src="item.avatar" mode="aspectFit" class="user"></image>
  78. <view class="flex">
  79. <view class="name dflex">{{item.nickName.replace(/^(.).*(.)$/,"$1***$2")}}<text class="time">{{item.createDate}}</text>
  80. </view>
  81. <view class="pinglun">{{item.evaluateText ? item.evaluateText : '此用户没有填写评价。'}}</view>
  82. <view class="plimg dflex" v-if="item.buyShow.length > 0">
  83. <image v-for="(it, index2) in item.buyShow" :key="index2" :src="it" mode="aspectFit"
  84. @tap="previewImg" :data-src="it" :data-list="item.buyShow"></image>
  85. </view>
  86. <!-- <view class="huifu">商家回复:感谢您对我们的支持,我们更加用心的服务好每一位客户!</view> -->
  87. </view>
  88. </view>
  89. </block>
  90. <view class="nodata" v-else>
  91. <image :src="picUrlss+'empty_dd.png'"></image>
  92. <text>商品还没有人评价</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. const req = require("../../utils/request");
  100. import mpHtml from "../mp-html/components/mp-html/mp-html";
  101. export default {
  102. components: {
  103. mpHtml
  104. },
  105. data() {
  106. return {
  107. picUrlss: req.public.picUrls,
  108. currentTab: 0,
  109. params: [],
  110. scoreList: [],
  111. isLoad: true,
  112. scoreTab: 0,
  113. overallRating: '0' //综合评分
  114. ,
  115. diyImgs: "",
  116. diyNodes: "",
  117. score: "",
  118. isOpenComments: "",
  119. config: {}
  120. };
  121. },
  122. props: {
  123. detail: String,
  124. proId: String,
  125. imgs: Array,
  126. form: {
  127. type: Object,
  128. default: () => ({})
  129. }
  130. },
  131. watch: {
  132. 'proId': function(oldValue, newValue) {
  133. // console.log(oldValue, newValue);
  134. },
  135. },
  136. options: {
  137. addGlobalClass: true
  138. },
  139. mounted() {
  140. // console.log(this.detail,"7899879")
  141. let that = this;
  142. that.isOpenCommentsFun();
  143. that.loadParams();
  144. that.joinFootprint();
  145. if (req.getStorage('productDiy')) {
  146. //富文本图片放大
  147. var diyNodes = req.getStorage('productDiy');
  148. if (diyNodes) {
  149. if (diyNodes.indexOf("src") >= 0) {
  150. //正则匹配所有图片路径
  151. var diyImgs = [];
  152. diyNodes = diyNodes.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture) {
  153. diyImgs.push(capture);
  154. that.setData({
  155. diyImgs: diyImgs
  156. });
  157. return '';
  158. });
  159. }
  160. } // console.log(diyNodes,this.data.imgs,this.data.diyImgs)
  161. // console.log(this.detail,"================");
  162. that.setData({
  163. diyNodes: diyNodes
  164. });
  165. }
  166. this.config = JSON.parse(req.getStorage('configRes'));
  167. },
  168. methods: {
  169. choose: function() {
  170. // console.log(123);
  171. let freshen = false;
  172. this.$emit('freshen', {
  173. detail: freshen
  174. });
  175. },
  176. tab(event) {
  177. const tabIndex = event.currentTarget.dataset.current;
  178. if (this.currentTab === tabIndex) return false;
  179. this.setData({
  180. currentTab: tabIndex
  181. });
  182. this.$emit('showTab', {
  183. detail: tabIndex
  184. });
  185. },
  186. joinFootprint() {
  187. req.postRequest('/api/footprint', {
  188. bindId: this.proId,
  189. type: 1
  190. }, () => {}, true);
  191. },
  192. loadParams() {
  193. let _ts = this;
  194. req.getRequest('/api/product/params', {
  195. id: this.proId
  196. }, data => {
  197. _ts.setData({
  198. params: data
  199. });
  200. });
  201. },
  202. loadScore(scoreType, from) {
  203. //买家评价
  204. let _ts = this;
  205. // console.log(this.isLoad, scoreType,this.form);
  206. // if (scoreType) {
  207. // this.isLoad = true; // this.setData({['form.page']:1})
  208. // }
  209. if (!this.isLoad) return false;
  210. this.isLoad = false;
  211. let userInfo = req.getStorage('userInfo');
  212. let form
  213. if (from) {
  214. form = from;
  215. } else {
  216. form = _ts.form;
  217. }
  218. form.bindId = _ts.proId; // form.uid = userInfo.id;
  219. form.type = scoreType;
  220. req.getRequest('/api/sysScore/getList', form, res => {
  221. if (res.list && res.list.length == 10) _ts.isLoad = true;
  222. if (_ts.form.page > 1) res.list = _ts.scoreList.concat(res.list);
  223. res.list.map(item => {
  224. if (typeof item.buyShow != 'object') {
  225. if (!item.buyShow) {
  226. item.buyShow = [];
  227. } else {
  228. item.buyShow = item.buyShow.split(',');
  229. }
  230. } // item.buyShow = !item.buyShow ? [] : item.buyShow.split(',');
  231. return item;
  232. });
  233. _ts.setData({
  234. scoreList: res.list
  235. });
  236. // console.log('评价列表', _ts.scoreList, _ts.isLoad);
  237. });
  238. },
  239. loadScoreData() {
  240. req.getRequest('/api/sysScore/statisticsScore', {
  241. productId: this.proId
  242. }, res => {
  243. // console.log('评价统计', res);
  244. res.serviceAttitude = res.serviceAttitude.toFixed(0) == 0 ? '5' : res.serviceAttitude.toFixed(
  245. 0);
  246. res.productRating = res.productRating.toFixed(0) == 0 ? '5' : res.productRating.toFixed(0);
  247. let overallRating = (Number(res.serviceAttitude) + Number(res.productRating)) / 2;
  248. this.setData({
  249. score: res,
  250. overallRating: overallRating
  251. });
  252. });
  253. },
  254. scoreTabFun(event) {
  255. this.form.page = 1
  256. this.isLoad = true
  257. let current = event.currentTarget.dataset.current;
  258. this.setData({
  259. scoreTab: current
  260. });
  261. this.$emit('scoreTab', {
  262. detail: current
  263. });
  264. this.$emit('getForm', {
  265. detail: this.form.page
  266. });
  267. this.loadScore(current);
  268. },
  269. chooseImg: function(e) {
  270. //预览
  271. var src = e.currentTarget.dataset.src;
  272. let freshen = false;
  273. this.$emit('freshen', {
  274. detail: freshen
  275. });
  276. uni.previewImage({
  277. current: src,
  278. // 当前显示图片的http链接
  279. urls: this.imgs
  280. });
  281. },
  282. chooseImg1: function(e) {
  283. //预览
  284. var src = e.currentTarget.dataset.src;
  285. let freshen = false;
  286. this.$emit('freshen', {
  287. detail: freshen
  288. });
  289. uni.previewImage({
  290. current: src,
  291. // 当前显示图片的http链接
  292. urls: this.diyImgs
  293. });
  294. },
  295. previewImg: function(e) {
  296. //预览评论买家秀
  297. var src = e.currentTarget.dataset.src;
  298. let list = e.currentTarget.dataset.list;
  299. let freshen = false;
  300. this.$emit('freshen', {
  301. detail: freshen
  302. });
  303. uni.previewImage({
  304. current: src,
  305. // 当前显示图片的http链接
  306. urls: list
  307. });
  308. },
  309. isOpenCommentsFun() {
  310. //是否开启评论
  311. let that = this;
  312. if (req.getStorage('configRes') && JSON.parse(req.getStorage('configRes')).is_open_comments) {
  313. let isOpenCommentss = JSON.parse(req.getStorage('configRes')).is_open_comments;
  314. if (isOpenCommentss == 1) {
  315. that.loadScore(that.scoreType);
  316. that.loadScoreData();
  317. }
  318. this.setData({
  319. isOpenComments: isOpenCommentss
  320. });
  321. } else {
  322. req.g('/api/config', res => {
  323. let isOpenCommentss = res.is_open_comments;
  324. if (isOpenCommentss == 1) {
  325. that.loadScore(that.scoreType);
  326. that.loadScoreData();
  327. }
  328. this.setData({
  329. isOpenComments: isOpenCommentss
  330. });
  331. req.setStorage('configRes', JSON.stringify(res));
  332. });
  333. }
  334. }
  335. }
  336. };
  337. </script>
  338. <style>
  339. @import "./index.css";
  340. </style>