<template>
    <a-drawer
        :title="formData.id ? '编辑双次过磅记录表' : '增加双次过磅记录表'"
        :width="600"
        :visible="visible"
        :destroy-on-close="true"
        :footer-style="{ textAlign: 'right' }"
        @close="onClose"
    >
        <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
            <a-form-item label="出入库:入库/出库：" name="depotBizType">
                <a-select v-model:value="formData.depotBizType" placeholder="请选择出入库:入库/出库" :options="depotBizTypeOptions" />
            </a-form-item>
            <a-form-item label="车牌号码：" name="licensePlate">
                <a-input v-model:value="formData.licensePlate" placeholder="请输入车牌号码" allow-clear />
            </a-form-item>
            <a-form-item label="车次编码：yyyymmdd****：" name="carNumber">
                <a-input v-model:value="formData.carNumber" placeholder="请输入车次编码：yyyymmdd****" allow-clear />
            </a-form-item>
            <a-form-item label="过毛时间：" name="grossTime">
                <a-date-picker v-model:value="formData.grossTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择过毛时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="过皮时间：" name="tareTime">
                <a-date-picker v-model:value="formData.tareTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择过皮时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="皮重类型：" name="tareType">
                <a-input v-model:value="formData.tareType" placeholder="请输入皮重类型" allow-clear />
            </a-form-item>
            <a-form-item label="毛量：" name="grossWeight">
                <a-input v-model:value="formData.grossWeight" placeholder="请输入毛量" allow-clear />
            </a-form-item>
            <a-form-item label="皮重：" name="tareWeight">
                <a-input v-model:value="formData.tareWeight" placeholder="请输入皮重" allow-clear />
            </a-form-item>
            <a-form-item label="净重：" name="netWeight">
                <a-input v-model:value="formData.netWeight" placeholder="请输入净重" allow-clear />
            </a-form-item>
            <a-form-item label="过毛称重状态：" name="grossWeightOperateType">
                <a-input v-model:value="formData.grossWeightOperateType" placeholder="请输入过毛称重状态" allow-clear />
            </a-form-item>
            <a-form-item label="过皮称重状态：" name="tareWeightOperateType">
                <a-input v-model:value="formData.tareWeightOperateType" placeholder="请输入过皮称重状态" allow-clear />
            </a-form-item>
            <a-form-item label="过皮称重操作时间：" name="tareWeightOperateTime">
                <a-date-picker v-model:value="formData.tareWeightOperateTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择过皮称重操作时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="库房确认状态：" name="storehouseType">
                <a-input v-model:value="formData.storehouseType" placeholder="请输入库房确认状态" allow-clear />
            </a-form-item>
            <a-form-item label="司机姓名：" name="driverName">
                <a-input v-model:value="formData.driverName" placeholder="请输入司机姓名" allow-clear />
            </a-form-item>
            <a-form-item label="司机电话：" name="driverMobile">
                <a-input v-model:value="formData.driverMobile" placeholder="请输入司机电话" allow-clear />
            </a-form-item>
            <a-form-item label="货品名称：" name="goodsName">
                <a-input v-model:value="formData.goodsName" placeholder="请输入货品名称" allow-clear />
            </a-form-item>
            <a-form-item label="规格型号：" name="goodsModel">
                <a-input v-model:value="formData.goodsModel" placeholder="请输入规格型号" allow-clear />
            </a-form-item>
            <a-form-item label="收货单位：" name="receiptCompany">
                <a-input v-model:value="formData.receiptCompany" placeholder="请输入收货单位" allow-clear />
            </a-form-item>
            <a-form-item label="发货单位：" name="shippingCompany">
                <a-input v-model:value="formData.shippingCompany" placeholder="请输入发货单位" allow-clear />
            </a-form-item>
            <a-form-item label="运输路线：" name="transportCompany">
                <a-input v-model:value="formData.transportCompany" placeholder="请输入运输路线" allow-clear />
            </a-form-item>
            <a-form-item label="运输单位：" name="transportRoute">
                <a-input v-model:value="formData.transportRoute" placeholder="请输入运输单位" allow-clear />
            </a-form-item>
            <a-form-item label="记录支付类型（字典 0：关闭、1：开启）：" name="recordPayType">
                <a-input v-model:value="formData.recordPayType" placeholder="请输入记录支付类型（字典 0：关闭、1：开启）" allow-clear />
            </a-form-item>
            <a-form-item label="扫码称重支付开关（字典 0：关闭、1：开启）：" name="scanWeightType">
                <a-input v-model:value="formData.scanWeightType" placeholder="请输入扫码称重支付开关（字典 0：关闭、1：开启）" allow-clear />
            </a-form-item>
            <a-form-item label="扫码称重支付类型（字典 1：动态称重单价支付、2：动态称重区间支付、3：货品单价支付）：" name="payWeightType">
                <a-input v-model:value="formData.payWeightType" placeholder="请输入扫码称重支付类型（字典 1：动态称重单价支付、2：动态称重区间支付、3：货品单价支付）" allow-clear />
            </a-form-item>
            <a-form-item label="扫码称重支付依据类型（字典 1：毛重收费、2：净重收费）：" name="payWeightBasisType">
                <a-input v-model:value="formData.payWeightBasisType" placeholder="请输入扫码称重支付依据类型（字典 1：毛重收费、2：净重收费）" allow-clear />
            </a-form-item>
            <a-form-item label="扫码称重支付LED和语音提示类型（字典 1：支付前提示重量、2：支付后提示重量）：" name="payWeightLedyyType">
                <a-input v-model:value="formData.payWeightLedyyType" placeholder="请输入扫码称重支付LED和语音提示类型（字典 1：支付前提示重量、2：支付后提示重量）" allow-clear />
            </a-form-item>
            <a-form-item label="扫码称重支付单价：单位--分：" name="payWeightPrice">
                <a-input v-model:value="formData.payWeightPrice" placeholder="请输入扫码称重支付单价：单位--分" allow-clear />
            </a-form-item>
            <a-form-item label="扫码称重支付重量：单位--公斤：" name="payWeightUnit">
                <a-input v-model:value="formData.payWeightUnit" placeholder="请输入扫码称重支付重量：单位--公斤" allow-clear />
            </a-form-item>
            <a-form-item label="总金额：单位分：" name="paymentMoney">
                <a-input v-model:value="formData.paymentMoney" placeholder="请输入总金额：单位分" allow-clear />
            </a-form-item>
            <a-form-item label="已支付金额：单位分：" name="paidMoney">
                <a-input v-model:value="formData.paidMoney" placeholder="请输入已支付金额：单位分" allow-clear />
            </a-form-item>
            <a-form-item label="未支付金额：单位分：" name="unpaidMoney">
                <a-input v-model:value="formData.unpaidMoney" placeholder="请输入未支付金额：单位分" allow-clear />
            </a-form-item>
            <a-form-item label="支付状态（字典 1：无需支付、2：待支付、3：已支付、4：现金支付）：" name="paymentType">
                <a-input v-model:value="formData.paymentType" placeholder="请输入支付状态（字典 1：无需支付、2：待支付、3：已支付、4：现金支付）" allow-clear />
            </a-form-item>
            <a-form-item label="支付次数（字典 1：无需支付、2：正常支付、3：补充支付）：" name="paymentNumType">
                <a-input v-model:value="formData.paymentNumType" placeholder="请输入支付次数（字典 1：无需支付、2：正常支付、3：补充支付）" allow-clear />
            </a-form-item>
            <a-form-item label="云端数据推送状态（字典 1：无需推送、2：新增推送成功、3：新增推送失败、4：修改送成功、5：修改推送失败）：" name="cloudPushFlag">
                <a-input v-model:value="formData.cloudPushFlag" placeholder="请输入云端数据推送状态（字典 1：无需推送、2：新增推送成功、3：新增推送失败、4：修改送成功、5：修改推送失败）" allow-clear />
            </a-form-item>
            <a-form-item label="新增推送时间：" name="cloudPushAddTime">
                <a-date-picker v-model:value="formData.cloudPushAddTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择新增推送时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="修改推送时间：" name="cloudPushUpdateTime">
                <a-date-picker v-model:value="formData.cloudPushUpdateTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择修改推送时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="接口数据推送状态：" name="apiPushFlag">
                <a-input v-model:value="formData.apiPushFlag" placeholder="请输入接口数据推送状态" allow-clear />
            </a-form-item>
            <a-form-item label="新增推送时间：" name="apiPushAddTime">
                <a-date-picker v-model:value="formData.apiPushAddTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择新增推送时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="修改推送时间：" name="apiPushUpdateTime">
                <a-date-picker v-model:value="formData.apiPushUpdateTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择修改推送时间" style="width: 100%" />
            </a-form-item>
            <a-form-item label="过磅次数类型：" name="weighingType">
                <a-input v-model:value="formData.weighingType" placeholder="请输入过磅次数类型" allow-clear />
            </a-form-item>
        </a-form>
        <template #footer>
            <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
            <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
        </template>
    </a-drawer>
