<template>
  <div id="achiDetail">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="top">
          <el-col :span="7" class="left">
            <el-carousel trigger="click" height="345px" :autoplay="false">
              <el-carousel-item v-for="(item, index) in detailInfo.image" :key="index">
                <el-image :src="item.url" style="width:99%;height:345px;border: 1px solid #ccc;"></el-image>
              </el-carousel-item>
            </el-carousel>
          </el-col>
          <el-col :span="17" class="right">
            <el-col :span="24" class="name textOver">
              {{ detailInfo.name || '暂无' }}
            </el-col>
            <el-col :span="24">
              <el-col :span="3" class="otherInfo textOver">
                成果单位
              </el-col>
              <el-col :span="21" class="otherInfo textOver">
                {{ detailInfo.company }}
                <el-link v-if="detailInfo.companyweb != null || ''" :href="detailInfo.companyweb" :underline="false" target="_blank"
                  >({{ detailInfo.companyweb }})</el-link
                >
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                所属领域
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.field || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                合作方式
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.cooperation || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                成果状态
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.achievestatus || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                成果来源
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.achievesource || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                成果权属
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.achieveown || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                意向价格
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.intentionprice || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                联系人
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.contacts || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                电子邮箱
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.email || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="24">
              <el-col :span="3" class="otherInfo textOver">
                项目路演
              </el-col>
              <el-col :span="21" class="otherInfo textOver">
                {{ detailInfo.roadshow || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                专利信息
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.patentinfo || '暂无' }}
              </el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6" class="otherInfo textOver">
                专利状态
              </el-col>
              <el-col :span="18" class="otherInfo textOver">
                {{ detailInfo.patentstatus || '暂无' }}
              </el-col>
            </el-col>
          </el-col>
        </el-col>
        <el-col :span="24" class="down">
          <el-col :span="24" class="downInfo">
            <el-col :span="4" class="tit">
              <h2>成果简介</h2>
            </el-col>
            <el-col :span="20" class="info">
              {{ detailInfo.achievebrief || '暂无' }}
            </el-col>
          </el-col>
          <el-col :span="24" class="downInfo">
            <el-col :span="4" class="tit">
              <h2>技术特点</h2>
            </el-col>
            <el-col :span="20" class="info">
              {{ detailInfo.features || '暂无' }}
            </el-col>
          </el-col>
          <el-col :span="24" class="downInfo">
            <el-col :span="4" class="tit">
              <h2>技术团队</h2>
            </el-col>
            <el-col :span="20" class="info">
              {{ detailInfo.team || '暂无' }}
            </el-col>
          </el-col>
          <el-col :span="24" class="downInfo">
            <el-col :span="4" class="tit">
              <h2>商业预期</h2>
            </el-col>
            <el-col :span="20" class="info">
              {{ detailInfo.expectations || '暂无' }}
            </el-col>
          </el-col>
          <el-col :span="24" class="downInfo">
            <el-col :span="4" class="tit">
              <h2>合作要求</h2>
            </el-col>
            <el-col :span="20" class="info">
              {{ detailInfo.condition || '暂无' }}
            </el-col>
          </el-col>
        </el-col>
        <el-col :span="24" class="anniu" v-if="displayBtn">
          <el-button type="primary" size="mini" v-if="this.user.uid != detailInfo.userid" @click="btnPhone()">交流洽谈</el-button>
          <el-button type="success" size="mini" v-if="this.user.uid != detailInfo.userid" @click="onSubmit()">供求对接</el-button>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog title="对接" :visible.sync="dialogTableVisible">
      <chat :room="room"></chat>
    </el-dialog>
  </div>
</template>

<script>
import _ from 'lodash';
import { mapState, createNamespacedHelpers } from 'vuex';
import chat from '@/layout/market/parts/chat.vue';
const { mapActions: personalRoom } = createNamespacedHelpers('personalroom');
const { mapActions: transaction } = createNamespacedHelpers('transaction');
export default {
  name: 'achiDetail',
  props: {
    detailInfo: { type: Object },
    displayBtn: { type: Boolean },
  },
  components: { chat },
  data: function() {
    return { dialogTableVisible: false, room: {} };
  },
  created() {},
  methods: {
    ...personalRoom(['create', 'countDelete']),
    ...transaction({ buyProduct: 'create' }),
    // 对接
    async btnPhone() {
      if (!this.room.id) {
        //TODO 请求房间号
        let obj = {};
        if (!this.user.uid) {
          // this.$message.error('游客身份无法与卖家对话,请先注册');
          this.$message({
            dangerouslyUseHTMLString: true,
            message: '<strong><a href="http://free.liaoningdoupo.com/platlive/webLogin" style="color:red;">游客身份无法与卖家对话,请先注册</a></strong>',
            type: 'error',
          });
          return;
        } else {
          obj.buyer_id = this.user.uid;
          obj.buyer_name = this.user.name;
        }
        if (!this.detailInfo.userid) {
          this.$message.error('缺少卖家信息,请联系卖家或管理员');
          return;
        } else {
          obj.seller_id = this.detailInfo.userid;
          obj.seller_name = this.detailInfo.contacts;
        }
        let res = await this.create(obj);
        if (this.$checkRes(res)) {
          this.$set(this, `room`, res.data);
        }
      }
      this.dialogTableVisible = true;
    },
    // 洽谈
    onSubmit() {
      this.$emit('onSubmit', { data: this.detailInfo });
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped>
.main {
  margin: 10px 0 0 0;
  .top {
    height: 360px;
    overflow: hidden;
    .right {
      padding: 0 0 0 10px;
      .name {
        font-size: 18px;
        font-weight: bold;
        padding: 10px;
        border: 1px solid #ccc;
      }
      .otherInfo {
        padding: 10px;
        font-size: 16px;
        border: 1px solid #ccc;
      }
    }
  }
  .down {
    margin: 0 0 15px 0;
    .downInfo {
      border: 1px solid #ccc;
      .tit {
        height: 150px;
        line-height: 150px;
        text-align: center;
        border-right: 1px solid #ccc;
      }
      .info {
        font-size: 16px;
        padding: 10px;
        height: 150px;
      }
    }
  }
  .anniu {
    text-align: center;
    /deep/.el-button {
      margin: 0 10px;
    }
  }
}
</style>
