goods.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  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.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 class="border-radius-xs" v-if="((item.reviewImgs).indexOf(',')) != -1"
  184. mode="aspectFill" :lazy-load="true" :src="((item.reviewImgs).substring(0, ((item.reviewImgs).indexOf(','))))"></image>
  185. <image class="border-radius-xs" v-else
  186. mode="aspectFill" :lazy-load="true" :src="item.reviewImgs"></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. margin-bottom: -20px;
  968. position: relative;
  969. padding: 0 20rpx;
  970. height: 100%;
  971. border-radius: 22rpx 22rpx 0 0;
  972. background-color: #fff;
  973. overflow-y: auto;
  974. .pop_icon {
  975. position: absolute;
  976. top: 20rpx;
  977. right: 30rpx;
  978. width: 58rpx;
  979. height: 58rpx;
  980. }
  981. .pop_header {
  982. display: flex;
  983. margin-top: 30rpx;
  984. .header_img {
  985. width: 200rpx;
  986. height: 200rpx;
  987. }
  988. .header_info {
  989. flex: 1;
  990. padding-left: 20rpx;
  991. display: flex;
  992. flex-direction: column;
  993. justify-content: space-around;
  994. width: 100%;
  995. height: 200rpx;
  996. color: #ea6d67;
  997. font-size: 30rpx;
  998. .info_price {
  999. flex: 1;
  1000. display: flex;
  1001. align-items: center;
  1002. text {
  1003. font-size: 60rpx;
  1004. }
  1005. }
  1006. .info_tags {
  1007. flex: 1;
  1008. display: flex;
  1009. align-items: center;
  1010. .tag {
  1011. padding: 5rpx;
  1012. margin-right: 10rpx;
  1013. border-radius: 10rpx;
  1014. border: 1rpx solid #ea6d67;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. .pop_title {
  1020. margin: 10rpx 0;
  1021. font-size: 40rpx;
  1022. text {
  1023. margin-left: 15rpx;
  1024. color: #ccc;
  1025. }
  1026. }
  1027. .pop_tags {
  1028. display: flex;
  1029. .active_sku{
  1030. padding: 20rpx 30rpx;
  1031. margin-right: 20rpx;
  1032. font-size: 30rpx;
  1033. border-radius: 40rpx;
  1034. background-color: #f6f6f6;
  1035. // border: 1rpx solid #999;
  1036. // padding: 3rpx 10rpx 3rpx 10rpx;
  1037. // font-size: 24rpx;
  1038. // margin-right: 10rpx;
  1039. // border-radius: 5rpx;
  1040. }
  1041. .active_sku_color{
  1042. padding: 20rpx 30rpx;
  1043. margin-right: 20rpx;
  1044. font-size: 30rpx;
  1045. border-radius: 40rpx;
  1046. background-color: #ffbc49;
  1047. // border: 1rpx solid #990002;
  1048. // padding: 3rpx 10rpx 3rpx 10rpx;
  1049. // font-size: 24rpx;
  1050. // margin-right: 10rpx;
  1051. // border-radius: 5rpx;
  1052. // color: #990002;
  1053. }
  1054. // .tag {
  1055. // padding: 20rpx 30rpx;
  1056. // margin-right: 20rpx;
  1057. // font-size: 30rpx;
  1058. // border-radius: 40rpx;
  1059. // background-color: #f6f6f6;
  1060. // }
  1061. }
  1062. .pop_num {
  1063. margin-top: 15rpx;
  1064. }
  1065. }
  1066. </style>