goodsDetail.vue 32 KB

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