invite-proxy.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view class="invite-proxy">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
  4. <view class="content">
  5. <view v-if="!logged" class="app-item item">
  6. <text>邀请人</text>
  7. <text>{{ recom_nickname }}</text>
  8. </view>
  9. <view v-if="!logged" class="app-item item">
  10. <text>邀请码</text>
  11. <text>{{ invite_code }}</text>
  12. </view>
  13. <view v-if="!logged" class="app-item item">
  14. <text>联系方式</text>
  15. <text>{{ recom_mobile }}</text>
  16. </view>
  17. <view v-if="!logged" class="form">
  18. <navigator url="../phone-area/phone-area" class="phone-area">
  19. <text class="text">国家/地区</text>
  20. <text class="area">{{ areaName }}({{ areaCode == '86' ? '+' : '' }}{{ areaCode }})</text>
  21. <text class="icon cuIcon-right"></text>
  22. </navigator>
  23. <view class="item">
  24. <text class="icon cuIcon-mobilefill"></text>
  25. <input maxlength="11" type="number" v-model="phone" placeholder="请输入手机号" />
  26. <text v-if="phone" class="cuIcon-roundclosefill" @tap="clearPhone"></text>
  27. </view>
  28. <view class="item">
  29. <text class="icon cuIcon-markfill"></text>
  30. <input maxlength="6" type="number" v-model="verifycode" placeholder="请输入6位验证码" />
  31. <text v-if="verifycode" class="cuIcon-roundclosefill" @tap="clearVerify"></text>
  32. <view class="countdown" @tap="getCode">
  33. 发送验证码 <text v-if="countDown">{{ ' ' + countDown }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. <view v-if="!logged" class="app-item item item-space">
  38. <text>微信昵称</text>
  39. <input v-model="wx_nickname" placeholder="请填写微信昵称" />
  40. </view>
  41. <view v-if="!logged" class="app-item item">
  42. <text>真实姓名</text>
  43. <input v-model="real_name" maxlength="32" placeholder="请填写真实姓名" />
  44. </view>
  45. <view v-if="!logged" class="app-item item">
  46. <text>身份证号</text>
  47. <input type="text" @input="inputChange" v-model="id_card_num" maxlength="18" placeholder="请填写身份证号" />
  48. </view>
  49. <button v-if="isREG && !logged" class="big-btn bg" @tap="submit">立即加入</button>
  50. <view id="erweima" style="display: none;"></view>
  51. <image style="width: 0; height: 0;" src="../../static/avatar.jpg"></image>
  52. <view id="imgWrapper">
  53. <image class="showCan" v-if="src" :src="src" ></image>
  54. </view>
  55. <view v-if="logged" class="basecolor sharetext">{{ src ? '长按二维码发送给代理即可邀请加入' : '' }}</view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import { _API_GetVerifyCode, _API_Reg, _API_Login, _API_LoginWX, _API_GzhWebInit } from '@/apis/verify.js'
  61. import { _API_SubAuthInfo } from '@/apis/user.js'
  62. export default {
  63. data() {
  64. return {
  65. title: '欢迎加入大卫博士',
  66. recom_nickname: '',
  67. recom_mobile: '',
  68. invite_code: '',
  69. wx_nickname: '',
  70. real_name: '',
  71. id_card_num: '',
  72. areaName: '中国大陆', // 手机号地区名称
  73. areaCode: '86', // 手机号地区代码
  74. phone: '', // 手机号
  75. verifycode: '', // 验证码
  76. countDown: 0, // 倒计时
  77. isREG: true,
  78. src: ''
  79. };
  80. },
  81. computed: {
  82. logged() { return this.$store.state.app.token }
  83. },
  84. created() {
  85. uni.showLoading({ mask: true })
  86. uni.$on('CHOOSEPHONECODE', (name, code) => { // 监听 chooseArea 事件更新
  87. this.areaName = name // 修改选择的手机号地区名称
  88. this.areaCode = code // 修改选择的手机号地区代码
  89. })
  90. if (this.$store.state.app.token) {
  91. const script = document.createElement('script')
  92. script.type = 'text/javascript'
  93. script.src = 'http://res.wx.qq.com/open/js/jweixin-1.4.0.js'
  94. document.getElementsByTagName('head')[0].appendChild(script)
  95. script.onload = () => {
  96. _API_GzhWebInit().then(res => {
  97. window.history.replaceState({}, '', res.url.split('.cn')[1])
  98. setTimeout(() => {
  99. const img = document.getElementsByTagName('img')[0]
  100. $('#erweima').qrcode({ width: 333, height: 333, text: res.url })
  101. document.getElementsByTagName('canvas')[0].getContext('2d').drawImage(img, 123, 123, 80, 80)
  102. wx.config(res)
  103. wx.ready(() => {
  104. wx.updateAppMessageShareData({
  105. title: `我是${this.$store.state.userinfo.nickname}, 邀请你加入大卫博士`,
  106. desc: '传递健康,改变命运。',
  107. link: res.url,
  108. imgUrl: 'http://api.app.jiuweiyun.cn/public/uploads/logo.jpg'
  109. })
  110. })
  111. wx.error(res => window.history.replaceState({}, '', `/api/gzh/david`))
  112. uni.hideLoading()
  113. const can = document.createElement('canvas')
  114. const pixelRatio = window.devicePixelRatio || 1;
  115. const ctx = can.getContext('2d')
  116. const backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
  117. ctx.mozBackingStorePixelRatio ||
  118. ctx.msBackingStorePixelRatio ||
  119. ctx.oBackingStorePixelRatio ||
  120. ctx.backingStorePixelRatio || 1;
  121. const ratio = pixelRatio / backingStoreRatio;
  122. can.width = uni.upx2px(680) * ratio
  123. can.height = uni.upx2px(960) * ratio
  124. can.style.width = uni.upx2px(680) + 'px'
  125. can.style.height = uni.upx2px(960) + 'px'
  126. ctx.scale(ratio, ratio);
  127. ctx.fillStyle="#ffffff";
  128. ctx.fillRect(0, 0, uni.upx2px(680), uni.upx2px(960));
  129. ctx.fillStyle="#000000";
  130. ctx.font=`${uni.upx2px(42)}px Arial`;
  131. ctx.textAlign="center";
  132. ctx.drawImage(img, uni.upx2px(276), uni.upx2px(16), uni.upx2px(128), uni.upx2px(128))
  133. ctx.fillText(`“${this.recom_nickname.length > 18 ? this.recom_nickname.slice(0, 18) + '...' : this.recom_nickname }”`, uni.upx2px(340), uni.upx2px(206))
  134. ctx.fillStyle="#333333";
  135. ctx.font=`${uni.upx2px(36)}px Arial`;
  136. ctx.fillText(`邀请你加入大卫博士`, uni.upx2px(340), uni.upx2px(271))
  137. ctx.drawImage(document.getElementsByTagName('canvas')[0], uni.upx2px(80), uni.upx2px(332), uni.upx2px(517), uni.upx2px(518))
  138. ctx.font=`${uni.upx2px(36)}px Arial`;
  139. ctx.fillStyle="#F76454";
  140. ctx.fillText(`长按-识别二维码-填写信息`, uni.upx2px(340), uni.upx2px(910))
  141. this.src = can.toDataURL("image/png")
  142. }, 567)
  143. })
  144. }
  145. } else {
  146. uni.hideLoading()
  147. }
  148. },
  149. onLoad({ nickname, mobile, invite_code }) {
  150. this.recom_nickname = decodeURIComponent(nickname)
  151. this.recom_mobile = mobile
  152. this.invite_code = invite_code
  153. if (!this.recom_nickname || !this.recom_mobile || !this.invite_code) {
  154. uni.showToast({ title: '用户信息获取失败,请重新登陆' })
  155. uni.navigateBack()
  156. }
  157. },
  158. methods: {
  159. inputChange() {
  160. this.id_card_num = this.id_card_num.trim()
  161. },
  162. getCode() { // 点击获取手机验证码
  163. if (this.phone.length) { // 手机号是否输入
  164. if (this.countDown) { // 如果正在倒计时
  165. uni.toast('验证码已发送,请稍后重试')
  166. } else {
  167. uni.showLoading({ mask: true }) // 显示 loading
  168. _API_GetVerifyCode({ mobile: this.phone, code: this.areaCode, type: 'invite' }).then(res => {
  169. if (res.code == 200) {
  170. if (res.data.status == 0) { // 登录 // 0、 1 代表用户是登录 或 注册
  171. this.isREG = false // 隐藏提交
  172. uni.toast('该手机号已注册!请直接登陆!') // 提示邀请码发送成功
  173. } else {
  174. this.isREG = true // 显示提交
  175. uni.toast('验证码发送成功') // 提示邀请码发送成功
  176. this.countDown = 120 // 倒计时时长
  177. this.timer = setInterval(() => { // 开始倒计时
  178. this.countDown --
  179. if (this.countDown <= 0) { // 倒计时结束清除倒计时
  180. this.countDown = 0
  181. clearInterval(this.timer)
  182. }
  183. }, 1000)
  184. }
  185. } else if (res.code == 900) {
  186. this.isREG = false // 隐藏提交
  187. uni.toast('该手机号已注册!请直接登陆!') // 提示邀请码发送成功
  188. } else { // code 300 表示禁止获取验证码,禁止登陆
  189. uni.toast('获取验证码失败')
  190. }
  191. })
  192. }
  193. } else {
  194. uni.toast('手机号格式不正确,请重新输入')
  195. }
  196. },
  197. submit() { // 点击登录/注册
  198. if (!this.phone.length) { uni.toast('手机号格式不正确,请重新输入'); return }
  199. if (!(this.verifycode.length == 6)) { uni.toast('验证码格式不正确,请重新输入'); return }
  200. if (!this.wx_nickname.length) {
  201. uni.toast('微信昵称不能为空')
  202. return
  203. }
  204. if (!this.real_name.match(/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/)) {
  205. uni.toast('真实姓名不符合要求')
  206. return
  207. }
  208. if (!this.id_card_num.match(/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/)) {
  209. uni.toast('身份号码不合法')
  210. return
  211. }
  212. uni.showLoading({ mask: true }) // 显示 loading
  213. if (!this.requesting) {
  214. this.requesting = true
  215. setTimeout(() => this.requesting = false, 567)
  216. _API_Reg({
  217. mobile: this.phone,
  218. verify_code: this.verifycode,
  219. recom_code: this.invite_code,
  220. code: this.areaCode
  221. }).then(res => {
  222. uni.showLoading({ mask: true }) // 显示 loading
  223. if (res.code == 200) { // 注册成功
  224. this.$store.commit('app/LOGIN', res.data.token) // 保存 token
  225. _API_SubAuthInfo({ // 提交信息
  226. wechatname: this.wx_nickname,
  227. realname: this.real_name,
  228. cre_num: this.id_card_num
  229. }).then(res => {
  230. if (res.code === 200) { // 提交成功
  231. this.$store.commit('userinfo/UPDATA_USERINFO', { cert_status: 1 })
  232. uni.redirectTo({ url:'../auth-progress/auth-progress' }) // redirect 到 审核进度页面
  233. } else if (res.code === 300) {
  234. uni.showToast({ title: res.message })
  235. }
  236. })
  237. } else if (res.code == 300) { // 验证码不正确
  238. uni.toast('验证码错误')
  239. }
  240. })
  241. }
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .invite-proxy {
  248. @include page();
  249. .content {
  250. #imgWrapper {
  251. flex: 1;
  252. @include flex();
  253. .showCan {
  254. width: 680rpx;
  255. height: 960rpx;
  256. border-radius: 14rpx;
  257. box-shadow:0px 0px 23px 2px rgba(194,133,58,0.5);
  258. }
  259. }
  260. .sharetext {
  261. font-size: 88rpx;
  262. text-align: center;
  263. margin: 8rpx 0;
  264. box-sizing: border-box;
  265. padding: 0 24rpx;
  266. }
  267. .form {
  268. padding: 30rpx;
  269. margin-top: 10rpx;
  270. box-sizing: border-box;
  271. background-color: #FFFFFF;
  272. .phone-area {
  273. @include flex();
  274. justify-content: space-between;
  275. .text {
  276. font-size: 32rpx;
  277. }
  278. .area {
  279. color: #42b983;
  280. }
  281. }
  282. .item {
  283. @include flex();
  284. height: 110rpx;
  285. padding-top: 20rpx;
  286. box-sizing: border-box;
  287. color: $app-sec-text-color;
  288. border-bottom: 1rpx solid #B2B2B2;
  289. .icon, .cuIcon-roundclosefill {
  290. margin: 0 20rpx;
  291. font-size: 36rpx;
  292. }
  293. input {
  294. flex: 1;
  295. height: 84rpx;
  296. margin-left: 15rpx;
  297. }
  298. .countdown {
  299. @include flex();
  300. height: 50rpx;
  301. font-size: 24rpx;
  302. padding: 0 20rpx;
  303. background: #FFEFF0;
  304. margin-right: 20rpx;
  305. border-radius: 33rpx;
  306. color: $app-base-color;
  307. text {
  308. margin-left: 8rpx;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. </style>