info.vue 8.8 KB

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