index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="bill-ward">
  3. <view
  4. v-for="(item, index) in posterConfig"
  5. :key="index"
  6. :style="backPosition(item)"
  7. >
  8. <image
  9. :style="item.css"
  10. v-if="(item.type == 0 || item.type == 2) && item.checked"
  11. :src="$method.splitImgHost(item.name)"
  12. mode=""
  13. />
  14. <view
  15. :style="item.css"
  16. v-if="item.type == 1"
  17. style="white-space: pre-wrap"
  18. >
  19. {{ item.name }}
  20. </view>
  21. <view class="code-box" v-if="item.type == 3">
  22. <tki-qrcode
  23. :cid="item.codeUrl"
  24. ref="qrcode"
  25. :val="item.codeUrl"
  26. :size="item.height * 2 - 20"
  27. unit="upx"
  28. background="#ffffff"
  29. foreground="#000000"
  30. pdground="#000000"
  31. :lv="3"
  32. :onval="true"
  33. :loadMake="true"
  34. />
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import { getSharePoster, bindLink } from "@/utils/bill";
  41. import { authorize, backOpenId } from "@/common/authorize";
  42. import { openidLogin } from "@/utils/login";
  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. uni.setStorageSync("BillHerf", window.location.href);
  57. },
  58. onShow() {
  59. this.backUrl();
  60. backOpenId(this.login);
  61. authorize();
  62. this.getSharePoster();
  63. },
  64. components: {
  65. tkiQrcode,
  66. },
  67. methods: {
  68. getSharePoster() {
  69. getSharePoster(this.options).then((res) => {
  70. this.billDetail = res;
  71. let posterConfig = JSON.parse(res.posterConfig);
  72. this.posterConfig = this.changeData(posterConfig);
  73. this.share(posterConfig);
  74. });
  75. },
  76. changeData(data) {
  77. Object.keys(data)
  78. .filter((key) => {
  79. if (key == "distribution" || key == "cardCode") {
  80. data[key].codeUrl =
  81. this.billDetail[
  82. key == "distribution" ? "urlCard" : "urlActivity"
  83. ];
  84. }
  85. return data[key].checked;
  86. })
  87. .forEach((key) => this.backStyle(data[key].css));
  88. return Object.values(data);
  89. },
  90. px2rpx(data) {
  91. if (!data.includes("px")) {
  92. return data;
  93. }
  94. return data.split("px")[0] * 2 + "rpx";
  95. },
  96. backPosition(item) {
  97. return {
  98. position: "absolute",
  99. left: item.left * 2 + "rpx",
  100. top: item.top * 2 + "rpx",
  101. width: item.width * 2 + "rpx",
  102. height: item.height * 2 + "rpx",
  103. };
  104. },
  105. backStyle(item) {
  106. Object.keys(item).forEach((e) => {
  107. item[e] = this.px2rpx(item[e]);
  108. });
  109. },
  110. bindLink() {
  111. bindLink({
  112. linkCode: this.options.linkCode,
  113. distributionId: this.options.distributionId,
  114. });
  115. },
  116. share(data) {
  117. wechat
  118. .share({
  119. title: this.billDetail.activityName,
  120. desc: data.advertise.name,
  121. imgUrl: this.$method.splitImgHost(data.goods.name),
  122. link: this.backUrl(),
  123. })
  124. .then((res) => {
  125. this.$method.isLogin() && this.bindLink();
  126. });
  127. },
  128. login(openid) {
  129. openidLogin({ openid }).then((data) => {
  130. this.$store.commit("LOGIN_CB", data);
  131. this.$store.dispatch("getUserInfo");
  132. });
  133. },
  134. backUrl() {
  135. let url = window.location.href;
  136. if (url.includes("&code")) {
  137. url = url.split("&code")[0];
  138. }
  139. return url;
  140. },
  141. },
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. .bill-ward {
  146. position: relative;
  147. .code-box {
  148. padding: 10rpx;
  149. background: #ffffff;
  150. box-sizing: border-box;
  151. }
  152. }
  153. </style>