info.vue 14 KB

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