userinfo.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="usermain-item ">
  5. <view>头像</view>
  6. <view>
  7. <image src="../../static/image/logo.png" v-if="avatar==null" mode=""
  8. style="width: 111rpx;height: 111rpx;border-radius: 50%;"></image>
  9. <!-- #ifdef MP-WEIXIN -->
  10. <button v-else open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  11. <image style="width: 100rpx;height: 100rpx;border-radius: 50%" :src="avatar"></image>
  12. </button>
  13. <!-- #endif -->
  14. <!-- #ifndef MP-WEIXIN -->
  15. <image v-else :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
  16. @click="uploadImg()">
  17. </image>
  18. <!-- #endif -->
  19. <!-- <image v-else :src="avatar" mode="" style="width: 111rpx;height: 111rpx;border-radius: 50%;">
  20. </image> -->
  21. </view>
  22. </view>
  23. <view class="usermain-item item-padding ">
  24. <view>用户名</view>
  25. <view>
  26. <view class="cu-form-group">
  27. <input type="nickname" v-model="userName" placeholder="请输入用户名" />
  28. </view>
  29. </view>
  30. </view>
  31. <view class="usermain-item item-padding ">
  32. <view>年龄</view>
  33. <view>
  34. <view class="cu-form-group">
  35. <input v-model="age" />
  36. </view>
  37. </view>
  38. </view>
  39. <!-- <view class="usermain-item item-padding">
  40. <view >姓名</view>
  41. <view class="cu-form-group">
  42. <input v-model="realName" placeholder="请填写您的真实姓名" />
  43. </view>
  44. </view> -->
  45. <!-- <view class="usermain-item item-padding ">
  46. <view>职业</view>
  47. <view>
  48. <view class="cu-form-group">
  49. <input v-model="occupation" placeholder="请输入职业"/>
  50. </view>
  51. </view>
  52. </view> -->
  53. </view>
  54. <view class="footer-btn">
  55. <view class="usermain-btn" @click="messagebtn()">保存</view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import configdata from '../../common/config.js';
  61. export default {
  62. data() {
  63. return {
  64. occupation: '',
  65. avatar: '../../static/image/logo.png',
  66. userName: '',
  67. nickName: '',
  68. userId: '',
  69. realName: '',
  70. weChatId: "",
  71. password: '',
  72. platform: '',
  73. createTime: '',
  74. money: '',
  75. jiFen: '',
  76. status: '',
  77. zhiFuBao: '',
  78. zhiFuBaoName: '',
  79. age: 0
  80. };
  81. },
  82. onLoad(e) {
  83. this.getUserInfo()
  84. },
  85. methods: {
  86. //微信填写能力获取头像
  87. onChooseAvatar(e) {
  88. // console.log(e.detail.avatarUrl)
  89. let that = this;
  90. let token = uni.getStorageSync('token');
  91. uni.showLoading({
  92. title: '上传中...'
  93. });
  94. uni.uploadFile({
  95. url: that.config("APIHOST1") + '/alioss/upload', //仅为示例,非真实的接口地址
  96. filePath: e.detail.avatarUrl,
  97. header: {
  98. token: token
  99. },
  100. name: 'file',
  101. success: uploadFileRes => {
  102. let url = JSON.parse(uploadFileRes.data).data;
  103. that.$Request.postJson(
  104. '/app/user/updateUserImageUrl?avatar=' + url).then(
  105. res => {
  106. uni.hideLoading();
  107. if (res.code === 0) {
  108. that.$queue.showToast(
  109. "更新成功");
  110. that.getUserInfo();
  111. }
  112. });
  113. }
  114. });
  115. },
  116. goMyAddress() {
  117. uni.navigateTo({
  118. url: '../jifen/myaddress'
  119. });
  120. },
  121. uploadImg() {
  122. let token = uni.getStorageSync('token')
  123. if (!token) {
  124. this.goLoginInfo();
  125. return;
  126. }
  127. let that = this;
  128. var url = null;
  129. uni.showActionSheet({
  130. // itemList按钮的文字接受的是数组
  131. itemList: ["查看头像", "从相册选择图片"],
  132. success(e) {
  133. var index = e.tapIndex
  134. if (index === 0) {
  135. // 用户点击了预览当前图片
  136. // 可以自己实现当前头像链接的读取
  137. let url = that.avatar;
  138. let arr = []
  139. arr.push(url)
  140. uni.previewImage({
  141. // 预览功能图片也必须是数组的
  142. urls: arr
  143. })
  144. } else if (index === 1) {
  145. uni.chooseImage({
  146. count: 1, //默认9
  147. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  148. sourceType: ['album'], //从相册选择
  149. success: function(res) {
  150. uni.showLoading({
  151. title: '上传中...'
  152. });
  153. let token = uni.getStorageSync('token');
  154. let userId = uni.getStorageSync('userId');
  155. uni.uploadFile({
  156. url: that.config("APIHOST1") +
  157. '/alioss/upload', //真实的接口地址
  158. filePath: res.tempFilePaths[0],
  159. header: {
  160. token: token
  161. },
  162. name: 'file',
  163. success: uploadFileRes => {
  164. url = JSON.parse(uploadFileRes.data);
  165. that.avatar = url.data
  166. uni.hideLoading();
  167. }
  168. });
  169. }
  170. });
  171. }
  172. }
  173. })
  174. },
  175. config: function(name) {
  176. var info = null;
  177. if (name) {
  178. var name2 = name.split("."); //字符分割
  179. if (name2.length > 1) {
  180. info = configdata[name2[0]][name2[1]] || null;
  181. } else {
  182. info = configdata[name] || null;
  183. }
  184. if (info == null) {
  185. let web_config = cache.get("web_config");
  186. if (web_config) {
  187. if (name2.length > 1) {
  188. info = web_config[name2[0]][name2[1]] || null;
  189. } else {
  190. info = web_config[name] || null;
  191. }
  192. }
  193. }
  194. }
  195. return info;
  196. },
  197. getUserInfo() {
  198. let userId = uni.getStorageSync('userId')
  199. this.$Request.getT("/app/user/selectUserById").then(res => {
  200. if (res.code == 0) {
  201. this.$queue.setData('avatar', res.data.avatar);
  202. this.$queue.setData('userId', res.data.userId);
  203. this.$queue.setData('userName', res.data.userName);
  204. this.$queue.setData('age', res.data.age);
  205. this.age = res.data.age ? res.data.age : 0;
  206. this.occupation = res.data.occupation;
  207. this.avatar = res.data.avatar;
  208. this.userName = res.data.nickName;
  209. }
  210. uni.hideLoading();
  211. });
  212. },
  213. // 保存
  214. messagebtn() {
  215. if (!this.userName) {
  216. // this.$queue.showToast('用户名不能为空');
  217. uni.showToast({
  218. title: "用户名不能为空",
  219. icon: "none"
  220. })
  221. } else {
  222. uni.showModal({
  223. title: '温馨提示',
  224. content: '确定保存信息',
  225. success: e => {
  226. if (e.confirm) {
  227. this.$Request.postJson("/app/user/updateUser", {
  228. nickName: this.userName,
  229. avatar: this.avatar,
  230. occupation: this.occupation,
  231. age: this.age
  232. }).then(res => {
  233. if (res.code === 0) {
  234. uni.showToast({
  235. title: '保存成功',
  236. icon: "none"
  237. })
  238. setTimeout(function() {
  239. uni.navigateBack()
  240. }, 1000)
  241. } else {
  242. uni.showToast({
  243. title: res.msg,
  244. icon: "none"
  245. })
  246. }
  247. })
  248. }
  249. }
  250. });
  251. }
  252. }
  253. },
  254. // userphone(){
  255. // uni.navigateTo({
  256. // url:'/pages/my/userphone'
  257. // })
  258. // }
  259. };
  260. </script>
  261. <style>
  262. page {
  263. /* background: #1c1b20; */
  264. background: #FFFFFF;
  265. }
  266. button::after {
  267. border: none;
  268. background-color: none;
  269. }
  270. button {
  271. position: relative;
  272. display: block;
  273. margin-left: auto;
  274. margin-right: auto;
  275. padding-left: 0px;
  276. padding-right: 0px;
  277. box-sizing: border-box;
  278. text-decoration: none;
  279. /* line-height: 1.35; */
  280. overflow: hidden;
  281. color: #666666;
  282. /* background-color: #fff; */
  283. background-color: rgba(255, 255, 255, 0) !important;
  284. width: 100%;
  285. height: 100%;
  286. /* margin-top: 90rpx; */
  287. }
  288. .usermain-item {
  289. display: flex;
  290. align-items: center;
  291. margin: 0 40rpx;
  292. padding: 10rpx 0;
  293. justify-content: space-between;
  294. border-bottom: 1rpx solid #e5e5e5;
  295. /* border-bottom: 2rpx solid #f2f2f2; */
  296. }
  297. .usermain-item.item-padding {
  298. /* padding: 0; */
  299. }
  300. .cu-form-group {
  301. padding: 0;
  302. background: #ffffff;
  303. text-align: right;
  304. }
  305. .cu-form-group input {
  306. background: #ffffff;
  307. font-size: 28rpx;
  308. /* color: #fff; */
  309. }
  310. .footer-btn {
  311. margin-top: 150rpx;
  312. }
  313. .footer-btn .usermain-btn {
  314. color: #FFFFFF;
  315. background: #346EF6;
  316. text-align: center;
  317. width: 450rpx;
  318. height: 80rpx;
  319. font-size: 28rpx;
  320. line-height: 80rpx;
  321. margin: 0 auto;
  322. border-radius: 40rpx;
  323. }
  324. </style>