耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

379 lines
8.0 KiB

  1. <template>
  2. <view class="user-info flex-1">
  3. <view class="row">
  4. <text>头像</text>
  5. <view class="pic_box">
  6. <view class="pic_box">
  7. <button open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
  8. <u-avatar size="80" :src="form.headUrl || ''" @click="selectFile"></u-avatar>
  9. </button>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="row" @click="toPage">
  14. <text>昵称</text>
  15. <u-input v-model="form.nickName" disabled input-align="right" placeholder="请设置姓名" @click="toPage" />
  16. </view>
  17. <view class="row flex align-center">
  18. <text>手机号码</text>
  19. <u-input v-model="form.phone" disabled input-align="right" placeholder="请设置手机号码" />
  20. <!-- <text>{{ form.phone }}</text> -->
  21. </view>
  22. <view class="row flex align-center">
  23. <text>性别</text>
  24. <view class="flex align-center" @click="showPopup('sexShow')">
  25. <u-input v-model="form.sex" disabled placeholder="请设置性别" input-align="right"
  26. @click="showPopup('sexShow')" />
  27. <u-icon name="arrow-right" class="m-l-10"></u-icon>
  28. </view>
  29. </view>
  30. <view class="row flex align-center">
  31. <text>生日</text>
  32. <view class="flex-1 flex align-center justify-end" @click="showPopup('birthdayShow')">
  33. <u-input v-model="form.birthday" disabled placeholder="您还未设置生日" input-align="right"
  34. @click="showPopup('birthdayShow')" />
  35. <u-icon name="arrow-right" class="m-l-10"></u-icon>
  36. </view>
  37. </view>
  38. <u-select v-model="sexShow" :list="sexList" @confirm="sexConfirm" />
  39. <u-picker mode="time" v-model="birthdayShow" @confirm="birthdayConfirm" confirm-color="#01AEEA" />
  40. </view>
  41. </template>
  42. <script>
  43. const defaultAvatarUrl =
  44. 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  45. import {
  46. mapState
  47. } from "vuex";
  48. import config_img from "@/utils/js/config.js";
  49. import {
  50. UPLOAD_IMG
  51. } from '@/config/settings.js'
  52. import {
  53. TOKEN_HEADER_NAME
  54. } from '@/config/settings.js'
  55. export default {
  56. data() {
  57. return {
  58. uploadUrl: UPLOAD_IMG,
  59. status: 'watch',
  60. img_url: config_img.img_url,
  61. form: {
  62. nickName: '',
  63. sex: '',
  64. phone: '',
  65. headUrl: '',
  66. birthday: ''
  67. },
  68. sexShow: false,
  69. birthdayShow: false,
  70. sexList: [{
  71. value: "1",
  72. label: "男",
  73. },
  74. {
  75. value: "2",
  76. label: "女",
  77. },
  78. ],
  79. };
  80. },
  81. onLoad() {
  82. console.log(this.userInfo)
  83. const getUserInfo = this.$storage.getStorage("__user_info")
  84. this.form = getUserInfo
  85. this.form.birthday = this.form.birthday.substr(0, 10)
  86. uni.$on('EDITNAME', val => {
  87. this.form.nickName = val
  88. this.editUserInfo({
  89. nickName: val
  90. })
  91. })
  92. },
  93. computed: {
  94. // ...mapState({
  95. // userInfo: (state) => state.userInfo,
  96. // }),
  97. // disabled () {
  98. // return this.status === 'edit' ? false : true
  99. // },
  100. // btnTxt () {
  101. // return this.status === 'edit' ? '保存' : '修改'
  102. // }
  103. },
  104. onUnload() {
  105. this.$off('EDITNAME')
  106. },
  107. methods: {
  108. onChooseAvatar(e) {
  109. console.log("===================")
  110. console.log(e)
  111. },
  112. preserve() {
  113. if (this.status === 'watch') return this.status = 'edit'
  114. console.log(this.$refs.uUpload.lists, this.fileList)
  115. },
  116. onSuccess(data) {
  117. this.setUserInfo({
  118. headUrl: data.result
  119. });
  120. },
  121. sexConfirm(arr) {
  122. this.form.sex = arr[0].label
  123. this.editUserInfo({
  124. sex: this.form.sex
  125. })
  126. },
  127. birthdayConfirm(time) {
  128. let {
  129. year,
  130. month,
  131. day
  132. } = time;
  133. this.form.birthday = `${year}-${month}-${day}`;
  134. this.editUserInfo({
  135. birthday: this.form.birthday
  136. })
  137. },
  138. showPopup(key) {
  139. if (!this.disabled) this[key] = true
  140. },
  141. toPage() {
  142. this.$tools.navigateTo({
  143. url: `/pages/my/information/editName?name=${this.form.nickName}`
  144. })
  145. },
  146. editUserInfo(params = {}, status = 0) {
  147. uni.showLoading();
  148. this.$api('editUserInfo', params)
  149. .then(res => {
  150. uni.hideLoading();
  151. let {
  152. code,
  153. message,
  154. result
  155. } = res
  156. this.$Toast(message)
  157. if (code === 200) {
  158. if (status == 1) {
  159. // 上传图片
  160. console.log(params.headUrl, 12313)
  161. this.form.headUrl = params.headUrl
  162. }
  163. // 更新用户信息
  164. this.getUserInfo();
  165. }
  166. }).catch(err => {
  167. uni.hideLoading();
  168. this.$Toast(err.message)
  169. })
  170. },
  171. selectFile(e) {
  172. console.log(e)
  173. // disabled
  174. uni.showActionSheet({
  175. itemList: ['拍照', '选择一张照片'],
  176. success: res => {
  177. this.chooseImage(res.tapIndex)
  178. },
  179. fail: err => {
  180. // this.$Toast(err.errMsg);
  181. }
  182. })
  183. },
  184. // 更新用户信息
  185. getUserInfo() {
  186. return new Promise((resolve, reject) => {
  187. this.$api('getUserInfo').then(res => {
  188. let {
  189. code,
  190. result,
  191. message
  192. } = res;
  193. if (code == 200) {
  194. this.$storage.removeStorage('__user_info')
  195. let userInfo = {
  196. ...result.account,
  197. ...result.userInfo
  198. }
  199. // 更新用户信息缓存
  200. // this.userInfo = userInfo
  201. this.$storage.setStorage("__user_info", userInfo)
  202. // this.getAddressInfo();
  203. resolve(result)
  204. } else {
  205. reject(message)
  206. }
  207. }).catch(err => {
  208. reject(err.message)
  209. })
  210. })
  211. },
  212. chooseImage() {
  213. uni.chooseImage({
  214. count: 1,
  215. sourceType: ['album', 'camera'],
  216. sizeType: ['original', 'compressed'],
  217. success: res => {
  218. res.tempFiles.map((val, index) => {
  219. // this.fileList.push({
  220. // url: val.path,
  221. // progress: 0,
  222. // error: false,
  223. // file: val,
  224. // });
  225. uni.uploadFile({
  226. url: this.uploadUrl,
  227. filePath: val.path,
  228. name: 'file',
  229. header: {
  230. [TOKEN_HEADER_NAME]: this.$store.state.userToken
  231. },
  232. success: res => {
  233. console.log(res)
  234. const img = JSON.parse(res.data)
  235. this.editUserInfo({
  236. headUrl: img.result
  237. }, 1)
  238. },
  239. fail: err => {
  240. console.log(err)
  241. }
  242. })
  243. });
  244. },
  245. fail: error => {
  246. this.$Toast(error);
  247. }
  248. })
  249. }
  250. },
  251. };
  252. </script>
  253. <style lang="scss" scoped>
  254. .user-info {
  255. padding-bottom: 140rpx;
  256. &-footer {
  257. z-index: 1;
  258. height: 120rpx;
  259. bottom: 0;
  260. left: 0;
  261. width: 100%;
  262. background: #fff;
  263. /deep/.u-btn {
  264. width: 660rpx;
  265. height: 80rpx;
  266. }
  267. }
  268. }
  269. .pic_box {
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. /deep/.u-list-item {
  274. margin: 0;
  275. width: 89rpx !important;
  276. height: 89rpx !important;
  277. border-radius: 50%;
  278. .u-preview-image {
  279. width: 89rpx;
  280. height: 89rpx;
  281. border-radius: 50%;
  282. }
  283. image {
  284. width: 89rpx;
  285. height: 89rpx;
  286. border-radius: 50%;
  287. overflow: hidden;
  288. // border: 1px solid #707070;
  289. }
  290. }
  291. image {
  292. width: 89rpx;
  293. height: 89rpx;
  294. border-radius: 50%;
  295. // border: 1px solid #707070;
  296. }
  297. }
  298. /deep/ .u-calendar__action {
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. }
  303. .row {
  304. width: 691rpx;
  305. height: 110rpx;
  306. margin: 0 auto;
  307. font-size: 32rpx;
  308. color: #000000;
  309. padding-left: 10rpx;
  310. padding-right: 37rpx;
  311. box-sizing: border-box;
  312. display: flex;
  313. justify-content: space-between;
  314. align-items: center;
  315. border-bottom: 1px solid #ccc;
  316. .data_time {
  317. padding-right: 30rpx;
  318. }
  319. }
  320. .content {
  321. width: 520rpx;
  322. height: 300rpx;
  323. background-color: #fff;
  324. border-radius: 20rpx;
  325. overflow: hidden;
  326. .contentRow {
  327. display: flex;
  328. flex-direction: column;
  329. text {
  330. margin-left: 18rpx;
  331. margin-top: 20rpx;
  332. font-size: 45rpx;
  333. font-weight: bold;
  334. }
  335. /deep/ u-input {
  336. flex: 1;
  337. margin: 10rpx 30rpx 10rpx;
  338. }
  339. }
  340. .btn_box {
  341. display: flex;
  342. .close {
  343. width: 180rpx;
  344. color: #707070;
  345. }
  346. .change {
  347. background-color: #01aeea;
  348. color: #fff;
  349. width: 180rpx;
  350. display: flex;
  351. justify-content: center;
  352. align-items: center;
  353. font-size: 32rpx;
  354. font-weight: bold;
  355. }
  356. }
  357. }
  358. </style>