<template>
    <div class="releaseDetails">
        <el-row>
            <div class="content_title">
                <span>对接详情-{{ resourceSupplyDemand.name }}</span>
            </div>
        </el-row>
        <el-row>
            <ul class="title">
                <li style="width:88px">状态</li>
                <li style="width:180px">单位名称</li>
                <li style="width:89px">联系人</li>
                <li style="width:135px">联系方式</li>
                <li style="width:317px">对接消息</li>
                <li style="width:110px;text-align: center;">操作</li>
            </ul>
        </el-row>
        <el-row v-for="item in list" :key="item.id">
            <ul class="row">
                <li class="status">
                    <span
                        class="wait"
                        v-if="item.status === 'AWAIT' || item.status === null || item.status === undefined"
                        >等待对接</span
                    >
                    <span class="now" v-if="item.status === 'CONDUCTED'">正在对接</span>
                    <span class="success" v-if="item.status === 'SUCCEED'">对接成功</span>
                    <span class="fail" v-if="item.status === 'DEFEAT'">对接失败</span>
                    <span class="fail" v-if="item.status === 'TERMINATION '">终止并删除</span>
                </li>
                <li class="company">{{ item.orgName }}</li>
                <li class="name">{{ resourceSupplyDemand.contact }}</li>
                <li class="tel">{{ resourceSupplyDemand.phone }}</li>
                <li class="mes">
                    <!-- <p>{{ item.description }}</p> -->
                    <span @click="unfold(item.id, 1)">{{ appear === item.id ? '收起详情' : '展开详情' }}</span>
                </li>
                <li class="operat">
                    <div v-if="state === 3">
                        <span class="fail" @click="dialogReplyVisible = true">回复</span>
                        <span class="fail" @click="dialogVisible = true">编辑</span>
                    </div>
                    <div v-else>
                        <span @click="dialogReplyVisible = true">回复</span>
                        <span @click="dialogVisible = true">编辑</span>
                    </div>
                </li>
            </ul>
            <div class="detail" v-if="item.id === appear">
                <div class="detail_tit">沟通记录</div>
                <div class="detail_item" v-for="record in recordList" :key="record.id">
                    <div class="detail_name" v-if="record.conversationId === item.id">{{ record.nickname }}</div>
                    <div class="detail_con" v-if="record.conversationId === item.id">
                        {{ record.content }}
                    </div>
                    <div class="detail_time" v-if="record.conversationId === item.id">{{ record.createdAt }}</div>
                </div>
            </div>
            <!-- 回复 -->
            <el-dialog title="回复" :visible.sync="dialogReplyVisible" width="660px" center>
                <div class="dialog_con">
                    <span>回复内容</span>
                    <textarea name="" id="" cols="30" rows="10" v-model="model.content"></textarea>
                </div>
                <div class="btn">
                    <button class="cancel" @click="dialogReplyVisible = false">取消</button>
                    <button class="sumbit" @click="save(item.id)">提交</button>
                </div>
            </el-dialog>
            <!-- 编辑 -->
            <el-dialog title="更改对接状态" :visible.sync="dialogVisible" width="660px" center>
                <div class="edit">
                    <div class="edit_info">
                        <div class="edit_item" :class="{ active: editTab === 'SUCCEED' }" @click="editTab = 'SUCCEED'">
                            对接成功
                        </div>
                        <div class="edit_item" :class="{ active: editTab === 'DEFEAT' }" @click="editTab = 'DEFEAT'">
                            对接失败
                        </div>
                        <div
                            class="edit_item"
                            :class="{ active: editTab === 'TERMINATION' }"
                            @click="editTab = 'TERMINATION'"
                        >
                            终止并删除
                        </div>
                    </div>
                    <button class="sumbit" @click="saveMessage(item.id)">提交</button>
                </div>
            </el-dialog>
        </el-row>
    </div>
</template>

