<template>
  <SysDialog
    class="financial-share"
    :visible="dialog.visible"
    :confirm-loading="dialog.confirmLoading"
    v-bind="getBindValue"
    @onClose="onClose"
    @onConfirm="onconfirm"
  >
    <template #content>
      <el-form ref="financialShareFormRef" :model="financialShareParams">
        <el-row>
          <el-col :span="24">
            <el-form-item
              prop="rateVersionId"
              label-width="90px"
              label="汇率版本"
              :rules="[
                {
                  required: true,
                  message: '请输入汇率版本',
                  trigger: 'change',
                },
              ]"
            >
              <el-select
                v-model="financialShareParams.rateVersionId"
                filterable
              >
                <el-option
                  v-for="item in billRateList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </template>
  </SysDialog>
</template>
<script lang="ts" setup>
import SysDialog from "@/components/SysDialog.vue";
import useDialog from "@/hooks/useDialog";
import { ref, reactive, unref } from "vue";
import { useEleFormValidate } from "@/hooks/useEleFormValidate";
import { BillShareParam } from "@/api/financial/financialBillList/financialBillListModel";
import type { ListIitem } from "@/api/base/BaseDataModel";

defineProps<{ billRateList: ListIitem[] }>();
const emit = defineEmits(["saveVersion"]);
// 弹框一些配置
const getBindValue = reactive({
  title: "账单分摊",
  width: 360,
  height: 0,
});
//弹框属性
const { dialog, onClose, onShow, setLoading } = useDialog();
const financialShareFormRef = ref();
// 校验表单
const { formValidate } = useEleFormValidate();

const financialShareParams = reactive<Partial<BillShareParam>>({
  rateVersionId: undefined,
  billSummaryId: undefined,
});
// 显示、隐藏
const onclose = () => {
  financialShareParams.rateVersionId = undefined;
  onClose();
};
const show = (data) => {
  if (data.id) financialShareParams.billSummaryId = data.id;
  onShow();
};
const onconfirm = async () => {
  const isValidate = await formValidate(unref(financialShareFormRef));
  if (!isValidate) return;
  emit("saveVersion", financialShareParams, onclose, setLoading);
};
//父组件调用子组件显示弹框
//暴露出去给外部使用
defineExpose({
  show,
});
</script>
<style lang="scss" scoped>
.financial-share {
}
</style>
