info.vue 15 KB

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