<script>
import pageableTable from '@/mixins/pageableTable';
import { stringify } from 'qs';
export default {
    mixins: [pageableTable],
    name: 'releaseDetails',
    data() {
        return {
            model: {},
            state: 0, //对接状态
            appear: 0, //detail 默认隐藏
            dialogReplyVisible: false, // 回复
            dialogVisible: false, // 编辑
            editTab: '',
            // url: '/message/getMessage',
            query: { onExist: '0,2' },
            info: {},
            clickCount: 0,
            list: {},
            resourceSupplyDemand: {},
            recordList: {},
            orgName: ''
        };
    },
    created() {
        this.$http.get(`/conversation/getList/${this.$route.query.id}`).then(res => {
            this.list = res;
            this.resourceSupplyDemand = res[0].resourceSupplyDemand;
            this.orgName = res[0].orgName;
        });
        this.$http.get('/communicationRecord/all').then(res => {
            this.recordList = res.content;
        });
    },
    methods: {
        save(id) {
            this.model.conversationId = id;
            this.$http
                .post('/communicationRecord/save', this.model, { body: 'json' })
                .then(res => {
                    this.getData();
                    this.dialogReplyVisible = false;
                    this.$message.success('成功');
                    this.dialogVisible = false;
                    //this.$router.go(-1);
                })
                .catch(e => {
                    console.log(e);
                    this.dialogVisible = false;
                    this.$message.error(e.error);
                });
        },
        saveMessage(id) {
            if (this.editTab == '') {
                this.$message('请选择对接状态');
                return;
            }
            this.$http
                .post('/conversation/create', { id: id, status: this.editTab }, { body: 'json' })
                .then(res => {
                    this.getData();
                    this.$message.success('成功');
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        },
        beforeGetData() {
            var query = JSON.parse(localStorage.getItem('releaseParams'));
            this.info = query;
            console.log(this.info);
            if (query) {
                return { query: query };
            }
        },
        unfold(id, index) {
            this.clickCount += index;
            if (this.clickCount % 2 != 0) {
                this.appear = id;
            }
            if (this.appear === id && this.clickCount % 2 == 0) {
                this.appear = 0;
            }
            if (this.appear != 0 && this.appear != id) {
                this.appear = id;
            }
        }
    }
};
</script>
<style lang="less" scoped>
.content_title {
    height: 60px;
    line-height: 60px;
    box-sizing: border-box;
    padding-bottom: 20px;
    border-bottom: #f2f3f5 1px solid;
    > span {
        font-size: 16px;
        color: #000000;
        line-height: 30px;
        font-weight: 700;
    }
}
.title {
    height: 48px;
    line-height: 48px;
    background: #f2f3f5;
    margin-top: 18px;
    padding-left: 20px;
    box-sizing: border-box;
    li {
        float: left;
        font-size: 13px;
        color: #626366;
    }
}
.row {
    height: 100px;
    padding-left: 20px;
    box-sizing: border-box;
    display: flex;
    align-items: center;

    border: 1px solid #f2f3f5;
    .status {
        width: 88px;
        span {
            padding: 5px 3px;
            font-size: 12px;
        }
        .wait {
            background-color: #ffebe8;
            color: #ff4a33;
        }
        .now {
            background-color: #ebf9f7;
            color: #22b197;
        }
        .success {
            background-color: #fff2e5;
            color: #ff9629;
        }
        .fail {
            background-color: #f2f3f5;
            color: #939599;
        }
    }

    .company {
        font-size: 13px;
        width: 180px;
    }
    .name {
        font-size: 13px;
        width: 89px;
    }
    .tel {
        font-size: 13px;
        width: 135px;
    }
    .mes {
        width: 317px;
        p {
            width: 200px;
            font-size: 13px;
            line-height: 22px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            margin: 0px;
        }
        span {
            height: 22px;
            font-size: 12px;
            color: #bf1616;
            line-height: 22px;
            cursor: pointer;
        }
    }
    .operat {
        width: 110px;
        height: 100px;
        background: #ffffff;
        box-shadow: -3px 4px 4px 0px rgba(0, 0, 0, 0.05);
        border: 1px solid #f2f3f5;
        box-sizing: border-box;
        div {
            width: 110px;
            height: 100px;
            display: flex;
            align-items: center;
            justify-content: space-evenly;
            span {
                cursor: pointer;
                font-size: 13px;
                color: #bf1616;
            }
        }
    }
    .fail {
        color: #c8c9cc !important;
    }
}
.detail {
    background: #f5f7fa;
    padding: 20px 65px;
    .detail_tit {
        width: 90px;
        font-size: 12px;
        color: #c8c9cc;
        text-align: right;
    }
    .detail_item {
        margin-top: 12px;
        display: flex;
        .detail_name {
            width: 90px;
            height: 22px;
            font-size: 12px;
            color: #ad6363;
            line-height: 22px;
            text-align: right;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .detail_con {
            width: 555px;
            height: 22px;
            font-size: 12px;
            color: #626366;
            line-height: 22px;
            margin: 0 40px 0 10px;
        }
        .detail_time {
            height: 22px;
            font-size: 12px;
            color: #c8c9cc;
            line-height: 22px;
        }
    }
}
.el-dialog {
    .dialog_con {
        display: flex;
        padding: 0 40px;
        justify-content: space-between;
        span {
            height: 22px;
            font-size: 13px;
            color: #313233;
            line-height: 22px;
        }
        textarea {
            width: 440px;
            height: 120px;
            border: 1px solid #dcdfe6;
        }
    }
    .btn {
        margin-top: 60px;
        text-align: right;
        padding: 0 40px;
    }
    .cancel {
        width: 100px;
        height: 36px;
        background: #c4c7cc;
        border-radius: 4px;
        color: #fff;
        cursor: pointer;
    }
    .sumbit {
        width: 100px;
        height: 36px;
        background: #bf1616;
        border-radius: 4px;
        color: #fff;
        font-size: 13px;
        margin-left: 10px;
        cursor: pointer;
    }
}
.edit {
    text-align: center;
    .edit_info {
        display: flex;
        margin: 40px 0 60px;
        justify-content: space-evenly;
        .edit_item {
            cursor: pointer;
            width: 150px;
            height: 60px;
            font-size: 14px;
            line-height: 60px;
            text-align: center;
            border: 1px solid #dcdfe6;
            &.active {
                background: rgba(191, 22, 22, 0.12);
                border: 1px solid #bf1616;
                color: #bf1616;
            }
        }
    }
}
</style>
