userinfo.vue 8.7 KB

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