userinfo.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="usermain-item ">
  5. <view>头像</view>
  6. <view>
  7. <image src="../../static/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. let that = this;
  89. let token = uni.getStorageSync('token');
  90. uni.showLoading({
  91. title: '上传中...'
  92. });
  93. uni.uploadFile({
  94. url: that.config("APIHOST1") + '/alioss/upload', //仅为示例,非真实的接口地址
  95. filePath: e.detail.avatarUrl,
  96. // filePath: res.tempFilePaths[0],
  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. // url: 'https://daijiasf.xianmaxiong.com/sqx_fast/alioss/upload', //真实的接口地址
  159. filePath: res.tempFilePaths[0],
  160. header: {
  161. token: token
  162. },
  163. name: 'file',
  164. success: uploadFileRes => {
  165. url = JSON.parse(uploadFileRes.data);
  166. that.avatar = url.data
  167. uni.hideLoading();
  168. }
  169. });
  170. }
  171. });
  172. }
  173. }
  174. })
  175. },
  176. config: function(name) {
  177. var info = null;
  178. if (name) {
  179. var name2 = name.split("."); //字符分割
  180. if (name2.length > 1) {
  181. info = configdata[name2[0]][name2[1]] || null;
  182. } else {
  183. info = configdata[name] || null;
  184. }
  185. if (info == null) {
  186. let web_config = cache.get("web_config");
  187. if (web_config) {
  188. if (name2.length > 1) {
  189. info = web_config[name2[0]][name2[1]] || null;
  190. } else {
  191. info = web_config[name] || null;
  192. }
  193. }
  194. }
  195. }
  196. return info;
  197. },
  198. getUserInfo() {
  199. let userId = this.$queue.getData('userId');
  200. this.$Request.getT("/app/user/selectUserDetails?userId=" + userId).then(res => {
  201. if (res.code == 0) {
  202. this.$queue.setData('avatar', res.data.avatar);
  203. this.$queue.setData('userId', res.data.userId);
  204. this.$queue.setData('userName', res.data.userName);
  205. this.$queue.setData('age', res.data.age);
  206. this.age = res.data.age ? res.data.age : 0;
  207. this.occupation = res.data.occupation;
  208. this.avatar = res.data.avatar;
  209. this.userName = res.data.nickName;
  210. }
  211. uni.hideLoading();
  212. });
  213. },
  214. // 保存
  215. messagebtn() {
  216. if (!this.userName) {
  217. // this.$queue.showToast('用户名不能为空');
  218. uni.showToast({
  219. title: "用户名不能为空",
  220. icon: "none"
  221. })
  222. } else {
  223. uni.showModal({
  224. title: '温馨提示',
  225. content: '确定保存信息',
  226. success: e => {
  227. if (e.confirm) {
  228. this.$Request.postJson("/app/user/updateUser", {
  229. nickName: this.userName,
  230. avatar: this.avatar,
  231. occupation: this.occupation,
  232. age: this.age
  233. }).then(res => {
  234. if (res.code === 0) {
  235. uni.showToast({
  236. title: '保存成功',
  237. icon: "none"
  238. })
  239. setTimeout(function() {
  240. uni.navigateBack()
  241. }, 1000)
  242. } else {
  243. uni.showToast({
  244. title: res.msg,
  245. icon: "none"
  246. })
  247. }
  248. })
  249. }
  250. }
  251. });
  252. }
  253. }
  254. },
  255. // userphone(){
  256. // uni.navigateTo({
  257. // url:'/pages/my/userphone'
  258. // })
  259. // }
  260. };
  261. </script>
  262. <style>
  263. page {
  264. /* background: #1c1b20; */
  265. background: #FFFFFF;
  266. }
  267. button::after {
  268. border: none;
  269. background-color: none;
  270. }
  271. button {
  272. position: relative;
  273. display: block;
  274. margin-left: auto;
  275. margin-right: auto;
  276. padding-left: 0px;
  277. padding-right: 0px;
  278. box-sizing: border-box;
  279. text-decoration: none;
  280. /* line-height: 1.35; */
  281. overflow: hidden;
  282. color: #666666;
  283. /* background-color: #fff; */
  284. background-color: rgba(255, 255, 255, 0) !important;
  285. width: 100%;
  286. height: 100%;
  287. /* margin-top: 90rpx; */
  288. }
  289. .usermain-item {
  290. display: flex;
  291. align-items: center;
  292. margin: 0 40rpx;
  293. padding: 10rpx 0;
  294. justify-content: space-between;
  295. border-bottom: 1rpx solid #e5e5e5;
  296. /* border-bottom: 2rpx solid #f2f2f2; */
  297. }
  298. .usermain-item.item-padding {
  299. /* padding: 0; */
  300. }
  301. .cu-form-group {
  302. padding: 0;
  303. background: #ffffff;
  304. text-align: right;
  305. }
  306. .cu-form-group input {
  307. background: #ffffff;
  308. font-size: 28rpx;
  309. /* color: #fff; */
  310. }
  311. .footer-btn {
  312. margin-top: 150rpx;
  313. }
  314. .footer-btn .usermain-btn {
  315. color: #FFFFFF;
  316. background: #346EF6;
  317. text-align: center;
  318. width: 450rpx;
  319. height: 80rpx;
  320. font-size: 28rpx;
  321. line-height: 80rpx;
  322. margin: 0 auto;
  323. border-radius: 40rpx;
  324. }
  325. </style>