info.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <view >
  3. <image mode="widthFix" src="/static/wd_bg_login.jpg" class="login_full_img"></image>
  4. <view class="loginBox">
  5. <view style="display: flex;height: 160rpx;justify-content: center;" >
  6. <view style="text-align: center;">
  7. <image @click="editAvatar" :src="form.avatar?$method.splitImgHost(form.avatar, true):''" class="avatar"></image>
  8. <view class="nick">{{form.realname}}</view>
  9. <view>
  10. <view class="item" @click="editNickName">
  11. <view>我的昵称</view>
  12. <view>{{form.nickname}}<u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
  13. </view>
  14. <view>
  15. <picker @change="bindPickerChangeSex" :value="form.sex" :range="array_sex">
  16. <view class="item">
  17. <view>性别</view>
  18. <view class="rBox">
  19. <view class="picker">{{ array_sex[form.sex] }}</view>
  20. <u-icon name="arrow-right" color="#999999" size="28"></u-icon>
  21. </view>
  22. </view>
  23. </picker>
  24. </view>
  25. <view>
  26. <picker mode="date" :end="$method.getDate()" :value="form.userBirth" @change="bindDateChange">
  27. <view class="item">
  28. <view>年龄</view>
  29. <view class="rBox">
  30. <view class="picker">{{ $method.getYears(form.userBirth) }} 岁</view>
  31. <u-icon name="arrow-right" color="#999999" size="28"></u-icon>
  32. </view>
  33. </view>
  34. </picker>
  35. </view>
  36. <view class="item" @click="editIdCard">
  37. <view>关联学员身份</view>
  38. <view style="display: flex;">
  39. <view style="text-align: right;">
  40. <view>{{ form.realname }}</view>
  41. <view>{{ form.idCard }}</view>
  42. </view>
  43. <u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
  44. </view>
  45. <view>
  46. <pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion2">
  47. <view class="item">
  48. <view>所在城市</view>
  49. <view class="rBox">
  50. <view class="picker">{{ form.province || '-' }} {{ form.city || '-' }} {{ form.district || '-' }}</view>
  51. <u-icon name="arrow-right" color="#999999" size="28"></u-icon>
  52. </view>
  53. </view>
  54. </pick-regions>
  55. </view>
  56. <view class="item" @click="showPhone">
  57. <view>手机号码</view>
  58. <view>{{ form.telphone }}<u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <u-modal v-model="n_show" @confirm="confirmNick" :show-cancel-button="true" title="修改昵称">
  65. <view class="slot-content">
  66. <u-input v-model="nickname" type="nickname" placeholder="请输入昵称" />
  67. </view>
  68. </u-modal>
  69. <u-modal v-model="id_show" ref="uModal" :async-close="true" @confirm="confirmId" :show-cancel-button="true" title="修改关联信息">
  70. <view class="slot-content">
  71. <u-input v-model="realname" @input="inputName(realname)" type="nickname" placeholder="请输入真实姓名" />
  72. <u-input v-model="idCard" type="idcard" placeholder="请输入身份证" />
  73. </view>
  74. </u-modal>
  75. <u-popup v-model="showPhoneModal" mode="bottom" class="modal" border-radius="32">
  76. <view class="modal__content">
  77. <view class="top">
  78. <view class="top__line"></view>
  79. <view class="top__text">更换手机号码</view>
  80. </view>
  81. <view class="form">
  82. <u-form :model="telForm" ref="telForm">
  83. <view class="input-wrap">
  84. <u-form-item ref="tel" prop="tel"><u-input placeholder="手机号码" v-model="telForm.tel" /></u-form-item>
  85. <u-form-item prop="code">
  86. <u-input placeholder="验证码" v-model="telForm.code" />
  87. <view slot="right" @click="getCode" class="getcode">{{codeTips}}</view>
  88. </u-form-item>
  89. </view>
  90. <view class="btns">
  91. <view class="cancel" @click="showPhoneModal = false">取消</view>
  92. <view class="submit" :class="{able:canSubmit()}" @click="bindNewSubmit">确认更换</view>
  93. </view>
  94. </u-form>
  95. </view>
  96. </view>
  97. </u-popup>
  98. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  99. <u-navbar title="我的资料" :border-bottom="false" background="{ background: '#ffffff',opacity:0.4; }" title-color="#ffffff" back-icon-color="#ffffff">
  100. </u-navbar>
  101. </view>
  102. </template>
  103. <script>
  104. import {mapGetters} from 'vuex';
  105. export default {
  106. data() {
  107. return {
  108. showPhoneModal:false,
  109. form:{
  110. avatar:'',
  111. userBirth:''
  112. },
  113. telForm:{
  114. tel:'',
  115. code:'',
  116. },
  117. array_sex: ['男', '女'],
  118. n_show:false,
  119. defaultRegionCode: '440112',
  120. id_show:false,
  121. nickname:'',
  122. realname:'',
  123. idCard:'',
  124. codeTips:'',
  125. avatarUrl:'',
  126. avatarOssKey:'',
  127. rules: {
  128. tel: [
  129. {
  130. required: true,
  131. message: '请输入手机号',
  132. // 可以单个或者同时写两个触发验证方式
  133. trigger: ['change']
  134. },
  135. {
  136. validator: (rule, value, callback) => {
  137. // 上面有说,返回true表示校验通过,返回false表示不通过
  138. // this.$u.test.mobile()就是返回true或者false的
  139. return this.$u.test.mobile(value);
  140. },
  141. message: '手机号码格式不正确',
  142. // 触发器可以同时用blur和change
  143. trigger: ['change'],
  144. }
  145. ],
  146. code: [
  147. {
  148. required: true,
  149. message: '请输入验证码',
  150. // 可以单个或者同时写两个触发验证方式
  151. trigger: ['change'],
  152. }
  153. ],
  154. },
  155. };
  156. },
  157. onShow(){
  158. this.form = this.userInfo
  159. console.log(this.form,'0999')
  160. },
  161. onLoad(option) {
  162. },
  163. methods: {
  164. inputName(value) {
  165. if(value.trim()) {
  166. var reg = /[^\u0391-\uFFE5A-Za-z]/g;
  167. let newVal = value.trim().replace(reg,'')
  168. this.$nextTick(() => {
  169. this.realname = newVal;
  170. })
  171. }
  172. },
  173. bindPickerChangeSex(e) {
  174. let data = {sex:e.detail.value}
  175. this.submitForm(data)
  176. },
  177. uploadFile(options, int) {
  178. var self = this;
  179. return new Promise((resolve, reject) => {
  180. var data = {
  181. imageStatus: int
  182. };
  183. self.$api.aliyunpolicy(data).then(res => {
  184. console.log(res.data,6)
  185. if(res.data.code!=200){
  186. self.$method.showToast('签名错误'+JSON.stringify(res.data))
  187. return
  188. }
  189. var ossToken = res.data.data.resultContent;
  190. if(ossToken.host==null||ossToken.host==undefined){
  191. self.$method.showToast('上传路径报错'+JSON.stringify(res.data))
  192. return
  193. }
  194. uni.uploadFile({
  195. url: ossToken.host,
  196. name: 'file',
  197. filePath: options,
  198. fileType: 'image',
  199. header: {
  200. AuthorizationToken: 'WX ' + uni.getStorageSync('token')
  201. },
  202. formData: {
  203. key: ossToken.dir,
  204. OSSAccessKeyId: ossToken.accessid,
  205. policy: ossToken.policy,
  206. Signature: ossToken.signature,
  207. callback: ossToken.callback,
  208. success_action_status: 200
  209. },
  210. success: result => {
  211. if (result.statusCode === 200) {
  212. self.avatarOssKey = ossToken.dir;
  213. resolve();
  214. } else {
  215. uni.showToast({
  216. title: '上传失败',
  217. icon: 'none'
  218. });
  219. return;
  220. }
  221. },
  222. fail: error => {
  223. uni.showToast({
  224. title: '上传接口报错'+error,
  225. icon: 'none'
  226. });
  227. return;
  228. }
  229. });
  230. });
  231. });
  232. },
  233. imageInfos(){
  234. var self = this
  235. return new Promise((resolve, reject) => {
  236. uni.getImageInfo({
  237. src: self.avatarUrl,
  238. success: async res => {
  239. let canvasWidth = res.width; //图片原始长宽
  240. let canvasHeight = res.height;
  241. if (canvasWidth > 2000 || canvasHeight > 2000) {
  242. uni.compressImage({
  243. src: self.avatarUrl,
  244. quality: 75,
  245. width: '35%',
  246. height: '35%',
  247. success: async rest => {
  248. const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
  249. resolve()
  250. }
  251. });
  252. } else if (canvasWidth > 1000 || canvasHeight > 1000) {
  253. uni.compressImage({
  254. src: self.avatarUrl,
  255. quality: 75,
  256. width: '50%',
  257. height: '50%',
  258. success: async rest => {
  259. const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
  260. resolve()
  261. }
  262. });
  263. } else {
  264. console.log('无需压缩');
  265. const waitUpload = await self.uploadFile(self.avatarUrl, 0);
  266. resolve()
  267. }
  268. }
  269. });
  270. });
  271. },
  272. async submitAvatar(){
  273. const waitYS = await this.imageInfos();
  274. let data = {avatar:this.avatarOssKey}
  275. this.submitForm(data)
  276. },
  277. editAvatar(){
  278. let that = this
  279. uni.chooseImage({
  280. count: 1, //默认9
  281. sizeType: [ 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  282. success: function (res) {
  283. that.avatarUrl = res.tempFilePaths[0]
  284. that.submitAvatar()
  285. }
  286. });
  287. },
  288. //城市
  289. handleGetRegion2(region) {
  290. let data = {province:region[0].name,city:region[1].name,district:region[2].name}
  291. this.submitForm(data)
  292. },
  293. bindDateChange(e) {
  294. let data = {userBirth:e.detail.value}
  295. this.submitForm(data)
  296. },
  297. editIdCard(){
  298. this.id_show = true
  299. this.realname = this.form.realname
  300. this.idCard = this.form.idCard
  301. },
  302. confirmId(){
  303. if(this.realname==''){
  304. uni.showModal({
  305. title: "提示",
  306. content: '真实姓名不能为空',
  307. showCancel: false
  308. })
  309. this.$refs.uModal.clearLoading();
  310. return
  311. }
  312. if(this.idCard==''){
  313. uni.showModal({
  314. title: "提示",
  315. content: '身份证ID不能为空',
  316. showCancel: false
  317. })
  318. this.$refs.uModal.clearLoading();
  319. return
  320. }
  321. let idCardRe18 = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
  322. let idCardRe15 = /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/
  323. if(!idCardRe18.test(this.idCard) && !idCardRe15.test(this.idCard)){
  324. uni.showModal({
  325. title: "提示",
  326. content: '身份证ID不正确',
  327. showCancel: false
  328. })
  329. this.$refs.uModal.clearLoading();
  330. return
  331. }
  332. let data = {realname:this.realname,idCard:this.idCard}
  333. this.submitForm(data)
  334. },
  335. confirmNick(){
  336. if(this.nickname==''){
  337. uni.showModal({
  338. title: "提示",
  339. content: '昵称不能为空',
  340. showCancel: false
  341. })
  342. return
  343. }
  344. let data = {nickname:this.nickname}
  345. this.submitForm(data)
  346. },
  347. editNickName(){
  348. this.n_show = true
  349. this.nickname = this.form.nickname
  350. },
  351. submitForm(data){
  352. let self = this
  353. this.$api.appuserInfo(data).then(res => {
  354. if (res.data.code === 200) {
  355. setTimeout(()=>{
  356. this.id_show = false;
  357. uni.showToast({
  358. title: '提交成功',
  359. icon: 'none'
  360. });
  361. },500);
  362. self.$api.refreshUserInfo()
  363. }else{
  364. uni.showToast({
  365. title: res.data.msg,
  366. icon: 'none'
  367. });
  368. }
  369. });
  370. },
  371. showPhone() {
  372. this.showPhoneModal = true;
  373. this.$refs.telForm.setRules(this.rules)
  374. },
  375. canSubmit() {
  376. if(this.telForm.tel && this.telForm.code) {
  377. return true;
  378. }
  379. return false;
  380. },
  381. codeChange(text) {
  382. this.codeTips = text;
  383. },
  384. getCode() {
  385. let that = this
  386. if(that.$refs.uCode.canGetCode) {
  387. if(that.$refs.tel.validateState == 'success') {
  388. let datas = {tel:this.telForm.tel}
  389. that.$api.bindNewSms(datas).then(
  390. res => {
  391. if (res.data.code == 200) {
  392. that.$u.toast('验证码已发送');
  393. // 通知验证码组件内部开始倒计时
  394. that.$refs.uCode.start();
  395. } else {
  396. that.$u.toast(res.data.msg);
  397. }
  398. },
  399. err => {
  400. console.log(err);
  401. }
  402. );
  403. } else {
  404. this.$refs.tel.onFieldChange()
  405. }
  406. }
  407. },
  408. bindNewSubmit() {
  409. let that = this
  410. this.$refs.telForm.validate(valid => {
  411. if(valid) {
  412. let datas = {
  413. tel:this.telForm.tel,
  414. code:this.telForm.code,
  415. }
  416. that.$api.bindNewTel(datas).then(
  417. res => {
  418. if (res.data.code == 200) {
  419. that.showPhoneModal = false;
  420. that.$api.refreshUserInfo();
  421. uni.showModal({
  422. title: '提示',
  423. content: '绑定成功',
  424. showCancel:false,
  425. });
  426. } else {
  427. that.$u.toast(res.data.msg);
  428. }
  429. },
  430. err => {
  431. }
  432. );
  433. }
  434. })
  435. }
  436. },
  437. computed: {...mapGetters(['userInfo'])},
  438. watch:{
  439. userInfo(val, oldVal){//普通的watch监听
  440. if(val){
  441. this.form = this.userInfo
  442. }
  443. },
  444. }
  445. };
  446. </script>
  447. <style >
  448. page{
  449. background-color: #F0F1F5;
  450. }
  451. </style>
  452. <style scope lang="scss">
  453. .slot-content{
  454. margin: 30rpx;
  455. color: #606266;
  456. }
  457. .rBox{
  458. display: flex;
  459. }
  460. .item{
  461. width: 686rpx;
  462. height: 80rpx;
  463. background: #FFFFFF;
  464. border-radius: 24rpx;
  465. display: flex;
  466. color: #666666;
  467. align-items: center;
  468. justify-content: space-between;
  469. padding: 0 20rpx;
  470. margin-top: 30rpx;
  471. font-size: 24rpx;
  472. }
  473. .nick{
  474. font-size: 36rpx;
  475. font-weight: bold;
  476. color: #007AFF;
  477. margin-top: 20rpx;
  478. }
  479. .loginBox{
  480. position: relative;
  481. top: -80rpx;
  482. }
  483. .avatar{
  484. width: 160rpx;
  485. height: 160rpx;
  486. border-radius: 50%;
  487. }
  488. .login_full_img {
  489. display: block;
  490. width: 100%;
  491. height: 140px !important;
  492. z-index: -999;
  493. top: 0;
  494. }
  495. .full_img {
  496. display: block;
  497. width: 100%;
  498. z-index: -999;
  499. top: 0;
  500. }
  501. .loginBtn{
  502. width: 526rpx;
  503. height: 80rpx;
  504. background: linear-gradient(90deg, #015EEA, #00C0FA);
  505. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  506. border-radius: 40rpx;
  507. color: #FFFFFF;
  508. line-height: 80rpx;
  509. margin: 0 auto;
  510. margin-top: 50rpx;
  511. }
  512. .modal {
  513. &__content {
  514. position:relative;
  515. width: 750rpx;
  516. height: 1208rpx;
  517. background: #FFFFFF;
  518. box-shadow: 0px 0px 16rpx 4rpx #919CB2;
  519. border-radius: 32rpx 32rpx 0rpx 0rpx ;
  520. overflow: hidden;
  521. .top {
  522. border-bottom: 1rpx solid #eee;
  523. &__line {
  524. position: absolute;
  525. top: 10rpx;
  526. left: 50%;
  527. transform: translateX(-50%);
  528. width: 80rpx;
  529. height: 8rpx;
  530. background-color: #999;
  531. border-radius: 4rpx;
  532. }
  533. &__text {
  534. height: 77rpx;
  535. text-align: center;
  536. line-height: 90rpx;
  537. font-size: 24rpx;
  538. color: #999;
  539. position: relative;
  540. }
  541. }
  542. .form {
  543. margin: 24rpx auto 0;
  544. width: 686rpx;
  545. height: 360rpx;
  546. background: #FFFFFF;
  547. border-radius: 24rpx 24rpx 24rpx 24rpx;
  548. .input-wrap {
  549. padding:20rpx 80rpx;
  550. .getcode {
  551. color:#007AFF;
  552. font-size: 30rpx;
  553. }
  554. }
  555. .btns {
  556. display: flex;
  557. justify-content: space-between;
  558. margin-top:160rpx;
  559. .cancel {
  560. font-weight: bold;
  561. text-align: center;
  562. line-height: 80rpx;
  563. color:#007AFF;
  564. width: 200rpx;
  565. height: 80rpx;
  566. font-size: 30rpx;
  567. background: #F5F5F5;
  568. border-radius: 40rpx 40rpx 40rpx 40rpx;
  569. }
  570. .submit {
  571. font-weight: bold;
  572. opacity: 0.6;
  573. text-align: center;
  574. line-height: 80rpx;
  575. color:#fff;
  576. font-size: 30rpx;
  577. width: 438rpx;
  578. height: 80rpx;
  579. background: #007AFF;
  580. border-radius: 40rpx 40rpx 40rpx 40rpx;
  581. &.able {
  582. opacity: 1;
  583. }
  584. }
  585. }
  586. }
  587. }
  588. }
  589. </style>