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

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