info.vue 8.7 KB

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