<template>
    <div class="resource-detail">
        <div class="container">
            <el-breadcrumb separator="/" style="display: inline-block;">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item :to="{ path: '/resource' }">资源供需</el-breadcrumb-item>
                <el-breadcrumb-item>技术需求</el-breadcrumb-item>
                <el-breadcrumb-item><span style="color:#C8C9CC">需求详情</span></el-breadcrumb-item>
            </el-breadcrumb>

            <div class="detail">
                <div class="top">
                    <img :src="(list.images || [])[0]" />
                    <div class="info">
                        <div class="title">
                            <span>{{ list.name }}</span>
                            <!-- <i :class="list.status === 'PENDING' ? 'wait' : ''">
                                {{ list.status === 'PENDING' ? '等待对接' : '正在对接' }}</i
                            > -->
                            <i class="wait" v-if="list.conversationStatus === 'AWAIT'"> 等待对接 </i>
                            <i v-if="list.conversationStatus === 'CONDUCTED'"> 正在对接</i>
                        </div>
                        <div class="specs">
                            <div class="spec">
                                <div class="name">应用领域:</div>
                                <div class="value">{{ applicationField }}</div>
                            </div>
                            <div class="spec" v-if="this.$route.query.type == 'TECH_DEMAND'">
                                <div class="name">技术类型:</div>
                                <div class="value">{{ techType }}</div>
                            </div>
                            <!-- <div class="spec" v-if="this.$route.query.type == 'PRODUCT_DEMAND'">
                                <div class="name">应用领域</div>
                                <div class="value">{{ applicationField.name }}</div>
                            </div> -->
                            <div class="spec" v-if="this.$route.query.type == 'PRODUCT_DEMAND'">
                                <div class="name">设备类型:</div>
                                <div class="value">{{ dataType }}</div>
                            </div>
                            <div class="spec">
                                <div class="name">有效时间:</div>
                                <div class="value">{{ list.expireTime }}</div>
                            </div>

                            <div class="spec">
                                <div class="name">联系人:</div>
                                <div class="value">{{ list.contact }}</div>
                            </div>
                            <div class="spec">
                                <div class="name">联系方式:</div>
                                <div class="value">{{ list.phone }}</div>
                            </div>
                        </div>
                        <div class="btns">
                            <div class="btn btn-contact" @click="showDialog = true">
                                <img src="../assets/icon_msg.png" class="icon" />
                                <span>联系对接</span>
                            </div>
                            <div :class="active ? 'btn btn-delcollect' : 'btn btn-collect'" @click="collect()">
                                <img :src="src" class="icon" />
                                <span>{{ collectTitle }}</span>
                            </div>
                            <!--   <div class="btn btn-delcollect" @click="delCollection" v-if="status == true">
                                <img src="../assets/icon_collect_pre.png" class="icon" />
                                <span>取消收藏</span>
                            </div> -->
                        </div>
                    </div>
                </div>
                <div class="bottom">
                    <div class="description">
                        <div class="desc_left">
                            <div>
                                <!-- <img src="../assets/resourceDetail_img02.png" class="logo" /> -->
                                <img :src="orgInfo ? orgInfo.logo : null" class="logo" />
                                <div class="companyname">
                                    <!-- <img src="" alt="" /> -->
                                    <span>{{ orgInfo ? orgInfo.orgName : null }}</span>
                                </div>
                                <div
                                    class="companybtn"
                                    @click="
                                        $router.push({
                                            name: 'enterprise',
                                            query: { id: orgInfo.id, name: orgInfo.orgName, logo: orgInfo.logo }
                                        })
                                    "
                                >
                                    <!--      orgInfo: {
                                                    id: list.orgInfo.id,
                                                    orgName: list.orgInfo.orgName,
                                                    loge: list.orgInfo.loge
                                                } -->
                                    查看企业
                                </div>
                            </div>
                            <div class="recommend">
                                <recommendToU :type="$route.query.type"></recommendToU>
                                <!-- :dataType="dataType.id" -->
                            </div>
                        </div>
                        <div class="desc_right">
                            <div class="desc_title">详情介绍</div>
                            <div v-html="list.details"></div>
                        </div>
                    </div>
                </div>
            </div>
            <el-dialog :visible.sync="showDialog" title="联系对接" width="540px" center>
                <div style="padding-right:100px">
                    <el-form label-width="120px" label-position="right" :model="formData" :rules="rules" ref="formData">
                        <el-form-item prop="orgName" label="单位名称">
                            <el-input v-model="formData.orgName" placeholder="请输入单位名称"></el-input>
                        </el-form-item>
                        <el-form-item prop="contactName" label="联系人">
                            <el-input v-model="formData.contactName" placeholder="请输入联系人"></el-input>
                        </el-form-item>
                        <el-form-item prop="contactPhone" label="联系方式">
                            <el-input v-model="formData.contactPhone" placeholder="请输入联系方式"></el-input>
                        </el-form-item>
                        <el-form-item prop="content" label="对接描述">
                            <el-input
                                v-model="formData.content"
                                placeholder="请填写对接描述，不超过200字"
                                type="textarea"
                                :rows="5"
                                maxlength="200"
                                style="width:300px;"
                            ></el-input>
                        </el-form-item>
                    </el-form>
                </div>
                <span slot="footer">
                    <el-button type="primary" size="medium" class="cancel" @click="showDialog = false">取消</el-button>
                    <el-button type="primary" size="medium" class="submit" @click="saveMess()">提交</el-button>
                </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import recommendToU from '../components/resource/recommendToU';
