info.vue 15 KB

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