index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="page" :style="{ 'min-height': h + 'px', 'padding-top': mt + 'px' }" id="saveImage">
  3. <c-nav-bar title="预订二维码" :showHome="false"></c-nav-bar>
  4. <image :src="posterUrl" mode="widthFix" style="width: 100vw;" @tap="previewPoster"></image>
  5. <view class="bottom-buttons">
  6. <view class="btn copy-btn" @tap="copyShareLink">
  7. <text class="btn-text">复制分享链接</text>
  8. </view>
  9. <view class="btn save-btn" @tap="savePoster">
  10. <text class="btn-text">保存分享海报</text>
  11. </view>
  12. </view>
  13. <!-- <image src="https://fsy.shengsi.gov.cn/file/20240115/4cfb2a681dba4431800e88ba903d61a6.png" class="title" mode="widthFix"></image>
  14. <view class="code">
  15. </view>
  16. <view class="save-btn" @tap="saveImage">保存图片</view>
  17. <canvas canvas-id="myCanvas" class="my-canvas"></canvas> -->
  18. <!-- <image style="width: 70vw;" :src="posterUrl" mode="widthFix" @click="preview(posterUrl)"></image> -->
  19. <view style="position: fixed;left:-2000px;top: -2000px;">
  20. <l-painter ref="painter">
  21. <l-painter-image src="https://cdn.szhd.ycurm.top/fengxiao/bg2.png"
  22. css="width: 555rpx; height: 985rpx" />
  23. <l-painter-image :src="info.distributionCodeUrl"
  24. css="width: 140rpx; height: 140rpx;position:absolute;border-radius:50%;left:81rpx;top:712rpx" />
  25. <!-- <l-painter-image src="https://cdn.szhd.ycurm.top/fengxiao/qg.png"
  26. css="width: 46rpx; height: 46rpx;position:absolute;border-radius:50%;left:68rpx;top:708rpx" />
  27. <l-painter-image src="https://cdn.szhd.ycurm.top/fengxiao/qg.png"
  28. css="width: 84rpx; height: 29rpx;position:absolute;left:68rpx;top:778rpx;object-fit: fill;" /> -->
  29. <l-painter-image :src="stayInfo.picList[0]"
  30. css="width: 426rpx; height: 426rpx;position:absolute;left:64rpx;top:81rpx;object-fit: fill;" />
  31. <l-painter-text :text="stayInfo.name"
  32. css="width: 426rpx; height: 40rpx;position:absolute;left:64rpx;top:566rpx;font-size:24rpx;color:#222222;text-align:left" />
  33. <!-- <l-painter-text :text="'111'"
  34. css="width: 200rpx; height: 35rpx;position:absolute;left:126rpx;top:714rpx;font-size:24rpx;color:#222222;text-align:left" />
  35. <l-painter-text :text="'¥1'"
  36. css="width: 200rpx;height: 46rpx; position:absolute;left:164rpx;top:767rpx;font-size:32rpx;color:#FE2B00" />
  37. <l-painter-text :text="'1人已购买'"
  38. css="width: 200rpx;height: 46rpx; position:absolute;left:68rpx;top:822rpx;font-size:18rpx;color:#FE2B00" /> -->
  39. <l-painter-text :text="stayInfo.areaDetail"
  40. css="width: 270rpx; height: 120rpx;position:absolute;left:230rpx;top:700rpx;font-size:20rpx;color:#222222;text-align:left" />
  41. <l-painter-view
  42. css="background: #FFDD02; width: 200rpx;height: 40rpx; display: inline-block;position:absolute;left:260rpx;top:812rpx;border-radius:14rpx"></l-painter-view>
  43. <l-painter-text text="长按识别二维码"
  44. css="width: 200rpx;height: 40rpx;line-height:27rpx;position:absolute;left:260rpx;top:812rpx;font-size:18rpx;color:#222222;border-radius: 14rpx;text-align:center" />
  45. </l-painter>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. img: '',
  54. posterUrl: {},
  55. info: {},
  56. stayInfo: {}
  57. }
  58. },
  59. onLoad() {
  60. this.getCode();
  61. setTimeout(() => {
  62. this.setPost()
  63. }, 10);
  64. },
  65. onShow() {
  66. },
  67. methods: {
  68. onImgOK(e){
  69. console.log(e)
  70. //e.detail.path 图片路径
  71. },
  72. onImgErr(e){
  73. console.log(e)
  74. //e.detail.path 图片路径错误
  75. },
  76. setPost() {
  77. this.$refs.painter.canvasToTempFilePathSync({
  78. fileType: "jpg",
  79. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  80. pathType: 'url',
  81. quality: 1,
  82. success: (res) => {
  83. this.showPoster = true
  84. console.log(res.tempFilePath);
  85. this.posterUrl = res.tempFilePath
  86. },
  87. fail: (res) => {
  88. console.log(res);
  89. },
  90. });
  91. },
  92. getCode() {
  93. const merchantType = uni.getStorageSync('merchantType');
  94. let merchantId = uni.getStorageSync('merchantId');
  95. if (merchantType === 2) {
  96. const homestayId = uni.getStorageSync('homestayId');
  97. if (homestayId) {
  98. merchantId = homestayId;
  99. }
  100. }
  101. const params = {
  102. merchantId: merchantId,
  103. merchantType: merchantType,
  104. merchantName: uni.getStorageSync('merchantName'),
  105. page: 'pagesTrip/hotel/details/index?homestayId=' + merchantId
  106. };
  107. this.$api.get('/merchant/hotel/mine/getMerchantHomestayInfo/' + merchantId).then(res => {
  108. if (res.data.code == 0) {
  109. this.stayInfo = res.data.data;
  110. }
  111. })
  112. this.$api.post('/order/api/merchant/distribution/code/generate', params).then(res => {
  113. if (res.data && res.data.code === 0 && res.data.data && res.data.data.distributionCodeUrl) {
  114. this.info = res.data.data;
  115. }
  116. })
  117. },
  118. copyShareLink() {
  119. var that = this;
  120. if (!that.info.shortLink) {
  121. uni.showToast({ title: '分享链接暂未生成', icon: 'none' });
  122. return;
  123. }
  124. uni.setClipboardData({
  125. data: that.info.shortLink,
  126. success: function() {
  127. uni.showToast({ title: '链接已复制', icon: 'success' });
  128. }
  129. });
  130. },
  131. savePoster() {
  132. var that = this;
  133. if (!that.posterUrl) {
  134. uni.showToast({ title: '海报生成中,请稍后', icon: 'none' });
  135. return;
  136. }
  137. uni.saveImageToPhotosAlbum({
  138. filePath: that.posterUrl,
  139. success: function() {
  140. uni.showToast({ title: '保存成功', icon: 'success' });
  141. },
  142. fail: function(err) {
  143. console.error('保存失败', err);
  144. uni.showToast({ title: '保存失败', icon: 'none' });
  145. }
  146. });
  147. },
  148. previewPoster() {
  149. var that = this;
  150. if (!that.posterUrl) {
  151. uni.showToast({ title: '海报生成中,请稍后', icon: 'none' });
  152. return;
  153. }
  154. uni.previewImage({
  155. urls: [that.posterUrl]
  156. });
  157. },
  158. }
  159. }
  160. </script>
  161. <style scoped lang="less">
  162. .page {
  163. box-sizing: border-box;
  164. background-size: 100% 100%;
  165. display: flex;
  166. flex-direction: column;
  167. align-items: center;
  168. padding-bottom: 150rpx;
  169. }
  170. .bottom-buttons {
  171. position: fixed;
  172. bottom: 0;
  173. left: 0;
  174. right: 0;
  175. display: flex;
  176. justify-content: space-between;
  177. padding: 20rpx 30rpx;
  178. padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
  179. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  180. background: #fff;
  181. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
  182. z-index: 100;
  183. .btn {
  184. flex: 1;
  185. height: 88rpx;
  186. border-radius: 44rpx;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. margin: 0 10rpx;
  191. font-size: 28rpx;
  192. font-family: PingFangSC, PingFang SC;
  193. font-weight: 500;
  194. color: #fff;
  195. line-height: 40rpx;
  196. cursor: pointer;
  197. .btn-icon {
  198. margin-right: 8rpx;
  199. }
  200. &:active {
  201. opacity: 0.8;
  202. transform: scale(0.98);
  203. }
  204. }
  205. .copy-btn {
  206. background: #33AFFC;
  207. }
  208. .save-btn {
  209. background: #1372FF;
  210. }
  211. .title {
  212. width: calc(100% - 98rpx);
  213. margin: 214rpx 49rpx 0;
  214. }
  215. .code {
  216. width: 460rpx;
  217. height: 460rpx;
  218. background: #FFFFFF;
  219. box-shadow: 0rpx 3rpx 32rpx 1rpx rgba(72, 139, 255, 0.27);
  220. border-radius: 20rpx 20rpx 20rpx 20rpx;
  221. padding: 40rpx;
  222. box-sizing: border-box;
  223. margin: 83rpx auto 0;
  224. image {
  225. width: 100%;
  226. height: 100%;
  227. }
  228. }
  229. .my-canvas {
  230. position: fixed;
  231. left: -1000px;
  232. top: -1000px;
  233. width: 750px;
  234. height: 1334px;
  235. }
  236. }
  237. </style>