modifyInfo.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="container">
  3. <view class="ui-all">
  4. <form @submit="getUserProfile">
  5. <view class="avatar">
  6. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" class="getInfo">
  7. <view class="imgAvatar">
  8. <view class="iavatar" :style="'background: url('+avater+') no-repeat center/cover #eeeeee;'"></view>
  9. </view>
  10. <text class="avatarUrl-text">设置头像</text>
  11. </button>
  12. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" class="getInfo-btn-box">授权获取头像</button>
  13. </view>
  14. <view class="ui-list" style="flex-direction: column;align-items: flex-start;">
  15. <view style="display: flex;align-items: center;width: 100%;">
  16. <text class="ui-list-text">昵称</text>
  17. <input type="nickname" placeholder="点击使用微信昵称" v-model="nickname" name="nickName" placeholder-class="place" class="ui-list-input" @input = "bindnickName">
  18. <!-- <button class="ui-list-btn-box">使用微信昵称</button> -->
  19. </input>
  20. </view>
  21. <view style="font-size: 24rpx;color: #ff0000;">*点击使用微信昵称</view>
  22. </view>
  23. <button class="save" type="primary" formType="submit" hover-class="hoverClass">确认</button>
  24. </form>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { base_url } from '../../../apis/index.config.js'
  30. export default {
  31. data() {
  32. return {
  33. member_id:'',
  34. memberInfo:'',
  35. value: '请填写',
  36. url: '',
  37. nickname: '',
  38. avater: '',
  39. }
  40. },
  41. onShow() {
  42. this.member_id = uni.getStorageSync('member_id');
  43. this.memberInfo = uni.getStorageSync('memberInfo');
  44. // 获取用户信息
  45. this.getMemberInfo();
  46. },
  47. methods: {
  48. bindnickName(e) {
  49. this.nickname = e.detail.value;
  50. },
  51. //获取用户信息
  52. getMemberInfo(loading = true) {
  53. let that = this;
  54. let id = uni.getStorageSync('id');
  55. this.$request.getuserinfo({
  56. id
  57. }).then( res =>{
  58. console.log(res)
  59. that.avater = res.data.avater;
  60. that.nickname = res.data.nickname == '微信用户'?'':res.data.nickname;
  61. }).catch( e=>{
  62. console.log(e)
  63. })
  64. },
  65. // avatarChoose() {
  66. // let that = this;
  67. // uni.chooseImage({
  68. // count: 1,
  69. // sizeType: ['original', 'compressed'],
  70. // sourceType: ['album', 'camera'],
  71. // success(res) {
  72. // that.imgUpload(res.tempFilePaths);
  73. // const tempFilePaths = res.tempFilePaths;
  74. // }
  75. // });
  76. // },
  77. // 获取头像
  78. onChooseAvatar(e) {
  79. let that = this;
  80. console.log(e)
  81. const {
  82. avatarUrl
  83. } = e.detail
  84. that.avater = avatarUrl;
  85. },
  86. getphonenumber(e) {
  87. if (e.detail.iv) {
  88. console.log(e) //传后台解密换取手机号
  89. uni.showToast({
  90. title: '已授权',
  91. icon: 'none',
  92. duration: 2000
  93. })
  94. }
  95. },
  96. getUserProfile(e) {
  97. let that = this;
  98. let p = {
  99. nickname: e.detail.value.nickName,
  100. avater: that.avater?that.avater:'',
  101. }
  102. if(!p.avater){
  103. uni.showToast({
  104. title: '请先设置头像',
  105. icon: 'none'
  106. })
  107. return
  108. }
  109. if(!p.nickname){
  110. uni.showToast({
  111. title: '昵称不能为空',
  112. icon: 'none'
  113. })
  114. return
  115. }
  116. that.updata(p);
  117. },
  118. async updata(datas) {
  119. //传后台
  120. let that = this;
  121. await that.$request.saveuserInfo(datas).then( res =>{
  122. uni.showToast({
  123. title: '修改成功!',
  124. icon:'success'
  125. })
  126. setTimeout(() => {
  127. uni.navigateBack({
  128. delta: 1,
  129. })
  130. }, 1500);
  131. }).catch( e=>{
  132. console.log(e)
  133. })
  134. },
  135. imgUpload(file) {
  136. let that = this;
  137. uni.uploadFile({
  138. header: {
  139. Authorization: uni.getStorageSync('token')
  140. },
  141. url: 'https://ocr.lfwhzb.com/api/upload/image', //需传后台图片上传接口
  142. filePath: file[0],
  143. name: 'file',
  144. formData: {
  145. type: 'user_headimg'
  146. },
  147. success: function(res) {
  148. var data = JSON.parse(res.data);
  149. data = data.data;
  150. that.avater = that.url + data.img;
  151. that.headimg = that.url + data.img;
  152. },
  153. fail: function(error) {
  154. console.log(error);
  155. }
  156. });
  157. },
  158. },
  159. onLoad() {}
  160. }
  161. </script>
  162. <style lang="less">
  163. page{
  164. background-color: #fff;
  165. }
  166. .container {
  167. display: block;
  168. }
  169. .ui-all {
  170. padding: 20rpx;
  171. .avatar {
  172. width: 100%;
  173. text-align: left;
  174. padding: 20rpx 0;
  175. border-bottom: solid 1px #f2f2f2;
  176. position: relative;
  177. display: flex;
  178. align-items: center;
  179. justify-content: space-between;
  180. .getInfo {
  181. line-height: 1;
  182. background: #fff;
  183. display: flex;
  184. align-items: center;
  185. border: none;
  186. margin: 0;
  187. padding: 0;
  188. }
  189. .getInfo::after {
  190. border: none;
  191. }
  192. .imgAvatar {
  193. width: 120rpx;
  194. height: 120rpx;
  195. border-radius: 50%;
  196. display: inline-block;
  197. vertical-align: middle;
  198. overflow: hidden;
  199. .iavatar {
  200. width: 100%;
  201. height: 100%;
  202. display: block;
  203. }
  204. }
  205. .avatarUrl-text {
  206. display: inline-block;
  207. vertical-align: middle;
  208. color: #8e8e93;
  209. font-size: 28rpx;
  210. margin-left: 30rpx;
  211. }
  212. // &:after {
  213. // content: ' ';
  214. // width: 20rpx;
  215. // height: 20rpx;
  216. // border-top: solid 1px #030303;
  217. // border-right: solid 1px #030303;
  218. // transform: rotate(45deg);
  219. // -ms-transform: rotate(45deg);
  220. // /* IE 9 */
  221. // -moz-transform: rotate(45deg);
  222. // /* Firefox */
  223. // -webkit-transform: rotate(45deg);
  224. // /* Safari 和 Chrome */
  225. // -o-transform: rotate(45deg);
  226. // position: absolute;
  227. // top: 85rpx;
  228. // right: 0;
  229. // }
  230. .getInfo-btn-box{
  231. width: auto;
  232. font-size: 26rpx;
  233. padding: 10rpx 30rpx;
  234. color: #fff;
  235. background-color: #1684FC;
  236. border-radius: 6px;
  237. margin: 0;
  238. line-height: 1.5;
  239. }
  240. }
  241. .ui-list {
  242. width: 100%;
  243. text-align: left;
  244. padding: 20rpx 0;
  245. border-bottom: solid 1px #f2f2f2;
  246. position: relative;
  247. display: flex;
  248. align-items: center;
  249. margin-top: 40rpx;
  250. button{
  251. line-height: 1.5;
  252. margin: 0;
  253. font-size: 26rpx;
  254. padding: 10rpx 30rpx;
  255. margin-left: 10rpx;
  256. }
  257. button.ui-list-btn-box{
  258. color: #fff;
  259. background-color: #1684FC;
  260. }
  261. .ui-list-text {
  262. color: #4a4a4a;
  263. font-size: 28rpx;
  264. display: inline-block;
  265. vertical-align: middle;
  266. width: auto;
  267. text-align: center;
  268. padding-right: 20rpx;
  269. }
  270. .ui-list-input {
  271. color: #030303;
  272. font-size: 28rpx;
  273. display: inline-block;
  274. vertical-align: middle;
  275. flex: 1;
  276. padding: 10rpx 20rpx;
  277. background: #f2f2f2;
  278. }
  279. .picker-box {
  280. width: 90%;
  281. color: #030303;
  282. font-size: 28rpx;
  283. display: inline-block;
  284. vertical-align: middle;
  285. }
  286. // textarea {
  287. // color: #030303;
  288. // font-size: 30rpx;
  289. // vertical-align: middle;
  290. // height: 150rpx;
  291. // width: 100%;
  292. // margin-top: 50rpx;
  293. // }
  294. .place {
  295. color: #999999;
  296. font-size: 28rpx;
  297. }
  298. }
  299. .right:after {
  300. content: ' ';
  301. width: 20rpx;
  302. height: 20rpx;
  303. border-top: solid 1px #030303;
  304. border-right: solid 1px #030303;
  305. transform: rotate(45deg);
  306. -ms-transform: rotate(45deg);
  307. /* IE 9 */
  308. -moz-transform: rotate(45deg);
  309. /* Firefox */
  310. -webkit-transform: rotate(45deg);
  311. /* Safari 和 Chrome */
  312. -o-transform: rotate(45deg);
  313. position: absolute;
  314. top: 26rpx;
  315. right: 0;
  316. }
  317. .save {
  318. background: #1684FC;
  319. border: none;
  320. color: #ffffff;
  321. margin-top: 40rpx;
  322. font-size: 28rpx;
  323. }
  324. }
  325. .hoverClass{
  326. opacity: 0.8;
  327. }
  328. </style>