| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import { BasicType, IBestToast, YTAvoid, yTRouter } from "basic";
- import { DiaLogPageEnum, DiaLogParam } from "basic/src/main/ets/models/YTDiaLogModel";
- import { data } from "@kit.TelephonyKit";
- import { BabyInfo } from "../model/Index";
- import { BabyFoodApi } from "../Apis/BabyFoodApi";
- import { Type } from "@ohos.arkui.StateManagement";
- @ObservedV2
- export class IncreaseBabyInfoViewModel{
- @Trace babyInfo: BabyInfo = new BabyInfo()
- @Trace safeTop: number = 0
- forEachData: Array<BasicType> = [
- {
- text: '生日',
- message: '请选择宝宝生日',
- id: 'forEach-BirthDay',
- date: 'birthDate',
- click: () => {
- this.selectBirthDay()
- },
- }, {
- text: '宝宝姓名',
- message: '请输入宝宝姓名',
- date: 'name',
- id: 'forEach-Name',
- click: () => {
- this.inputName()
- }
- }, {
- text: '性别',
- message: '请选择宝宝性别',
- date: 'gender',
- id: 'forEach-Gender',
- click: () => {
- this.selectGender()
- },
- }
- ]
- constructor() {
- this.safeTop = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
- }
- /**
- * 重写的返回逻辑
- * @returns
- */
- _onBackPressed(ans?: string){
- if(ans) yTRouter.pop(ans, true)
- else yTRouter.pop()
- return true;
- }
- // 填写完成
- async complete(){
- if(!this.babyInfo.birthday) {
- IBestToast.show('请选择宝宝生日')
- return
- }
- if(!this.babyInfo.name) {
- IBestToast.show('请填写宝宝姓名')
- return
- }
- if(!this.babyInfo.gender) {
- IBestToast.show('请选择宝宝性别')
- return
- }
- try {
- await BabyFoodApi.addBabyInfo(BabyInfo.clone(this.babyInfo))
- this._onBackPressed('success')
- } catch (error){
- }
- }
- // 跳过填写
- notFill(){
- // this._onBackPressed()
- }
- // 选择生日
- selectBirthDay(){
- const param: DiaLogParam = {
- pageEnum: DiaLogPageEnum.DatePicker,
- param: {
- date: this.babyInfo.birthday
- }
- }
- yTRouter.router2NaviDiaLog(param, (ans) => {
- let date = ans.result
- if(date){
- this.babyInfo.birthday = date as string
- }
- })
- }
- // 选择性别
- selectGender(){
- const param: DiaLogParam = {
- pageEnum: DiaLogPageEnum.SelectGender,
- param: {
- number: this.babyInfo.gender
- }
- }
- yTRouter.router2NaviDiaLog(param, (ans) => {
- let res = ans.result
- if(res){
- this.babyInfo.gender = res == '男' ? 1 : 2
- }
- })
- }
- // 输入宝宝姓名
- inputName(){
- const param: DiaLogParam = {
- pageEnum: DiaLogPageEnum.TextInput,
- param: {
- text: this.babyInfo.name,
- message: '请输入宝宝姓名'
- }
- }
- yTRouter.router2NaviDiaLog(param, (ans) => {
- let res = ans.result
- if(res){
- this.babyInfo.name = res as string
- }
- })
- }
- }
|