invite-proxy.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="invite-proxy">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
  4. <view class="content">
  5. <view class="app-item item">
  6. <text>邀请人</text>
  7. <text>{{ recom_nickname }}</text>
  8. </view>
  9. <view class="app-item item">
  10. <text>邀请码</text>
  11. <text>{{ invite_code }}</text>
  12. </view>
  13. <view 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 class="showCan" v-if="src" :src="src" ></image>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import { _API_GetVerifyCode, _API_Reg, _API_Login, _API_LoginWX, _API_GzhWebInit } from '@/apis/verify.js'
  57. import { _API_SubAuthInfo } from '@/apis/user.js'
  58. export default {
  59. data() {
  60. return {
  61. title: '欢迎加入大卫博士',
  62. recom_nickname: '',
  63. recom_mobile: '',
  64. invite_code: '',
  65. wx_nickname: '',
  66. real_name: '',
  67. id_card_num: '',
  68. areaName: '中国大陆', // 手机号地区名称
  69. areaCode: '86', // 手机号地区代码
  70. phone: '', // 手机号
  71. verifycode: '', // 验证码
  72. countDown: 0, // 倒计时
  73. isREG: true,
  74. src: ''
  75. };
  76. },
  77. computed: {
  78. logged() { return this.$store.state.app.token }
  79. },
  80. created() {
  81. uni.showLoading({ mask: true })
  82. uni.$on('CHOOSEPHONECODE', (name, code) => { // 监听 chooseArea 事件更新
  83. this.areaName = name // 修改选择的手机号地区名称
  84. this.areaCode = code // 修改选择的手机号地区代码
  85. })
  86. if (this.$store.state.app.token) {
  87. const script = document.createElement('script')
  88. script.type = 'text/javascript'
  89. script.src = 'http://res.wx.qq.com/open/js/jweixin-1.4.0.js'
  90. document.getElementsByTagName('head')[0].appendChild(script)
  91. script.onload = () => {
  92. _API_GzhWebInit().then(res => {
  93. console.log(res)
  94. window.history.replaceState({}, '', `/api/gzh/${encodeURIComponent(this.recom_nickname)}/${this.recom_mobile}/${this.invite_code}/${res.timestamp}`)
  95. setTimeout(() => {
  96. $('#erweima').qrcode({ width: 333, height: 333, text: window.location.href })
  97. wx.config(res)
  98. wx.ready(() => {
  99. wx.updateAppMessageShareData({
  100. title: `我是${this.$store.state.userinfo.nickname}, 邀请你加入大卫博士`,
  101. desc: '传递健康,改变命运。',
  102. link: window.location.href,
  103. imgUrl: 'http://api.app.jiuweiyun.cn/public/uploads/logo.jpg',
  104. success () {
  105. uni.hideLoading()
  106. }
  107. })
  108. })
  109. wx.error(res => {
  110. uni.hideLoading()
  111. window.history.replaceState({}, '', `/api/gzh/david`)
  112. this.src = document.getElementsByTagName('canvas')[0].toDataURL("image/png")
  113. alert('微信分享初始化失败,请分享二维码给好友以邀请')
  114. })
  115. }, 123)
  116. })
  117. }
  118. } else {
  119. uni.hideLoading()
  120. }
  121. },
  122. onLoad({ data }) {
  123. this.recom_nickname = JSON.parse(data).nickname
  124. this.recom_mobile = JSON.parse(data).mobile
  125. this.invite_code = JSON.parse(data).invite_code
  126. window.history.replaceState({}, '', `/api/gzh/${encodeURIComponent(this.recom_nickname)}/${encodeURIComponent(this.recom_mobile)}/${encodeURIComponent(this.invite_code)}`)
  127. },
  128. methods: {
  129. inputChange() {
  130. this.id_card_num = this.id_card_num.trim()
  131. },
  132. getCode() { // 点击获取手机验证码
  133. if (this.phone.length) { // 手机号是否输入
  134. if (this.countDown) { // 如果正在倒计时
  135. uni.toast('验证码已发送,请稍后重试')
  136. } else {
  137. uni.showLoading({ mask: true }) // 显示 loading
  138. _API_GetVerifyCode({ mobile: this.phone, code: this.areaCode, type: 'invite' }).then(res => {
  139. if (res.code == 200) {
  140. if (res.data.status == 0) { // 登录 // 0、 1 代表用户是登录 或 注册
  141. this.isREG = false // 隐藏提交
  142. uni.toast('该手机号已注册!请直接登陆!') // 提示邀请码发送成功
  143. } else {
  144. this.isREG = true // 显示提交
  145. uni.toast('验证码发送成功') // 提示邀请码发送成功
  146. this.countDown = 120 // 倒计时时长
  147. this.timer = setInterval(() => { // 开始倒计时
  148. this.countDown --
  149. if (this.countDown <= 0) { // 倒计时结束清除倒计时
  150. this.countDown = 0
  151. clearInterval(this.timer)
  152. }
  153. }, 1000)
  154. }
  155. } else if (res.code == 900) {
  156. this.isREG = false // 隐藏提交
  157. uni.toast('该手机号已注册!请直接登陆!') // 提示邀请码发送成功
  158. } else { // code 300 表示禁止获取验证码,禁止登陆
  159. uni.toast('获取验证码失败')
  160. }
  161. })
  162. }
  163. } else {
  164. uni.toast('手机号格式不正确,请重新输入')
  165. }
  166. },
  167. submit() { // 点击登录/注册
  168. if (!this.phone.length) { uni.toast('手机号格式不正确,请重新输入'); return }
  169. if (!(this.verifycode.length == 6)) { uni.toast('验证码格式不正确,请重新输入'); return }
  170. if (!this.wx_nickname.length) {
  171. uni.toast('微信昵称不能为空')
  172. return
  173. }
  174. if (!this.real_name.match(/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/)) {
  175. uni.toast('真实姓名不符合要求')
  176. return
  177. }
  178. 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]$/)) {
  179. uni.toast('身份号码不合法')
  180. return
  181. }
  182. uni.showLoading({ mask: true }) // 显示 loading
  183. _API_Reg({
  184. mobile: this.phone,
  185. verify_code: this.verifycode,
  186. recom_code: this.invite_code,
  187. code: this.areaCode
  188. }).then(res => {
  189. uni.showLoading({ mask: true }) // 显示 loading
  190. if (res.code == 200) { // 注册成功
  191. this.$store.commit('app/LOGIN', res.data.token) // 保存 token
  192. _API_SubAuthInfo({ // 提交信息
  193. wechatname: this.wx_nickname,
  194. realname: this.real_name,
  195. cre_num: this.id_card_num
  196. }).then(res => {
  197. if (res.code === 200) { // 提交成功
  198. this.$store.commit('userinfo/UPDATA_USERINFO', { cert_status: 1 })
  199. uni.redirectTo({ url:'../auth-progress/auth-progress' }) // redirect 到 审核进度页面
  200. } else if (res.code === 300) {
  201. uni.showToast({ title: res.message })
  202. }
  203. })
  204. } else if (res.code == 300) { // 验证码不正确
  205. uni.toast('验证码错误')
  206. }
  207. })
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .invite-proxy {
  214. @include page();
  215. .showCan {
  216. width: 90vw;
  217. height: 90vw;
  218. margin: 5vw;
  219. }
  220. .content {
  221. .form {
  222. padding: 30rpx;
  223. margin-top: 10rpx;
  224. box-sizing: border-box;
  225. background-color: #FFFFFF;
  226. .phone-area {
  227. @include flex();
  228. justify-content: space-between;
  229. .text {
  230. font-size: 32rpx;
  231. }
  232. .area {
  233. color: #42b983;
  234. }
  235. }
  236. .item {
  237. @include flex();
  238. height: 110rpx;
  239. padding-top: 20rpx;
  240. box-sizing: border-box;
  241. color: $app-sec-text-color;
  242. border-bottom: 1rpx solid #B2B2B2;
  243. .icon, .cuIcon-roundclosefill {
  244. margin: 0 20rpx;
  245. font-size: 36rpx;
  246. }
  247. input {
  248. flex: 1;
  249. height: 84rpx;
  250. margin-left: 15rpx;
  251. }
  252. .countdown {
  253. @include flex();
  254. height: 50rpx;
  255. font-size: 24rpx;
  256. padding: 0 20rpx;
  257. background: #FFEFF0;
  258. margin-right: 20rpx;
  259. border-radius: 33rpx;
  260. color: $app-base-color;
  261. text {
  262. margin-left: 8rpx;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. </style>