info.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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="showPhoneModal = true">
  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><u-input placeholder="手机号码" v-model="telForm.tel" /></u-form-item>
  80. <u-form-item>
  81. <u-input placeholder="验证码" v-model="telForm.code" />
  82. <view slot="right" @click="getCode" class="getcode">获取验证码</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-navbar title="我的资料" :border-bottom="false" background="{ background: '#ffffff',opacity:0.4; }" title-color="#ffffff" back-icon-color="#ffffff">
  94. </u-navbar>
  95. </view>
  96. </template>
  97. <script>
  98. import {mapGetters} from 'vuex';
  99. export default {
  100. data() {
  101. return {
  102. showPhoneModal:false,
  103. form:{
  104. avatar:'',
  105. userBirth:new Date()
  106. },
  107. telForm:{
  108. tel:'',
  109. code:'',
  110. },
  111. array_sex: ['男', '女'],
  112. n_show:false,
  113. defaultRegionCode: '440112',
  114. id_show:false,
  115. nickname:'',
  116. realname:'',
  117. idCard:'',
  118. avatarUrl:'',
  119. avatarOssKey:''
  120. };
  121. },
  122. onShow(){
  123. this.form = this.userInfo
  124. console.log(this.form)
  125. },
  126. onLoad(option) {
  127. },
  128. methods: {
  129. bindPickerChangeSex(e) {
  130. let data = {sex:e.detail.value}
  131. this.submitForm(data)
  132. },
  133. uploadFile(options, int) {
  134. var self = this;
  135. return new Promise((resolve, reject) => {
  136. var data = {
  137. imageStatus: int
  138. };
  139. self.$api.aliyunpolicy(data).then(res => {
  140. console.log(res.data,6)
  141. if(res.data.code!=200){
  142. self.$method.showToast('签名错误'+JSON.stringify(res.data))
  143. return
  144. }
  145. var ossToken = res.data.data.resultContent;
  146. if(ossToken.host==null||ossToken.host==undefined){
  147. self.$method.showToast('上传路径报错'+JSON.stringify(res.data))
  148. return
  149. }
  150. uni.uploadFile({
  151. url: ossToken.host,
  152. name: 'file',
  153. filePath: options,
  154. fileType: 'image',
  155. header: {
  156. AuthorizationToken: 'WX ' + uni.getStorageSync('token')
  157. },
  158. formData: {
  159. key: ossToken.dir,
  160. OSSAccessKeyId: ossToken.accessid,
  161. policy: ossToken.policy,
  162. Signature: ossToken.signature,
  163. callback: ossToken.callback,
  164. success_action_status: 200
  165. },
  166. success: result => {
  167. if (result.statusCode === 200) {
  168. self.avatarOssKey = ossToken.dir;
  169. resolve();
  170. } else {
  171. uni.showToast({
  172. title: '上传失败',
  173. icon: 'none'
  174. });
  175. return;
  176. }
  177. },
  178. fail: error => {
  179. uni.showToast({
  180. title: '上传接口报错'+error,
  181. icon: 'none'
  182. });
  183. return;
  184. }
  185. });
  186. });
  187. });
  188. },
  189. imageInfos(){
  190. var self = this
  191. return new Promise((resolve, reject) => {
  192. uni.getImageInfo({
  193. src: self.avatarUrl,
  194. success: async res => {
  195. let canvasWidth = res.width; //图片原始长宽
  196. let canvasHeight = res.height;
  197. if (canvasWidth > 1000 || canvasHeight > 1000) {
  198. uni.compressImage({
  199. src: self.avatarUrl,
  200. quality: 75,
  201. width: '50%',
  202. height: '50%',
  203. success: async rest => {
  204. const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
  205. resolve()
  206. }
  207. });
  208. } else {
  209. console.log('无需压缩');
  210. const waitUpload = await self.uploadFile(self.avatarUrl, 0);
  211. resolve()
  212. }
  213. }
  214. });
  215. });
  216. },
  217. async submitAvatar(){
  218. const waitYS = await this.imageInfos();
  219. let data = {avatar:this.avatarOssKey}
  220. this.submitForm(data)
  221. },
  222. editAvatar(){
  223. let that = this
  224. uni.chooseImage({
  225. count: 1, //默认9
  226. sizeType: [ 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  227. success: function (res) {
  228. that.avatarUrl = res.tempFilePaths[0]
  229. that.submitAvatar()
  230. }
  231. });
  232. },
  233. //城市
  234. handleGetRegion2(region) {
  235. let data = {province:region[0].name,city:region[1].name,district:region[2].name}
  236. this.submitForm(data)
  237. },
  238. bindDateChange(e) {
  239. let data = {userBirth:e.detail.value}
  240. this.submitForm(data)
  241. },
  242. editIdCard(){
  243. this.id_show = true
  244. this.realname = this.form.realname
  245. this.idCard = this.form.idCard
  246. },
  247. confirmId(){
  248. if(this.realname==''){
  249. uni.showModal({
  250. title: "提示",
  251. content: '真实姓名不能为空',
  252. showCancel: false
  253. })
  254. return
  255. }
  256. if(this.idCard==''){
  257. uni.showModal({
  258. title: "提示",
  259. content: '身份证ID不能为空',
  260. showCancel: false
  261. })
  262. return
  263. }
  264. let data = {realname:this.realname,idCard:this.idCard}
  265. this.submitForm(data)
  266. },
  267. confirmNick(){
  268. if(this.nickname==''){
  269. uni.showModal({
  270. title: "提示",
  271. content: '昵称不能为空',
  272. showCancel: false
  273. })
  274. return
  275. }
  276. let data = {nickname:this.nickname}
  277. this.submitForm(data)
  278. },
  279. editNickName(){
  280. this.n_show = true
  281. this.nickname = this.form.nickname
  282. },
  283. submitForm(data){
  284. let self = this
  285. this.$api.appuserInfo(data).then(res => {
  286. if (res.data.code === 200) {
  287. setTimeout(()=>{
  288. uni.showToast({
  289. title: '提交成功',
  290. icon: 'none'
  291. });
  292. },500);
  293. self.$api.refreshUserInfo()
  294. }else{
  295. uni.showToast({
  296. title: res.data.msg,
  297. icon: 'none'
  298. });
  299. }
  300. });
  301. }
  302. },
  303. computed: {...mapGetters(['userInfo'])},
  304. watch:{
  305. userInfo(val, oldVal){//普通的watch监听
  306. if(val){
  307. this.form = this.userInfo
  308. }
  309. },
  310. }
  311. };
  312. </script>
  313. <style >
  314. page{
  315. background-color: #F0F1F5;
  316. }
  317. </style>
  318. <style scope lang="scss">
  319. .slot-content{
  320. margin: 30rpx;
  321. color: #606266;
  322. }
  323. .rBox{
  324. display: flex;
  325. }
  326. .item{
  327. width: 686rpx;
  328. height: 80rpx;
  329. background: #FFFFFF;
  330. border-radius: 24rpx;
  331. display: flex;
  332. color: #666666;
  333. align-items: center;
  334. justify-content: space-between;
  335. padding: 0 20rpx;
  336. margin-top: 30rpx;
  337. font-size: 24rpx;
  338. }
  339. .nick{
  340. font-size: 36rpx;
  341. font-weight: bold;
  342. color: #007AFF;
  343. margin-top: 20rpx;
  344. }
  345. .loginBox{
  346. position: relative;
  347. top: -80rpx;
  348. }
  349. .avatar{
  350. width: 160rpx;
  351. height: 160rpx;
  352. border-radius: 50%;
  353. }
  354. .login_full_img {
  355. display: block;
  356. width: 100%;
  357. height: 140px !important;
  358. z-index: -999;
  359. top: 0;
  360. }
  361. .full_img {
  362. display: block;
  363. width: 100%;
  364. z-index: -999;
  365. top: 0;
  366. }
  367. .loginBtn{
  368. width: 526rpx;
  369. height: 80rpx;
  370. background: linear-gradient(90deg, #015EEA, #00C0FA);
  371. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  372. border-radius: 40rpx;
  373. color: #FFFFFF;
  374. line-height: 80rpx;
  375. margin: 0 auto;
  376. margin-top: 50rpx;
  377. }
  378. .modal {
  379. &__content {
  380. position:relative;
  381. width: 750rpx;
  382. height: 1208rpx;
  383. background: #FFFFFF;
  384. box-shadow: 0px 0px 16rpx 4rpx #919CB2;
  385. border-radius: 32rpx 32rpx 0rpx 0rpx ;
  386. overflow: hidden;
  387. .top {
  388. border-bottom: 1rpx solid #eee;
  389. &__line {
  390. position: absolute;
  391. top: 10rpx;
  392. left: 50%;
  393. transform: translateX(-50%);
  394. width: 80rpx;
  395. height: 8rpx;
  396. background-color: #999;
  397. border-radius: 4rpx;
  398. }
  399. &__text {
  400. height: 77rpx;
  401. text-align: center;
  402. line-height: 90rpx;
  403. font-size: 24rpx;
  404. color: #999;
  405. position: relative;
  406. }
  407. }
  408. .form {
  409. margin: 24rpx auto 0;
  410. width: 686rpx;
  411. height: 360rpx;
  412. background: #FFFFFF;
  413. border-radius: 24rpx 24rpx 24rpx 24rpx;
  414. .input-wrap {
  415. padding:20rpx 80rpx;
  416. .getcode {
  417. color:#007AFF;
  418. font-size: 30rpx;
  419. }
  420. }
  421. .btns {
  422. display: flex;
  423. justify-content: space-between;
  424. margin-top:160rpx;
  425. .cancel {
  426. text-align: center;
  427. line-height: 80rpx;
  428. color:#007AFF;
  429. width: 200rpx;
  430. height: 80rpx;
  431. font-size: 30rpx;
  432. background: #F5F5F5;
  433. border-radius: 40rpx 40rpx 40rpx 40rpx;
  434. }
  435. .submit {
  436. text-align: center;
  437. line-height: 80rpx;
  438. color:#fff;
  439. font-size: 30rpx;
  440. width: 438rpx;
  441. height: 80rpx;
  442. background: #007AFF;
  443. border-radius: 40rpx 40rpx 40rpx 40rpx;
  444. }
  445. }
  446. }
  447. }
  448. }
  449. </style>