敢为人鲜小程序前端代码仓库
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.

303 lines
8.1 KiB

  1. <template>
  2. <view class="login">
  3. <view class="bg1"></view>
  4. <view class="title">
  5. 定制自己的形象
  6. </view>
  7. <view v-if="back" @click="$utils.navigateBack" style="position: absolute;top: 120rpx;left: 20rpx;">
  8. <uv-icon size="30rpx" color="#000" name="arrow-left"></uv-icon>
  9. </view>
  10. <button class="chooseAvatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  11. <image :src="form.headImage" mode="aspectFill"></image>
  12. </button>
  13. <input type="nickname" placeholder="给自己起一个响亮的名字" class="nickname" id="nickName" v-model="form.nickName" />
  14. <!-- <view class="sexSelect">
  15. <view
  16. @click="sexClick(item)"
  17. v-for="(item, index) in sexList"
  18. :key="index"
  19. :style="{color : form.sex == item.value ? item.actColor : '#333'}">
  20. <uv-icon
  21. size="30rpx"
  22. :color="form.sex == item.value ? item.actColor : '#333'"
  23. :name="item.icon"></uv-icon>
  24. {{ item.value }}
  25. </view>
  26. </view> -->
  27. <!-- <view class="address"
  28. @click="$refs.datetimePicker.open()">
  29. 您出生于{{ $dayjs(form.yearDate).format("YYYY") }}
  30. </view>
  31. <view class="address"
  32. @click="$refs.picker.open()">
  33. {{ form.address || '请选择居住地址'}}
  34. </view> -->
  35. <uv-datetime-picker ref="datetimePicker" v-model="form.yearDate" mode="year" :minDate="minDate"
  36. :maxDate="maxDate">
  37. </uv-datetime-picker>
  38. <uv-picker ref="picker" :columns="columns" keyName="name" @confirm="confirmAddress"></uv-picker>
  39. <view class="btn" @click="submit">
  40. 确认
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { mapState } from 'vuex'
  46. export default {
  47. data() {
  48. return {
  49. form: {
  50. headImage: '',
  51. nickName: '',
  52. sex: '男',
  53. yearDate: this.$dayjs().add(-18, 'y').valueOf(),//默认满18岁
  54. address: '',
  55. },
  56. maxDate: this.$dayjs().valueOf(),
  57. minDate: this.$dayjs().add(-100, 'y').valueOf(),
  58. sex: {
  59. : {
  60. name: 'man',
  61. color: '#5baaff',
  62. },
  63. : {
  64. name: 'woman',
  65. color: '#ff50b3',
  66. },
  67. },
  68. sexList: [
  69. {
  70. value: '男',
  71. icon: 'man',
  72. actColor: '#5baaff',
  73. },
  74. {
  75. value: '女',
  76. icon: 'woman',
  77. actColor: '#ff50b3',
  78. },
  79. ],
  80. columns: [],
  81. back: '',
  82. };
  83. },
  84. computed: {
  85. ...mapState(['cityList', 'userInfo']),
  86. },
  87. onLoad({ back }) {
  88. this.back = back
  89. // this.$nextTick(() => {
  90. // this.form.headImage = this.userInfo.headImage || this.form.headImage
  91. // this.form.nickName = this.userInfo.nickName || this.form.nickName
  92. // this.form.sex = this.userInfo.sex || this.form.sex
  93. // this.form.yearDate = this.userInfo.yearDate || this.form.yearDate
  94. // this.form.address = this.userInfo.address || this.form.address
  95. // })
  96. },
  97. onShow() {
  98. this.getCityList()
  99. this.getUserInfo()
  100. },
  101. computed: {},
  102. methods: {
  103. onChooseAvatar(res) {
  104. let self = this
  105. self.$Oss.ossUpload(res.target.avatarUrl)
  106. .then(url => {
  107. self.form.headImage = url
  108. })
  109. },
  110. sexClick(item) {
  111. this.form.sex = item.value
  112. },
  113. confirmAddress(e) {
  114. this.form.address = e.value[0].name
  115. },
  116. // 获取城市
  117. getCityList() {
  118. this.$api('getCityList', res => {
  119. if (res.code == 200) {
  120. this.columns = [
  121. res.result
  122. ]
  123. }
  124. })
  125. },
  126. getUserInfo() {
  127. this.$api('getInfo', res => {
  128. if (res.code == 200) {
  129. this.form.headImage = res.result.headImage || this.form.headImage
  130. this.form.nickName = res.result.nickName || this.form.nickName
  131. this.form.sex = res.result.sex || this.form.sex
  132. this.form.yearDate = res.result.yearDate &&
  133. this.$dayjs(res.result.yearDate + '-01-01').valueOf() || this.form.yearDate
  134. this.form.address = res.result.address || this.form.address
  135. }
  136. })
  137. },
  138. submit() {
  139. let self = this
  140. uni.createSelectorQuery().in(this)
  141. .select("#nickName")
  142. .fields({
  143. properties: ["value"],
  144. })
  145. .exec((res) => {
  146. const nickName = res?.[0]?.value
  147. self.form.nickName = nickName
  148. if (self.$utils.verificationAll(self.form, {
  149. headImage: '请选择头像',
  150. nickName: '请填写昵称',
  151. // address: '请选择居住地址',
  152. })) {
  153. return
  154. }
  155. let data = {
  156. ...self.form,
  157. // yearDate : this.$dayjs(self.form.yearDate).format("YYYY")
  158. }
  159. self.$api('updateInfo', data, res => {
  160. if (res.code == 200) {
  161. uni.reLaunch({
  162. url: '/pages/index/index'
  163. })
  164. }
  165. })
  166. })
  167. },
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .login {
  173. display: flex;
  174. flex-direction: column;
  175. justify-content: center;
  176. align-items: center;
  177. height: 100vh;
  178. background-color: #fff;
  179. overflow: hidden;
  180. .bg1 {
  181. width: 700rpx;
  182. height: 700rpx;
  183. border-radius: 50%;
  184. background-color: #ffc0b333;
  185. position: absolute;
  186. right: -300rpx;
  187. top: -300rpx;
  188. }
  189. .title {
  190. line-height: 45rpx;
  191. font-weight: 900;
  192. padding-bottom: 100rpx;
  193. font-size: 40rpx;
  194. }
  195. .chooseAvatar {
  196. width: 100%;
  197. padding: 0 !important;
  198. margin: 0 !important;
  199. border: none;
  200. background-color: #fff !important;
  201. width: 220rpx;
  202. height: 220rpx;
  203. border-radius: 50%;
  204. image {
  205. width: 200rpx;
  206. height: 200rpx;
  207. border-radius: 50%;
  208. box-shadow: 0 0 10rpx 10rpx #00000012;
  209. margin: 10rpx;
  210. }
  211. }
  212. .chooseAvatar::after {
  213. border: none;
  214. padding: 0 !important;
  215. margin: 0 !important;
  216. }
  217. .nickname {
  218. background-color: #f7f7f7;
  219. width: 600rpx;
  220. height: 80rpx;
  221. text-align: center;
  222. border-radius: 40rpx;
  223. margin-top: 30rpx;
  224. }
  225. .sexSelect {
  226. background-color: #f7f7f7;
  227. width: 600rpx;
  228. height: 80rpx;
  229. text-align: center;
  230. border-radius: 40rpx;
  231. margin-top: 30rpx;
  232. display: flex;
  233. align-items: center;
  234. font-size: 26rpx;
  235. line-height: 80rpx;
  236. overflow: hidden;
  237. &>view {
  238. flex: 1;
  239. display: flex;
  240. justify-content: center;
  241. align-content: center;
  242. height: 100%;
  243. }
  244. &>view:nth-child(1) {
  245. border-right: 1px solid #000;
  246. }
  247. }
  248. .address {
  249. background-color: #f7f7f7;
  250. width: 600rpx;
  251. height: 80rpx;
  252. text-align: center;
  253. border-radius: 40rpx;
  254. margin-top: 30rpx;
  255. line-height: 80rpx;
  256. color: #555;
  257. }
  258. .btn {
  259. // background: $uni-linear-gradient-btn-color;
  260. background: $uni-color;
  261. color: #fff;
  262. width: 80%;
  263. padding: 20rpx 0;
  264. text-align: center;
  265. border-radius: 15rpx;
  266. margin-top: 10vh;
  267. }
  268. }
  269. </style>