index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="merchantCode">
  3. <view class="code-list">
  4. <view class="code-item" @click="goCodeDetail(0)">
  5. <view class="code-illustrate">
  6. <image class="" :src="shopInfo.shopLogo" />
  7. <text>商家店铺码</text>
  8. </view>
  9. <view class="code-img">
  10. <canvas canvas-id="shopCode"></canvas>
  11. </view>
  12. </view>
  13. <view class="code-item" @click="goCodeDetail(1)">
  14. <view class="code-illustrate">
  15. <image class="" :src="shopInfo.shopLogo" />
  16. <text>商家收款码</text>
  17. </view>
  18. <view class="code-img">
  19. <image class="" :src="payCode" />
  20. </view>
  21. </view>
  22. <view class="code-item" @click="goCodeDetail(2)">
  23. <view class="code-illustrate">
  24. <image class="" :src="shopInfo.shopLogo" />
  25. <text>兑换专区码</text>
  26. </view>
  27. <view class="code-img">
  28. <canvas canvas-id="exchangeCode"></canvas>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. // 将 dist 目录下,weapp.qrcode.esm.js 复制到项目目录中
  36. import drawQrcode from "@/static/js/qrcode.js";
  37. import { getShopQrcode } from "@/config/index.js";
  38. export default {
  39. created() {
  40. this.getCode();
  41. },
  42. beforeMount() {
  43. // 获取本地存储的数据
  44. this.shopInfo = uni.getStorageSync("shopInfo");
  45. const { shopId, shopName } = this.shopInfo;
  46. // 生成店铺码
  47. this.setCode(
  48. `https://www.tuanfengkeji.cn/TFShop_Uni_H5/#/another-tf/another-user/shop/shop-detail?shopId=${shopId}`,
  49. "shopCode"
  50. );
  51. // 生成兑换码
  52. this.setCode(
  53. `https://test.tuanfengkeji.cn/TFShop_Uni_H5/#/another-tf/another-user/exchange/index?shopId=${shopId}&shopName=${shopName}`,
  54. "exchangeCode"
  55. );
  56. },
  57. data() {
  58. return {
  59. shopInfo: {},
  60. payCode: "",
  61. };
  62. },
  63. methods: {
  64. async getCode() {
  65. // 获取收款二维码
  66. let res = await getShopQrcode({ codeType: 1, state: 1 });
  67. this.payCode = res.data.shopCode;
  68. },
  69. // 生成二维码
  70. setCode(url, id) {
  71. drawQrcode({
  72. width: 100,
  73. height: 100,
  74. canvasId: id,
  75. // ctx: wx.createCanvasContext('myQrcode'),
  76. text: url,
  77. });
  78. },
  79. goCodeDetail(type){
  80. switch(type){
  81. case 0:
  82. uni.setStorageSync('code',`https://www.tuanfengkeji.cn/TFShop_Uni_H5/#/another-tf/another-user/shop/shop-detail?shopId=${this.shopInfo.shopId}`)
  83. break;
  84. case 1:
  85. uni.setStorageSync('code',this.payCode)
  86. break;
  87. case 2:
  88. uni.setStorageSync('code',`https://test.tuanfengkeji.cn/TFShop_Uni_H5/#/another-tf/another-user/exchange/index?shopId=${this.shopInfo.shopId}&shopName=${this.shopInfo.shopName}`)
  89. break;
  90. }
  91. // mixin 中的跳转
  92. this.navigateTo(`/user_module/codeDetail/index?type=${type}`);
  93. }
  94. },
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. .merchantCode {
  99. width: 100vw;
  100. min-height: 100vh;
  101. background-color: rgb(247, 247, 247);
  102. padding-top: 10rpx;
  103. box-sizing: border-box;
  104. .code-list {
  105. width: 100%;
  106. padding: 0 32rpx;
  107. box-sizing: border-box;
  108. .code-item {
  109. width: 100%;
  110. margin-top: 32rpx;
  111. border-radius: 16rpx;
  112. height: 250rpx;
  113. position: relative;
  114. .code-illustrate {
  115. position: absolute;
  116. top: 28rpx;
  117. left: 28rpx;
  118. @include flex(center, null, 22rpx);
  119. image {
  120. width: 72rpx;
  121. height: 72rpx;
  122. border-radius: 50%;
  123. border: 4rpx solid #ffffff;
  124. }
  125. text {
  126. color: #ffffff;
  127. font-size: 28rpx;
  128. font-weight: 700;
  129. }
  130. }
  131. .code-img {
  132. position: absolute;
  133. top: 50%;
  134. transform: translateY(-50%);
  135. right: 58rpx;
  136. /* border: 6rpx solid rgba(255, 255, 255, 0.3); */
  137. image {
  138. width: 200rpx;
  139. height: 200rpx;
  140. }
  141. canvas {
  142. width: 200rpx;
  143. height: 200rpx;
  144. }
  145. }
  146. &:nth-of-type(2) {
  147. .code-img {
  148. border: 0;
  149. }
  150. }
  151. &:nth-of-type(1) {
  152. background: linear-gradient(91deg, #24c4ef 0%, #46a8f7 99%);
  153. box-shadow: 0px 0px 10px 0px rgba(68, 169, 246, 0.5);
  154. }
  155. &:nth-of-type(2) {
  156. background: linear-gradient(91deg, #fc8857 0%, #fe5225 99%);
  157. box-shadow: 0px 0px 10px 0px rgba(254, 83, 38, 0.5);
  158. }
  159. &:nth-of-type(3) {
  160. background: linear-gradient(91deg, #7adbcf 0%, #46c9a3 99%);
  161. box-shadow: 0px 0px 10px 0px rgba(71, 201, 164, 0.5);
  162. }
  163. }
  164. }
  165. }
  166. </style>