setting.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="container">
  3. <view class="info-list">
  4. <view class="info-item">
  5. <view class="contacts avatar-warp">
  6. <text class="name">头像</text>
  7. <image class="avatar" @click="chooseImage()" :src="avatar"></image>
  8. </view>
  9. </view>
  10. <view class="info-item">
  11. <view class="contacts">
  12. <text class="name">称呼</text>
  13. <input class="weui-input value" type="nickname" @blur="getnickname" v-model="nickname" placeholder="请输入称呼"/>
  14. </view>
  15. </view>
  16. <view class="info-item">
  17. <view class="contacts">
  18. <text class="name">手机</text>
  19. <button class="button btn-normal value" open-type="getPhoneNumber" @click="changeMobile" @getphonenumber="getPhoneNumber">
  20. <text v-if="userInfo.mobile">{{ userInfo.mobile }}</text>
  21. <text style="color: #f9211c;margin-left: 2px;">更换</text>
  22. </button>
  23. </view>
  24. </view>
  25. <view class="info-item">
  26. <view class="contacts">
  27. <text class="name">密码</text>
  28. <button class="button btn-normal value" @click="changePassword">
  29. <text class="password">********</text>
  30. <text style="color: #f9211c;margin-left: 2px;">修改</text>
  31. </button>
  32. </view>
  33. </view>
  34. <view class="info-item">
  35. <view class="contacts">
  36. <text class="name">性别</text>
  37. <view class="value">
  38. <radio-group @change="genderChange">
  39. <label class="radio"><radio value="1" color="#113a28" :checked="userInfo.sex == '1' ? true : false"/>男</label>
  40. <label class="radio second"><radio value="0" color="#113a28" :checked="userInfo.sex == '0' ? true: false"/>女</label>
  41. </radio-group>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="info-item">
  46. <view class="contacts">
  47. <text class="name">生日</text>
  48. <picker class="value" mode="date" :value="userInfo.birthday" start="1900-01-01" @change="bindDateChange">
  49. <view class="picker">{{ userInfo.birthday ? userInfo.birthday : '选择生日' }}</view>
  50. </picker>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 底部操作按钮 -->
  55. <view class="footer-fixed" v-if="userInfo.id">
  56. <view class="btn-wrapper">
  57. <view class="btn-item btn-item-main" @click="save()">保存信息</view>
  58. </view>
  59. <view class="btn-wrapper">
  60. <view class="btn-item btn-item-out" @click="logout()">退出登录</view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import * as UserApi from '@/api/user'
  67. import * as UploadApi from '@/api/upload'
  68. import store from '@/store'
  69. export default {
  70. data() {
  71. return {
  72. //当前页面参数
  73. options: {},
  74. // 正在加载
  75. isLoading: true,
  76. userInfo: { avatar: '', name: '', sex: 0, birthday: '', hasPassword: '' },
  77. openCardPara: null,
  78. code: "",
  79. nickname: "",
  80. avatar: ""
  81. }
  82. },
  83. /**
  84. * 生命周期函数--监听页面加载
  85. */
  86. onLoad(options) {
  87. // 当前页面参数
  88. this.options = options;
  89. this.getUserInfo();
  90. },
  91. methods: {
  92. /**
  93. * 用户信息
  94. * */
  95. getUserInfo() {
  96. const app = this
  97. app.isLoading = true
  98. UserApi.info()
  99. .then(result => {
  100. app.userInfo = result.data.userInfo;
  101. if (result.data.openCardPara) {
  102. app.openCardPara = result.data.openCardPara;
  103. }
  104. app.nickname = app.userInfo.name;
  105. app.avatar = app.userInfo.avatar;
  106. app.isLoading = false;
  107. })
  108. },
  109. bindDateChange (e) {
  110. let that = this;
  111. that.userInfo.birthday = e.detail.value;
  112. },
  113. getnickname(e) {
  114. this.nickname = e.detail.value;
  115. },
  116. genderChange(e) {
  117. this.userInfo.sex = e.detail.value
  118. },
  119. /**
  120. * 获取会员手机
  121. * */
  122. getPhoneNumber(e) {
  123. if (e.detail.errMsg == "getPhoneNumber:ok") {
  124. this.onAuthSuccess(e)
  125. }
  126. },
  127. getCode(e) {
  128. const app = this
  129. return new Promise((resolve, reject) => {
  130. uni.login({
  131. provider: 'weixin',
  132. success: res => {
  133. e.detail.code = res.code
  134. UserApi.save(e.detail)
  135. .then(result => {
  136. app.userInfo.mobile = result.data.mobile
  137. })
  138. resolve(res.code)
  139. },
  140. fail: reject
  141. })
  142. })
  143. },
  144. onAuthSuccess(e) {
  145. this.getCode(e)
  146. },
  147. // 修改密码
  148. changePassword() {
  149. this.$navTo('pages/user/password?hasPassword=' + this.userInfo.hasPassword);
  150. console.log(this.userInfo.hasPassword);
  151. },
  152. // 修改手机号
  153. changeMobile() {
  154. // #ifdef H5
  155. this.$navTo('pages/user/mobile');
  156. // #endif
  157. },
  158. // 选择图片
  159. chooseImage() {
  160. const app = this
  161. // 选择图片
  162. uni.chooseImage({
  163. count: 1,
  164. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  165. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  166. success({ tempFiles }) {
  167. const imageList = tempFiles;
  168. return new Promise((resolve, reject) => {
  169. if (imageList.length > 0) {
  170. UploadApi.image(imageList)
  171. .then(files => {
  172. if (files && files.length > 0) {
  173. app.userInfo.avatar = files[0].fileName;
  174. app.avatar = files[0].domain + app.userInfo.avatar;
  175. }
  176. resolve(files)
  177. })
  178. .catch(err => reject(err))
  179. } else {
  180. resolve()
  181. }
  182. })
  183. }
  184. });
  185. },
  186. /**
  187. * 保存个人信息
  188. */
  189. save() {
  190. const app = this
  191. app.isLoading = true
  192. UserApi.save({"name": app.nickname, "avatar": app.avatar, "sex": app.userInfo.sex, "birthday": app.userInfo.birthday})
  193. .then(result => {
  194. app.userInfo = result.data
  195. app.isLoading = false
  196. app.$success('保存成功!')
  197. }).catch(err => {
  198. app.isLoading = false;
  199. })
  200. },
  201. /**
  202. * 退出登录
  203. */
  204. logout() {
  205. store.dispatch('Logout');
  206. this.$navTo('pages/user/index');
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .info-list {
  213. padding-bottom: 100rpx;
  214. margin-top: 25rpx;
  215. }
  216. // 项目内容
  217. .info-item {
  218. margin: 20rpx auto 20rpx auto;
  219. padding: 30rpx 40rpx;
  220. width: 94%;
  221. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  222. border-radius: 16rpx;
  223. background: #fff;
  224. .avatar-warp {
  225. line-height: 120rpx;
  226. }
  227. }
  228. .contacts {
  229. font-size: 30rpx;
  230. .name {
  231. margin-left:0px;
  232. }
  233. .value {
  234. float:right;
  235. color:#999999;
  236. text-align: right;
  237. .second {
  238. margin-left: .6rem;
  239. }
  240. }
  241. .password {
  242. text-align: right;
  243. float: left;
  244. padding-right: 5rpx;
  245. }
  246. .avatar {
  247. width: 120rpx;
  248. height: 120rpx;
  249. border-radius: 120rpx;
  250. border: solid 1px #cccccc;
  251. float: right;
  252. }
  253. }
  254. .item-option {
  255. display: flex;
  256. justify-content: space-between;
  257. height: 48rpx;
  258. }
  259. // 底部操作栏
  260. .footer-fixed {
  261. height: 100rpx;
  262. z-index: 11;
  263. .btn-wrapper {
  264. height: 100%;
  265. display: flex;
  266. align-items: center;
  267. padding: 0 20rpx;
  268. }
  269. .btn-item {
  270. flex: 1;
  271. font-size: 28rpx;
  272. height: 80rpx;
  273. line-height: 80rpx;
  274. text-align: center;
  275. color: #fff;
  276. border-radius: 40rpx;
  277. }
  278. .btn-item-main {
  279. background: linear-gradient(to right, #f9211c, #ff6335);
  280. }
  281. .btn-item-out {
  282. margin-top: 20rpx;
  283. background: #FFFFFF;
  284. border: 1px solid $fuint-theme;
  285. color: #666666;
  286. }
  287. }
  288. </style>