</template>

<script setup name="depotTruckWeighDoubleForm">
    import tool from '@/utils/tool'
    import { cloneDeep } from 'lodash-es'
    import { required } from '@/utils/formRules'
    import depotTruckWeighDoubleApi from '@/api/biz/depotTruckWeighDoubleApi'
    // 抽屉状态
    const visible = ref(false)
    const emit = defineEmits({ successful: null })
    const formRef = ref()
    // 表单数据
    const formData = ref({})
    const submitLoading = ref(false)
    const depotIdOptions = ref([])
    const depotBizTypeOptions = ref([])

    // 打开抽屉
    const onOpen = (record) => {
        visible.value = true
        if (record) {
            let recordData = cloneDeep(record)
            formData.value = Object.assign({}, recordData)
        }
        depotBizTypeOptions.value = tool.dictList('出入库')
    }
    // 关闭抽屉
    const onClose = () => {
        formRef.value.resetFields()
        formData.value = {}
        visible.value = false
    }
    // 默认要校验的
    const formRules = {
    }
    // 验证并提交数据
    const onSubmit = () => {
        formRef.value
            .validate()
            .then(() => {
                submitLoading.value = true
                const formDataParam = cloneDeep(formData.value)
                depotTruckWeighDoubleApi
                    .depotTruckWeighDoubleSubmitForm(formDataParam, !formDataParam.id)
                    .then(() => {
                        onClose()
                        emit('successful')
                    })
                    .finally(() => {
                        submitLoading.value = false
                    })
            })
    }
    // 抛出函数
    defineExpose({
        onOpen
    })
</script>
