info.vue 9.2 KB

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