userInfo.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view class="content">
  3. <!-- 个人信息 -->
  4. <view class="blur-bg-2"></view>
  5. <view class="top-btn">
  6. <view class="back x-c" @click="$navBack()">
  7. <image src='/static/image/new/icon_back.svg'></image>
  8. 返回
  9. </view>
  10. <view class="title x-c">
  11. <image src='/static/image/new/img_title1.svg'></image>
  12. <text>信息采集</text>
  13. <image src='/static/image/new/img_title2.svg'></image>
  14. </view>
  15. <view class="index x-c" @click="goIndex">
  16. <image src='/static/image/new/icon_home.svg'></image>
  17. 首页
  18. </view>
  19. </view>
  20. <view class="userBox">
  21. <view class="toptitle">
  22. <view class="tips">首先</view>
  23. 请您填写一些基本信息,这将帮助我为您提供更精准的分析。
  24. </view>
  25. <view class="userInfo y-bc">
  26. <view class="form-item">
  27. <text class="label">姓名</text>
  28. <input type="text" v-model="form.username" class="form-input" placeholder="请输入姓名"
  29. placeholder-class="text-input" :class="{'input-highlight': highlightStatus.username }"
  30. @focus="setHighlight('username', true)" @blur="setHighlight('username', false)" />
  31. </view>
  32. <view class="form-item">
  33. <text class="label">性别</text>
  34. <radio-group class="r-box x-f">
  35. <view class="select x-c" :class="form.sex==1?'active':''" @click="genderChange(1)">
  36. <image
  37. :src="form.sex==1?'/static/image/new/icon_manbai.svg':'/static/image/new/icon_man.svg'">
  38. </image>
  39. <text>男</text>
  40. </view>
  41. <view class="select x-c" :class="form.sex==0?'active':''" @click="genderChange(0)">
  42. <image
  43. :src="form.sex==0?'/static/image/new/icon_femalebai.svg':'/static/image/new/icon_female.svg'">
  44. </image>
  45. <text>女</text>
  46. </view>
  47. </radio-group>
  48. </view>
  49. <view class="form-item">
  50. <text class="label">手机号</text>
  51. <input type="number" v-model="form.phone" maxlength="11" class="form-input" placeholder="请输入手机号"
  52. placeholder-class="text-input" :class="{'input-highlight': highlightStatus.phone }"
  53. @focus="setHighlight('phone', true)" @blur="setHighlight('phone', false)" />
  54. </view>
  55. <view class="form-item">
  56. <text class="label">身份证号</text>
  57. <input type="text" v-model="form.idCard" maxlength="18" class="form-input" placeholder="请输入身份证号"
  58. placeholder-class="text-input" :class="{'input-highlight': highlightStatus.idCard }"
  59. @focus="setHighlight('idCard', true)" @blur="setHighlight('idCard', false)" />
  60. </view>
  61. <view class="form-item">
  62. <text class="label">年龄</text>
  63. <input type="number" v-model="form.age" class="form-input" placeholder="请输入年龄"
  64. placeholder-class="text-input" :class="{'input-highlight': highlightStatus.age }"
  65. @focus="setHighlight('age', true)" @blur="setHighlight('age', false)" />
  66. </view>
  67. <view class="form-item">
  68. <text class="label">身高(cm)</text>
  69. <input type="digit" v-model="form.height" class="form-input" placeholder="请输入身高"
  70. placeholder-class="text-input" :class="{'input-highlight': highlightStatus.height }"
  71. @focus="setHighlight('height', true)" @blur="setHighlight('height', false)" />
  72. </view>
  73. <view class="form-item">
  74. <text class="label">体重(kg)</text>
  75. <input type="digit" v-model="form.weight" class="form-input" placeholder="请输入体重"
  76. placeholder-class="text-input" :class="{'input-highlight': highlightStatus.weight }"
  77. @focus="setHighlight('weight', true)" @blur="setHighlight('weight', false)" />
  78. </view>
  79. <view class="btn-box" @click="onConfirm">提交</view>
  80. </view>
  81. </view>
  82. <CustomToast ref="toast"></CustomToast>
  83. </view>
  84. </template>
  85. <script>
  86. import {
  87. getUserInfoByUserId,
  88. getUserInfo,addUser
  89. } from '@/api/user.js';
  90. import CustomToast from '@/components/CustomToast.vue';
  91. export default {
  92. components: { CustomToast },
  93. data() {
  94. return {
  95. form: {
  96. username: '', // 姓名
  97. phone: '', // 手机号
  98. sex: 1, // 性别(1-男,0-女)
  99. age: '', // 年龄
  100. height: '', // 身高
  101. weight: '', // 体重
  102. idCard:'',
  103. // previousMedicalHistory: '', // 既往病史
  104. // habitList: [], //饮食习惯
  105. // historyOfAllergies: '' //过敏史
  106. },
  107. // 每个输入框的高亮状态
  108. highlightStatus: {
  109. username: false,
  110. phone: false,
  111. idCard: false,
  112. age: false,
  113. height: false,
  114. weight: false
  115. }
  116. }
  117. },
  118. onLoad(option) {
  119. },
  120. onShow() {
  121. },
  122. methods: {
  123. //首页
  124. goIndex(){
  125. uni.reLaunch({
  126. url: '/pages/index/index',
  127. animationType: 'none',
  128. animationDuration: 2000
  129. })
  130. },
  131. // 性别切换
  132. genderChange(sex) {
  133. this.form.sex = sex;
  134. },
  135. // 设置输入框高亮状态
  136. setHighlight(field, status) {
  137. this.$set(this.highlightStatus, field, status);
  138. },
  139. // 确认提交
  140. onConfirm() {
  141. // 表单校验
  142. if (this.form.username == null || this.form.username == '') {
  143. this.$refs.toast.showToast({
  144. title: "姓名不能为空",
  145. });
  146. return
  147. }
  148. const phoneReg = /^1[3-9]\d{9}$/;
  149. if (!phoneReg.test(this.form.phone)) {
  150. this.$refs.toast.showToast({
  151. title: "请输入正确的手机号",
  152. });
  153. return
  154. }
  155. const idCardReg = /(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  156. if (!idCardReg.test(this.form.idCard)) {
  157. this.$refs.toast.showToast({
  158. title: "请输入正确的身份证号",
  159. });
  160. return
  161. }
  162. if (this.form.age == null || this.form.age == '') {
  163. this.$refs.toast.showToast({
  164. title: "年龄不能为空",
  165. });
  166. return
  167. }
  168. if (this.form.height == null || this.form.height == '') {
  169. this.$refs.toast.showToast({
  170. title: "身高不能为空",
  171. });
  172. return
  173. }
  174. if (this.form.weight == null || this.form.weight == '') {
  175. this.$refs.toast.showToast({
  176. title: "体重不能为空",
  177. });
  178. return
  179. }
  180. console.log('表单提交数据:', this.form);
  181. uni.showLoading({
  182. title: "提交中...",
  183. mask: true
  184. })
  185. addUser(this.form).then(res => {
  186. if (res.code == 200) {
  187. setTimeout(() => {
  188. uni.hideLoading();
  189. // this.$refs.toast.showToast({ title: '提交成功', icon: 'success' })
  190. // uni.showToast({ title: '提交成功', icon: 'success' });
  191. uni.setStorageSync('AppToken', res.token);
  192. uni.setStorageSync('userInfo', JSON.stringify(res.additionalData));
  193. uni.navigateTo({
  194. url: '/pages/user/success'
  195. });
  196. // 重置表单+高亮状态
  197. this.form = {
  198. username: '',
  199. sex: 1,
  200. phone: '',
  201. idCard: '',
  202. age: '',
  203. height: '',
  204. weight: ''
  205. };
  206. // 重置高亮状态
  207. Object.keys(this.highlightStatus).forEach(key => {
  208. this.$set(this.highlightStatus, key, false);
  209. });
  210. }, 500);
  211. }else {
  212. this.$refs.toast.showToast({title: res.msg});
  213. }
  214. },rej => {});
  215. },
  216. }
  217. }
  218. </script>
  219. <style scoped lang="scss">
  220. page {
  221. background: #fff;
  222. font-size: 16px
  223. }
  224. .content {
  225. width: 100%;
  226. height: 100%;
  227. overflow: hidden;
  228. background: #D8F6EF;
  229. padding: 28px;
  230. display: flex;
  231. flex-direction: column;
  232. .blur-bg-2 {
  233. width: 350px;
  234. height: 350px;
  235. background: #FFFDCC;
  236. // opacity: 0.47;
  237. filter: blur(200px);
  238. position: absolute;
  239. z-index: 1;
  240. top: 60px;
  241. right: calc(0px - 107px);
  242. pointer-events: none
  243. }
  244. }
  245. .top-btn {
  246. display: flex;
  247. align-items: center;
  248. justify-content: space-between;
  249. z-index:2;
  250. .back {
  251. width: 140px;
  252. height: 48px;
  253. background: rgba(255, 255, 255, 0.64);
  254. border-radius: 45px 45px 45px 45px;
  255. border: 2px solid #FFFFFF;
  256. font-family: PingFang SC, PingFang SC;
  257. font-weight: 500;
  258. font-size: 22px;
  259. color: #327E6F;
  260. image {
  261. margin-right: 4px;
  262. width: 24px;
  263. height: 24px;
  264. }
  265. }
  266. .title {
  267. font-family: PingFang SC, PingFang SC;
  268. font-weight: 600;
  269. font-size: 36px;
  270. color: #327E6F;
  271. line-height: 54px;
  272. text {
  273. margin: 0 14px;
  274. }
  275. image {
  276. width: 153px;
  277. height: 25px;
  278. }
  279. }
  280. .index {
  281. width: 140px;
  282. height: 48px;
  283. background: rgba(255, 255, 255, 0.64);
  284. border-radius: 55px 55px 55px 55px;
  285. border: 2px solid #FFFFFF;
  286. font-family: PingFang SC, PingFang SC;
  287. font-weight: 500;
  288. font-size: 22px;
  289. color: #327E6F;
  290. image {
  291. margin-right: 4px;
  292. width: 24px;
  293. height: 24px;
  294. }
  295. }
  296. }
  297. .userBox {
  298. flex: 1;
  299. margin-top: 28px;
  300. background: rgba(255, 255, 255, 0.7);
  301. border-radius: 24px 24px 24px 24px;
  302. padding: 27px 40px;
  303. z-index: 9;
  304. .toptitle {
  305. display: flex;
  306. align-items: center;
  307. width: 100%;
  308. height: 66px;
  309. background: rgba(55, 195, 160, 0.17);
  310. border-radius: 12px 12px 12px 12px;
  311. font-family: PingFang SC, PingFang SC;
  312. font-weight: 400;
  313. font-size: 22px;
  314. color: #0C4035;
  315. line-height: 66px;
  316. padding: 0 22px;
  317. .tips {
  318. width: 56px;
  319. height: 28px;
  320. margin-right: 14px;
  321. line-height: 28px;
  322. font-family: PingFang SC, PingFang SC;
  323. font-weight: 500;
  324. font-size: 19px;
  325. color: #FFFFFF;
  326. text-align: center;
  327. background: linear-gradient(95deg, #3DDAB3 0%, #50D7E0 100%);
  328. border-radius: 5px 5px 5px 5px;
  329. }
  330. }
  331. .form-item {
  332. display: flex;
  333. align-items: center;
  334. margin-top: 32px;
  335. .label {
  336. width: 150px;
  337. font-family: PingFang SC, PingFang SC;
  338. font-weight: 400;
  339. font-size: 24px;
  340. color: #333333;
  341. }
  342. .r-box {
  343. width: 460px;
  344. .select {
  345. width: 128px;
  346. height: 48px;
  347. border-radius: 44px 44px 44px 44px;
  348. border: 2px solid #37C3A0;
  349. margin-right: 30px;
  350. text {
  351. font-family: PingFang SC, PingFang SC;
  352. font-weight: 400;
  353. font-size: 24px;
  354. color: #37C3A0;
  355. line-height: 48px;
  356. margin-left: 12px;
  357. }
  358. image {
  359. width: 24px;
  360. height: 24px;
  361. }
  362. &.active {
  363. background: #37C3A0;
  364. text {
  365. color: #FFFFFF;
  366. }
  367. }
  368. }
  369. }
  370. .form-input {
  371. width: 460px;
  372. height: 60px;
  373. padding: 7px 22px;
  374. box-sizing: border-box;
  375. background: #FFFFFF;
  376. box-shadow: 0px 2px 12px 0px rgba(86, 162, 143, 0.12);
  377. border-radius: 62px 62px 62px 62px;
  378. font-family: PingFang SC, PingFang SC;
  379. font-weight: 400;
  380. font-size: 24px;
  381. &.input-highlight {
  382. box-shadow: 0px 2px 12px 0px rgba(86,162,143,0.12);
  383. border: 2px solid #37C3A0;
  384. }
  385. }
  386. .text-input {
  387. color: #B1B1B1;
  388. }
  389. }
  390. .btn-box {
  391. margin-top: 50px;
  392. margin-bottom: 16px;
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. width: 360px;
  397. height: 68px;
  398. background: #37C3A0;
  399. border-radius: 121px 121px 121px 121px;
  400. font-family: PingFang SC, PingFang SC;
  401. font-weight: 600;
  402. font-size: 28px;
  403. color: #FFFFFF;
  404. }
  405. }
  406. </style>