<template>
    <ele-modal :visible.sync="visible" v-if="visible" title="发布" width="800px" append-to-body :close-on-click-modal="false">

        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row>
                <el-col :span="20">
                    <el-form-item label=" 图纸附件:" prop="technicalDrawings">
                        <fileUpload v-model="form.technicalDrawings" module="main" :showLib="false" :limit="5" />
                        <div v-if="form.technicalDrawings && form.technicalDrawings?.length">
                            <el-link v-for="link in form.technicalDrawings" :key="link.id" type="primary" :underline="false"
                                @click="downloadFile(link)">
                                {{ link.name }}</el-link>
                        </div>
                    </el-form-item>
                </el-col>

                <el-col :span="20">
                    <el-form-item label=" 附件:" prop="files">
                        <fileUpload v-model="form.files" module="main" :showLib="false" :limit="5" />
                        <div v-if="form.files && form.files?.length">
                            <el-link v-for="link in form.files" :key="link.id" type="primary" :underline="false"
                                @click="downloadFile(link)">
                                {{ link.name }}</el-link>
                        </div>
                    </el-form-item>
                </el-col>




                <el-col :span="20">
                    <el-form-item label="分批到货:" prop="">
                        <el-link type="primary" :underline="false" @click.native="handleMethod">
                            设置分批时间
                        </el-link>
                    </el-form-item>
                </el-col>


            </el-row>




        </el-form>


        <template v-slot:footer>
            <el-button @click="close">取消</el-button>
            <el-button type="primary" :loading="loading" @click="save">
                发布
            </el-button>
        </template>

        <timeDialog ref="timeDialogRef" @chooseTime="chooseTime"></timeDialog>
    </ele-modal>
</template>

<script>
import { release } from '@/api/outsourcing/index.js';
import fileUpload from '@/components/upload/fileUpload';
import { getFile } from "@/api/system/file";
import timeDialog from './timeDialog'
export default {
    components: {
        fileUpload,
        timeDialog
    },
    data() {
        return {
            visible: false,
            rowObj: {},
            form: {},
            rules: {},
            loading: false
        }
    },

    methods: {

        downloadFile(file) {
            getFile({ objectName: file.storePath }, file.name);
        },
        open(row) {

            this.visible = true
            this.rowObj = row
        },

        close() {
            this.visible = false
        },


        handleMethod() {
            this.$refs.timeDialogRef.open(this.rowObj)
        },

        chooseTime(timeList) {
            if (timeList.length > 0) {
                this.form.timeList = timeList
                this.form.deliveryMethod = 2
            } else {
                this.form.timeList = []
                this.form.deliveryMethod = 1
            }

        },

        save() {
            this.form.id = this.rowObj.id
            this.form['type'] = this.rowObj['type']
            release(this.form).then(res => {
                this.$emit('refresh')
                this.close()
            })
        },

    }
}
</script>

<style></style>