new_file.vue 9.1 KB

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