info.vue 15 KB

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