index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="bill-ward">
  3. <view v-for="(item, index) in posterConfig" :key="index">
  4. <image
  5. :style="item.css"
  6. v-if="item.type == 0 && item.checked"
  7. :src="$method.splitImgHost(item.name, true)"
  8. mode=""
  9. />
  10. <view :style="backPosition(item)" style="white-space: pre-wrap">
  11. <view :style="item.css" v-if="item.type == 1">
  12. {{ item.name }}
  13. </view>
  14. </view>
  15. <view :style="backPosition(item)">
  16. <image
  17. :style="item.css"
  18. v-if="item.type == 2"
  19. :src="$method.splitImgHost(item.name, true)"
  20. mode=""
  21. />
  22. </view>
  23. <view class="code-box" v-if="item.type == 3" :style="backPosition(item)">
  24. <tki-qrcode
  25. :cid="item.codeUrl"
  26. ref="qrcode"
  27. :val="item.codeUrl"
  28. :size="item.height * 2 - 20"
  29. unit="upx"
  30. background="#ffffff"
  31. foreground="#000000"
  32. pdground="#000000"
  33. :lv="3"
  34. :onval="true"
  35. :loadMake="true"
  36. />
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { getSharePoster } from "@/utils/bill";
  43. import tkiQrcode from "tki-qrcode";
  44. import wechat from "@/common/wechat";
  45. export default {
  46. data() {
  47. return {
  48. options: {},
  49. posterConfig: [],
  50. billDetail: {},
  51. bg: {},
  52. };
  53. },
  54. onLoad(options) {
  55. this.options = options;
  56. this.getSharePoster();
  57. this.share();
  58. uni.setStorageSync("BillHerf", window.location.href);
  59. },
  60. components: {
  61. tkiQrcode,
  62. },
  63. methods: {
  64. getSharePoster() {
  65. getSharePoster(this.options).then((res) => {
  66. this.billDetail = res;
  67. this.posterConfig = this.changeData(JSON.parse(res.posterConfig));
  68. });
  69. },
  70. changeData(data) {
  71. Object.keys(data)
  72. .filter((key) => {
  73. if (key == "distribution" || key == "cardCode") {
  74. data[key].codeUrl =
  75. this.billDetail[
  76. key == "distribution" ? "urlCard" : "urlActivity"
  77. ];
  78. }
  79. return data[key].checked;
  80. })
  81. .forEach((key) => this.backStyle(data[key].css));
  82. return Object.values(data);
  83. },
  84. px2rpx(data) {
  85. if (!data.includes("px")) {
  86. return data;
  87. }
  88. return data.split("px")[0] * 2 + "rpx";
  89. },
  90. backPosition(item) {
  91. return {
  92. position: "absolute",
  93. left: item.left * 2 + "rpx",
  94. top: item.top * 2 + "rpx",
  95. width: item.width * 2 + "rpx",
  96. height: item.height * 2 + "rpx",
  97. };
  98. },
  99. backStyle(item) {
  100. Object.keys(item).forEach((e) => {
  101. item[e] = this.px2rpx(item[e]);
  102. });
  103. },
  104. share() {
  105. //分享微信好友
  106. wechat.share({
  107. title: "穷期先生的名片",
  108. desc: "拥有多年财富管理经验的理财专家",
  109. imgUrl: "",
  110. link: "h.xyyxt.net",
  111. });
  112. },
  113. },
  114. };
  115. </script>
  116. <style lang="scss" scoped>
  117. .bill-ward {
  118. position: relative;
  119. .code-box {
  120. padding: 10rpx;
  121. background: #ffffff;
  122. box-sizing: border-box;
  123. }
  124. }
  125. </style>