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

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