goods.vue 31 KB

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