<template>
  <div>
    <a-form ref="formRef" :model="searchFormData" :rules="formRules">
      <a-row :gutter="20">
        <a-col :span="24" align="right">
          <a-form-item>
            <a-button @click="refreshData()" type="primary" ghost>更新</a-button>
          </a-form-item>
        </a-col>
        <!-- 基本信息 -->
        <a-col :span="8">
          <a-form-item label="残疾证号" name="'disabledNo'">
            <a-input v-model:value="searchFormData.disabledNo" placeholder="请输入残疾证号" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="残疾类型" name="disabledType">
            <a-select v-model:value="searchFormData.disabledType" allowClear>
              <a-select-option v-for="item in dicsStore.dictOptions.DISABILITY_TYPES" :key="item.dval"
                :value="item.dval">{{ item.introduction }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="残疾等级" name="disabledLv">
            <a-select v-model:value="searchFormData.disabledLv" allowClear>
              <a-select-option v-for="item in dicsStore.dictOptions.Disability_Level" :key="item.dval"
                :value="item.dval">{{
                  item.introduction }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="是否已签订托养协议" name="agreementSigned">
            <a-select v-model:value="searchFormData.agreementSigned" allowClear>
              <a-select-option key="1" value="1">是</a-select-option>
              <a-select-option key="2" value="2">否</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="托养开始时间" name="starCareService">
            <a-date-picker v-model:value="searchFormData.starCareService" placeholder="请选择开始日期" style="width: 100%;" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="托养结束时间" name="endCareService">
            <a-date-picker v-model:value="searchFormData.endCareService" placeholder="请选择结束日期" style="width: 100%;" />
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="托养协议照片" name="careServiceImgs">
            <gx-upload v-model="searchFormData.careServiceImgs" accept-types=".jpg,.png,.webp" />
          </a-form-item>
        </a-col>

      </a-row>
    </a-form>
  </div>
</template>

<script setup>
import { ref, defineProps } from 'vue';
import { useDicsStore } from '@/store'
import apis from '@/apis'
import { config } from '@/config'
import dayjs from 'dayjs';
import { message } from 'ant-design-vue';
import { getBirthDate, spliceUrl } from '@/utils/util'
const dicsStore = useDicsStore()
const searchFormData = ref({})
const formRules = ref({

})
const props = defineProps({
  formData: {
    type: Object,
    default: () => ({})
  }
});
getPageList()

async function getPageList() {
  try {
    console.log(1111)
    const { success, data, total } = await apis.contacts.getInfo({ id: props.formData.id })
      .catch(() => {
        throw new Error()
      })
    if (config('http.code.success') === success) {
      searchFormData.value = data
      searchFormData.value.careServiceImgs = data.careServiceImgs ? data.careServiceImgs.map(item => config('http.apiUpload') + item) : []
      searchFormData.value.starCareService = dayjs(data.starCareService)
      searchFormData.value.endCareService = dayjs(data.endCareService)
    }
  } catch (error) {
    console.log(error)
  }
}
async function refreshData() {
  try {
    const params = {
      ...searchFormData.value,
      careServiceImgs: searchFormData.value.careServiceImgs && searchFormData.value.careServiceImgs.length > 0 ? searchFormData.value.careServiceImgs.map(item => spliceUrl(item)) : []
    }
    const { success, data, total } = await apis.contacts.updateInfo(params)
      .catch(() => {
        throw new Error()
      })

    if (config('http.code.success') === success) {
      message.success('信息更新成功')
      getPageList()
    }
  } catch (error) {

  }
}
</script>
<style scoped>
.label {
  display: inline-block;
  line-height: 45px;
}
</style>