index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <view class="login main-bg shadow">
  3. <view class="header header-long-bg">
  4. <view class="header-text font-forty font-color1">Hi</view>
  5. <view class="header-text font-forty font-color1">惠军通欢迎您</view>
  6. <image class="header-img" src="../../static/logo9.png"></image>
  7. <!-- <image class="header-title" src="../../static/logo5.png"></image> -->
  8. <view class="login-form">
  9. <view class="login-form-title font-forty font-color2">
  10. <!-- 登录 -->
  11. <u-tabs
  12. :list="tabsList"
  13. :is-scroll="false"
  14. :current="current"
  15. font-size="40"
  16. active-color="#2E4F1C"
  17. inactive-color="#2E4F1C"
  18. bar-width="50"
  19. bar-height="8"
  20. @change="change"></u-tabs>
  21. </view>
  22. <view class="login-form-view">
  23. <u-form :model="form" ref="uForm" :rules="rules">
  24. <u-form-item
  25. :leftIconStyle="{color: '#2E4F1C', fontSize: '40rpx'}"
  26. left-icon="account-fill"
  27. label-width="180"
  28. :label-position="labelPosition"
  29. prop="userName">
  30. <u-input
  31. v-model="form.userName"
  32. placeholder-style="color: #2E4F1C;"
  33. :placeholder="namePlaceholder" />
  34. </u-form-item>
  35. <u-form-item
  36. prop="userPWD"
  37. label-width="180"
  38. :label-position="labelPosition">
  39. <view class="form-item">
  40. <image src="../../static/idcard.png" class="form-img"></image>
  41. <u-input
  42. v-model="form.userPWD"
  43. placeholder-style="color: #2E4F1C;"
  44. :type="type11"
  45. :placeholder="pwdPlaceholder" />
  46. </view>
  47. </u-form-item>
  48. <u-form-item :label-position="labelPosition" v-if="radioShow">
  49. <u-radio-group v-model="radio" @change="radioGroupChange" :wrap="radioCheckWrap" active-color="#2E4F1C">
  50. <u-radio shape="circle" v-for="(item, index) in radioList" key="index" :name="item.id">{{ item.name }}</u-radio>
  51. </u-radio-group>
  52. </u-form-item>
  53. </u-form>
  54. <view class="font-twenty-two font-color2" style="text-align: center;" @click="gotoDetails">请认真阅读平台服务协议《服务及隐私协议》使用平台</view>
  55. <view @click="submit" class="form-submit">立即登录</view>
  56. </view>
  57. </view>
  58. </view>
  59. <u-toast ref="uToast" />
  60. </view>
  61. </template>
  62. <script>
  63. import { mapState, mapMutations } from 'vuex';
  64. import server from "@/api/index";
  65. export default {
  66. components: {},
  67. data() {
  68. return {
  69. gotoAdd: null,
  70. person_id: null,
  71. type11: 'text',
  72. labelPosition: 'left',
  73. namePlaceholder: '',
  74. pwdPlaceholder: '',
  75. radioCheckWrap: false,
  76. tabsList:[],
  77. radioShow: false,
  78. radioList: [
  79. {
  80. name: '军人',
  81. id: '2',
  82. checked: true,
  83. disabled: false
  84. },
  85. {
  86. name: '优抚对象',
  87. id: '3',
  88. checked: false,
  89. disabled: false
  90. },
  91. // {
  92. // name: '商铺',
  93. // id: '1',
  94. // checked: false,
  95. // disabled: false
  96. // },
  97. // {
  98. // name: '管理员',
  99. // id: '4',
  100. // checked: false,
  101. // disabled: false
  102. // }
  103. ],
  104. radio: '2',
  105. type: '2',
  106. current: 0,
  107. form: {
  108. userName: '',
  109. userPWD: '',
  110. type: ''
  111. },
  112. rules: {
  113. userName: [
  114. {
  115. required: true,
  116. message: '请输入!',
  117. trigger: ['change','blur'],
  118. }
  119. ],
  120. userPWD: [
  121. {
  122. required: true,
  123. message: '请输入!',
  124. trigger: ['change','blur']
  125. }
  126. ]
  127. }
  128. }
  129. },
  130. onReady() {
  131. this.$refs.uForm.setRules(this.rules);
  132. },
  133. onLoad(e) {
  134. this.person_id = e.id;
  135. console.log('e.type', e.type)
  136. if(e.type){
  137. this.gotoAdd = e.type
  138. }
  139. if(e.id === '2'){
  140. this.tabsList=[{name: '登录'}, {name: '注册'}];
  141. this.radioShow = true;
  142. }else{
  143. this.tabsList=[{name: '登录'}];
  144. this.radioShow = false;
  145. }
  146. this.radioGroupChange(e.id);
  147. },
  148. onShow() {
  149. this.current = 0;
  150. // this.radioGroupChange('军人')
  151. },
  152. methods:{
  153. ...mapMutations(['setRole']),
  154. change(index) {
  155. console.log(index)
  156. this.current = index;
  157. if(index === 1){
  158. uni.navigateTo({
  159. url: '/pages/soldier/home/identity?id=' + '123'
  160. })
  161. }
  162. },
  163. gotoDetails(){
  164. uni.navigateTo({
  165. url: '/pages/soldier/home/yxDetails'
  166. })
  167. },
  168. // radio选择发生变化
  169. radioGroupChange(e) {
  170. this.type = e;
  171. // this.radio =e;
  172. if(e === '2' || e === '3'){
  173. this.namePlaceholder = '请输入姓名';
  174. this.pwdPlaceholder = '请输入身份证号后四位';
  175. this.type11 = 'text';
  176. }else if(e === '1' || e === '4'){
  177. this.namePlaceholder = '请输入账号';
  178. this.pwdPlaceholder = '请输入密码';
  179. this.type11 = 'password';
  180. }
  181. },
  182. submit() {
  183. let _this = this;
  184. this.$refs.uForm.validate(valid => {
  185. if (valid) {
  186. if(_this.type === '2' || _this.type === '3'){
  187. console.log('this.form.userPWD', _this.form.userPWD.length)
  188. if(_this.form.userPWD.length === 4){
  189. uni.showLoading({
  190. title: '登录中...',
  191. mask: true
  192. });
  193. this.loginFn()
  194. }else{
  195. _this.$refs.uToast.show({
  196. title: '请输入身份证号后四位!',
  197. type: 'default',
  198. })
  199. }
  200. }else{
  201. uni.showLoading({
  202. title: '登录中...',
  203. mask: true
  204. });
  205. this.loginFn()
  206. }
  207. } else {
  208. }
  209. });
  210. },
  211. loginFn(){
  212. let _this = this
  213. this.form.type = this.type
  214. server.login(this.form).then(res => {
  215. if(res.code === 200){
  216. uni.hideLoading();
  217. let type = ''
  218. uni.setStorageSync('role', res.data.type);//存入权限
  219. _this.setRole(res.data.type);
  220. uni.setStorage({
  221. key: "userInfo",
  222. data: res.data,
  223. success: () => {
  224. if(this.gotoAdd === 'add'){
  225. uni.redirectTo({
  226. url: '/pages/soldier/user/add'
  227. });
  228. }else{
  229. uni.switchTab({
  230. url: '/pages/index/index'
  231. })
  232. }
  233. }
  234. });
  235. }else if(res.code === 500){
  236. uni.hideLoading();
  237. if(res.data === "4"){
  238. // if(this.type === '军人'){
  239. // uni.navigateTo({
  240. // url: '/pages/soldier/home/identity?name=' + this.form.userName + '&pwd=' + this.form.userPWD
  241. // })
  242. // }else{
  243. _this.$refs.uToast.show({
  244. title: res.msg,
  245. type: 'default',
  246. })
  247. // }
  248. }else if(res.data === "1"){
  249. _this.$refs.uToast.show({
  250. title: res.msg,
  251. type: 'default',
  252. })
  253. }
  254. }else{
  255. _this.$refs.uToast.show({
  256. title: '登录失败,请重新输入!',
  257. type: 'default',
  258. })
  259. }
  260. }).catch(() => {})
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. /deep/ .u-form-item__message{
  267. padding-left: 50rpx!important;
  268. }
  269. /deep/ .u-input__input{
  270. color: #2E4F1C!important;
  271. font-size: 28rpx;
  272. font-family: PingFangSC-Regular, PingFang SC;
  273. font-weight: 400;
  274. }
  275. /deep/ .u-border, .u-border-bottom, .u-border-left, .u-border-right, .u-border-top, .u-border-top-bottom{
  276. }
  277. /deep/ .u-form-item{
  278. display: -webkit-box;
  279. display: -webkit-flex;
  280. display: flex;
  281. -webkit-box-orient: horizontal;
  282. -webkit-box-direction: normal;
  283. -webkit-flex-direction: row;
  284. flex-direction: row;
  285. box-sizing: border-box;
  286. line-height: 96rpx;
  287. -webkit-flex-direction: column;
  288. flex-direction: column;
  289. background: rgba(46, 79, 28, 0.05);
  290. border-radius: 48rpx;
  291. height: 96rpx;
  292. margin-bottom: 60rpx;
  293. padding-left: 30rpx!important;
  294. }
  295. .login{
  296. width: 100%;
  297. height: 100vh;
  298. position: relative;
  299. .header{
  300. width: 100%;
  301. height: 400rpx;
  302. padding-top: 64rpx;
  303. padding-left: 30rpx;
  304. position: relative;
  305. .header-text{
  306. height: 96rpx;
  307. line-height: 96rpx;
  308. }
  309. .header-img{
  310. width:166.4rpx;
  311. height:190.4rpx;
  312. // height: 200rpx;
  313. // border-radius: 64rpx;
  314. // background-color: #FFFFFF;
  315. position: absolute;
  316. bottom: 90rpx;
  317. right: 60rpx;
  318. // box-shadow:4rpx 4rpx 300rpx #E6A23C;
  319. }
  320. .header-title{
  321. width: 100rpx;
  322. height: 30rpx;
  323. position: absolute;
  324. bottom: 70rpx;
  325. right: 75rpx;
  326. }
  327. .login-form{
  328. position: absolute;
  329. top: 350rpx;
  330. left: 30rpx;
  331. width: calc(100% - 60rpx);
  332. height: 975rpx;
  333. background: #FFFFFF;
  334. border-radius: 24rpx;
  335. .login-form-title{
  336. width: 100%;
  337. height: 227rpx;
  338. text-align: center;
  339. padding-top: 55rpx;
  340. letter-spacing: 2rpx;
  341. font-weight: 600;
  342. }
  343. .login-form-view{
  344. padding-left: 60rpx;
  345. width: calc(100% - 60rpx);
  346. height: 252rpx;
  347. .form-item{
  348. display: flex;
  349. .form-img{
  350. width: 40rpx;
  351. height: 40rpx;
  352. padding-top: 15rpx;
  353. padding-right: 18rpx;
  354. }
  355. }
  356. .form-submit{
  357. margin-top: 60rpx;
  358. width: 570rpx;
  359. height: 96rpx;
  360. background: linear-gradient(117deg, #5B873C 0%, #2E4F1C 100%);
  361. border-radius: 49rpx;
  362. font-size: 36rpx;
  363. font-family: PingFangSC-Medium, PingFang SC;
  364. font-weight: 500;
  365. color: #fff;
  366. text-align: center;
  367. line-height: 96rpx;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. </style>