<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            :title="popupTitle"
            :async="true"
            width="1000px"
            @confirm="handleSubmit"
            @close="handleClose"
        >
            <el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
                <!-- <el-row>
                    <el-col :span="6">
                        <el-form-item label="用户" prop="nickname">
                            <el-input v-model="formData.nickname" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="电话" prop="phone">
                            <el-input v-model="formData.phone" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="地址" prop="address">
                            <el-input
                                v-model="formData.address"
                                type="input"
                                style="width: 400px"
                            />
                        </el-form-item>
                    </el-col>
                </el-row> -->
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="到货时间" prop="arrival_time">
                            <el-date-picker
                                v-model="formData.arrival_time"
                                type="datetime"
                                :readonly="false"
                                clearable
                                value-format="YYYY-MM-DD HH:mm:ss"
                                placeholder="请选择到货时间"
                                style="width: 180px"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="桌数" prop="tables">
                            <el-input-number v-model="formData.tables" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="办事天数" prop="days">
                            <el-input-number v-model="formData.days" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="厨师" prop="chef">
                            <el-input v-model="formData.chef" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="电话" prop="chef_phone">
                            <el-input v-model="formData.chef_phone" type="input" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="备注" prop="purpose">
                            <el-input
                                v-model="formData.purpose"
                                type="input"
                                style="width: 480px"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="内部备注" prop="mark">
                            <el-input v-model="formData.mark" type="input" style="width: 480px" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="4">
                        <el-form-item label="分单员" prop="splitting_officer">
                            <el-input v-model="formData.splitting_officer" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="跟单员" prop="merchandiser">
                            <el-input v-model="formData.merchandiser" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="仓管员" prop="distribution_personnel">
                            <el-input v-model="formData.distribution_personnel" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="运输员" prop="transporter">
                            <el-input v-model="formData.transporter" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="门店员" prop="system_store_name">
                            <el-input v-model="formData.system_store_name" type="input" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="区域经理" prop="regional_manager">
                            <el-input v-model="formData.regional_manager" type="input" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </popup>
    </div>
</template>

<script lang="ts" setup name="storeOrderEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiStoreOrderSetSystemStore } from '@/api/store_order'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
import { apiPurchaseOrderTransferAdvanceOrder } from '@/api/beforehand_order'

const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')

// 弹窗标题
const popupTitle = computed(() => {
    return (mode.value = '转预订单设置')
})
// 表单数据
const formData = reactive({
    id: 0,
    order_type: 4,
    store_id: '',
    // nickname: '',
    // phone: '',
    // address: '',
    arrival_time: '',
    purpose: '',
    tables: 0,
    days: 0,
    chef: '',
    chef_phone: '',
    splitting_officer: '',
    merchandiser: '何月英',
    distribution_personnel: '余友',
    transporter: '',
    system_store_name: '',
    regional_manager: '张波',
    mark: ''
})

// 表单验证
const formRules = reactive<any>({})

const getDetail = (data: any[]) => {
    // formData.nickname = data.real_name
    // formData.phone = data.user_phone
    // formData.address = data.user_address
    formData.store_id = data.store_id
    formData.id = data.id
}
// 提交按钮
const handleSubmit = async () => {
    const data = { ...formData }
    await apiPurchaseOrderTransferAdvanceOrder(data)
    popupRef.value?.close()
    emit('success')
}

//打开弹窗
const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}
const storeList = ref([])

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

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