Auth.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view v-if="isShow" class="maskAuth">
  3. <view>
  4. <view class="contentBox" :class="isAuth ? 'contentBox_bg2':''">
  5. <view class="contentMain">
  6. <text class="fixedTitle" :class="isAuth ? 'fixedTitle_plus':''" >{{isAuth ?'绑定团队':'身份认证'}}</text>
  7. <view v-if="isAuth">
  8. <view v-if="(userinfo.team_id && userinfo.team_id!==0) || team.name">
  9. <text class="fixedTitle2">你好</text>
  10. <text class="teamTitle">这里是 {{team.name}},请您 按照提示确认绑定。</text>
  11. </view>
  12. <view v-else>
  13. <text class="teamTitle">您现在还未加入任何团队</text>
  14. </view>
  15. </view>
  16. <view v-else>
  17. <input type="text" placeholder="输入您的名字" v-model="submit.name" class="authInput">
  18. <input type="idcard" placeholder="输入您的手机号或档案号" v-model="submit.cre_num" maxlength="11" class="authInput">
  19. </view>
  20. <text class="fixedTitle3">注释:请根据提示进行身份证 实名认证后,进行绑定团队</text>
  21. </view>
  22. <button v-if="!isAuth" type="primary" class="submitBtn" @click="submitAuth">去绑定团队</button>
  23. <button v-else type="primary" class="submitBtn" @click="submitSure">{{(userinfo.team_id && userinfo.team_id!==0) ? '确定团队' : '确定' }}</button>
  24. </view>
  25. <!-- <view>
  26. <image class="closeBtn" src="/static/auth_close.png" @click="handleClose"></image>
  27. </view> -->
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {toAuth,sureTeam} from '../api/index.js'
  33. import { mapState } from "vuex"
  34. export default{
  35. name:"auth",
  36. data(){
  37. return {
  38. isShow:false,
  39. submit:{
  40. name:'',
  41. cre_num: ''
  42. },
  43. team:{
  44. name:"",
  45. id:""
  46. },
  47. isAuth:false
  48. }
  49. },
  50. computed:{
  51. ...mapState(["userinfo"])
  52. },
  53. methods:{
  54. // 提交认证
  55. submitAuth(){
  56. const that = this
  57. let {name,cre_num} = this.submit
  58. name=name.trim()
  59. cre_num=cre_num.trim()
  60. if(!name){
  61. // 验证用户名,身份证不能为空且格式正确
  62. uni.showToast({
  63. title:"用户名不能为空",
  64. icon:"none",
  65. duration:2500
  66. })
  67. return false;
  68. }
  69. if(!cre_num){
  70. uni.showToast({
  71. title:"密码不能为空",
  72. icon:"none",
  73. duration:2500
  74. })
  75. return false;
  76. }
  77. const phonereg = /^1[3|4|5|7|8][0-9]\d{8}$/
  78. if(cre_num.length === 11){
  79. if(!phonereg.test(cre_num)){
  80. uni.showToast({
  81. title:"请输入正确的手机号",
  82. icon:"none",
  83. duration:2500
  84. })
  85. return false;
  86. }
  87. }else if(cre_num.length === 8){
  88. }else{
  89. if(!phonereg.test(cre_num)){
  90. uni.showToast({
  91. title:"请输入正确的手机号或档案号",
  92. icon:"none",
  93. duration:2500
  94. })
  95. return false;
  96. }
  97. }
  98. // 提交
  99. toAuth({
  100. name:name,
  101. cre_num:cre_num,
  102. openid:that.$store.state.openid
  103. }).then(res=>{
  104. const { error_code,msg } = res
  105. if(error_code===200){
  106. const { data,openid } = res
  107. const { token,teamname,teamid } = data
  108. that.$store.commit("change_token",token);
  109. uni.setStorage({
  110. key:"token",
  111. data:token
  112. })
  113. // 是否认证,是否确认团队
  114. uni.setStorage({
  115. key:"isSure",
  116. data:1
  117. })
  118. uni.setStorage({
  119. key:"sureTeam",
  120. data:teamname
  121. })
  122. that.$store.commit("change_openid",openid);
  123. this.isAuth=true
  124. that.team={
  125. name:teamname,
  126. id:teamid
  127. }
  128. }else{
  129. const len=this.submit.cre_num.length
  130. let {msg}=res
  131. if(len===11){
  132. msg="不存在该手机号,请换档案号试试"
  133. }else if(len===8){
  134. msg="不存在该档案号,请换手机号试试"
  135. }else{
  136. msg+=",手机号或档案号不正确"
  137. }
  138. uni.showToast({
  139. title:msg,
  140. icon:'none'
  141. })
  142. }
  143. })
  144. },
  145. handleOpen(){
  146. this.isShow=true
  147. },
  148. handleSure(){
  149. this.isAuth=true
  150. },
  151. handleTeam(){
  152. this.team.name=uni.getStorageSync("sureTeam")
  153. },
  154. handleClose(){
  155. if(uni.getStorageSync("isSure") ===0 || uni.getStorageSync("isSure")){
  156. uni.showToast({
  157. title:"请认证并确认团队",
  158. icon:"none"
  159. })
  160. }else{
  161. this.isShow=false
  162. }
  163. },
  164. // 确认团队
  165. submitSure(){
  166. const that = this
  167. sureTeam().then(res=>{
  168. const { error_code } = res;
  169. if(error_code===200){
  170. uni.removeStorage({
  171. key:"cert"
  172. })
  173. // 是否认证,是否确认团队
  174. uni.removeStorage({
  175. key:"isSure"
  176. })
  177. // 删除团队名
  178. uni.removeStorage({
  179. key:"sureTeam"
  180. })
  181. that.$store.dispatch("getUser");
  182. that.$parent.getMessageList();
  183. that.handleClose()
  184. }else{
  185. const {msg}=res
  186. uni.showToast({
  187. title:msg,
  188. icon:'none'
  189. })
  190. }
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style scoped lang="scss">
  197. .contentBox{
  198. width: 627rpx;
  199. height: 762rpx;
  200. background: url(../static/auth_bg.jpg);
  201. background-size: 100% 100%;
  202. border-radius: 4px;
  203. position: relative;
  204. }
  205. .contentBox_bg2{
  206. background: url(../static/auth_bg2.jpg);
  207. background-size: 100% 100%;
  208. }
  209. .closeBtn{
  210. display: block;
  211. width: 51rpx;
  212. height: 51rpx;
  213. margin: 0 auto;
  214. margin-top: 39rpx;
  215. }
  216. .contentMain{
  217. width: 503rox;
  218. height: 362rpx;
  219. background: url(../static/auth_bg2.png);
  220. background-size: 100% 100%;
  221. position: absolute;
  222. top: 166rpx;
  223. left: 50%;
  224. margin-left: -301rpx;
  225. padding: 60rpx 90rpx;
  226. color: #404040;
  227. font-size: 24rpx;
  228. }
  229. .fixedTitle{
  230. display: block;
  231. font-size: 30rpx;
  232. color: #666666;
  233. text-align: center;
  234. margin-bottom: 30rpx;
  235. }
  236. .fixedTitle_plus{
  237. margin-bottom: 40rpx;
  238. }
  239. .teamTitle{
  240. display: block;
  241. margin-top: 24rpx;
  242. margin-bottom: 50rpx;
  243. }
  244. .fixedTitle3{
  245. color: #929292;
  246. font-size: 20rpx;
  247. display: block;
  248. }
  249. .authInput{
  250. width: calc(100% - 40rpx);
  251. height: 70rpx;
  252. line-height: 70rpx;
  253. padding: 0 20rpx;
  254. font-size: 24rpx;
  255. border-radius: 3px;
  256. box-shadow:0px 0px 4rpx 0px rgba(141,141,141,1);
  257. margin-bottom: 40rpx;
  258. }
  259. .submitBtn{
  260. font-size: 28rpx;
  261. background: $uni-btn-bg-color;
  262. width: 237rpx;
  263. height: 70rpx;
  264. line-height: 70rpx;
  265. border-top-left-radius: 70rpx;
  266. border-bottom-left-radius: 70rpx;
  267. border-top-right-radius: 70rpx;
  268. border-bottom-right-radius: 70rpx;
  269. position: absolute;
  270. bottom: 39rpx;
  271. left: 50%;
  272. margin-left: -118.5rpx;
  273. }
  274. .maskAuth{
  275. position: fixed;
  276. top: 0;
  277. bottom: 0;
  278. left: 0;
  279. right: 0;
  280. background: rgba(0,0,0,.4);
  281. z-index: 999;
  282. display: flex;
  283. justify-content: center;
  284. align-items: center;
  285. }
  286. </style>