CodeCreatePopup.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view
  3. class="code-mask" :style="{
  4. 'opacity': codePicUrl ? '1' : '0',
  5. 'z-index':
  6. codePicUrl ? '99' : '-1'
  7. }"
  8. >
  9. <view
  10. class="code-wrapper" :style="{
  11. transform: codePicUrl ? 'scale(1)' : 'scale(0)'
  12. }"
  13. >
  14. <view class="header">
  15. <view style="display: flex;justify-content: center;align-items: center;">
  16. <image
  17. class="header-icon"
  18. :src="userInfo.avatarUrl || require('../../static/images/new-user/default-user-avatar.png')" mode=""
  19. />
  20. <text>
  21. <text v-if="type === 'userInvitation'">我的邀请码:</text>
  22. <text v-if="type === 'franchiseeInvitation'">我的加盟商码:</text>
  23. <text v-else-if="type === 'shopInvitation'">我的商家码:</text>
  24. <text v-else-if="type === 'teamMembersInvitation'">我的社区邀请码:</text>
  25. </text>
  26. <text>
  27. <text v-if="type === 'userInvitation' || type === 'franchiseeInvitation' || type === 'shopInvitation' || type === 'teamMembersInvitation'">
  28. <text>{{ createCode }}</text>
  29. <text style="margin-left: 12upx;font-size: 26upx;color: #0061C8;" @click="$copy(createCode)">复制</text>
  30. </text>
  31. <text v-else></text>
  32. </text>
  33. </view>
  34. <view>
  35. 昵称:{{ userInfo.name || userInfo.wechatName }}&nbsp;&nbsp;&nbsp;&nbsp;用户ID:{{ userInfo.buyerUserId }}
  36. </view>
  37. </view>
  38. <view class="big-wrapper">
  39. <image src="../../static/images/user/center-logo.png" class="big-icon" />
  40. </view>
  41. <view class="images">
  42. <view class="zhiwen">
  43. <image src="../../static/images/icon/zhi.png" alt="" />
  44. <text>长按扫码</text>
  45. </view>
  46. <view style="text-align: center;">
  47. <image class="code" :src="codePicUrl" alt="" />
  48. <view
  49. v-if="type === 'userInvitation'" style="font-size: 26upx;color: #06a6f0;"
  50. @click="$copy(`${rootUrl}/#/pages/jump/jump?userId=${userInfo.buyerUserId}&type=bindingUser&code=${createCode}`)"
  51. >
  52. 复制链接
  53. </view>
  54. <view
  55. v-else-if="type === 'franchiseeInvitation'" style="font-size: 26upx;color: #06a6f0;"
  56. @click="$copy(`${rootUrl}/#/pages/jump/jump?userId=${userInfo.buyerUserId}&type=bindingUser&code=${createCode}`)"
  57. >
  58. 复制链接
  59. </view>
  60. <view
  61. v-else-if="type === 'shopInvitation'" style="font-size: 26upx;color: #06a6f0;"
  62. @click="$copy(`${rootUrl}/#/pages/jump/jump?userId=${userInfo.buyerUserId}&type=bindingShop&code=${createCode}`)"
  63. >
  64. 复制链接
  65. </view>
  66. <view
  67. v-else-if="type === 'teamMembersInvitation'" style="font-size: 26upx;color: #06a6f0;"
  68. @click="$copy(`${rootUrl}/#/pages/jump/jump?userId=${userInfo.buyerUserId}&type=bindingTeamMembers&code=${userInfo.phone}`)"
  69. >
  70. 复制链接
  71. </view>
  72. </view>
  73. </view>
  74. <button class="uni-btn" @click="(type = '') || (createCode = '') || (qrcodeUrl = '') || (codePicUrl = '')">
  75. 取消
  76. </button>
  77. </view>
  78. <!-- 生成二维码 -->
  79. <view v-if="qrcodeUrl && createCode">
  80. <uqrcode
  81. ref="uqrcode" class="generate-code-container" canvas-id="qrcode" :value="qrcodeUrl + createCode"
  82. @complete="handleCompleteCode"
  83. ></uqrcode>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. // import jsQR from 'jsqr'
  89. import { A_TF_MAIN } from '../../config'
  90. import { T_STORAGE_KEY } from '../../constant'
  91. import { getUserInfoCodeApi, getPlatformRelationshipCodeApi } from '../../api/anotherTFInterface'
  92. export default {
  93. name: 'CodeCreatePopup',
  94. props: {
  95. // type: {
  96. // type: String,
  97. // required: true
  98. // }
  99. },
  100. data() {
  101. return {
  102. rootUrl: A_TF_MAIN,
  103. userInfo: {},
  104. type: '',
  105. createCode: '',
  106. qrcodeUrl: '',
  107. codePicUrl: ''
  108. }
  109. },
  110. methods: {
  111. getCode(type) {
  112. if (!type) return
  113. this.type = type
  114. this.userInfo = uni.getStorageSync(T_STORAGE_KEY)
  115. uni.showLoading({
  116. title: '生成中...'
  117. })
  118. if (type === 'userInvitation') {
  119. getPlatformRelationshipCodeApi({})
  120. .then((res) => {
  121. this.createCode = res.data.invitationCode || ''
  122. this.qrcodeUrl = `${this.rootUrl}/#/pages/jump/jump?userId=${this.userInfo.buyerUserId}&type=bindingUser&code=`
  123. })
  124. } else if (type === 'franchiseeInvitation') {
  125. getPlatformRelationshipCodeApi({})
  126. .then((res) => {
  127. this.createCode = res.data.invitationCode || ''
  128. this.qrcodeUrl = `${this.rootUrl}/#/pages/jump/jump?userId=${this.userInfo.buyerUserId}&type=bindingFranchisee&code=`
  129. })
  130. } else if (type === 'shopInvitation') {
  131. this.createCode = this.userInfo.phone || ''
  132. this.qrcodeUrl = `${this.rootUrl}/#/pages/jump/jump?userId=${this.userInfo.buyerUserId}&type=bindingShop&code=`
  133. // this.$refs.uqrcode.make({})
  134. } else if (type === 'teamMembersInvitation') {
  135. getUserInfoCodeApi({
  136. type: 1
  137. }).then((res) => {
  138. this.createCode = res.data.invitationCode || ''
  139. this.qrcodeUrl = `${this.rootUrl}/#/pages/jump/jump?userId=${this.userInfo.buyerUserId}&type=bindingTeamMembers&code=`
  140. })
  141. }
  142. },
  143. // 完成
  144. handleCompleteCode(e) {
  145. if (e.success) {
  146. this.$refs.uqrcode.toTempFilePath({
  147. success: (res) => {
  148. this.codePicUrl = res.tempFilePath
  149. uni.hideLoading()
  150. }
  151. })
  152. }
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .generate-code-container {
  159. position: absolute;
  160. top: -10000upx;
  161. }
  162. .code-mask {
  163. position: fixed;
  164. top: 0;
  165. left: 0;
  166. width: 100vw;
  167. height: 100vh;
  168. display: flex;
  169. justify-content: center;
  170. align-items: center;
  171. background-color: rgba(0, 0, 0, 0.5);
  172. transition: all 350ms;
  173. opacity: 0;
  174. .code-wrapper {
  175. width: 600upx;
  176. padding: 30upx;
  177. box-sizing: border-box;
  178. background-color: #fff;
  179. border-radius: 20upx;
  180. transform: scale(0);
  181. transition: all 350ms;
  182. .images {
  183. display: flex;
  184. margin: 30upx 0;
  185. justify-content: space-around;
  186. .zhiwen {
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. flex-direction: column;
  191. color: #999999;
  192. image {
  193. width: 120upx;
  194. height: 120upx;
  195. margin-bottom: 10upx;
  196. }
  197. }
  198. image {
  199. width: 200upx;
  200. height: 200upx;
  201. object-fit: cover;
  202. }
  203. }
  204. .header {
  205. display: flex;
  206. flex-direction: column;
  207. justify-content: center;
  208. align-items: center;
  209. .header-icon {
  210. width: 60upx;
  211. height: 60upx;
  212. margin-right: 10px;
  213. border-radius: 50%;
  214. }
  215. }
  216. .big-wrapper {
  217. width: 100%;
  218. margin-top: 40upx;
  219. justify-content: center;
  220. display: flex;
  221. .big-icon {
  222. width: 280upx;
  223. height: 280upx;
  224. object-fit: cover;
  225. }
  226. }
  227. .code {
  228. width: 540upx;
  229. height: 540upx;
  230. object-fit: cover;
  231. // border-radius: 54upx;
  232. }
  233. .uni-btn {
  234. padding-top: 20upx;
  235. border-top: 1upx solid #ccc;
  236. font-size: 32upx;
  237. letter-spacing: 1em;
  238. color: #ccc;
  239. }
  240. }
  241. }
  242. </style>