<template>
    <lj-win-common title="邮件详情">
        <mu-button icon slot="header_right" style="font-size:18px;width:100%;color:red" onclick="$lj.toast('待商量开发!')">
            删除
        </mu-button>
        <template slot="body">
            <div class="msgBody">
                <div class="msgTitle">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-biaoti"></use>
                    </svg>
                    {{mainObject.s_msgtitle}}
                </div>
                <div class="msgSendEmp">
                    发件人 : {{mainObject.sendemp}}
                </div>
                <div class="msgSendEmp" v-if="ifSent">
                    收件人 : {{mainObject.Empname}}
                </div>
                <div class="msgSendEmp">
                    发件时间 : {{mainObject.senddt}}
                </div>
                <div class="msgSendEmp" v-if="mainObject.dealflag==1 && !ifSent">
                    确认时间 : {{mainObject.dealdt}}
                </div>
                <mu-divider></mu-divider>
                <div class="msgContent">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-email-open"></use>
                    </svg>
                    :
                    <div v-html="mainObject.s_msg"></div>
                    <div v-if="mainObject.billcode !==''" class="relCode">相关单号 : {{mainObject.billcode}}</div>
                </div>
                <mu-divider></mu-divider>
                <div class="msgSendEmp" v-if="FJList.length > 0">附件 : </div>
                <!--附件 -->
                <template v-for="(file,index) in FJList">
                    <lj-fj :fileName="file.filename" :fileType="file.type" :fileSize = file.filesize :md5="file.md5" :fileid="file.fjid" :requestType="'MailAnnex'"/>
                </template>
            </div>

        </template>
        <div slot="footer" v-if="!ifSent">
            <!-- <mu-row>
                <mu-col tag="mu-button" color="primary" :disabled="ifDeal" @click.native="openFlag">{{footTitle}}</mu-col>
            </mu-row> -->
            <mu-button color="primary" large @click.native="openFlag" style="width:100%" :disabled="ifDeal">
                {{footTitle}}
            </mu-button>
            <mu-bottom-sheet :open.sync="openAlert">
                <mu-list style="padding-bottom: 20px;">
                    <mu-sub-header style="text-align:center">是否确认此消息</mu-sub-header>
                    <mu-row style="font-size:18px">
                        <mu-col span="6" style="text-align:center;color:red" @click="closeAlertDialog">取消</mu-col>
                        <mu-col span="6" style="text-align:center;color:#2196f3" @click="DealMsg">确认</mu-col>
                    </mu-row>
                </mu-list>
            </mu-bottom-sheet>
        </div>


    </lj-win-common>
</template>

<script>
    import LjWinCommon from "components/lj-win-common";
    import LjFj from 'components/lj-fj'
    export default {
        name: "email-detail",
        components: {
            LjWinCommon,
            LjFj
        },
        data() {
            return {
                mainObject: {},
                footTitle: "确认消息",
                openAlert: false,
                ifDeal: false,
                FJList: [],
                ifSent:false,
            }
        },
        created() {
            let pageParam = $lj.getPageParam();
            if (pageParam.ifSent) {
                this.ifSent = pageParam.ifSent;
            }
            if (pageParam.mainObject) {
                this.mainObject = pageParam.mainObject;
                if (this.mainObject.dealflag == 1) {
                    this.footTitle = "消息已确定";
                    this.ifDeal = true;
                }
            }
            this.updateReadFlag();
            // this.ReloadFJ();
        },
        methods: {
            ReloadFJ() {
                let self = this;
                let requestBody = {
                    token: $lj.getStorage("token"),
                    msgid: self.mainObject.msgid,
                };
                $lj.postLJRequest("GetL1FJInfo", requestBody, function (ret) {
                    if (ret) {
                        // let FJList = [];
                        self.FJList = ret.FJInfo;
                        // for (let i = 0; i < FJList.length; i++) {
                        //     self.FJList.push({
                        //         fileName: FJList[i].filename,
                        //         fileType: FJList[i].type,
                        //         filemd5: FJList[i].md5
                        //     })
                        // }
                    }
                })
            },
            updateReadFlag() {
                let self = this;
                let requestBody = {
                    token: $lj.getStorage("token"),
                    msgids: self.mainObject.msgid,
                };
                $lj.postLJRequest("ReadMail", requestBody, function (ret) {
                    if (ret) {
                        self.ReloadFJ();
                    }
                })
            },
            DealMsg() {
                let self = this;
                let requestBody = {
                    token: $lj.getStorage("token"),
                    msgids: self.mainObject.msgid,
                };
                $lj.postLJRequest("DealMail", requestBody, function (ret) {
                    if (ret) {
                        $lj.toast("确认成功!");
                        self.openAlert = false;
                        $lj.closeWin();
                        $lj.sendEvent("timespace_refresh");
                    }
                })
            },
            openFlag() {
                this.openAlert = true;
            },
            handleFJ(file) {
                // let user = $lj.getStorage("userInfo");
                // let url;
                // if (user.picBaseUrl) {
                //     url = user.picBaseUrl + file.filemd5;
                // }
                // console.log(url)
                // var alink = document.createElement("a");
                // alink.href = url;
                // alink.download = "pic"; //图片名
                // alink.click();
            },
            closeAlertDialog() {
                this.openAlert = false;
            },
        }
    }
</script>

<style>
    .msgBody {
        background-color: #ffffff;
        padding: 10px;
    }

    .msgTitle {
        font-weight: bold;
        font-size: 22px;
        margin: 10px;
    }

    .msgSendEmp {
        font-size: 15px;
        margin: 10px;
    }

    .msgFile {
        font-size: 15px;
        margin: 10px;
        text-decoration: underline;
    }

    .msgContent {
        /* font-weight: bold; */
        font-size: 15px;
        margin: 10px;
    }

    .relCode {
        /* text-decoration: underline; */
        color: #2196f3;
        font-size: 15px;
    }
</style>