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

        <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-table ref="multipleTable"  :data="form.timeList" tooltip-effect="dark" style="width: 100%" stripe
                :header-cell-style="{ background: '#EEEEEE', border: 'none' }">



                <el-table-column  align="center"  label="数量" prop="purchaseQuantity">
                    <template slot-scope="{ row, $index }">
                        <el-form-item :prop="'timeList.' + $index + '.purchaseQuantity'"
                          >
                            <el-input placeholder="请输入" clearable v-model="row.purchaseQuantity"></el-input>
                        </el-form-item>

                    </template>
                </el-table-column>



                <el-table-column align="center"  label="到货时间">
                    <template slot-scope="{ row, $index }">
                        <el-form-item :prop="'timeList.' + $index + '.requireDeliveryTime'"
                            >
                            <el-date-picker clearable v-model="row.requireDeliveryTime" value-format="timestamp"
                                placeholder="请选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </template></el-table-column>

       


            </el-table>


            </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, 'release', this.form.timeList )
        },

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

        },

        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>