goodsDetail.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. <template>
  2. <view class="goods-detail-wrapper">
  3. <!-- <view @click="toHome" class="to-home-img">-->
  4. <!-- <u-icon size="24rpx" name="arrow-left" bold="true" color="#666666"></u-icon>-->
  5. <!-- </view>-->
  6. <u-swiper :list="detailData.slider||[]" keyName="url"
  7. :indicatorStyle="{right: '20rpx', bottom: '20rpx', width: '100px',marginLeft: 'auto'}" indicator
  8. indicatorMode="number" height="100vw" imgMode="aspectFit">
  9. </u-swiper>
  10. <view class="content-box">
  11. <!-- 详情 -->
  12. <view class="common-card">
  13. <view class="display-flex-between ">
  14. <text class="fw700 title">
  15. {{ detailData.goods_name ||""}}
  16. </text>
  17. <view class="display-flex-center">
  18. <view @click="collectHandler" style="display: flex;flex-direction: column; align-items: center;">
  19. <u-icon name="heart" size="50rpx"
  20. :color="goodsCollected ? '#F39800' : '#717171’'"></u-icon>
  21. <text class="fenxiang">
  22. 收藏
  23. </text>
  24. </view>
  25. <view @click="generatePoster"
  26. style="margin-left: 30rpx;flex:1;display: flex;flex-direction: column; align-items: center;">
  27. <image style="width: 36rpx;height: 36rpx;margin: 8rpx 0" src="/static/fenxiang.png" mode="aspectFill">
  28. </image>
  29. <text class="fenxiang">
  30. 分享
  31. </text>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="fs12 sub-title">{{ detailData.remark||"" }}</view>
  36. <view class="display-flex-between">
  37. <view>
  38. <text class="fs12 fw400 color-556">
  39. </text>
  40. <text
  41. class="fs20 color-556 fw700">
  42. {{ goodsType == 'msGoods' ? detailData.price_seckill||"" : detailData.price_selling||"" }}
  43. </text>
  44. </view>
  45. </view>
  46. <view class="display-flex-between">
  47. <view>
  48. <text class="text-through fs12 color-666">¥{{ detailData.price_market ||""}}</text>
  49. </view>
  50. <view class="fs12 color-666">销量:{{ (detailData.stock_sale||0) + (detailData.stock_virtual||0) }}件</view>
  51. </view>
  52. <!-- <view class="display-flex-center">-->
  53. <!-- <view class="tag-red mb5 mr5" v-if="detailData.limit_money">满额赠品(满{{detailData.limit_money}}元赠)-->
  54. <!-- </view>-->
  55. <!-- <view v-for="(item, index) in freeData" :key="index" class="tag-red mb5 mr5">{{item.sNum}}件包邮</view>-->
  56. <!-- </view>-->
  57. </view>
  58. <!-- 运费 -->
  59. <view v-if="detailData.truck_type == 1" class="common-card ">
  60. <view class="display-flex-between display-flex-center">
  61. <view>
  62. <text class="mr10 color-777 fs14">运费</text>
  63. <text class="color-333 fs14">¥{{ truckData.firstAmt || 0 }}</text>
  64. </view>
  65. <view class="color-777 fs14">已售 {{ detailData.stock_sales + detailData.stock_virtual }} | 剩余 {{ (detailData.stock_total - detailData.stock_sales)}}</view>
  66. </view>
  67. <u-divider></u-divider>
  68. <view @click="suitHandler" class=" display-flex-between display-flex-center">
  69. <view>
  70. <text class="mr10 color-777 fs14 ">已选</text>
  71. <text class="color-333 fs14">{{ selectSuitDisplay }}</text>
  72. </view>
  73. <u1-icon name="arrow-right" color="#3A3A3A"></u1-icon>
  74. </view>
  75. <!-- <view class="color-7a fs13">已售1 | 剩余150</view> -->
  76. <!-- <u1-icon name="arrow-right" color="#3A3A3A"></u1-icon> -->
  77. </view>
  78. <!-- 参数 -->
  79. <view class="common-card" style="padding: 0;">
  80. <u-sticky zIndex="90">
  81. <view style="background-color: #fff;">
  82. <u-tabs lineColor="#C29556 " line-width="36" lineHeight="3" :inactiveStyle="{
  83. fontWeight: '400',
  84. fontSize: '24rpx',
  85. color: '#333333',
  86. lineHeight: '40rpx'
  87. }" :activeStyle="{
  88. fontWeight: '400',
  89. fontSize: '28rpx',
  90. color: '#333333',
  91. lineHeight: '40rpx'
  92. }" :list="detailList" @click="detailClick"></u-tabs>
  93. </view>
  94. </u-sticky>
  95. <view style="padding: 40rpx 40rpx;">
  96. <view class="mb5 display-flex-center fw600" id="detail_0">
  97. <image src="/static/good_detail1.png" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"
  98. mode=""></image>
  99. <text>商品详情</text>
  100. </view>
  101. <u-parse :content="detailData.content"></u-parse>
  102. <view id="detail_1" class="mb5 mt10 display-flex-center fw600">
  103. <image src="/static/good_detail2.png" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"
  104. mode=""></image>
  105. <text>商品规格</text>
  106. </view>
  107. <u-parse :content="detailData.info"></u-parse>
  108. <view class="mb5 mt10 display-flex-center fw600" id="detail_2">
  109. <image src="/static/good_detail3.png" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"
  110. mode=""></image>
  111. <text>售后保障</text>
  112. </view>
  113. <u-parse :content="sell_serv"></u-parse>
  114. </view>
  115. </view>
  116. </view>
  117. <view class="bottom-navigation">
  118. <view class="bottom-navigation-div">
  119. <view style="width: 40rpx;margin-right: 30rpx" @click="toJump( 1)" >
  120. <van-image
  121. height="36rpx"
  122. src="/static/hd-icon-a.png"
  123. width="36rpx"
  124. style="display: flex;align-items: center; justify-content: center;"
  125. />
  126. <span>
  127. 首页
  128. </span>
  129. </view>
  130. <view style="width: 40rpx;position:relative;margin-right: 30rpx" open-type="contact">
  131. <van-image
  132. height="36rpx"
  133. src="/static/hd-icon-c.png"
  134. width="36rpx"
  135. style="display: flex;align-items: center; justify-content: center;"
  136. />
  137. <span>
  138. 客服
  139. </span>
  140. <button style="position: absolute;width: 100%;height: 100%;z-index: 999;opacity: 0;top:0;"
  141. open-type="contact" ></button>
  142. </view>
  143. <view style="width: 60rpx;margin-right: 30rpx;position:relative;" @click="toJump( 3)" >
  144. <van-image
  145. height="36rpx"
  146. src="/static/bottom-menu-cert.png"
  147. width="36rpx"
  148. style="display: flex;align-items: center; justify-content: center;"
  149. />
  150. <u-badge :absolute="true" bgColor="#CA9359" :offset="[-5,-5]" :value="cartNumber">
  151. </u-badge>
  152. <span>
  153. 购物车
  154. </span>
  155. </view>
  156. </view>
  157. <button class="add-cart-button" @click="toAddCert">加入购物车</button>
  158. <button class="submit-order-button" @click="toApply">提交订单</button>
  159. </view>
  160. <u-toast ref="createPosterLoading"></u-toast>
  161. <u-overlay :show="showPosterFlag" :mask-click-able="false">
  162. <view class="poster-wrap">
  163. <image :src="posterImgSrc" class="poster-img" mode="widthFix"></image>
  164. </view>
  165. <view class="poster-box">
  166. <view class="poster-btn">
  167. <view class="poster-btn-left">
  168. <image style="height: 26px;width 26px;" src="@/static/icon-wechat.png" mode="heightFix"/>
  169. <view>分享好友</view>
  170. <u-button open-type="share"
  171. customStyle="position: absolute;top:0;bottom:0;left:0;right:0;opacity: 0;">
  172. </u-button>
  173. </view>
  174. <view class="poster-btn-right" @click="downloadPoster">
  175. <u-icon name="download" color="#815BFF" size="36"></u-icon>
  176. <view>保存海报</view>
  177. </view>
  178. </view>
  179. <view class="cancel-btn" @click="closePainter">取消</view>
  180. </view>
  181. </u-overlay>
  182. <!-- 海报生成器 -->
  183. <l-painter ref="painter" isCanvasToTempFilePath @success="painterSuccess"
  184. css="width: 610rpx;box-sizing: border-box; background: #fff;padding: 20rpx;border-radius: 32rpx 32rpx 32rpx 32rpx;"
  185. v-if="detailData.goods_name&&showPoster" hidden>
  186. <!-- <l-painter-image :src="imageUrl" css="display: block; width: 100%; height: 146rpx;" />-->
  187. <l-painter-view css="height: 570rpx;width: 570rpx;">
  188. <l-painter-image :src="detailData.cover" css="width: 100%; height: 100%;"/>
  189. </l-painter-view>
  190. <l-painter-view
  191. css="display: flex; align-items: center; justify-content: space-between; padding: 40rpx 10rpx 0;">
  192. <l-painter-text :text="detailData.goods_name"
  193. css="display: block; width: 368rpx;height: 72rpx;font-weight: 400;font-size: 28rpx;color: #444444;line-height: 36rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;box-sizing: border-box;"/>
  194. <l-painter-view css="width: 1rpx;height: 60rpx; border-left: 1rpx solid #888888;">
  195. </l-painter-view>
  196. <l-painter-view css="display: flex; align-items: flex-end">
  197. <l-painter-text css="font-size: 24rpx; font-weight: 500;color: #FF424F;line-height: 38rpx"
  198. :text="`¥`"></l-painter-text>
  199. <l-painter-text css="font-size: 32rpx; font-weight: 500;color: #FF424F;line-height: 38rpx;"
  200. :text="`${detailData.price_selling}`"></l-painter-text>
  201. </l-painter-view>
  202. </l-painter-view>
  203. <l-painter-view
  204. css="display: flex; align-items: center; justify-content: space-between; padding: 36rpx 10rpx 10rpx;">
  205. <l-painter-view css="width: 228rpx;height: 104rpx;">
  206. <l-painter-view>
  207. <l-painter-text
  208. css="display: block; font-size: 24rpx; font-weight: 400; color: #888888; line-height: 52rpx;"
  209. text="① 保存图片到相册"></l-painter-text>
  210. </l-painter-view>
  211. <l-painter-view>
  212. <l-painter-text
  213. css="display: block; font-size: 24rpx; font-weight: 400; color: #888888; line-height: 52rpx;"
  214. text="② 打开微信扫码可见"></l-painter-text>
  215. </l-painter-view>
  216. </l-painter-view>
  217. <l-painter-image :src="erCodeImg" css="width: 176rpx; height: 176rpx;"/>
  218. </l-painter-view>
  219. </l-painter>
  220. <!-- <l-painter ref="painter" isCanvasToTempFilePath @success="painterSuccess"-->
  221. <!-- css="width: 750rpx; background: #fff;padding: 20rpx" v-if="detailData.goods_name&&showPoster" hidden>-->
  222. <!-- <l-painter-image :src="imageUrl" css="display: block; width: 100%; height: 146rpx;"/>-->
  223. <!-- <l-painter-view css="display: block; padding: 43rpx 0 22rpx 0;">-->
  224. <!-- <l-painter-text :text="detailData.goods_name"-->
  225. <!-- css=" color: #1D161F; font-size: 36rpx; fontWeight: 500; line-height: 42rpx;"/>-->
  226. <!-- </l-painter-view>-->
  227. <!-- <l-painter-view css="position: relative; height: 580rpx;">-->
  228. <!-- <l-painter-image :src="detailData.cover" css="object-fit: contain; width: 100%; height: 100%;"/>-->
  229. <!-- </l-painter-view>-->
  230. <!-- <l-painter-view-->
  231. <!-- css="display: flex; align-items: center; justify-content: space-between; padding-top: 38rpx;">-->
  232. <!-- <l-painter-view css="flex: 1;">-->
  233. <!-- <l-painter-view>-->
  234. <!-- <l-painter-text css="font-size: 32rpx; font-weight: 500; color: #858585; line-height: 38rpx;"-->
  235. <!-- text="售价:"></l-painter-text>-->
  236. <!-- <l-painter-text css="font-size: 32rpx; font-weight: 500; color: #7B52C8; line-height: 38rpx;"-->
  237. <!-- :text="`¥${detailData.price_selling}`"></l-painter-text>-->
  238. <!-- </l-painter-view>-->
  239. <!-- <l-painter-view css="margin-top: 11rpx;">-->
  240. <!-- <l-painter-text-->
  241. <!-- css="display: block; font-size: 28rpx; font-weight: 500; color: #858585; line-height: 33rpx;"-->
  242. <!-- text="长按小程序码参与"></l-painter-text>-->
  243. <!-- </l-painter-view>-->
  244. <!-- </l-painter-view>-->
  245. <!-- <l-painter-image :src="erCodeImg" css="width: 200rpx; height: 200rpx;"/>-->
  246. <!-- </l-painter-view>-->
  247. <!-- </l-painter>-->
  248. <!-- 选套装 -->
  249. <u-popup :show="show" mode="bottom" :safeAreaInsetTop="true" round="10" closeable @close="close" @open="open">
  250. <view class="suit-content">
  251. <view class="display-flex-center mr20 mb30 ">
  252. <u--image :src="detailData.cover" width="176rpx" height="176rpx" ></u--image>
  253. <view class="ml15">
  254. <view v-if="pageOptions.type == 'msGoods'">
  255. <text class="fs12 color-556 fw400">¥</text>
  256. <text class="fs20 color-556 fw700 mr20">{{ (goodSuitPriceData.price || 0) * suitNum }}</text>
  257. </view>
  258. <view v-else>
  259. <text class="fs12 color-556 fw400">¥</text>
  260. <text class="fs20 color-556 fw700 mr20">{{ (goodSuitPriceData.price || 0) * suitNum }}</text>
  261. </view>
  262. <view class="color-777 mt5">
  263. <text>已选择 {{ selectSuitDisplay }}</text>
  264. </view>
  265. </view>
  266. </view>
  267. <!-- 普通商品规格 -->
  268. <template v-if="pageOptions.type == 'common'">
  269. <view v-for="(item, pIndex) in goodsSpecData" :key="pIndex">
  270. <view class="fw700 mb10">{{ item.name }}</view>
  271. <view class="suit-btn-box">
  272. <view class="suit-btn" @click="suitChange(suit, item)" :key="index"
  273. :class="[suit.isChecked ? 'suit-btn-active' : '']" v-for="(suit, index) in item.list">
  274. {{ suit.name }}
  275. </view>
  276. </view>
  277. </view>
  278. </template>
  279. <!-- 秒杀商品规格 -->
  280. <template v-else>
  281. <view class="suit-btn-box">
  282. <view class="suit-btn suit-btn-column" @click="suitChange(suit, item)" :key="index"
  283. :class="[suit.isChecked ? 'suit-btn-active' : '', suit.disabled ? 'suit-btn-disabled' : '']"
  284. v-for="(suit, index) in goodsSpecData">
  285. {{ suit.spec }}
  286. </view>
  287. </view>
  288. </template>
  289. <view class="mb30" >
  290. <view class="fw700 mb20">数量</view>
  291. <u-number-box :min="1" integer v-model="suitNum" :max="(detailData.stock_total - detailData.stock_sales)"></u-number-box>
  292. </view>
  293. <view class="common-btn" @click="submit">提交</view>
  294. </view>
  295. </u-popup>
  296. <!-- <u-keyboard @backspace="backspace" data-ref="uKeyboard" mode="number" :show="showNumber"></u-keyboard>-->
  297. <login-pop v-model="showUserRegister" @updateUserInfo="reUserInfo"></login-pop>
  298. </view>
  299. </template>
  300. <script>
  301. import LoginPop from '@/components/LoginPop.vue'
  302. import {
  303. makeErCode
  304. } from "@/common/api/task.js";
  305. import {
  306. getGoodsDetail,
  307. getGiftGoodsDetail,
  308. getMsGoodsDetail,
  309. getPointsGoodsDetail,
  310. msGoodsCreateOrder,
  311. giftAddCart,
  312. addCollect,
  313. delCollect,
  314. checkCollect
  315. } from '@/common/api/good.js'
  316. export default {
  317. components: {
  318. LoginPop
  319. },
  320. data() {
  321. return {
  322. showNumber:true,
  323. erCodeImg: '',
  324. pageOptions: {},
  325. totalDetailData: {},
  326. selectSuitData: {},
  327. currentSuitIndex: 0,
  328. suitNum: 1,
  329. show: false,
  330. freeData: [],
  331. imageUrl: "",
  332. detailList: [{
  333. name: '商品详情'
  334. }, {
  335. name: '商品规格'
  336. }, {
  337. name: '售后保障'
  338. }],
  339. currentNum: 0,
  340. detailData: {},
  341. goodsSpecData: [],
  342. truckData: {},
  343. showPoster: false,
  344. showPosterFlag:false,
  345. posterImgSrc: "",
  346. selectedSuitPriceData: [],
  347. goodSuitPriceData: {
  348. price: 0
  349. },
  350. goodsType: 'common',
  351. currentOperateType: '', // 1:购物车,2:立即购买
  352. cartNumber: 0,
  353. sell_serv: '',
  354. isUserRegister: false,
  355. showUserRegister: false,
  356. goodsCollected: false,
  357. btn_color: null,
  358. }
  359. },
  360. computed: {
  361. beUsedCode() {
  362. return this.detailData.code
  363. },
  364. selectSuitDisplay() {
  365. console.log(2333, this.selectedSuitPriceData)
  366. if (this.goodsType == 'common') {
  367. let tempData = this.selectedSuitPriceData.map(item => {
  368. return `${item.group_name}:${item.spec_name}`
  369. })
  370. return tempData.join(',')
  371. } else if (this.goodsType == 'gift') {
  372. return this.detailData.goods_spec
  373. } else {
  374. return this.goodSuitPriceData.goods_spec
  375. }
  376. },
  377. currentTypeApi() {
  378. let result = {
  379. detailApi: getGoodsDetail,
  380. params: {
  381. goods_code: this.pageOptions.code
  382. }
  383. }
  384. switch (this.pageOptions.type) {
  385. case 'gift':
  386. result.detailApi = getGiftGoodsDetail
  387. break;
  388. case 'points':
  389. result.detailApi = getPointsGoodsDetail
  390. break;
  391. case 'msGoods':
  392. result = {
  393. detailApi: getMsGoodsDetail,
  394. params: {
  395. id: this.pageOptions.code
  396. }
  397. }
  398. break;
  399. default:
  400. break;
  401. }
  402. return result
  403. }
  404. },
  405. onLoad(options) {
  406. let pagePath = "/subPages/goodsDetail/goodsDetail";
  407. // 如果有 options,拼接查询参数
  408. if (options && Object.keys(options).length > 0) {
  409. const queryString = Object.keys(options)
  410. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options[key])}`)
  411. .join('&');
  412. pagePath += '?' + queryString;
  413. }
  414. uni.setStorageSync('showPage', pagePath);
  415. setTimeout(() => {
  416. uni.removeStorageSync('showPage');
  417. }, 5000);
  418. this.pageOptions = options
  419. this.goodsType = options.type
  420. this.getAfterSalePage()
  421. this.maekErImg(options.code)
  422. const configs = uni.getStorageSync('configs')
  423. if (configs) {
  424. this.btn_color = configs.btn_color
  425. }
  426. this.$nextTick(() => {
  427. this.getDetail()
  428. this.getCartNumber()
  429. })
  430. },
  431. onShow() {
  432. let configs = uni.getStorageSync('configs') || {}
  433. this.imageUrl=configs?.shop_poster_logoimg ||`${this.$C.imageUrl}home_logo.png`
  434. console.log(this.imageUrl,"============================")
  435. this.reUserInfo()
  436. },
  437. onShareAppMessage(res) {
  438. if (res.from === 'button') { // 来自页面内分享按钮
  439. console.log(res.target)
  440. }
  441. let userInfo = uni.getStorageSync('userInfo')
  442. userInfo = userInfo && JSON.parse(userInfo) || {}
  443. if (userInfo.id) {
  444. this.pageOptions.id = userInfo.id
  445. }
  446. return {
  447. title: this.detailData.goods_name,
  448. path: `/subPages/goodsDetail/goodsDetail${this.$stringPageOptions(this.pageOptions)}`
  449. }
  450. },
  451. onShareTimeline() {
  452. let userInfo = uni.getStorageSync('userInfo')
  453. userInfo = userInfo && JSON.parse(userInfo) || {}
  454. const posterImage = this.detailData.video && this.detailData.slider.length > 1 ? this.detailData.slider[1]
  455. .url : this.detailData.slider[0].url
  456. if (userInfo.id) {
  457. this.pageOptions.id = userInfo.id
  458. }
  459. return {
  460. title: this.detailData.goods_name,
  461. path: `/subPages/goodsDetail/goodsDetail${this.$stringPageOptions(this.pageOptions)}`,
  462. imageUrl: posterImage
  463. }
  464. },
  465. watch: {
  466. goodsSpecData: {
  467. handler(nv) {
  468. console.log(9999, nv)
  469. let priceSuit = []
  470. if (this.goodsType == 'common') {
  471. nv.forEach(pItem => {
  472. let tempList = pItem.list.filter(item => item.isChecked)
  473. tempList = tempList.map(item => {
  474. return {
  475. group_name: item.group,
  476. spec_name: item.name
  477. }
  478. })
  479. priceSuit = priceSuit.concat(tempList)
  480. })
  481. this.selectedSuitPriceData = priceSuit
  482. this.getSuitPrice()
  483. } else if (this.goodsType == 'msGoods') {
  484. const checkedData = nv.find(item => item.isChecked)
  485. this.goodSuitPriceData = {
  486. price: checkedData.price_seckill,
  487. goods_spec: checkedData.goods_spec,
  488. sku_id: checkedData.id,
  489. }
  490. }
  491. },
  492. deep: true
  493. }
  494. },
  495. methods: {
  496. checkCollect() {
  497. checkCollect({
  498. code: this.detailData.code
  499. }).then(res => {
  500. this.goodsCollected = !!(res.data && res.data.id)
  501. console.log(this.goodsCollected)
  502. })
  503. },
  504. collectHandler() {
  505. if (!this.isUserRegister) {
  506. this.showUserRegister = true
  507. return
  508. }
  509. if (this.goodsCollected) {
  510. // 取消收藏
  511. delCollect({
  512. code: this.detailData.code
  513. }).then(res => {
  514. this.goodsCollected = false
  515. uni.showToast({
  516. title: '取消收藏'
  517. })
  518. })
  519. } else {
  520. // 收藏
  521. addCollect({
  522. code: this.detailData.code
  523. }).then(res => {
  524. this.goodsCollected = true
  525. uni.showToast({
  526. title: '收藏成功'
  527. })
  528. })
  529. }
  530. },
  531. detailClick(item) {
  532. console.log(item.index)
  533. uni.pageScrollTo({
  534. selector: `#detail_${item.index}`
  535. })
  536. },
  537. reUserInfo() {
  538. const userInfo = uni.getStorageSync("userInfo");
  539. if (
  540. userInfo &&
  541. JSON.parse(userInfo).vip_code == 1 &&
  542. JSON.parse(userInfo).nickname != "" &&
  543. JSON.parse(userInfo).headimg != ""
  544. ) {
  545. this.isUserRegister = true;
  546. } else {
  547. this.isUserRegister = false;
  548. }
  549. },
  550. backspace() {
  551. },
  552. getAfterSalePage() {
  553. this.$api.getData({
  554. id: 4
  555. }).then(res => {
  556. this.sell_serv = res.data.content
  557. })
  558. },
  559. suitHandler() {
  560. this.currentOperateType = ''
  561. if (this.goodsType != 'gift') {
  562. this.show = true
  563. }
  564. },
  565. getCartNumber() {
  566. this.$api.getCartNumber().then(res => {
  567. this.cartNumber = res.data.cart_num
  568. })
  569. },
  570. getSuitPrice() {
  571. this.$api.getPriceBySuit({
  572. goods_code: this.pageOptions.code,
  573. spec: this.selectedSuitPriceData
  574. }).then(res => {
  575. this.goodSuitPriceData = res.data
  576. })
  577. },
  578. toAddCert() {
  579. // 加入购物车
  580. if (!this.isUserRegister) {
  581. this.showUserRegister = true
  582. return
  583. }
  584. if (this.goodsType == 'gift') {
  585. giftAddCart({
  586. code: this.detailData.code
  587. }).then(res => {
  588. uni.showToast({
  589. title: '已加入购物车'
  590. })
  591. this.getCartNumber()
  592. })
  593. } else {
  594. this.currentOperateType = 1
  595. this.show = true
  596. }
  597. },
  598. maekErImg(code) {
  599. let that = this;
  600. const data = {
  601. path: '/subPages/goodsDetail/goodsDetail?code=' + code,
  602. type: 'file'
  603. // ['api-name']: 'wxapp',
  604. // ['api-token']: uni.getStorageSync(`token`)
  605. }
  606. this.$api.getQRCode(data).then(res => {
  607. console.log("base64==", res.data.base64)
  608. this.erCodeImg = res.data.url
  609. })
  610. },
  611. generatePoster(){
  612. uni.showToast({
  613. title: "海报生成中,请稍后。。。",
  614. icon: 'none',
  615. duration: 1500
  616. })
  617. this.posterImgSrc =""
  618. this.showPoster=true
  619. },
  620. painterSuccess(tempFilePath) {
  621. this.showPosterFlag = true
  622. this.posterImgSrc = tempFilePath // 用于预览或保存
  623. },
  624. closePainter() {
  625. this.showPosterFlag = false
  626. this.showPoster = false
  627. this.posterImgSrc = "" // 用于预览或保存
  628. },
  629. downloadPoster() {
  630. // console.log(222, this.posterImgSrc)
  631. // uni.saveImageToPhotosAlbum({
  632. // filePath: this.posterImgSrc,
  633. // complete:() => {
  634. // this.showPoster = false
  635. // }
  636. // })
  637. let _this = this
  638. this.$refs.painter.canvasToTempFilePathSync({
  639. fileType: "jpg",
  640. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  641. pathType: 'url',
  642. quality: 1,
  643. success: (res) => {
  644. console.log(res.tempFilePath);
  645. // 非H5 保存到相册
  646. // H5 提示用户长按图另存
  647. uni.saveImageToPhotosAlbum({
  648. filePath: res.tempFilePath,
  649. success: function () {
  650. uni.showToast({
  651. title: '保存成功'
  652. })
  653. _this.closePainter()
  654. }
  655. });
  656. },
  657. })
  658. },
  659. handlePoster(showPoster) {
  660. if (showPoster) {
  661. this.$refs.createPosterLoading.show({
  662. type: 'loading',
  663. message: "海报生成中...",
  664. duration: 1000,
  665. complete: () => {
  666. this.showPoster = showPoster;
  667. }
  668. })
  669. return
  670. }
  671. this.showPoster = showPoster;
  672. // uni.showLoading({
  673. // title: '海报生成中...',
  674. // })
  675. // setTimeout(function () {
  676. // uni.hideLoading();
  677. // this.showPoster = true;
  678. // }, 1000);
  679. },
  680. suitChange(item, pItem) {
  681. if (item.disabled) return
  682. if (this.goodsType == 'common') {
  683. pItem.list.forEach(spec => [
  684. spec.isChecked = false
  685. ])
  686. } else {
  687. this.goodsSpecData.forEach(spec => {
  688. spec.isChecked = false
  689. })
  690. }
  691. item.isChecked = true
  692. // this.selectSuitData = item
  693. // this.currentSuitIndex = index
  694. },
  695. close() {
  696. this.show = false
  697. },
  698. open() {
  699. },
  700. getDetail() {
  701. this.currentTypeApi.detailApi(this.currentTypeApi.params).then(res => {
  702. const {
  703. goods = {}, items = [], truck = {}
  704. } = res.data
  705. this.totalDetailData = res.data
  706. // this.sell_serv = res.data.sell_serv
  707. this.detailData = goods
  708. console.log(res.data.free)
  709. this.freeData = res.data.free || []
  710. this.truckData = truck.content && truck.content.length ? truck.content[0].rule : {}
  711. this.selectSuitData = items || []
  712. let data_specs = []
  713. if (this.goodsType == 'common') {
  714. data_specs = this.detailData.data_specs
  715. if (Array.isArray(data_specs)) {
  716. data_specs.forEach(pItem => {
  717. pItem.list = pItem.list.map((item, index) => {
  718. if (index === 0) {
  719. this.$set(item, 'isChecked', true)
  720. } else {
  721. this.$set(item, 'isChecked', false)
  722. }
  723. return item
  724. })
  725. })
  726. }
  727. } else if (this.goodsType == 'msGoods') {
  728. data_specs = res.data.items
  729. this.detailData.price_seckill = res.data.price_seckill
  730. if (Array.isArray(data_specs)) {
  731. data_specs.forEach((pItem, index) => {
  732. const {
  733. status,
  734. stock_sale,
  735. stock
  736. } = pItem
  737. if (index === 0) {
  738. this.$set(pItem, 'isChecked', true)
  739. } else {
  740. this.$set(pItem, 'isChecked', false)
  741. }
  742. this.$set(pItem, 'disabled', !(status == 1 && stock_sale < stock))
  743. })
  744. }
  745. }
  746. this.goodsSpecData = data_specs
  747. console.log(99999, this.detailData)
  748. this.detailData.slider = this.detailData.slider.map(item => {
  749. return {
  750. url: item
  751. }
  752. })
  753. if (this.detailData.video) {
  754. this.detailData.slider.unshift({
  755. url: this.detailData.video
  756. })
  757. }
  758. this.checkCollect()
  759. }).catch(() => {
  760. uni.hideLoading()
  761. })
  762. },
  763. submit() {
  764. if (!this.isUserRegister) {
  765. this.showUserRegister = true
  766. return
  767. }
  768. if (this.currentOperateType === 1) {
  769. // 添加购物车
  770. this.$api.addToShoppingCart({
  771. sku_id: this.goodSuitPriceData.sku_id,
  772. num: this.suitNum
  773. }).then(res => {
  774. this.show = false
  775. uni.showToast({
  776. title: '已加入购物车'
  777. })
  778. this.getCartNumber()
  779. })
  780. } else if (this.currentOperateType === 2) {
  781. // this.show = false
  782. if (this.goodsType == 'common') {
  783. let specText = this.selectedSuitPriceData.map(item => {
  784. return `${item.group_name}::${item.spec_name}`
  785. })
  786. const sendData = {
  787. items: [{
  788. code: this.pageOptions.code,
  789. count: this.suitNum,
  790. spec: specText.join(';;')
  791. }]
  792. }
  793. this.$api.createOrder(sendData).then(res => {
  794. uni.showToast({
  795. title: '订单创建成功'
  796. })
  797. uni.navigateTo({
  798. url: `/subPages/settleCenter/settleCenter?orderNo=${res.data.order_no}`
  799. })
  800. })
  801. } else {
  802. // 秒杀下单
  803. const sendData = {
  804. sk_goods_id: this.pageOptions.code,
  805. goods_spec: this.goodSuitPriceData.goods_spec,
  806. num: this.suitNum
  807. }
  808. msGoodsCreateOrder(sendData).then(res => {
  809. uni.showToast({
  810. title: '订单创建成功'
  811. })
  812. uni.navigateTo({
  813. url: `/subPages/settleCenter/settleCenter?orderNo=${res.data.order_no}&type=msGoods`
  814. })
  815. })
  816. }
  817. } else {
  818. this.show = false
  819. }
  820. },
  821. toHome() {
  822. uni.navigateBack({
  823. delta: 1
  824. })
  825. },
  826. toApply() {
  827. // 立即购买去选择规格
  828. if (!this.isUserRegister) {
  829. this.showUserRegister = true
  830. return
  831. }
  832. this.currentOperateType = 2
  833. this.show = true
  834. },
  835. toJump( index) {
  836. if(index==1){
  837. uni.switchTab({
  838. url:'/pages/home/index'
  839. });
  840. }else if(index==3){
  841. if (!this.isUserRegister) {
  842. this.showUserRegister = true
  843. return
  844. }
  845. uni.switchTab({
  846. url:'/pages/shoppingCart/shoppingCart'
  847. });
  848. }
  849. },
  850. }
  851. }
  852. </script>
  853. <style lang="scss" scoped>
  854. ::v-deep {
  855. img {
  856. width: 100%;
  857. }
  858. }
  859. .poster-wrap {
  860. text-align: center;
  861. margin-top: 100rpx;
  862. .poster-img {
  863. width: 610rpx;
  864. height: 944rpx;
  865. }
  866. }
  867. .poster-box {
  868. background-color: #F5F6F8;
  869. width: calc(100% - 120rpx);
  870. padding: 20rpx 60rpx 60rpx;
  871. position: absolute;
  872. bottom: 0;
  873. }
  874. .poster-btn {
  875. display: flex;
  876. justify-content: space-around;
  877. align-items: flex-end;
  878. font-size: 28rpx;
  879. text-align: center;
  880. &-left {
  881. position: relative
  882. }
  883. &-right {
  884. display: flex;
  885. flex-direction: column;
  886. align-items: center;
  887. }
  888. }
  889. .cancel-btn {
  890. height: 72rpx;
  891. border-radius: 80rpx;
  892. text-align: center;
  893. line-height: 72rpx;
  894. background-color: #fff;
  895. margin-top: 16rpx;
  896. }
  897. .goods-detail-wrapper {
  898. //margin-top: 60rpx;
  899. background-color: $primary-bg-color;
  900. padding-bottom: 146rpx;
  901. ::v-deep {
  902. .u-swiper-indicator {
  903. padding: 0 !important
  904. }
  905. }
  906. .to-home-img {
  907. position: absolute;
  908. left: 30rpx;
  909. top: 100rpx;
  910. border-radius: 52rpx;
  911. width: 52rpx;
  912. height: 52rpx;
  913. background-color: #F0F0F2;
  914. z-index: 1;
  915. // 上下左右居中
  916. display: flex;
  917. align-items: center;
  918. justify-content: center;
  919. font-weight: 700 !important;
  920. }
  921. .content-box {
  922. padding: 20rpx 20rpx 0;
  923. .title {
  924. line-height: 36rpx;
  925. font-size: 30rpx;
  926. }
  927. .sub-title {
  928. color: #717171;
  929. margin: 30rpx 0 24rpx;
  930. }
  931. .detail-title {
  932. display: flex;
  933. align-items: center;
  934. font-size: 28rpx;
  935. font-weight: 600;
  936. margin-bottom: 18rpx;
  937. .title-icon {
  938. width: 3rpx;
  939. height: 24rpx;
  940. background: linear-gradient(180deg, #9276FE 0%, rgba(217, 217, 217, 0) 100%);
  941. border-radius: 0rpx 0rpx 0rpx 0rpx;
  942. margin-right: 8rpx;
  943. }
  944. }
  945. }
  946. .bottom-part {
  947. position: fixed;
  948. bottom: 0;
  949. background-color: #fff;
  950. width: calc(100% - 60rpx);
  951. padding: 14rpx 30rpx 30rpx;
  952. display: flex;
  953. justify-content: space-between;
  954. z-index: 100;
  955. .bar-list {
  956. display: flex;
  957. width: calc(100% - 340rpx);
  958. // justify-content: space-between;
  959. font-size: 22rpx;
  960. text-align: center;
  961. color: #525051;
  962. }
  963. .bar-list-icon {
  964. position: relative;
  965. margin-right: 15rpx;
  966. }
  967. }
  968. }
  969. .common-btn {
  970. //width: 160rpx;
  971. //flex-shrink: 0;
  972. background: linear-gradient( 315deg, #CA9359 0%, #E2B98E 100%)!important;
  973. border-radius: 292rpx 292rpx 292rpx 292rpx!important;
  974. border:0;
  975. }
  976. .suit-content {
  977. padding: 0 40rpx 60rpx;
  978. max-height: 80vh;
  979. box-sizing: border-box;
  980. overflow-y: auto;
  981. .suit-btn-box {
  982. display: flex;
  983. // justify-content: space-between;
  984. .suit-btn {
  985. background-color: #F6F6F6;
  986. border-radius: 8rpx;
  987. border: 1rpx solid transparent;
  988. height: 76rpx;
  989. line-height: 76rpx;
  990. text-align: center;
  991. width: calc(33% - 20rpx);
  992. color: #232323;
  993. margin-right: 20rpx;
  994. box-sizing: border-box;
  995. margin-bottom: 40rpx;
  996. &-active {
  997. color: #C29556;
  998. background-color: #F9F2E6 ;
  999. }
  1000. &-disabled {
  1001. background-color: #fffafa;
  1002. border-color: #d0d0d0;
  1003. color: #ababab;
  1004. }
  1005. &-column {
  1006. width: 100%;
  1007. text-align: left;
  1008. padding: 0 10rpx;
  1009. flex-shrink: 0;
  1010. }
  1011. }
  1012. }
  1013. }
  1014. .bottom-navigation{
  1015. position: fixed;
  1016. // 文字垂直居中
  1017. display: flex;
  1018. align-items: center;
  1019. justify-content: center;
  1020. bottom: 0;
  1021. height: 100rpx;
  1022. width: calc(100% - 40rpx);
  1023. background: #FFFFFF;
  1024. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  1025. border-radius: 24rpx 24rpx 0rpx 0rpx;
  1026. border: 0rpx solid #979797;
  1027. padding: 20rpx 20rpx 68rpx 20rpx ;
  1028. z-index: 100;
  1029. &-div{
  1030. height: 76rpx;
  1031. width: 270rpx;
  1032. // 文字垂直居中
  1033. display: flex;
  1034. align-items: center;
  1035. padding-left: 30rpx;
  1036. padding-top: 10rpx;
  1037. span{
  1038. font-family: PingFang SC, PingFang SC;
  1039. font-weight: 400;
  1040. font-size: 20rpx;
  1041. color: #333333;
  1042. line-height: 32rpx;
  1043. text-align: left;
  1044. font-style: normal;
  1045. text-transform: none;
  1046. }
  1047. }
  1048. .add-cart-button {
  1049. width: 216rpx;
  1050. height: 76rpx;
  1051. background: linear-gradient( 315deg, #323130 0%, #575757 100%);;
  1052. border-radius: 292rpx 292rpx 292rpx 292rpx;
  1053. font-family: PingFang SC, PingFang SC;
  1054. font-weight: 400;
  1055. font-size: 28rpx;
  1056. color: #FFFFFF;
  1057. line-height: 36rpx;
  1058. text-align: center;
  1059. font-style: normal;
  1060. text-transform: none;
  1061. // 文字垂直居中
  1062. display: flex;
  1063. margin-right: 20rpx;
  1064. align-items: center;
  1065. justify-content: center;
  1066. padding: 0;
  1067. }
  1068. .submit-order-button {
  1069. width: 216rpx;
  1070. height: 76rpx;
  1071. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  1072. border-radius: 292rpx 292rpx 292rpx 292rpx;
  1073. font-family: PingFang SC, PingFang SC;
  1074. font-weight: 400;
  1075. font-size: 28rpx;
  1076. color: #FFFFFF;
  1077. line-height: 36rpx;
  1078. text-align: center;
  1079. font-style: normal;
  1080. text-transform: none;
  1081. // 文字垂直居中
  1082. display: flex;
  1083. align-items: center;
  1084. justify-content: center;
  1085. padding: 0;
  1086. }
  1087. }
  1088. .fenxiang {
  1089. font-weight: 400;
  1090. font-size: 18rpx;
  1091. color: #333333;
  1092. line-height: 24rpx;
  1093. text-align: left;
  1094. font-style: normal;
  1095. text-transform: none;
  1096. }
  1097. </style>