info.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. this.$u.toast('上传成功')
  222. self.avatarOssKey = ossToken.dir;
  223. resolve();
  224. // } else {
  225. // uni.showToast({
  226. // title: '上传失败',
  227. // icon: 'none'
  228. // });
  229. // return;
  230. // }
  231. },
  232. fail: error => {
  233. uni.showToast({
  234. title: '上传接口报错'+error,
  235. icon: 'none'
  236. });
  237. return;
  238. },
  239. });
  240. });
  241. });
  242. },
  243. imageInfos(){
  244. var self = this
  245. return new Promise((resolve, reject) => {
  246. uni.getImageInfo({
  247. src: self.avatarUrl,
  248. success: async res => {
  249. let canvasWidth = res.width; //图片原始长宽
  250. let canvasHeight = res.height;
  251. if (canvasWidth > 2000 || canvasHeight > 2000) {
  252. uni.compressImage({
  253. src: self.avatarUrl,
  254. quality: 75,
  255. width: '35%',
  256. height: '35%',
  257. success: async rest => {
  258. const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
  259. resolve(waitUpload)
  260. }
  261. });
  262. } else if (canvasWidth > 1000 || canvasHeight > 1000) {
  263. uni.compressImage({
  264. src: self.avatarUrl,
  265. quality: 75,
  266. width: '50%',
  267. height: '50%',
  268. success: async rest => {
  269. const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
  270. resolve(waitUpload)
  271. }
  272. });
  273. } else {
  274. const waitUpload = await self.uploadFile(self.avatarUrl, 0);
  275. resolve(waitUpload)
  276. }
  277. },
  278. fail: (err) => {
  279. this.$u.toast('图片上传失败')
  280. }
  281. });
  282. });
  283. },
  284. async submitAvatar(){
  285. const waitYS = await this.imageInfos();
  286. let data = {avatar:this.avatarOssKey}
  287. this.submitForm(data)
  288. },
  289. editAvatar(){
  290. let that = this
  291. uni.chooseImage({
  292. count: 1, //默认9
  293. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  294. success: function (res) {
  295. console.log('res:,', res)
  296. that.avatarUrl = res.tempFilePaths[0]
  297. that.submitAvatar()
  298. }
  299. });
  300. },
  301. //城市
  302. handleGetRegion2(region) {
  303. let data = {province:region[0].name,city:region[1].name,district:region[2].name}
  304. this.submitForm(data)
  305. },
  306. bindDateChange(e) {
  307. let data = {userBirth:e.detail.value}
  308. this.submitForm(data)
  309. },
  310. editIdCard(){
  311. return;
  312. this.id_show = true
  313. this.realname = this.form.realname
  314. this.idCard = this.form.idCard
  315. },
  316. confirmId(){
  317. if(this.realname==''){
  318. uni.showModal({
  319. title: "提示",
  320. content: '真实姓名不能为空',
  321. showCancel: false
  322. })
  323. this.$refs.uModal.clearLoading();
  324. return
  325. }
  326. if(this.idCard==''){
  327. uni.showModal({
  328. title: "提示",
  329. content: '身份证ID不能为空',
  330. showCancel: false
  331. })
  332. this.$refs.uModal.clearLoading();
  333. return
  334. }
  335. 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]$/
  336. 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}$/
  337. if(!idCardRe18.test(this.idCard) && !idCardRe15.test(this.idCard)){
  338. uni.showModal({
  339. title: "提示",
  340. content: '身份证ID不正确',
  341. showCancel: false
  342. })
  343. this.$refs.uModal.clearLoading();
  344. return
  345. }
  346. let data = {realname:this.realname,idCard:this.idCard}
  347. this.submitForm(data)
  348. },
  349. confirmNick(){
  350. if(this.nickname==''){
  351. uni.showModal({
  352. title: "提示",
  353. content: '昵称不能为空',
  354. showCancel: false
  355. })
  356. return
  357. }
  358. let data = {nickname:this.nickname}
  359. this.submitForm(data)
  360. },
  361. editNickName(){
  362. this.n_show = true
  363. this.nickname = this.form.nickname
  364. },
  365. submitForm(data){
  366. let self = this
  367. this.$api.appuserInfo(data).then(res => {
  368. if (res.data.code === 200) {
  369. setTimeout(()=>{
  370. this.id_show = false;
  371. uni.showToast({
  372. title: '提交成功',
  373. icon: 'none'
  374. });
  375. },500);
  376. self.$api.refreshUserInfo()
  377. }else{
  378. uni.showToast({
  379. title: res.data.msg,
  380. icon: 'none'
  381. });
  382. }
  383. });
  384. },
  385. showPhone() {
  386. return;
  387. this.showPhoneModal = true;
  388. this.$refs.telForm.setRules(this.rules)
  389. },
  390. canSubmit() {
  391. if(this.telForm.tel && this.telForm.code) {
  392. return true;
  393. }
  394. return false;
  395. },
  396. codeChange(text) {
  397. this.codeTips = text;
  398. },
  399. getCode() {
  400. let that = this
  401. if(that.$refs.uCode.canGetCode) {
  402. if(that.$refs.tel.validateState == 'success') {
  403. let datas = {tel:this.telForm.tel}
  404. that.$api.bindNewSms(datas).then(
  405. res => {
  406. if (res.data.code == 200) {
  407. that.$u.toast('验证码已发送');
  408. // 通知验证码组件内部开始倒计时
  409. that.$refs.uCode.start();
  410. } else {
  411. that.$u.toast(res.data.msg);
  412. }
  413. },
  414. err => {
  415. console.log(err);
  416. }
  417. );
  418. } else {
  419. this.$refs.tel.onFieldChange()
  420. }
  421. }
  422. },
  423. bindNewSubmit() {
  424. let that = this
  425. this.$refs.telForm.validate(valid => {
  426. if(valid) {
  427. let datas = {
  428. tel:this.telForm.tel,
  429. code:this.telForm.code,
  430. }
  431. that.$api.bindNewTel(datas).then(
  432. res => {
  433. if (res.data.code == 200) {
  434. that.showPhoneModal = false;
  435. that.$api.refreshUserInfo();
  436. uni.showModal({
  437. title: '提示',
  438. content: '绑定成功',
  439. showCancel:false,
  440. });
  441. } else {
  442. that.$u.toast(res.data.msg);
  443. }
  444. },
  445. err => {
  446. }
  447. );
  448. }
  449. })
  450. }
  451. },
  452. computed: {...mapGetters(['userInfo'])},
  453. watch:{
  454. userInfo(val, oldVal){//普通的watch监听
  455. if(val){
  456. this.form = this.userInfo
  457. }
  458. },
  459. }
  460. };
  461. </script>
  462. <style >
  463. page{
  464. background-color: #F0F1F5;
  465. }
  466. </style>
  467. <style scope lang="scss">
  468. .slot-content{
  469. margin: 30rpx;
  470. color: #606266;
  471. }
  472. .rBox{
  473. display: flex;
  474. }
  475. .item{
  476. width: 686rpx;
  477. height: 80rpx;
  478. background: #FFFFFF;
  479. border-radius: 24rpx;
  480. display: flex;
  481. color: #666666;
  482. align-items: center;
  483. justify-content: space-between;
  484. padding: 0 20rpx;
  485. margin-top: 30rpx;
  486. font-size: 24rpx;
  487. }
  488. .nick{
  489. font-size: 36rpx;
  490. font-weight: bold;
  491. color: #007AFF;
  492. margin-top: 20rpx;
  493. }
  494. .loginBox{
  495. position: relative;
  496. top: -80rpx;
  497. }
  498. .avatar{
  499. width: 160rpx;
  500. height: 160rpx;
  501. border-radius: 50%;
  502. }
  503. .login_full_img {
  504. display: block;
  505. width: 100%;
  506. height: 140px !important;
  507. z-index: -999;
  508. top: 0;
  509. }
  510. .full_img {
  511. display: block;
  512. width: 100%;
  513. z-index: -999;
  514. top: 0;
  515. }
  516. .loginBtn{
  517. width: 526rpx;
  518. height: 80rpx;
  519. background: linear-gradient(90deg, #015EEA, #00C0FA);
  520. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  521. border-radius: 40rpx;
  522. color: #FFFFFF;
  523. line-height: 80rpx;
  524. margin: 0 auto;
  525. margin-top: 50rpx;
  526. }
  527. .modal {
  528. &__content {
  529. position:relative;
  530. width: 750rpx;
  531. height: 1208rpx;
  532. background: #FFFFFF;
  533. box-shadow: 0px 0px 16rpx 4rpx #919CB2;
  534. border-radius: 32rpx 32rpx 0rpx 0rpx ;
  535. overflow: hidden;
  536. .top {
  537. border-bottom: 1rpx solid #eee;
  538. &__line {
  539. position: absolute;
  540. top: 10rpx;
  541. left: 50%;
  542. transform: translateX(-50%);
  543. width: 80rpx;
  544. height: 8rpx;
  545. background-color: #999;
  546. border-radius: 4rpx;
  547. }
  548. &__text {
  549. height: 77rpx;
  550. text-align: center;
  551. line-height: 90rpx;
  552. font-size: 24rpx;
  553. color: #999;
  554. position: relative;
  555. }
  556. }
  557. .form {
  558. margin: 24rpx auto 0;
  559. width: 686rpx;
  560. height: 360rpx;
  561. background: #FFFFFF;
  562. border-radius: 24rpx 24rpx 24rpx 24rpx;
  563. .input-wrap {
  564. padding:20rpx 80rpx;
  565. .getcode {
  566. color:#007AFF;
  567. font-size: 30rpx;
  568. }
  569. }
  570. .btns {
  571. display: flex;
  572. justify-content: space-between;
  573. margin-top:160rpx;
  574. .cancel {
  575. font-weight: bold;
  576. text-align: center;
  577. line-height: 80rpx;
  578. color:#007AFF;
  579. width: 200rpx;
  580. height: 80rpx;
  581. font-size: 30rpx;
  582. background: #F5F5F5;
  583. border-radius: 40rpx 40rpx 40rpx 40rpx;
  584. }
  585. .submit {
  586. font-weight: bold;
  587. opacity: 0.6;
  588. text-align: center;
  589. line-height: 80rpx;
  590. color:#fff;
  591. font-size: 30rpx;
  592. width: 438rpx;
  593. height: 80rpx;
  594. background: #007AFF;
  595. border-radius: 40rpx 40rpx 40rpx 40rpx;
  596. &.able {
  597. opacity: 1;
  598. }
  599. }
  600. }
  601. }
  602. }
  603. }
  604. </style>