info.vue 14 KB

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