userinfo.vue 9.7 KB

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