时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

693 lines
17 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <view>
  3. <skeleton :loading="skeletonLoading" :row="12" :showAvatar="false" :showTitle="true">
  4. <block v-if="isRight(goods_detail)">
  5. <!-- 商品图片轮播 -->
  6. <swiper :current="current" :indicator-dots="goods_detail.banners.length > 1 ? true : false"
  7. :circular="true" class="swiper-box" indicator-active-color="#FE9903">
  8. <swiper-item v-for="(item, index) in goods_detail.banners" :key="item.id">
  9. <image mode="aspectFill" :src="item.cover" style="width: 100%; height: 100%;"
  10. @click="lookImg(index)"></image>
  11. </swiper-item>
  12. </swiper>
  13. <view class="bill-position" @tap='formSubmit()'>
  14. <button class="cu-btn1 margin-left-sm lf-font-28 lf-m-20">
  15. 分享海报
  16. </button>
  17. </view>
  18. <!-- 商品主要信息 -->
  19. <view class="head-info">
  20. <view class="lf-font-40">{{ goods_detail.name }}</view>
  21. <view class="lf-row-between lf-font-24 lf-m-t-30 lf-p-b-20">
  22. <view class="lf-flex price">
  23. <lf-price :price="goods_detail.specs[0].selling_price"></lf-price>
  24. <view class="lf-m-l-20">¥{{ goods_detail.specs[0].original_price }}</view>
  25. <view v-if="goods_detail.specs[0].cost">{{ goods_detail.specs[0].cost }}</view>
  26. </view>
  27. <view class="lf-font-24 lf-text-right">
  28. <view class="lf-color-gray">{{ goods_detail.specs[0].sold_stock_text }}</view>
  29. <view class="lf-color-primary">{{ goods_detail.specs[0].stock_text }}</view>
  30. </view>
  31. </view>
  32. <view class="label-box" v-if="goods_detail.tags && goods_detail.tags.length">
  33. <view class="label-item" v-for="(item, index) in goods_detail.tags" :key="index">{{ item }}
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 地址信息 -->
  38. <view class="address-box">
  39. <view class="lf-font-32 lf-font-bold">适用门店</view>
  40. <view class="lf-m-t-20 lf-row-between">
  41. <view class="lf-flex">
  42. <image mode="aspectFill" class="lf-fle shop-img" :src="goods_detail.store.cover"
  43. v-if="goods_detail.store.cover"></image>
  44. <image mode="aspectFill" class="lf-fle shop-img" src="../../static/center/shop-logo.png"
  45. v-else></image>
  46. <view class="lf-font-32 lf-m-l-20 lf-line-1" style="max-width: 512rpx;">
  47. {{ goods_detail.store.name }}</view>
  48. </view>
  49. <view @click="makePhoneCall(goods_detail.store.tel)">
  50. <text class="lf-iconfont lf-icon-dianhua lf-font-40" style="color: #3A62FF;"></text>
  51. </view>
  52. </view>
  53. <view class="lf-flex lf-m-t-20" @click="openMap">
  54. <view style="width: 60rpx; height: 60rpx;" class="lf-row-center">
  55. <text class="lf-iconfont lf-icon-dizhi lf-font-40" style="color: #555555;"></text>
  56. </view>
  57. <view class="lf-m-l-20 lf-font-28" style="color: #555555;">{{ goods_detail.store.address }}
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 商品详情 -->
  62. <view class="goods-detail">
  63. <view class="lf-font-32 lf-font-bold lf-m-b-20">商品详情</view>
  64. <rich-text :nodes="formatRichText(goods_detail.content)"
  65. v-if="goods_detail.content_type == 'rich_text'"></rich-text>
  66. <image class="goods-img" :src="item" v-for="(item, index) in goods_detail.content" :key="index"
  67. v-if="goods_detail.content_type == 'img'"></image>
  68. </view>
  69. <!-- 修饰专用 -->
  70. <view class="extra"></view>
  71. <!-- 吸底操作按钮 -->
  72. <view class="lf-row-between fixed-bottom">
  73. <view class="lf-flex lf-p-t-10 lf-p-b-10">
  74. <view class="lf-flex-column lf-row-center icon-item"
  75. @click="$url('/pages/index/index', {type: 'switch'})">
  76. <image class="icon-img" src="../../static/center/home.png"></image>
  77. <view class="lf-m-t-1">首页</view>
  78. </view>
  79. <view class="lf-flex-column lf-row-center icon-item"
  80. @click="$url('/pages/contactService/index')">
  81. <image class="icon-img" src="../../static/center/service.png"></image>
  82. <view class="lf-m-t-1">客服</view>
  83. </view>
  84. <view class="lf-flex-column lf-row-center icon-item" @click="switchCollect">
  85. <image class="icon-img" src="../../static/center/collect-active.png" v-if="is_collect">
  86. </image>
  87. <image class="icon-img" src="../../static/center/collect.png" v-else></image>
  88. <view class="lf-m-t-1">{{ is_collect ? '已收藏' : '收藏' }}</view>
  89. </view>
  90. <button class="lf-flex-column lf-row-center icon-item" open-type="share">
  91. <image class="icon-img" src="../../static/center/share.png"></image>
  92. <view class="lf-m-t-1">分享</view>
  93. </button>
  94. </view>
  95. <button class="btn" @click="toAddOrder">立即抢购</button>
  96. </view>
  97. <!-- 回到顶部 -->
  98. <!-- <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}" :icon-style="{color: '#ffffff'}"></u-back-top> -->
  99. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}">
  100. </u-back-top>
  101. </block>
  102. </skeleton>
  103. <view class="canvas-box">
  104. <canvas style="width: 375px;height: 667px;position:fixed;top:9999px" canvas-id="mycanvas" />
  105. </view>
  106. <view class='imagePathBox' v-if="maskHidden == true && imagePath" @click="maskHidden = false ">
  107. <image :src="imagePath" class='shengcheng' mode="widthFix"></image>
  108. <button class='baocun' @click.stop="saveBill()">保存相册分享到朋友圈</button>
  109. </view>
  110. </view>
  111. </template>
  112. <script>
  113. export default {
  114. data() {
  115. return {
  116. current: 0, // 轮播下标
  117. goods_id: 0,
  118. goods_detail: {},
  119. is_collect: 0, // 1为当前收藏商品了,0为否
  120. skeletonLoading: true,
  121. base64Img: '',
  122. checkArea: 'Cannot find module',
  123. maskHidden: false,
  124. info: {
  125. avatar: '',
  126. nickname: '',
  127. id: '',
  128. tel: '',
  129. tags: []
  130. },
  131. showLogin: true,
  132. imagePath: '',
  133. userToken: '',
  134. wxCode: '',
  135. onceCode: '',
  136. pt: 1
  137. }
  138. },
  139. computed: {
  140. isRight() {
  141. return function(val) {
  142. return this.$shared.isRight(val);
  143. }
  144. }
  145. },
  146. onLoad(options) {
  147. this.goods_id = options.id;
  148. this.pt = options.pt || 1;
  149. this.getGoodsDetail();
  150. this.getWxCode()
  151. },
  152. methods: {
  153. getWxCode() {
  154. uni.request({
  155. url: 'http://dev-gxsky.com/api/salesman/qrcode', //仅为示例,并非真实接口地址。
  156. data: {
  157. scene: 'route=goods&id=2&pt=2',
  158. page: 'pages/route/index',
  159. width: '2800'
  160. },
  161. method: 'POST',
  162. success: (res) => {
  163. this.wxCode = res.data.data.base_url
  164. if (this.wxCode) {
  165. this.getwxCodeImg()
  166. }
  167. }
  168. });
  169. },
  170. //海报开始
  171. //保存头像
  172. getwxCodeImg() {
  173. var imgSrc = this.wxCode; //base64编码
  174. var save = wx.getFileSystemManager();
  175. var number = Math.random();
  176. save.writeFile({
  177. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg',
  178. data: imgSrc,
  179. encoding: 'base64',
  180. success: res => {
  181. this.onceCode = wx.env.USER_DATA_PATH + '/pic' + number + '.jpg'
  182. },
  183. fail: err => {
  184. console.log(err)
  185. }
  186. })
  187. },
  188. createNewImg() {
  189. var that = this;
  190. var context = wx.createCanvasContext('mycanvas');
  191. var path = "../../static/images/bill.png";
  192. context.drawImage(path, 0, 0, 375, 667);
  193. //绘制二维码
  194. let wxcode = that.onceCode
  195. context.drawImage(wxcode, 18, 530, 120, 120);
  196. //绘制名字
  197. // context.setFontSize(24);
  198. // context.setFillStyle('#fff');
  199. // context.setTextAlign('center');
  200. // context.fillText(name, 34, 620);
  201. context.stroke();
  202. context.draw();
  203. //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
  204. setTimeout(function() {
  205. wx.canvasToTempFilePath({
  206. canvasId: 'mycanvas',
  207. success: function(res) {
  208. that.imagePath = res.tempFilePath;
  209. if (that.imagePath) {
  210. that.canvasHidden = true
  211. that.maskHidden = true
  212. }
  213. console.log('海报生成成功')
  214. console.log(res)
  215. console.log('图片链接', that.imagePath)
  216. },
  217. fail: function(res) {
  218. console.log(res);
  219. }
  220. });
  221. }, 200);
  222. },
  223. saveBill() {
  224. var that = this
  225. wx.saveImageToPhotosAlbum({
  226. filePath: that.imagePath,
  227. success(res) {
  228. wx.showModal({
  229. content: '图片已保存到相册,赶紧晒一下吧~',
  230. showCancel: false,
  231. confirmText: '好的',
  232. confirmColor: '#333',
  233. success: function(res) {
  234. if (res.confirm) {
  235. console.log('用户点击确定');
  236. that.maskHidden = false
  237. }
  238. },
  239. fail: function(res) {
  240. that.maskHidden = false
  241. }
  242. })
  243. }
  244. })
  245. },
  246. formSubmit() {
  247. var that = this;
  248. wx.showToast({
  249. title: '生成海报中...',
  250. icon: 'loading',
  251. duration: 1000
  252. });
  253. wx.hideToast()
  254. if(that.onceCode) {
  255. that.createNewImg()
  256. }
  257. },
  258. //海报结束
  259. getGoodsDetail() {
  260. let that = this;
  261. this.$http(this.API.API_GOODS_DETAIL, {
  262. goods_id: this.goods_id
  263. }).then(res => {
  264. this.skeletonLoading = false;
  265. this.goods_detail = res.data;
  266. this.is_collect = Boolean(res.data.user.is_collect);
  267. }).catch(err => {
  268. this.skeletonLoading = false;
  269. setTimeout(() => {
  270. that.$toBack();
  271. }, 1000);
  272. })
  273. },
  274. // 切换商品收藏
  275. switchCollect() {
  276. let userInfo = uni.getStorageSync('userinfo') || {};
  277. if (!userInfo.id || !userInfo.nickname || !userInfo.avatar) {
  278. this.$url('/pages/login/index?type=userinfo');
  279. return;
  280. }
  281. this.$http(this.API.API_COLLECT_DEAL, {
  282. goods_id: this.goods_id
  283. }).then(res => {
  284. this.$msg(res.msg);
  285. this.is_collect = Boolean(res.data.user.is_collect);
  286. })
  287. },
  288. // 拨打电话
  289. makePhoneCall(phoneStr) {
  290. uni.makePhoneCall({
  291. phoneNumber: String(phoneStr)
  292. })
  293. },
  294. // 打开地图
  295. openMap() {
  296. // return;
  297. uni.openLocation({
  298. longitude: 108.36637,
  299. latitude: 22.817746,
  300. scale: 18,
  301. name: this.goods_detail.store.address
  302. })
  303. },
  304. // 跳转到确认下单页面
  305. toAddOrder() {
  306. let goods_id = this.goods_detail.id;
  307. let goods_specs_id = this.goods_detail.specs[0].id
  308. this.$url('/pages/order/confirm-order?goods_id=' + goods_id + '&goods_specs_id=' + goods_specs_id +'&pt='+ this.pt);
  309. },
  310. // 预览图片
  311. lookImg(index) {
  312. this.$u.throttle(() => {
  313. let goods_banner = this.goods_detail.banners || [];
  314. let banners = goods_banner.map(item => item.cover);
  315. uni.previewImage({
  316. urls: banners,
  317. current: index
  318. })
  319. }, 200);
  320. },
  321. // 富文本处理
  322. formatRichText(richText) {
  323. if (richText != null) {
  324. let newRichText = richText.replace(/<img[^>]*>/gi, function(match, capture) {
  325. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  326. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  327. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  328. return match;
  329. });
  330. newRichText = newRichText.replace(/style="[^"]+"/gi, function(match, capture) {
  331. match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi,
  332. 'width:100%;');
  333. return match;
  334. });
  335. newRichText = newRichText.replace(/<br[^>]*\/>/gi, '');
  336. newRichText = newRichText.replace(/\<img/gi,
  337. '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
  338. return newRichText;
  339. } else {
  340. return null;
  341. }
  342. }
  343. },
  344. onShareAppMessage() {
  345. let goods = this.goods_detail;
  346. let title = goods.name;
  347. let imageUrl = goods.share_cover || goods.cover;
  348. let path = '/pages/route/index?route=goods_detail&id=' + goods.id;
  349. return {
  350. title,
  351. path,
  352. imageUrl
  353. }
  354. }
  355. }
  356. </script>
  357. <style>
  358. page {
  359. background-color: #f5f5f5;
  360. overflow-x: hidden;
  361. }
  362. </style>
  363. <style lang="scss" scoped="scoped">
  364. .bill-position {
  365. position: absolute;
  366. top: 0;
  367. right: 0;
  368. }
  369. .cu-btn1 {
  370. position: relative;
  371. display: inline-flex;
  372. align-items: center;
  373. justify-content: center;
  374. box-sizing: border-box;
  375. padding: 0 30rpx;
  376. font-size: 28rpx;
  377. height: 64rpx;
  378. line-height: 1;
  379. text-align: center;
  380. text-decoration: none;
  381. overflow: visible;
  382. margin-left: initial;
  383. transform: translate(0upx, 0upx);
  384. margin-right: initial;
  385. background-color: rgba(0, 0, 0, 0.5);
  386. color: #FFFFFF;
  387. border-radius: 33rpx;
  388. }
  389. .swiper-box {
  390. width: 750rpx;
  391. height: 520rpx;
  392. background-color: #FFFFFF;
  393. }
  394. .head-info {
  395. width: 750rpx;
  396. height: auto;
  397. box-sizing: border-box;
  398. padding: 0 32rpx;
  399. padding-top: 20rpx;
  400. background-color: #FFFFFF;
  401. // .price>view:nth-of-type(1){
  402. // color: #FF0000;
  403. // margin-right: 22rpx;
  404. // font-weight: bold;
  405. // }
  406. .price>view:nth-of-type(1) {
  407. text-decoration: line-through;
  408. color: #777777;
  409. margin-right: 22rpx;
  410. }
  411. .price>view:nth-of-type(2) {
  412. width: max-content;
  413. padding: 0 18rpx;
  414. height: 46rpx;
  415. background-color: #FE9903;
  416. border-radius: 10rpx;
  417. display: flex;
  418. justify-content: center;
  419. align-items: center;
  420. color: #FFFFFF;
  421. }
  422. .label-box {
  423. min-height: 130rpx;
  424. width: 100%;
  425. border-top: 1rpx solid #E5E5E5;
  426. display: flex;
  427. flex-wrap: wrap;
  428. padding: 30rpx 0 10rpx 0;
  429. .label-item {
  430. width: 156rpx;
  431. height: 70rpx;
  432. border-radius: 10rpx;
  433. border: 2rpx solid #FE9903;
  434. display: flex;
  435. justify-content: center;
  436. align-items: center;
  437. font-size: 28rpx;
  438. color: #FE9903;
  439. margin-right: 20rpx;
  440. margin-bottom: 20rpx;
  441. }
  442. }
  443. }
  444. .address-box {
  445. width: 750rpx;
  446. height: auto;
  447. box-sizing: border-box;
  448. background-color: #FFFFFF;
  449. padding: 32rpx;
  450. margin-top: 20rpx;
  451. .shop-img {
  452. width: 60rpx;
  453. height: 60rpx;
  454. border-radius: 50%;
  455. }
  456. }
  457. .goods-detail {
  458. width: 750rpx;
  459. height: auto;
  460. background-color: #FFFFFF;
  461. padding: 32rpx;
  462. box-sizing: border-box;
  463. margin-top: 20rpx;
  464. .goods-img {
  465. width: 100%;
  466. }
  467. }
  468. .extra {
  469. width: 100%;
  470. height: 120rpx;
  471. padding-bottom: constant(safe-area-inset-bottom);
  472. padding-bottom: env(safe-area-inset-bottom);
  473. box-sizing: content-box;
  474. }
  475. .fixed-bottom {
  476. position: fixed;
  477. bottom: 0;
  478. left: 0;
  479. background-color: #FFFFFF;
  480. width: 100%;
  481. height: auto;
  482. padding: 0 32rpx;
  483. border-top: 1rpx solid #e5e5e5;
  484. padding-bottom: constant(safe-area-inset-bottom);
  485. padding-bottom: env(safe-area-inset-bottom);
  486. .icon-item {
  487. margin-right: 16rpx;
  488. background-color: transparent;
  489. margin: 0;
  490. line-height: initial;
  491. font-size: 28rpx;
  492. font-weight: inherit;
  493. margin-right: 10rpx;
  494. padding: 0;
  495. width: 88rpx;
  496. &:first-child {
  497. padding-left: 0;
  498. }
  499. .icon-img {
  500. height: 50rpx;
  501. width: 50rpx;
  502. }
  503. }
  504. .btn {
  505. margin: 0;
  506. padding: 0;
  507. width: 208rpx;
  508. height: 80rpx;
  509. background-color: #FE9903;
  510. color: #FFFFFF;
  511. line-height: 80rpx;
  512. font-size: 32rpx;
  513. border-radius: 42rpx;
  514. }
  515. }
  516. //海报
  517. .bgImg {
  518. display: block;
  519. width: 100%;
  520. height: 366rpx;
  521. }
  522. .mine {
  523. display: block;
  524. text-align: center;
  525. color: #333;
  526. margin-top: 44rpx;
  527. }
  528. .code {
  529. display: block;
  530. text-align: center;
  531. color: #333;
  532. font-size: 76rpx;
  533. font-weight: bold;
  534. margin-top: 30rpx;
  535. }
  536. .who {
  537. display: block;
  538. margin-top: 80rpx;
  539. font-size: 32rpx;
  540. color: #333;
  541. text-align: center;
  542. }
  543. .inputBox {
  544. text-align: center;
  545. margin-top: 44rpx;
  546. }
  547. .input {
  548. text-align: center;
  549. width: 440rpx;
  550. height: 88rpx;
  551. border-radius: 44rpx;
  552. background: #f5f5f5;
  553. font-size: 32rpx;
  554. display: inline-block;
  555. }
  556. .btn {
  557. width: 160rpx;
  558. height: 88rpx;
  559. border-radius: 44rpx;
  560. background: rgba(254, 153, 3, 1);
  561. color: #333;
  562. font-size: 32rpx;
  563. display: inline-block;
  564. line-height: 88rpx;
  565. margin-left: 40rpx;
  566. }
  567. button[class="btn"]::after {
  568. border: 0;
  569. }
  570. .tishi {
  571. display: block;
  572. text-align: center;
  573. color: #999;
  574. margin-top: 30rpx;
  575. }
  576. .shareText {
  577. display: block;
  578. text-align: center;
  579. color: #333;
  580. font-size: 28rpx;
  581. margin-top: 100rpx;
  582. }
  583. .imgBox {
  584. text-align: center;
  585. width: 100%;
  586. margin-top: 60rpx;
  587. padding-bottom: 120rpx;
  588. }
  589. .img {
  590. display: inline-block;
  591. width: 100%;
  592. height: 100%;
  593. }
  594. .m_l {
  595. margin-left: 180rpx;
  596. }
  597. .zfbtn {
  598. display: inline-block;
  599. width: 120rpx;
  600. height: 120rpx;
  601. border-radius: 50%;
  602. background: transparent;
  603. outline: none;
  604. border: 0;
  605. padding: 0;
  606. }
  607. button[class="zfbtn"]::after {
  608. border: 0;
  609. }
  610. button[class="zfbtn m_l"]::after {
  611. border: 0;
  612. }
  613. .imagePathBox {
  614. width: 100%;
  615. height: 100%;
  616. background: rgba(0, 0, 0, 0.7);
  617. position: fixed;
  618. top: 0;
  619. left: 0;
  620. right: 0;
  621. bottom: 0;
  622. z-index: 10;
  623. }
  624. .shengcheng {
  625. width: 80%;
  626. height: 80%;
  627. position: fixed;
  628. top: 50rpx;
  629. left: 50%;
  630. margin-left: -40%;
  631. z-index: 10;
  632. }
  633. .baocun {
  634. display: block;
  635. width: 80%;
  636. height: 80rpx;
  637. padding: 0;
  638. line-height: 80rpx;
  639. text-align: center;
  640. position: fixed;
  641. bottom: 50rpx;
  642. left: 10%;
  643. background: rgba(254, 153, 3, 1);
  644. color: #fff;
  645. font-size: 32rpx;
  646. border-radius: 44rpx;
  647. }
  648. button[class="baocun"]::after {
  649. border: 0;
  650. }
  651. </style>