info.vue 15 KB

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