goods.vue 31 KB

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