goods.vue 31 KB

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