<template>
    <div>
        <el-dialog title="邮件内容" :visible="emailVidable"  @close="cancel" center
            :distroy-on-close="true">
            <div>
                <el-form>
                    <el-col :span="24">
                        <el-form-item label="邮件主题：" label-width="100px">
                           <div>主题</div>
                        </el-form-item>
                    </el-col>
                     <el-col :span="12">
                        <el-form-item label="收件人：" label-width="100px">
                           <div>收件人</div>
                        </el-form-item>
                    </el-col>
                     <el-col :span="12">
                        <el-form-item label="发件人：" label-width="100px">
                           <div>发件人</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="邮件附件：" label-width="100px">
                           <div  style="color: blue; cursor: pointer" @click="viewAttachments">附件</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="邮件正文：" label-width="100px">
                            <el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="sendData"></el-input>
                        </el-form-item>
                    </el-col>
                </el-form>
                
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel" class="endbutton1" round><span>取 消</span></el-button>
                <el-button @click="submitSend" class="endbutton1" type="primary" round><span>确 认</span></el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {
    updateSendContent,update
} from "@/api/deliveryRecord/deliveryRecord.js";
export default {
    props: ["emailVidable", "emailRow","queryParams"],
    data() {
        return {
            sendData:'',
            fileURL: window.location.origin + "/API",
        };
    },
    watch: {
        emailVidable(val){
            if(val){
                this.sendData = this.emailRow.mailContent;
            }
        }
    },
    methods: {
        cancel() {
            this.$emit("cancelEmail");
        },
        submitSend() {
            console.log(this.emailRow.mailContent)
            this.updateSendContentFn({
                id:this.emailRow.id,
                mailContent:this.sendData
            })
        },
        updateSendContentFn(data){
            update(data).then(res=>{
                this.$message.success('更新成功');
                this.$emit("cancelEmail");
                this.$emit('getList',this.queryParams);
            })
        },
        // 查看附件下载附件
        viewAttachments(val){
            window.open(this.fileURL + val);
        }
    },
};
</script>

<style lang="scss" scoped></style>