<route lang="json5" type="page">
{
  style: { navigationBarTitleText: '称重录入' },
}
</route>

<template>
  <view class="container">
    <wd-form ref="form" :model="model" class="px-2">
      <wd-cell-group custom-class="group" title="称重信息" border>
        <wd-input
          label="牛号"
          label-width="100px"
          prop="earTag"
          clearable
          v-model="model.earTag"
          placeholder="请输入牛号"
          required
        />

        <wd-cell title="体重" title-width="100px" prop="value1" right required>
          <view style="text-align: left">
            <wd-input-number
              v-model="model.weight"
              @change="handleChange"
              :precision="2"
              :step="0.1"
            />
            <text class="pl-2 mt-2">KG</text>
          </view>
        </wd-cell>
        <wd-input
          label="体高"
          label-width="100px"
          prop="earTag"
          clearable
          required
          v-model="model.earTag"
          placeholder="请输入价格"
        />
        <!-- <wd-input label="操作人" label-width="100px" prop="value2" disabled v-model="model.user" /> -->
        <wd-calendar
          label="称重时间"
          prop="date"
          label-width="100px"
          type="datetime"
          hide-second
          v-model="model.date"
          :min-date="minDate"
          :max-date="maxDate"
          :disabled-date="disableFutureDates"
          required
        />

        <wd-textarea
          label="备注信息"
          label-width="100px"
          v-model="model.remark"
          :maxlength="200"
          clearable
          show-word-limit
          placeholder="请输入备注"
          auto-height
        />
      </wd-cell-group>
      <view class="footer mt-5 pb-10 center">
        <wd-button type="info" size="medium" class="mr-4" @click="goBack">取消</wd-button>
        <wd-button type="primary" size="medium" @click="handleSubmit">提交</wd-button>
      </view>
    </wd-form>
  </view>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'

defineOptions({
  name: 'neckRing',
})

// form信息
const model = reactive<{
  value1: string
  value2: string
  date: number
  earTag: string | null
  user: string
  weight: string
  remark: string
}>({
  value1: '',
  value2: '',
  date: Date.now(),
  earTag: '',
  user: 'hss',
  weight: '321.2',
  remark: '',
})

// 取消返回上一级
function goBack() {
  uni.navigateBack({
    delta: 1,
  })
}

// 日期选择器
const today = new Date()
const minDate = ref(new Date(2000, 0, 1)) // 可选择的最早日期
const maxDate = ref(today)

const disableFutureDates = (date: Date) => {
  return date > today
}

const form = ref()

function handleChange({ value }) {
  // console.log(value)
}

function handleSubmit() {
  form.value
    .validate()
    .then(({ valid, errors }) => {
      if (valid) {
        // showSuccess({
        //   msg: '校验通过',
        // })
      }
    })
    .catch((error) => {
      console.log(error, 'error')
    })
}
</script>

<style lang="scss" scoped>
.container {
  padding-bottom: 10rem;
  background: #fff;
}
</style>
