info.vue 14 KB

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