goods.vue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. <template>
  2. <view>
  3. <!-- 01. 轮播区 -->
  4. <view class="swiper-area w-full pos-f">
  5. <swiper class="h-full pos-r" indicator-dots circular="true" duration="400">
  6. <swiper-item v-for="(item, index) in swiperDatas" :key="index">
  7. <view class="wh-full"><image :src="item" class="wh-full loaded" lazy-load="true" mode="aspectFill"></image></view>
  8. </swiper-item>
  9. </swiper>
  10. </view>
  11. <!-- 02. 商品数据区 -->
  12. <view class="goods-area bg-main padding">
  13. <view class="price-box dflex-b">
  14. <view>
  15. <text class="price fwb fs-big">{{ goods.price || '' }}</text>
  16. <text class="m-price" v-if="goods.marketPrice > 0">{{ goods.marketPrice || '' }}</text>
  17. </view>
  18. <view class="dflex fs-sm ft-dark">
  19. <!-- #ifdef MP-WEIXIN || H5 -->
  20. <!-- <view class="margin-right-sm dflex" @click="shareOpen">
  21. <view class="iconfont iconfenxiang padding-right-xs"></view>
  22. <text>分享</text>
  23. </view> -->
  24. <!-- #endif -->
  25. <!-- #ifdef MP-ALIPAY || MP-BAIDU || MP-QQ || MP-TOUTIAO -->
  26. <!-- <button class="btn no-border padding-0 fs-sm ft-dark" open-type="share" @click="shareOpen">
  27. <view class="margin-right-sm dflex">
  28. <view class="iconfont iconfenxiang padding-right-xs"></view>
  29. <text>分享</text>
  30. <text>{{ goods.shareCnt || '0' }}</text>
  31. </view>
  32. </button> -->
  33. <!-- #endif -->
  34. <view class="margin-right-sm dflex">
  35. <view class="padding-right-xs padding-right-xs">已售</view>
  36. <text>{{ goods.saleCnt || '0' }}</text>
  37. </view>
  38. <view class="dflex">
  39. <view class="padding-right-xs padding-right-xs">库存</view>
  40. <text>{{ goods.stockNum || '0' }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <text class="title1 fs">{{ goods.name || '' }}</text>
  45. </view>
  46. <view class="gap"></view>
  47. <!-- 分享 -->
  48. <use-popup mode="bottom" bgclass=" " v-model="shareShow">
  49. <view class="share-area margin border-radius bg-main" @click="shareClose">
  50. <view class="tac w-full padding-sm">分享</view>
  51. <view class="padding-lr margin-bottom-xl dflex-b pos-r">
  52. <!-- #ifdef MP-WEIXIN -->
  53. <button class="dflex-c dflex-flow-c no-border btn" style="color: #07c160" open-type="share">
  54. <view class="iconfont iconweixin padding-lr-sm border-radius-c fs-xxxl"></view>
  55. <view class="dflex-c fs-sm ft-dark">微信好友</view>
  56. </button>
  57. <!-- <view class="vertical-line"></view> -->
  58. <!-- #endif -->
  59. <!-- <button class="dflex-c dflex-flow-c no-border btn ft-base" @click="createPoster">
  60. <view class="iconfont iconhaibao1 padding-lr-sm border-radius-c fs-xxxl"></view>
  61. <view class="dflex-c fs-sm ft-dark">生成海报</view>
  62. </button> -->
  63. </view>
  64. </view>
  65. </use-popup>
  66. <!-- 海报二维码 -->
  67. <view class="qrcode tac padding-tb pos-f pos-tl-c">
  68. <!-- <use-qrcode :onval="true" :val="posterQRcode" :show="false" loading-text="生成海报中" qrsize="200" @result="posterQRcodeResult"></use-qrcode> -->
  69. </view>
  70. <!-- 海报 -->
  71. <view v-if="posterShow && !posterUrl" class="poster pos-f pos-tl-c padding">
  72. <l-painter custom-style="position: fixed;z-index: -1;top: -200vh;left: -100vw;" :board="posterData" isRenderImage @success="posterSuccess" />
  73. </view>
  74. <!-- <use-popup mode="bottom" bgclass=" " v-model="posterShow" @close="">
  75. <view class="padding border-radius margin">
  76. <view v-if="!posterUrl" class="tac bg-main padding border-radius pos-a pos-l-c" style="bottom: 45vh">海报生成中,请稍等</view>
  77. <view class="w-full" style="height: 70vh"><image :src="posterUrl" class="wh-full" mode="aspectFit"></image></view>
  78. <view class="padding w-full margin-top">
  79. <view class="dflex-b border-radius-big"> -->
  80. <!-- #ifdef MP -->
  81. <!-- <view class="tac padding-tb-sm flex1 bg-base" @click="posterSave">保存到相册</view> -->
  82. <!-- #endif -->
  83. <!-- #ifdef H5 || MP-360 -->
  84. <!-- <view class="tac padding-tb-sm flex1 bg-base">长按图片保存到相册</view> -->
  85. <!-- #endif -->
  86. <!-- </view>
  87. </view>
  88. </view>
  89. </use-popup> -->
  90. <!-- 03. 规格区 -->
  91. <!-- <view v-if="skuDatas.length > 0" class="sku-area bg-main padding-lr padding-top padding-bottom-xs pos-r">
  92. <view class="con dflex dflex-wrap-w">
  93. <view
  94. class="margin-right-sm margin-bottom-sm dflex bg-drak border-radius-lg padding-tb-16 padding-lr"
  95. :class="{ active: item.selected }"
  96. v-for="(item, index) in skuDatas"
  97. :key="index"
  98. @click="selectSKU(item)"
  99. >
  100. <text class="fs-xs">{{ item.name }}</text>
  101. </view>
  102. </view>
  103. </view>
  104. <view v-if="skuDatas.length > 0" class="gap"></view> -->
  105. <!-- 04.01 优惠券 -->
  106. <!-- <use-list-title title="优惠" tip="领取优惠券" color="#ff6a6c" iconfont="iconyouhui" @goto="couponShow = true"></use-list-title> -->
  107. <!-- 04.01 优惠券弹出层 -->
  108. <use-popup mode="bottom" v-model="couponShow" @open="couponOpen">
  109. <!-- 优惠券区 -->
  110. <scroll-view>
  111. <view class="coupon-area padding bg-drak">
  112. <view class="coupon-item bg-main pos-r fs-xs" v-for="(item, index) in couponDatas" :key="index">
  113. <view class="content pos-r padding dflex-b">
  114. <view class="">
  115. <view class="margin-bottom-xs fs">{{ item.name }}</view>
  116. <view class="ft-dark">有效期至 {{ item.end_time.split(' ')[0] }}</view>
  117. </view>
  118. <view class="tar">
  119. <view class="margin-bottom-xs price">{{ item.price }}</view>
  120. <view v-if="item.order_amount > 0" class="ft-dark">满{{ item.order_amount }}可用</view>
  121. <view v-else class="ft-dark">不限</view>
  122. </view>
  123. <view class="circle l"></view>
  124. <view class="circle r"></view>
  125. </view>
  126. <view class="dflex-b">
  127. <text class="ft-dark padding-lr">{{ item.type }}</text>
  128. <text class="ft-base padding-tb-sm padding-lr" @click="couponReceive(item.id)">立即领取</text>
  129. </view>
  130. </view>
  131. </view>
  132. </scroll-view>
  133. </use-popup>
  134. <!-- 04.02 服务标签 -->
  135. <view class="bg-main padding-lr padding-top padding-bottom-xs pos-r" @click="tagShow = true">
  136. <view class="dflex dflex-wrap-w">
  137. <view v-for="(item, index) in tagDatas" :key="index" class="margin-right-sm margin-bottom-sm dflex">
  138. <view class="iconfont iconyiwancheng- fwb fs-xs ft-base margin-right-xs"></view>
  139. <text class="fs-xs">{{ item.data.tagName }}</text>
  140. </view>
  141. </view>
  142. <!-- <view class="icon-detail pos-a"><view class="iconfont iconxiangqing ft-dark fs-sm"></view></view> -->
  143. </view>
  144. <view class="gap"></view>
  145. <!-- 04.02 服务标签弹出层 -->
  146. <use-popup mode="bottom" v-model="tagShow">
  147. <view class="tac w-full padding-sm">服务说明</view>
  148. <view class="padding-lr padding-bottom-sm">
  149. <view v-for="(item, index) in tagDatas" :key="index" class="margin-right-sm margin-bottom-sm dflex dflex-s">
  150. <view class="iconfont iconyiwancheng- fwb fs ft-base margin-right-xs"></view>
  151. <view>
  152. <view class="fs-sm">{{ item.data.tagName }}</view>
  153. <view class="fs-xs">{{ item.data.tagDesc }}</view>
  154. </view>
  155. </view>
  156. </view>
  157. </use-popup>
  158. <!-- 05. 评价区 -->
  159. <view class="evaluate-area" v-if="evaluateDatas.length > 0">
  160. <use-list-title :title="evaluateTitle" tip="" color="#ff6a6c" iconfont=" " @goto="toevaluate"></use-list-title>
  161. <view class="padding-lr bg-main">
  162. <view class="eva-box dflex-s padding-bottom-lg" v-for="(item, index) in evaluateDatas" :key="index">
  163. <image class="portrait border-radius-c" :src="item.userImg"></image>
  164. <view class="right-area flex1 padding-left-sm">
  165. <view class="dflex-b ft-dark">
  166. <view class="dflex">
  167. <text class="name margin-right">{{ item.createBy }}</text>
  168. <use-rate :value="item.reviewCnt" disabled></use-rate>
  169. </view>
  170. <text class="time fs-xs">{{ $api.format(item.createTime, 'yyyy-MM-dd') }}</text>
  171. </view>
  172. <view class="fs-sm ft-main padding-top-xs padding-bottom-sm">{{ item.reviewContent }}</view>
  173. <view class="dflex dflex-wrap-w">
  174. <!-- <image
  175. class=""
  176. mode="widthFix"
  177. v-for="(img, i) in item.reviewImgs"
  178. :lazy-load="true"
  179. :key="i"
  180. :src="img"
  181. @click="preview(item.reviewImgs, img)"
  182. ></image> -->
  183. <image
  184. class="border-radius-xs"
  185. v-if="item.reviewImgs.indexOf(',') != -1"
  186. mode="aspectFill"
  187. :lazy-load="true"
  188. :src="item.reviewImgs.substring(0, item.reviewImgs.indexOf(','))"
  189. ></image>
  190. <image class="border-radius-xs" v-else mode="aspectFill" :lazy-load="true" :src="item.reviewImgs"></image>
  191. </view>
  192. <view class="">
  193. <text class="fs-xs ft-dark">{{ item.goods_type || '套餐1' }}</text>
  194. </view>
  195. </view>
  196. </view>
  197. </view>
  198. <view class="gap"></view>
  199. </view>
  200. <!-- 06. 详情区 -->
  201. <view class="detail-area bg-main">
  202. <view class="d-header padding dflex-c"><text>图文详情</text></view>
  203. <rich-text class="pro-detail" :nodes="goods.desc"></rich-text>
  204. </view>
  205. <!-- 07. 操作区 -->
  206. <view class="oper-area pos-f dflex-b w-full padding-lr-sm">
  207. <view class="btn-area dflex dflex-flow-c" @click="tohome">
  208. <text class="iconfont iconshouye-1"></text>
  209. <text>首页</text>
  210. </view>
  211. <!-- #ifndef MP-ALIPAY || H5 || MP-360 -->
  212. <button class="btn no-border dflex" open-type="contact">
  213. <view class="btn-area dflex-c dflex-flow-c">
  214. <text class="iconfont iconkefu-01"></text>
  215. <text>客服</text>
  216. </view>
  217. </button>
  218. <!-- #endif -->
  219. <view class="btn-area dflex dflex-flow-c" :class="{ active: favorite }" @click="tofavorite">
  220. <text class="iconfont" :class="favorite ? 'iconshoucang-' : 'iconshoucang-01'"></text>
  221. <text>收藏</text>
  222. </view>
  223. <view class="flex1 btn-container dflex-b border-radius-big">
  224. <view class="tac padding-tb-sm flex1 bg-warn" v-if="goods.stockNum > goods.saleCnt && goods.state == 1" @click="tocart(goods)">加入购物车</view>
  225. <view class="tac padding-tb-sm flex1 bg-base-gou" v-if="goods.stockNum > goods.saleCnt && goods.state == 1" @click="tobuy(goods)">立即购买</view>
  226. <view class="tac padding-tb-sm flex1 bg-disabled" v-if="goods.stockNum == goods.saleCnt && goods.state == 1">已售磐</view>
  227. <view class="tac padding-tb-sm flex1 bg-disabled" v-if="goods.state == 0">已下架</view>
  228. </view>
  229. </view>
  230. <!-- #ifdef MP-ALIPAY -->
  231. <view class="fixed-top dflex-c dflex-flow-c"><contact-button tnt-inst-id="0Xu_1aaW" scene="SCE00225456" size="50" color="#bbb" /></view>
  232. <!-- #endif -->
  233. <!-- 置顶 -->
  234. <use-totop ref="usetop" bottom="120"></use-totop>
  235. <!-- 点击加入购物车弹窗区域 -->
  236. <uv-popup ref="addPopup" bgColor="none" :safeAreaInsetBottom="false">
  237. <view class="body_pop">
  238. <!-- 关闭图标区域 -->
  239. <img class="pop_icon" src="../../../static/index/close3.png" @click="handleClosePop" />
  240. <!-- 顶部信息区域 -->
  241. <view class="pop_header">
  242. <img class="header_img" mode="aspectFill" :src="cartImg" />
  243. <view class="header_info">
  244. <view class="info_price">
  245. <text>{{ cartPrice }}</text>
  246. </view>
  247. <!-- <view class="info_tags">
  248. <view class="tag">包邮</view>
  249. <view class="tag">8600积分</view>
  250. </view> -->
  251. </view>
  252. </view>
  253. <!-- <view class="con dflex dflex-wrap-w">
  254. <view
  255. class="margin-right-sm margin-bottom-sm dflex bg-drak border-radius-lg padding-tb-16 padding-lr"
  256. :class="{ active: item.selected }"
  257. v-for="(item, index) in skuDatas"
  258. :key="index"
  259. @click="selectSKU(item)"
  260. >
  261. <text class="fs-xs">{{ item.name }}</text>
  262. </view>
  263. </view> -->
  264. <!-- 颜色区域 -->
  265. <view v-for="(item, index) in skuAttrDatas" :key="index">
  266. <view class="pop_title">{{ item.attrName }}({{ item.attrValues.length }})</view>
  267. <view class="pop_tags">
  268. <view
  269. :class="item2.type == true ? 'active_sku_color' : 'active_sku'"
  270. @click="selectSKU(index, index2)"
  271. v-for="(item2, index2) in item.attrValues"
  272. :key="index2"
  273. >
  274. {{ item2.attrValue }}
  275. </view>
  276. </view>
  277. </view>
  278. <!-- 容量区域 -->
  279. <!-- <view class="pop_title">容量(3)</view>
  280. <view class="pop_tags">
  281. <view class="tag">256G+512G</view>
  282. <view class="tag">256G</view>
  283. <view class="tag">256G</view>
  284. </view> -->
  285. <!-- 购买数量区域 -->
  286. <view class="pop_title">
  287. 购买数量
  288. <text>库存{{ cartSale }}件</text>
  289. </view>
  290. <view class="pop_num">
  291. <uni-number-box @change="changeValue" />
  292. </view>
  293. <view class="flex1 btn-container dflex-b border-radius-big" style="margin-top: 50px">
  294. <view class="tac padding-tb-sm flex1 bg-warn" v-if="goods.stockNum > goods.saleCnt && goods.state == 1" @click="tocartSKU(goods)">加入购物车</view>
  295. <view class="tac padding-tb-sm flex1 bg-base-gou" v-if="goods.stockNum > goods.saleCnt && goods.state == 1" @click="tobuySku(goods)">立即购买</view>
  296. <view class="tac padding-tb-sm flex1 bg-disabled" v-if="goods.stockNum == goods.saleCnt && goods.state == 1">已售磐</view>
  297. <view class="tac padding-tb-sm flex1 bg-disabled" v-if="goods.state == 0">已下架</view>
  298. </view>
  299. </view>
  300. `
  301. </uv-popup>
  302. </view>
  303. </template>
  304. <script>
  305. // #ifdef MP-ALIPAY
  306. import aliParse from 'mini-html-parser2'
  307. // #endif
  308. import { collectif, footgoods, goodsxiang, collecttian, cartadd, pingjia } from '../../utils/api_goods.js'
  309. import usePopup from '../../components/use-popup/use-popup.vue'
  310. import useListTitle from '../../components/use-list-title/use-list-title.vue'
  311. import useRate from '../../components/use-rate/use-rate.vue'
  312. import usetotop from '../../components/use-totop/use-totop.vue'
  313. import lPainter from '@/packageShang/uni_modules/lime-painter/components/lime-painter/'
  314. import uposter from '@/packageShang/common/poster.js'
  315. import { mapState } from 'vuex'
  316. export default {
  317. components: {
  318. lPainter,
  319. useListTitle,
  320. useRate,
  321. usePopup,
  322. usetotop
  323. },
  324. computed: {
  325. ...mapState(['islogin', 'member'])
  326. },
  327. data() {
  328. return {
  329. // 商品ID
  330. id: 0,
  331. // 分享ID
  332. mid: 0,
  333. // 商品数据
  334. goods: {},
  335. // 轮播图
  336. swiperDatas: [],
  337. // SKU
  338. sku: {},
  339. skuDatas: [],
  340. cartNum: '1', //商品加购数量
  341. cartImg: '', //加购图片
  342. cartPrice: '', //加购价格
  343. cartSale: '', //加购库存
  344. skuId: '', //选中sku
  345. // 分享
  346. shareShow: false,
  347. // 海报
  348. posterQRcode: '',
  349. posterUrl: '',
  350. posterShow: false,
  351. posterData: {},
  352. //优惠券
  353. couponShow: false,
  354. couponDatas: [],
  355. // 服务标签
  356. tagShow: false,
  357. tagDatas: [],
  358. // 商品评价
  359. evaluateDatas: [],
  360. evaluateTitle: '评价',
  361. // 商品详情
  362. html_nodes: '',
  363. // 收藏
  364. favorite: false, //是否收藏
  365. scrollTop: 0,
  366. skuAttrDatas: [] //商品属性数组
  367. }
  368. },
  369. watch: {
  370. sku(e) {
  371. this.goods.price = e.price
  372. this.goods.marketPrice = e.market_price
  373. this.goods.stockNum = e.num
  374. }
  375. },
  376. onShareAppMessage: function (ops) {
  377. let _this = this
  378. let mid = 0
  379. if (_this.member && _this.member._id) {
  380. mid = _this.member._id
  381. }
  382. return {
  383. title: _this.goods.share_title,
  384. path: `/pages/goods/goods?id=${this.id}&mid=${mid}`, //这里设定都是以"/page"开头,并拼接好传递的参数
  385. success: function (res) {
  386. // 转发成功
  387. console.log('转发成功', res)
  388. },
  389. fail: function (res) {
  390. // 转发失败
  391. console.log('转发失败', res)
  392. }
  393. }
  394. },
  395. onPageScroll(e) {
  396. //this.scrollTop = e.scrollTop;
  397. this.$refs.usetop.change(e.scrollTop)
  398. },
  399. onLoad(options) {
  400. if (options) {
  401. this.mid = options.mid || ''
  402. if (options.id) {
  403. this.id = options.id
  404. } else if (options.q) {
  405. let query = decodeURIComponent(options.q) || decodeURIComponent(uni.getStorageInfoSync('__scene_query_q'))
  406. this.resolveQueryq(query)
  407. }
  408. }
  409. if (!this.id) {
  410. this.$api.msg('商品ID无效')
  411. return
  412. }
  413. },
  414. onShow(options) {
  415. if (!this.id) {
  416. const query = decodeURIComponent(uni.getStorageInfoSync('__scene_query_q'))
  417. this.resolveQueryq(query)
  418. }
  419. var _self = this
  420. var header = {
  421. 'Mall-Token': uni.getStorageSync('tokenId')
  422. }
  423. //是否收藏
  424. var data = _self.id
  425. collectif(data, header).then((res) => {
  426. if (res.data) {
  427. _self.favorite = true
  428. } else {
  429. _self.favorite = false
  430. }
  431. _self.loadData()
  432. })
  433. //商品足迹
  434. footgoods(data, header).then((res) => {
  435. if (res.success) {
  436. }
  437. })
  438. },
  439. methods: {
  440. loadData() {
  441. let _self = this
  442. var data = _self.id
  443. _self.swiperDatas = []
  444. goodsxiang(data).then((res) => {
  445. if (res.success) {
  446. _self.swiperDatas = res.data.imgs.split(',')
  447. _self.goods = res.data
  448. // 服务标签
  449. if (typeof _self.goods.goodsServiceTags === 'string') {
  450. _self.goods.goodsServiceTags = _self.goods.goodsServiceTags.split(',').filter((x) => x)
  451. }
  452. let __tagDatas = []
  453. _self.goods.goodsServiceTags.forEach((data, index) => {
  454. __tagDatas.push({
  455. data: data,
  456. selected: index == 0
  457. })
  458. })
  459. _self.tagDatas = __tagDatas
  460. //商品属性数组
  461. _self.skuAttrDatas = _self.goods.skuGroups
  462. _self.skuAttrDatas.forEach((el, index) => {
  463. el.attrValues.forEach((item, ins) => {
  464. _self.skuAttrDatas[index].attrValues[0].type = true
  465. })
  466. })
  467. console.log(_self.skuAttrDatas, 'po')
  468. // 商品SKU
  469. _self.skuDatas = _self.goods.skus
  470. // for(var i=0;i<_self.skuDatas.length;i++){
  471. // _self.skuDatas[i].spec=_self.skuDatas[i].saleAttrs[0].attrValue
  472. // _self.skuDatas[i].spec2=_self.skuDatas[i].saleAttrs[1].attrValue
  473. // }
  474. console.log(_self.skuDatas, 'sku')
  475. _self.cartPrice = _self.skuDatas[0].price
  476. _self.cartImg = _self.skuDatas[0].skuImg
  477. _self.cartSale = _self.skuDatas[0].stockNum
  478. _self.skuId = _self.skuDatas[0].skuId
  479. // let __goods_skus = _self.goods.skus;
  480. // if (__goods_skus.length > 0) {
  481. // let __skuDatas = [];
  482. // __goods_skus.forEach((sku, index) => {
  483. // // { id: 1, name: '45寸(大规格)', price: 788, market_price: 999, num: 0, selected: !0 },
  484. // __skuDatas.push({
  485. // id: sku.skuId,
  486. // sku: sku.saleAttrs,
  487. // name: sku.skuName,
  488. // price: sku.price,
  489. // market_price: sku.marketPrice || _self.goods.marketPrice,
  490. // num: sku.stockNum,
  491. // selected: index == 0,
  492. // img:sku.skuImg,
  493. // sale:sku.stockNum
  494. // });
  495. // });
  496. // _self.skuDatas = __skuDatas;
  497. // _self.cartImg=_self.skuDatas[0].img
  498. // _self.cartPrice=_self.skuDatas[0].price
  499. // _self.cartSale=_self.skuDatas[0].sale
  500. // _self.skuId=_self.skuDatas[0].id
  501. // }
  502. // // SKU
  503. // if (this.skuDatas.length > 0) {
  504. // this.sku = this.skuDatas[0];
  505. // }
  506. }
  507. })
  508. //商品评价
  509. var data = '?goodsId=' + _self.id
  510. pingjia(data).then((res) => {
  511. console.log('评价', res)
  512. if (res.success) {
  513. // 商品评价
  514. _self.evaluateDatas = res.data.list
  515. if (res.data.evaluate_cnt) _self.evaluateTitle = `评价(${res.data.evaluate_cnt})`
  516. // if (typeof res.data.goods.imgs === 'string') {
  517. // _self.swiperDatas = res.data.goods.imgs.split(',').filter(x => x);
  518. // } else {
  519. // _self.swiperDatas = res.data.goods.imgs;
  520. // }
  521. }
  522. })
  523. // await this.$func.usemall
  524. // .call('goods/detail', {
  525. // goods_id: this.id,
  526. // share_mid: this.mid
  527. // })
  528. // .then(res => {
  529. // if (res.code === 200) {
  530. // // 商品评价
  531. // this.evaluateDatas = res.datas.evaluate;
  532. // if (res.datas.evaluate_cnt) this.evaluateTitle = `评价(${res.datas.evaluate_cnt})`;
  533. // if (typeof res.datas.goods.imgs === 'string') {
  534. // this.swiperDatas = res.datas.goods.imgs.split(',').filter(x => x);
  535. // } else {
  536. // this.swiperDatas = res.datas.goods.imgs;
  537. // }
  538. // this.goods = res.datas.goods;
  539. // // 商品详情
  540. // let __goods_detail = res.datas.goods_detail;
  541. // // #ifndef MP-ALIPAY
  542. // this.html_nodes = __goods_detail.desc_mobile;
  543. // // #endif
  544. // // #ifdef MP-ALIPAY
  545. // this.html_nodes = [];
  546. // aliParse(__goods_detail.desc_mobile.replace(/"><*/gi, '"/><'), (err, nodes) => {
  547. // if (!err) {
  548. // this.html_nodes = nodes;
  549. // }
  550. // });
  551. // // #endif
  552. // // 商品SKU
  553. // let __goods_skus = res.datas.goods_skus;
  554. // if (__goods_skus.length > 0) {
  555. // let __skuDatas = [];
  556. // __goods_skus.forEach((sku, index) => {
  557. // // { id: 1, name: '45寸(大规格)', price: 788, market_price: 999, num: 0, selected: !0 },
  558. // __skuDatas.push({
  559. // id: sku._id,
  560. // sku: sku.goods_sku,
  561. // name: sku.spec,
  562. // price: sku.price,
  563. // market_price: sku.market_price || this.goods.market_price,
  564. // num: sku.stock_num,
  565. // selected: index == 0
  566. // });
  567. // });
  568. // this.skuDatas = __skuDatas;
  569. // }
  570. // // SKU
  571. // if (this.skuDatas.length > 0) {
  572. // this.sku = this.skuDatas[0];
  573. // }
  574. // // 服务标签
  575. // if (typeof this.goods.tags === 'string') {
  576. // this.goods.tags = this.goods.tags.split(',').filter(x => x);
  577. // }
  578. // let __tagDatas = [];
  579. // this.goods.tags.forEach((data, index) => {
  580. // __tagDatas.push({
  581. // name: data,
  582. // selected: index == 0
  583. // });
  584. // });
  585. // this.tagDatas = __tagDatas;
  586. // // 收藏状态
  587. // this.favorite = this.goods.collected === 1;
  588. // return;
  589. // }
  590. // this.$api.msg(res.msg);
  591. // });
  592. },
  593. // 处理 query q 数据
  594. resolveQueryq(query) {
  595. const arr = query.split('/').slice(-1)[0].split('_')
  596. if (arr.length == 2) this.mid = arr[1]
  597. this.id = arr[0]
  598. },
  599. // 图片预览
  600. preview(imgs, cur) {
  601. if (!imgs) return
  602. uni.previewImage({
  603. urls: imgs,
  604. current: cur,
  605. longPressActions: {
  606. itemList: ['发送给朋友', '保存图片', '收藏'],
  607. success: function (data) {
  608. console.log(res)
  609. },
  610. fail: function (err) {
  611. console.log(err)
  612. }
  613. }
  614. })
  615. },
  616. // 打开分享
  617. shareOpen() {
  618. // if (!this.loginCheck()) return;
  619. this.shareShow = true
  620. },
  621. // 关闭分享
  622. shareClose() {
  623. // if (!this.loginCheck()) return;
  624. this.shareShow = false
  625. },
  626. // 创建海报
  627. createPoster() {
  628. if (this.posterUrl) {
  629. this.posterShow = true
  630. return
  631. }
  632. uni.showLoading({
  633. title: '生成海报中'
  634. })
  635. // #ifdef MP
  636. // 此处的二维码内容,需自己在小程序端配置普通二维码规则
  637. this.posterQRcode = `https://usemall.use-cloud.com/wxmp-product/${this.goods.id}_${this.member._id}`
  638. // #endif
  639. // #ifdef H5
  640. // 如果为 h5,二维码内容需配置为线上版本产品详情路径
  641. this.posterQRcode = `https://usemall-h5.use-cloud.com/#/pages/goods/goods?id=${this.goods.id}&mid=${this.member._id}`
  642. // #endif
  643. },
  644. // 海报二维码生成成功
  645. posterQRcodeResult(res) {
  646. // 获取产品海报数据
  647. this.posterData = uposter.getGoodsData(this.member, this.goods, res)
  648. // console.log('this.posterData', this.posterData);
  649. this.posterShow = true
  650. },
  651. // 海报生成完成
  652. posterSuccess(res) {
  653. this.posterUrl = res
  654. uni.hideLoading()
  655. },
  656. // 保存海报
  657. posterSave() {
  658. if (this.posterUrl) {
  659. uni.showLoading({
  660. title: '保存中'
  661. })
  662. uni.saveImageToPhotosAlbum({
  663. filePath: this.posterUrl,
  664. success: function () {
  665. uni.hideLoading()
  666. uni.showToast({
  667. title: '海报保存成功',
  668. icon: 'success',
  669. duration: 2000
  670. })
  671. }
  672. })
  673. }
  674. },
  675. // 选择商品SKU
  676. selectSKU(i, is) {
  677. this.skuAttrDatas[i].attrValues.forEach((item, ins) => {
  678. this.$set(this.skuAttrDatas[i].attrValues[ins], 'type', false)
  679. })
  680. this.$set(this.skuAttrDatas[i].attrValues[is], 'type', true)
  681. let list = []
  682. this.skuAttrDatas.forEach((item, ins) => {
  683. item.attrValues.forEach((el, index) => {
  684. if (el.type == true) {
  685. list.push({ attrValue: el.attrValue })
  686. }
  687. })
  688. })
  689. var list2 = []
  690. this.skuDatas.forEach((item, index2) => {
  691. list2 = []
  692. item.saleAttrs.forEach((el, index) => {
  693. list2.push({ attrValue: el.attrValue })
  694. })
  695. console.log(JSON.stringify(list), 'p')
  696. console.log(JSON.stringify(list2), 'p2')
  697. console.log(JSON.stringify(list) == JSON.stringify(list2))
  698. if (JSON.stringify(list) == JSON.stringify(list2)) {
  699. this.cartPrice = item.price
  700. this.cartImg = item.skuImg
  701. this.cartSale = item.stockNum
  702. this.skuId = item.skuId
  703. }
  704. })
  705. },
  706. // 评论
  707. toevaluate() {
  708. uni.navigateTo({
  709. url: `/pages/goods/goods-evaluate?id=${this.id}`
  710. })
  711. },
  712. // 首页
  713. tohome() {
  714. this.$api.tohome()
  715. },
  716. // 收藏
  717. tofavorite() {
  718. // if (!this.loginCheck()) return;
  719. this.favorite = !this.favorite
  720. let _data = {
  721. goods_id: this.id,
  722. state: !this.favorite ? '已取消' : '已收藏'
  723. }
  724. var header = {
  725. 'Mall-Token': uni.getStorageSync('tokenId')
  726. }
  727. var data = this.id
  728. collecttian(data, header).then((res) => {
  729. if (res.success) {
  730. !this.favorite ? this.$api.msg('取消成功') : this.$api.msg('收藏成功')
  731. return
  732. }
  733. this.$api.msg(res.msg)
  734. })
  735. },
  736. // 加入购物车
  737. tocart(params) {
  738. var _self = this
  739. console.log(params)
  740. if (params.enableSku == 1) {
  741. _self.$refs.addPopup.open('bottom')
  742. } else {
  743. var data = '?num=1&' + 'goodId=' + params.id
  744. cartadd(data).then((res) => {
  745. if (res.success) {
  746. _self.$api.msg('加购成功')
  747. return
  748. }
  749. _self.$api.msg(res.msg)
  750. })
  751. }
  752. },
  753. //yousku加购
  754. tocartSKU(params) {
  755. var _self = this
  756. var data = '?num=' + _self.cartNum + '&' + 'goodId=' + params.id + '&skuId=' + this.skuId
  757. cartadd(data).then((res) => {
  758. if (res.success) {
  759. _self.$api.msg('加购成功')
  760. return
  761. }
  762. _self.$api.msg(res.msg)
  763. })
  764. },
  765. // 立即购买
  766. tobuy(item) {
  767. let _this = this
  768. // if (!this.loginCheck()) return;
  769. if (item.enableSku == 1) {
  770. _this.$refs.addPopup.open('bottom')
  771. } else {
  772. uni.navigateTo({
  773. url: `/packageShang/pages/order/create?goods_id=${_this.id}&type=1&num=1`
  774. })
  775. }
  776. },
  777. //yousku购买
  778. tobuySku(item) {
  779. uni.navigateTo({
  780. url: `/packageShang/pages/order/create?goods_id=${this.id}&skuId=${this.skuId}&type=1&num=${this.cartNum}`
  781. })
  782. },
  783. // 点击弹窗关闭图标回调
  784. handleClosePop() {
  785. this.$refs.addPopup.close()
  786. },
  787. changeValue(value) {
  788. console.log('返回数值:', value)
  789. if (value > this.cartSale) {
  790. this.cartNum = this.cartSale
  791. } else {
  792. this.cartNum = value
  793. }
  794. }
  795. }
  796. }
  797. </script>
  798. <style lang="scss">
  799. @import url('/packageShang/components/iconfont/iconfont.css');
  800. @import url('/packageShang/common/common.scss');
  801. page {
  802. background: $page-color-base;
  803. padding-bottom: 120rpx;
  804. }
  805. contact-button {
  806. display: flex;
  807. justify-content: center;
  808. align-items: center;
  809. width: 50px;
  810. height: 50px;
  811. }
  812. .fixed-top {
  813. bottom: 230rpx;
  814. }
  815. /* 01. 轮播区 */
  816. .swiper-area {
  817. height: 720rpx;
  818. top: 0;
  819. z-index: -1;
  820. }
  821. /* #ifndef MP */
  822. .swiper-area {
  823. margin-top: calc(44px + env(safe-area-inset-top));
  824. margin-top: 44px;
  825. }
  826. /* #endif */
  827. /* #ifdef APP-PLUS */
  828. .swiper-area {
  829. margin-top: 0;
  830. }
  831. /* #endif */
  832. /* 02. 商品数据区 */
  833. .goods-area {
  834. margin-top: 720rpx;
  835. .price-box {
  836. display: flex;
  837. align-items: baseline;
  838. }
  839. .title1 {
  840. height: 46rpx;
  841. line-height: 46rpx;
  842. }
  843. .title {
  844. color: $font-color-dark;
  845. height: 46rpx;
  846. line-height: 46rpx;
  847. }
  848. }
  849. .share-area {
  850. .vertical-line {
  851. right: 50%;
  852. height: 40%;
  853. }
  854. }
  855. /* 03. 规格区 */
  856. .tag .active {
  857. background: $base-color;
  858. color: #fff !important;
  859. }
  860. /* 04. 服务区 */
  861. .icon-detail {
  862. right: 30rpx;
  863. top: 24rpx;
  864. }
  865. /* 05. 评价 */
  866. .evaluate-area {
  867. .portrait {
  868. flex-shrink: 0;
  869. width: 80rpx;
  870. height: 80rpx;
  871. }
  872. .right-area {
  873. image {
  874. margin-right: 10rpx;
  875. margin-bottom: 10rpx;
  876. height: 200rpx;
  877. width: 30%;
  878. }
  879. }
  880. }
  881. /* 06. 详情区 */
  882. .detail-area {
  883. .d-header {
  884. font-size: $font-base + 2upx;
  885. position: relative;
  886. text {
  887. padding: 0 20rpx;
  888. background: #fff;
  889. position: relative;
  890. z-index: 1;
  891. }
  892. &:after {
  893. position: absolute;
  894. left: 50%;
  895. top: 50%;
  896. transform: translateX(-50%);
  897. width: 300rpx;
  898. height: 0;
  899. content: '';
  900. border-bottom: 1px solid #ccc;
  901. }
  902. }
  903. /* 产品详情 */
  904. .pro-detail {
  905. width: 100%;
  906. overflow: hidden;
  907. -webkit-touch-callout: none;
  908. img {
  909. width: 100%;
  910. max-width: 100%;
  911. overflow: hidden;
  912. }
  913. }
  914. }
  915. /* 07. 操作区 */
  916. .oper-area {
  917. left: 0;
  918. bottom: 0;
  919. background: rgba(255, 255, 255, 0.95);
  920. box-shadow: 0 0 20rpx 0 #f0f0f0;
  921. height: 100rpx;
  922. z-index: 95;
  923. .btn-area {
  924. font-size: $font-sm;
  925. color: $font-color-base;
  926. width: 96rpx;
  927. .iconfont {
  928. font-size: 40rpx;
  929. line-height: 48rpx;
  930. }
  931. }
  932. }
  933. /* 优惠券区 */
  934. .coupon-area {
  935. max-height: 60vh;
  936. min-height: 30vh;
  937. .coupon-item {
  938. margin-bottom: 20rpx;
  939. &:last-child {
  940. margin-bottom: 0;
  941. }
  942. .content {
  943. &:after {
  944. position: absolute;
  945. left: 0;
  946. bottom: 0;
  947. content: '';
  948. width: 100%;
  949. height: 0;
  950. border-bottom: 1px dashed #f3f3f3;
  951. transform: scaleY(50%);
  952. }
  953. }
  954. .circle {
  955. position: absolute;
  956. bottom: -10rpx;
  957. z-index: 10;
  958. width: 20rpx;
  959. height: 20rpx;
  960. background: #f5f5f5;
  961. border-radius: 50%;
  962. &.r {
  963. right: -6rpx;
  964. }
  965. &.l {
  966. left: -6rpx;
  967. }
  968. }
  969. }
  970. }
  971. // 加入购物车弹窗样式
  972. .body_pop {
  973. margin-bottom: -20px;
  974. position: relative;
  975. padding: 0 20rpx;
  976. height: 100%;
  977. border-radius: 22rpx 22rpx 0 0;
  978. background-color: #fff;
  979. overflow-y: auto;
  980. .pop_icon {
  981. position: absolute;
  982. top: 20rpx;
  983. right: 30rpx;
  984. width: 58rpx;
  985. height: 58rpx;
  986. }
  987. .pop_header {
  988. display: flex;
  989. margin-top: 30rpx;
  990. .header_img {
  991. width: 200rpx;
  992. height: 200rpx;
  993. }
  994. .header_info {
  995. flex: 1;
  996. padding-left: 20rpx;
  997. display: flex;
  998. flex-direction: column;
  999. justify-content: space-around;
  1000. width: 100%;
  1001. height: 200rpx;
  1002. color: #ea6d67;
  1003. font-size: 30rpx;
  1004. .info_price {
  1005. flex: 1;
  1006. display: flex;
  1007. align-items: center;
  1008. text {
  1009. font-size: 60rpx;
  1010. }
  1011. }
  1012. .info_tags {
  1013. flex: 1;
  1014. display: flex;
  1015. align-items: center;
  1016. .tag {
  1017. padding: 5rpx;
  1018. margin-right: 10rpx;
  1019. border-radius: 10rpx;
  1020. border: 1rpx solid #ea6d67;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. .pop_title {
  1026. margin: 10rpx 0;
  1027. font-size: 40rpx;
  1028. text {
  1029. margin-left: 15rpx;
  1030. color: #ccc;
  1031. }
  1032. }
  1033. .pop_tags {
  1034. display: flex;
  1035. .active_sku {
  1036. padding: 20rpx 30rpx;
  1037. margin-right: 20rpx;
  1038. font-size: 30rpx;
  1039. border-radius: 40rpx;
  1040. background-color: #f6f6f6;
  1041. // border: 1rpx solid #999;
  1042. // padding: 3rpx 10rpx 3rpx 10rpx;
  1043. // font-size: 24rpx;
  1044. // margin-right: 10rpx;
  1045. // border-radius: 5rpx;
  1046. }
  1047. .active_sku_color {
  1048. padding: 20rpx 30rpx;
  1049. margin-right: 20rpx;
  1050. font-size: 30rpx;
  1051. border-radius: 40rpx;
  1052. background-color: #ffbc49;
  1053. // border: 1rpx solid #990002;
  1054. // padding: 3rpx 10rpx 3rpx 10rpx;
  1055. // font-size: 24rpx;
  1056. // margin-right: 10rpx;
  1057. // border-radius: 5rpx;
  1058. // color: #990002;
  1059. }
  1060. // .tag {
  1061. // padding: 20rpx 30rpx;
  1062. // margin-right: 20rpx;
  1063. // font-size: 30rpx;
  1064. // border-radius: 40rpx;
  1065. // background-color: #f6f6f6;
  1066. // }
  1067. }
  1068. .pop_num {
  1069. margin-top: 15rpx;
  1070. }
  1071. }
  1072. </style>