personalData.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view class="personalData">
  3. <view class="form">
  4. <uni-forms :modelValue="formData" label-position="top">
  5. <uni-forms-item label="昵称" name="nickname">
  6. <uni-easyinput placeholderStyle="color: #999; font-size:30rpx " type="text"
  7. v-model="formData.nickname" placeholder="请输入姓名" />
  8. </uni-forms-item>
  9. <!--地区选择-->
  10. <uni-forms-item label="地区" name="region">
  11. <pickerAddress @change="change">
  12. <view class="selectType">
  13. <view class="uni-input">
  14. <text style="color: #999999 ; font-size: 30rpx;" v-if="region==''">所在地区</text>
  15. <text style="font-size: 30rpx;" v-if="region!=''">{{region}}</text>
  16. </view>
  17. <image src="/static/icon/right.png"
  18. style="width: 14rpx;height: 24rpx;position: absolute;top:24rpx;right: 24rpx;">
  19. </image>
  20. </view>
  21. </pickerAddress>
  22. </uni-forms-item>
  23. <uni-forms-item label="性别" name="sex">
  24. <view class="sex">
  25. <picker mode="selector" :value="sex_text" :range='sexSelect' @change="bindSexChange">
  26. <view class="uni-input" @change="bindSexChange">
  27. <text v-if="formData.sex==''||formData.sex==null"
  28. style="color: #999999; font-size: 30rpx; ">选择性别</text>
  29. <text v-if="formData.sex!=''">{{sex_text}}</text>
  30. </view>
  31. <image src="/static/icon/right.png" @change="bindSexChange"
  32. style="width: 14rpx;height: 24rpx;position: absolute;top:22rpx;right: 30rpx;"></image>
  33. </picker>
  34. </view>
  35. </uni-forms-item>
  36. <uni-forms-item label="手机号" name="phone">
  37. <uni-easyinput maxlength="11" placeholderStyle="color: #999; font-size:30rpx " type="number"
  38. v-model="formData.mobile" placeholder="输入手机号" @blur="getPhone" />
  39. </uni-forms-item>
  40. <uni-forms-item label="生日" name="birthday">
  41. <view class="birthday">
  42. <picker mode="date" :value="formData.birthday" :start="startDate" :end="endDate"
  43. @change="bindDateChange">
  44. <view class="uni-input" @change="bindDateChange">
  45. <text v-if="formData.birthday==''||formData.birthday==null"
  46. style="color: #999999; font-size: 30rpx; ">选择生日</text>
  47. <text v-if="formData.birthday!=''">{{formData.birthday}}</text>
  48. </view>
  49. <image src="/static/icon/right.png" @change="bindDateChange"
  50. style="width: 14rpx;height: 24rpx;position: absolute;top:22rpx;right: 30rpx;"></image>
  51. </picker>
  52. </view>
  53. </uni-forms-item>
  54. <view class="keep-msg" @click="saveBtn">
  55. <text>保存信息</text>
  56. </view>
  57. </uni-forms>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import pickerAddress from '@/uni_modules/hu-pickerAddress/hu-pickerAddress.vue'
  63. export default {
  64. components: {
  65. pickerAddress
  66. },
  67. data() {
  68. const currentDate = this.getDate({
  69. format: true
  70. })
  71. return {
  72. formData: {
  73. nickname: '',
  74. sex: '',
  75. birthday: '',
  76. mobile: '',
  77. area_id: ''
  78. },
  79. sexSelect: ['男', '女', '其他'],
  80. sex_text: '',
  81. region: '',
  82. }
  83. },
  84. computed: {
  85. startDate() {
  86. return this.getDate('start');
  87. },
  88. endDate() {
  89. return this.getDate('end');
  90. }
  91. },
  92. onLoad() {
  93. this.formData.nickname = this.$store.getters.userInfo.nickname
  94. //获取用户信息
  95. this.getUserInfo()
  96. },
  97. onUnload() {
  98. uni.$emit('refreshAdminName',this.formData.nickname )
  99. },
  100. methods: {
  101. //获取用户信息
  102. getUserInfo(){
  103. this.$api.my.userInfo().then(res=>{
  104. console.log(res.data,'---->用户信息');
  105. let obj ={}
  106. obj.nickname = res.data.nickname
  107. obj.mobile = res.data.mobile
  108. obj.sex = res.data.sex
  109. obj.birthday = res.data.birthday
  110. obj.area_id = res.data.area_id
  111. this.region = res.data.region
  112. this.formData = obj
  113. if(this.formData.sex == 0){
  114. this.sex_text = '未知'
  115. }else if(this.formData.sex == 1){
  116. this.sex_text = '男'
  117. }else if(this.formData.sex == 2){
  118. this.sex_text = '女'
  119. }
  120. this.$store.getters.userInfo.nickname = obj.nickname
  121. })
  122. },
  123. //获取手机号
  124. getPhone() {
  125. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  126. if (!phoneReg.test(this.formData.mobile)) {
  127. uni.showToast({
  128. title: '请输入合法手机号',
  129. icon: "none"
  130. })
  131. return
  132. }
  133. },
  134. change(ret) {
  135. this.region = ret.data.join('-')
  136. this.formData.area_id = ret.code[2]
  137. },
  138. bindDateChange: function(e) {
  139. this.formData.birthday = e.detail.value
  140. },
  141. bindSexChange: function(e) {
  142. if (e.detail.value == 0) {
  143. this.sex_text = '男'
  144. this.formData.sex = 1
  145. } else if (e.detail.value == 1) {
  146. this.sex_text = '女'
  147. this.formData.sex = 2
  148. } else {
  149. this.sex_text = '其他'
  150. this.formData.sex = 0
  151. }
  152. },
  153. getDate(type) {
  154. const date = new Date();
  155. let year = date.getFullYear();
  156. let month = date.getMonth() + 1;
  157. let day = date.getDate();
  158. if (type === 'start') {
  159. year = year - 60;
  160. } else if (type === 'end') {
  161. year = year;
  162. }
  163. month = month > 9 ? month : '0' + month;
  164. day = day > 9 ? day : '0' + day;
  165. return `${year}-${month}-${day}`;
  166. },
  167. //保存信息
  168. saveBtn() {
  169. if (this.formData.nickname == '') {
  170. uni.showToast({
  171. title: '请输入昵称',
  172. icon: "none"
  173. })
  174. return
  175. }
  176. if (this.formData.area_id == '') {
  177. uni.showToast({
  178. title: '请输入地区',
  179. icon: "none"
  180. })
  181. return
  182. }
  183. if (this.formData.sex == '') {
  184. uni.showToast({
  185. title: '请输入性别',
  186. icon: "none"
  187. })
  188. return
  189. }
  190. if (this.formData.mobile == '') {
  191. uni.showToast({
  192. title: '请输入手机号',
  193. icon: "none"
  194. })
  195. return
  196. }
  197. if (this.formData.birthday == '') {
  198. uni.showToast({
  199. title: '请输入生日',
  200. icon: "none"
  201. })
  202. return
  203. }
  204. this.$api.my.refreshPersonData(this.formData).then(res => {
  205. if (res.code == 0) {
  206. uni.showToast({
  207. title: '保存成功',
  208. icon: "none"
  209. })
  210. setTimeout(()=>{
  211. uni.switchTab({
  212. url:'/pages/my/my'
  213. })
  214. },500)
  215. // let personData = JSON.parse(JSON.stringify(this.formData))
  216. // personData.region = this.region
  217. // personData.sex = this.sex_text
  218. // console.log(personData,'---->personDate');
  219. // this.$store.dispatch('user/person',personData)
  220. } else {
  221. uni.showToast({
  222. title: res.msg,
  223. icon: "none"
  224. })
  225. }
  226. })
  227. },
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. $pageColor:#F9F9F9;
  233. $bgColor:#FFFFFF;
  234. .personalData {
  235. height: 100%;
  236. background: $pageColor;
  237. }
  238. .selectType {
  239. width: 100%;
  240. height: 74rpx;
  241. background: #FFFFFF;
  242. border-radius: 8rpx;
  243. border: 2rpx solid #EAEAEA;
  244. display: flex;
  245. align-items: center;
  246. padding-left: 20rpx;
  247. box-sizing: border-box;
  248. position: relative;
  249. }
  250. .keep-msg {
  251. width: 100%;
  252. height: 92rpx;
  253. background: linear-gradient(270deg, #FF6200 0%, #FF9342 100%);
  254. border-radius: 12rpx;
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. text {
  259. font-weight: bold;
  260. color: #FFFFFF;
  261. font-size: 30rpx;
  262. }
  263. }
  264. .form {
  265. padding: 24rpx 48rpx 0 50rpx;
  266. .birthday,
  267. .sex {
  268. width: 652rpx;
  269. height: 74rpx;
  270. background: #FFFFFF;
  271. border-radius: 8rpx;
  272. border: 1px solid #EAEAEA;
  273. display: flex;
  274. align-items: center;
  275. padding-left: 20rpx;
  276. box-sizing: border-box;
  277. position: relative;
  278. }
  279. }
  280. ::v-deep .uni-forms-item__label {
  281. font-weight: bold;
  282. color: #333333;
  283. font-size: 32rpx;
  284. }
  285. ::v-deep .uni-easyinput__content-input {
  286. color: #333333;
  287. font-size: 32rpx;
  288. }
  289. ::v-deep .is-input-border {
  290. border-color: #e5e5e5 !important;
  291. background-color: #fff !important;
  292. }
  293. ::v-deep .uni-icons {
  294. color: #c0c4cc !important;
  295. font-size: 24px !important;
  296. }
  297. </style>