<template>
    <div class="edit-popup">
        <popup ref="popupRef" title="详情" :async="true" width="550px" :cancelButtonText="false" :confirmButtonText="false">
            <el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
                <el-form-item label="所属商户" prop="merchant">
                    <el-input v-model="formData.merchant" clearable placeholder="请输入所属商户" :readonly="true" />
                </el-form-item>
                <el-form-item label="归属门店" prop="store_id">
                    <el-input v-model="formData.store_id" clearable placeholder="请输入归属门店" :readonly="true" />
                </el-form-item>
                <el-form-item label="客户ID" prop="customer">
                    <el-input v-model="formData.customer" clearable placeholder="请输入客户ID" :readonly="true" />
                </el-form-item>
                <el-form-item label="单据时间" prop="time">
                    <el-input v-model="formData.time" clearable placeholder="请输入单据时间" :readonly="true" />
                </el-form-item>
                <el-form-item label="单据编号" prop="number">
                    <el-input v-model="formData.number" clearable placeholder="请输入单据编号" :readonly="true" />
                </el-form-item>
                <el-form-item label="单据金额" prop="total">
                    <el-input v-model="formData.total" clearable placeholder="请输入单据金额" :readonly="true" />
                </el-form-item>
                <el-form-item label="抵扣金额" prop="deduction_price">
                    <el-input v-model="formData.deduction_price" clearable placeholder="请输入抵扣金额" :readonly="true" />
                </el-form-item>
                <el-form-item label="实际金额" prop="actual">
                    <el-input v-model="formData.actual" clearable placeholder="请输入实际金额" :readonly="true" />
                </el-form-item>
                <el-form-item label="实收金额" prop="money">
                    <el-input v-model="formData.money" clearable placeholder="请输入实收金额" :readonly="true" />
                </el-form-item>
                <el-form-item label="支付方式 0余额 1微信 2小程序 3 h5  4支付宝 5 支付宝扫码 6 微信扫码 8先货后款 10对公转账" prop="pay_type">
                    <el-select class="flex-1" v-model="formData.pay_type" clearable
                        placeholder="请选择支付方式 0余额 1微信 2小程序 3 h5  4支付宝 5 支付宝扫码 6 微信扫码 8先货后款 10对公转账" :disabled="true">
                        <el-option v-for="(item, index) in dictData.pay_type" :key="index" :label="item.name"
                            :value="parseInt(item.value)" />
                    </el-select>
                </el-form-item>
                <el-form-item label="备注信息" prop="data">
                    <el-input v-model="formData.data" clearable placeholder="请输入备注信息" :readonly="true" />
                </el-form-item>
                <el-form-item label="审核状态[0:未审核|1:已审核]" prop="type">
                    <el-radio-group v-model="formData.type" placeholder="请选择审核状态[0:未审核|1:已审核]" :disabled="true">
                        <el-radio v-for="(item, index) in dictData.auditing_type" :key="index"
                            :label="parseInt(item.value)">
                            {{ item.name }}
                        </el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="审核人" prop="auditinguser">
                    <el-input v-model="formData.auditinguser" clearable placeholder="请输入审核人" :readonly="true" />
                </el-form-item>
                <el-form-item label="审核时间" prop="auditingtime">
                    <el-date-picker :readonly="true" class="flex-1 !flex" v-model="formData.auditingtime" clearable
                        type="datetime" value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择审核时间">
                    </el-date-picker>
                </el-form-item>

                <el-form-item label="扩展信息" prop="more">
                    <el-input v-model="formData.more" clearable placeholder="请输入扩展信息" :readonly="true" />
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>

<script lang="ts" setup name="cashierclassDETAILS">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiCashierclassAdd, apiCashierclassEdit, apiCashierclassDetail } from '@/api/cashierclass'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')



// 表单数据
const formData = reactive({
    id: '',
    merchant: '',
    store_id: '',
    customer: '',
    time: '',
    number: '',
    total: '',
    deduction_price: '',
    actual: '',
    money: '',
    pay_type: '',
    data: '',
    type: '',
    auditinguser: '',
    auditingtime: '',
    more: '',
})



// 获取详情
const setFormData = async (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }

    //@ts-ignore
    formData.auditingtime = timeFormat(formData.auditingtime, 'yyyy-mm-dd hh:MM:ss')
}

const getDetail = async (row: Record<string, any>) => {
    const data = await apiCashierclassDetail({
        id: row.id
    })
    setFormData(data)
}

//打开弹窗
const open = () => {
    popupRef.value?.open()
}

// 关闭回调
const handleClose = () => {
    emit('close')
}



defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