export default {
    name: 'resourceDetail',
    components: {
        recommendToU
    },
    data() {
        return {
            showDialog: false,
            formData: {},
            list: {},
            orgInfo: {},
            active: false,
            collectTitle: '收藏',
            src: require('../assets/icon_collect_pre.png'),
            rules: {
                orgName: [{ required: true, message: '请输入单位名称', trigger: 'blur' }],
                contactName: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
                contactPhone: [{ required: true, message: '请输入联系方式', trigger: 'blur' }],
                content: [{ required: true, message: '请填写对接描述', trigger: 'blur' }]
            },
            child: {
                id: this.$route.query.id,
                type: this.$route.query.type
            },
            // techTypeId: '',
            // jslxDataTypeOptions: [],
            resSnDPropertyList: {},
            techType: '',
            applicationField: '',
            dataType: ''
        };
    },
    created() {
        this.getData();
        // this.getDataType({ query: { keyType: 'jslx' } }, this.jslxDataTypeOptions);
        // console.log(this.jslxDataTypeOptions);
    },
    computed: {
        userInfo() {
            return this.$store.state.userInfo;
        }
    },
    methods: {
        getData() {
            if (this.$route.query.id) {
                if (this.$route.query.type == 'TECH_DEMAND') {
                    this.$http.get(`/resourceSupplyAndDemand/get/${this.$route.query.id}`).then(res => {
                        this.list = res;
                        this.orgInfo = res.orgInfo;
                        this.resSnDPropertyList = res.resSnDPropertyList;
                        // console.log(this.resSnDPropertyList);
                        let arr = [...this.resSnDPropertyList].find(item => item.name == '技术类型');
                        this.techType = arr.value;
                        let str = [...this.resSnDPropertyList].find(item => item.name == '应用领域');
                        this.applicationField = str.value;
                        this.getToCollect();

                        // for (var i = 0; i < this.resSnDPropertyList.length; i++) {
                        //     let a = this.resSnDPropertyList[i].value;
                        //     for (var j = 0; j < this.jslxDataTypeOptions.length; j++) {
                        //         let b = this.jslxDataTypeOptions[j].value;
                        //         if (a == b) {
                        //             this.techTypeId = this.jslxDataTypeOptions[j].label;
                        //         }
                        //     }
                        // }
                    });
                } else if (this.$route.query.type == 'PRODUCT_DEMAND') {
                    this.$http.get(`/resourceSupplyAndDemand/get/${this.$route.query.id}`).then(res => {
                        this.list = res;
                        this.orgInfo = res.orgInfo;
                        this.resSnDPropertyList = res.resSnDPropertyList;
                        let arr = [...this.resSnDPropertyList].find(item => item.name == '设备类型');
                        this.dataType = arr.value;
                        let str = [...this.resSnDPropertyList].find(item => item.name == '应用领域');
                        this.applicationField = str.value;
                        this.getToCollect();
                    });
                }

                /* else if (this.$route.query.type == 3) {
                this.$http.get(`/financingNeeds/get/${this.$route.query.id}`).then(res => {
                    this.list = res;
                    this.dataType = res.dataType;
                    this.applicationField = res.applicationField;
                });
            } */
            }
        },
        getDataType(data, list) {
            this.$http
                .get('/dataType/all', data)
                .then(res => {
                    if (res.content.length > 0) {
                        res.content.forEach(item => {
                            list.push({
                                label: item.name,
                                value: item.id
                            });
                        });
                    }
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        },
        collect() {
            if (this.$store.state.userInfo) {
                if (this.active) {
                    this.active = false;
                    this.collectTitle = '收藏';
                    this.src = require('../assets/icon_collect_pre.png');
                } else {
                    this.active = true;
                    this.collectTitle = '取消收藏';
                    this.src = require('../assets/icon_delcollect.png');
                }
                this.add();
            } else {
                this.$alert('用户未登录，请先进行登录?', '提示', {
                    confirmButtonText: '确定',
                    type: 'warning'
                });
            }
        },
        getToCollect() {
            this.$http
                .get(`/collect/get/${this.$route.query.id}`)
                .then(res => {
                    if (res) {
                        this.active = true;
                        this.collectTitle = '取消收藏';
                        this.src = require('../assets/icon_delcollect.png');
                    } else {
                        this.active = false;
                        this.collectTitle = '收藏';
                        this.src = require('../assets/icon_collect_pre.png');
                    }
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        },
        saveMess() {
            this.showDialog = false;
            if (this.$route.query.id) {
                // var data;
                // if (this.$route.query.type == 'TECH_DEMAND') {
                //     this.formData['resourceSupplyDemand'] = {
                //         id: this.$route.query.id,
                //         name: this.list.name
                //     };
                // } else if (this.$route.query.type == 'PRODUCT_DEMAND') {
                //     this.formData['resourceSupplyDemand'] = {
                //         id: this.$route.query.id,
                //         name: this.list.name
                //     };
                // }
                this.formData.sndId = this.$route.query.id;
                this.save('/conversation/create', this.formData);
            }
        },
        save(url, data) {
            this.$http
                .post(url, data)
                .then(res => {
                    if (res) {
                        this.$refs['formData'].resetFields();
                        this.$message.success('对接成功');
                    }
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        },
        add() {
            if (this.$route.query.id) {
                // var data;
                // if (this.$route.query.type == 'TECH_DEMAND') {
                //     data = { id: this.$route.query.id };
                // } else if (this.$route.query.type == 'PRODUCT_DEMAND') {
                //     data = { id: this.$route.query.id };
                // }
                // this.save('/collect/get', data);
                // this.save(`/collect/${this.$route.query.id}`);
                this.$http
                    .get(`/collect/${this.$route.query.id}`)
                    .then(res => {
                        if (res) {
                            this.$message.success('收藏成功');
                        }
                    })
                    .catch(e => {
                        console.log(e);
                        this.$message.error(e.error);
                    });
            }
        }
    }
};
</script>
<style lang="less" scoped>
.container {
    width: 1200px;
    margin: auto;
}
.resource-detail {
    background-color: #fff;
}
.el-main {
    background: #fff !important;
}
.el-breadcrumb {
    height: 60px;
    line-height: 60px;
    padding: 0 100px;
    /deep/.el-breadcrumb__inner {
        font-size: 12px;
        color: #000 !important;
    }
}
.detail {
    padding: 0px 100px 20px;
    background: white;
    // margin-top: 20px;
    .top {
        .flex();
        .cover {
            width: 483px;
            height: 332px;
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }
        img {
            width: 361px;
            height: 361px;
        }
        .info {
            // flex-grow: 1;
            margin-left: 70px;
            height: 361px;
            // .flex-col();
            // justify-content: space-between;
            .title {
                font-size: 24px;
                // font-weight: bold;
                color: black;
                // line-height: 33px;
                .flex();
                span {
                    max-width: 410px;
                }
                i {
                    // width: 53px;
                    font-size: 12px;
                    color: #22b197;
                    background: #ebf9f7;
                    padding: 5px 3px;
                    margin-left: 12px;
                    font-style: normal;
                }
                .wait {
                    background-color: #ffebe8;
                    color: #ff4a33;
                }
            }
            .specs {
                .flex-col();
                font-size: 14px;
                margin-top: 20px;
                // font-weight: bold;
                color: black;
                .spec {
                    height: 26px;
                    line-height: 26px;
                    margin-bottom: 8px;
                    .flex();
                    .name {
                        width: 84px;
                        color: #939599;
                    }
                    .value {
                        color: #000;
                    }
                }
            }
            .btns {
                .flex();
                margin-top: 60px;
                .btn {
                    width: 130px;
                    height: 44px;
                    border-radius: 4px;
                    font-size: 14px;
                    .flex();
                    justify-content: center;
                    cursor: pointer;
                    user-select: none;
                    .icon {
                        width: 16px;
                        height: 16px;
                        margin-right: 7px;
                    }
                }
                .btn-contact {
                    background: #bf1616;
                    color: white;
                }
                .btn-collect {
                    background: #f7e3e3;
                    // border: 1px solid #bf1616;
                    color: #bf1616;
                    margin-left: 20px;
                    box-sizing: border-box;
                }
                .btn-delcollect {
                    background: #f2f3f5;
                    // border: 1px solid #bf1616;
                    color: #939599;
                    margin-left: 20px;
                }
            }
        }
    }
    .desc {
        margin-top: 30px;
        font-weight: bold;
        color: black;
        line-height: 22px;
    }
}
.bottom {
    margin-top: 60px;
    .description {
        display: flex;
        .desc_left {
            margin-right: 30px;
            .logo {
                width: 180px;
                height: 180px;
                object-fit: cover;
            }
            .companyname {
                width: 180px;
                height: 44px;
                line-height: 44px;
                font-size: 14px;
                color: #000;
                margin-bottom: 10px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
            .companybtn {
                width: 180px;
                height: 38px;
                line-height: 38px;
                background: #bf1616;
                border-radius: 4px;
                text-align: center;
                font-size: 13px;
                color: #fff;
                cursor: pointer;
            }
            .recommend {
                margin-top: 40px;
                .rec_card_title {
                    font-size: 16px;
                    font-weight: 500;
                    color: #000000;
                }
                .rec_card_line {
                    width: 180px;
                    height: 1px;
                    background: #f2f3f5;
                    margin: 7px 0 16px;
                }
                .rec_card {
                    border: 1px solid #f5f7fa;
                    margin-bottom: 16px;
                    img {
                        width: 180px;
                        height: 180px;
                    }

                    .rec_card_name {
                        height: 44px;
                        line-height: 44px;
                        padding-left: 12px;
                        font-size: 14px;
                    }
                }
            }
        }
        .desc_right {
            .desc_title {
                font-size: 16px;
                font-weight: 500;
                color: #000000;
                margin: 8px 0 28px;
            }
        }
    }
}
.el-dialog {
    .cancel {
        width: 100px;
        height: 36px;
        background: #c4c7cc;
        border-radius: 4px;
        border: none;
    }
    .submit {
        width: 100px;
        height: 36px;
        background: #bf1616;
        border-radius: 4px;
        border: none;
    }
}
</style>
