info.vue 13 KB

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