userinfo.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. });
  126. let token = uni.getStorageSync('token');
  127. let userId = uni.getStorageSync('userId');
  128. uni.uploadFile({
  129. url: that.config("APIHOST1") + '/alioss/upload', //真实的接口地址
  130. filePath: res.tempFilePaths[0],
  131. header: {
  132. token: token
  133. },
  134. name: 'file',
  135. success: uploadFileRes => {
  136. url = JSON.parse(uploadFileRes.data);
  137. that.avatar = url.data
  138. uni.hideLoading();
  139. }
  140. });
  141. }
  142. });
  143. }
  144. }
  145. })
  146. },
  147. config: function(name) {
  148. var info = null;
  149. if (name) {
  150. var name2 = name.split("."); //字符分割
  151. if (name2.length > 1) {
  152. info = configdata[name2[0]][name2[1]] || null;
  153. } else {
  154. info = configdata[name] || null;
  155. }
  156. if (info == null) {
  157. let web_config = cache.get("web_config");
  158. if (web_config) {
  159. if (name2.length > 1) {
  160. info = web_config[name2[0]][name2[1]] || null;
  161. } else {
  162. info = web_config[name] || null;
  163. }
  164. }
  165. }
  166. }
  167. return info;
  168. },
  169. getUserInfo() {
  170. // let userId = uni.getStorageSync('userId')
  171. this.$Request.get("/sys/user/info").then(res => {
  172. if (res.code == 0) {
  173. this.$queue.setData('avatar', res.user.userEntity.avatar);
  174. this.$queue.setData('userId', res.user.userId);
  175. this.$queue.setData('userName', res.user.userEntity.userName);
  176. this.$queue.setData('phone', res.user.userEntity.phone);
  177. this.$queue.setData('age', res.user.userEntity.age);
  178. this.sex = res.user.userEntity.sex
  179. this.age = res.user.userEntity.age
  180. this.phone = res.user.userEntity.phone;
  181. this.avatar = res.user.userEntity.avatar;
  182. this.userName = res.user.userEntity.userName;
  183. if (this.userName == null) {
  184. this.userName = res.user.userEntity.nickName;
  185. } else {
  186. this.userName = res.user.userEntity.userName;
  187. }
  188. }
  189. uni.hideLoading();
  190. });
  191. },
  192. // 保存
  193. messagebtn() {
  194. let that = this
  195. if (!that.userName) {
  196. // this.$queue.showToast('用户名不能为空');
  197. uni.showToast({
  198. title: "用户名不能为空",
  199. icon: "none"
  200. })
  201. } else if (!that.phone) {
  202. // this.$queue.showToast('用户名不能为空');
  203. uni.showToast({
  204. title: "联系电话不能为空",
  205. icon: "none"
  206. })
  207. } else {
  208. uni.showModal({
  209. title: '温馨提示',
  210. content: '确定保存信息',
  211. success: e => {
  212. if (e.confirm) {
  213. that.$Request.postJson("/shop/shopmoney/updateUser", {
  214. userName: that.userName,
  215. avatar: that.avatar,
  216. phone: that.phone,
  217. sex: that.sex,
  218. age:that.age
  219. }).then(res => {
  220. if (res.code === 0) {
  221. uni.showToast({
  222. title: '保存成功',
  223. icon: "none"
  224. })
  225. setTimeout(function() {
  226. uni.navigateBack()
  227. }, 1000)
  228. } else {
  229. uni.showToast({
  230. title: res.msg,
  231. icon: "none"
  232. })
  233. }
  234. })
  235. }
  236. }
  237. });
  238. }
  239. }
  240. },
  241. // userphone(){
  242. // uni.navigateTo({
  243. // url:'/pages/my/userphone'
  244. // })
  245. // }
  246. };
  247. </script>
  248. <style>
  249. page {
  250. /* background: #1c1b20; */
  251. }
  252. .usermain {
  253. background: #ffffff;
  254. /* color: #fff; */
  255. }
  256. .usermain-item {
  257. display: flex;
  258. align-items: center;
  259. margin: 0 40rpx;
  260. padding: 10rpx 0;
  261. justify-content: space-between;
  262. border-bottom: 1rpx solid #e5e5e5;
  263. /* border-bottom: 2rpx solid #f2f2f2; */
  264. }
  265. .usermain-item.item-padding {
  266. /* padding: 0; */
  267. }
  268. .cu-form-group {
  269. padding: 0;
  270. background: #ffffff;
  271. text-align: right;
  272. }
  273. .cu-form-group input {
  274. background: #ffffff;
  275. font-size: 28rpx;
  276. /* color: #fff; */
  277. }
  278. .footer-btn {
  279. margin-top: 150rpx;
  280. }
  281. .footer-btn .usermain-btn {
  282. /* color: #FFFFFF; */
  283. background: #FCD202;
  284. text-align: center;
  285. width: 450rpx;
  286. height: 80rpx;
  287. font-size: 28rpx;
  288. line-height: 80rpx;
  289. margin: 0 auto;
  290. border-radius: 40rpx;
  291. }
  292. </style>