userinfo.vue 7.6 KB

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