时空网前端
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.

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