<template>
  <div id="context">
    <el-col :span="24" class="one">
      <el-col :span="7" class="oneLeft">
        <el-carousel trigger="click" height="210px">
          <template v-if="detailInfo.image && detailInfo.image.length > 0">
            <el-carousel-item v-for="(item, index) in detailInfo.image" :key="index">
              <el-image :src="item.url" style="width:100%"> </el-image>
            </el-carousel-item>
          </template>
        </el-carousel>
      </el-col>
      <el-col :span="17" class="oneRight">
        <p class="textOver">
          {{ detailInfo.name }}
        </p>
        <p>
          <span>产品类型:{{ detailInfo.product_type_name || '暂无' }}</span>
          <span>收费标准:{{ detailInfo.price || '暂无' }}/{{ detailInfo.priceunit || '暂无' }}</span>
        </p>
        <p>
          <span>
            交易方式:{{ detailInfo.business === '0' ? '公用' : detailInfo.business === '1' ? '转让' : detailInfo.business === '2' ? '竞价' : '暂无' }}
          </span>
          <span>研发阶段:{{ detailInfo.phase == 1 ? '阶段成果' : detailInfo.phase == 2 ? '最终成果' : '暂无' }}</span>
        </p>
        <p>
          <span>联系人:{{ detailInfo.contact_user || '暂无' }}</span>
          <span>联系电话:{{ detailInfo.contact_tel || '暂无' }}</span>
        </p>
      </el-col>
      <el-col :span="24" class="newDown">
        <div>
          <p>应用领域：</p>
          <p>{{ detailInfo.field || '暂无' }}</p>
        </div>
        <div>
          <p>
            <span>产品参数:</span>
            <span>
              <el-button type="text" @click="product_argsDia = true">查看详情</el-button>
            </span>
          </p>
        </div>
        <div>
          <p>服务范围:</p>
          <p class="moreScope" v-if="scope != ''">{{ detailInfo.scope || '暂无' }}</p>
          <p class="moreScope1" v-else>{{ detailInfo.scope || '暂无' }}</p>
          <span v-if="detailInfo.scope != null && detailInfo.scope.length > 420">
            <el-button size="mini" @click="scopeMore()" v-if="scope != ''">更多</el-button>
            <el-button size="mini" @click="scopeMore1()" v-else>收起</el-button>
          </span>
        </div>
        <div></div>
        <div>
          <p>产品简介:</p>
          <p class="introduction" v-if="introduction != ''">{{ detailInfo.introduction || '暂无' }}</p>
          <p class="introduction1" v-else>{{ detailInfo.introduction || '暂无' }}</p>
          <el-button size="mini" v-if="detailInfo.introduction != null && detailInfo.introduction.length > 420">
            <span v-if="introduction != ''" @click="introductionMore()">更多</span>
            <span v-else @click="introductionMore1()">收起</span>
          </el-button>
        </div>
      </el-col>
      <el-col :span="24" class="anniu">
        <el-button type="primary" @click="btnPhone()" v-if="this.user.uid != detailInfo.userid">对接聊天</el-button>
        <el-button v-if="this.user.uid != detailInfo.userid" @click="onSubmit()" type="success">洽谈交易</el-button>
        <!-- <el-button @click="onSubmit" type="success">对接聊天</el-button><el-button @click="onSubmit" type="primary">洽谈交易</el-button></el-col -->
      </el-col>
      <el-dialog title="对接聊天" :visible.sync="dialogTableVisible">
        <el-col :span="24" class="two">
          <chat :room="room"></chat>
        </el-col>
      </el-dialog>
      <el-dialog title="参数" class="argsDialog" :visible.sync="product_argsDia">
        <el-table :data="detailInfo.product_args" border style="width: 100%">
          <el-table-column prop="arg_name" label="参数名称" :show-overflow-tooltip="true"> </el-table-column>
          <el-table-column prop="memo" label="参数内容" :show-overflow-tooltip="true"> </el-table-column>
        </el-table>
      </el-dialog>
    </el-col>
  </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: 'context',
  props: {
    detailInfo: null,
  },
  components: {
    chat,
  },
  data: () => ({
    product_argsDia: false,
    dialogTableVisible: false,
    dialogFormVisible: false,
    scope: '123',
    introduction: '123',
    room: {},
  }),
  created() {},
  computed: {
    ...mapState(['user']),
  },
  methods: {
    // ...mapProduct(['fetch']),
    ...personalRoom(['create', 'countDelete']),
    ...transaction({ buyProduct: 'create' }),
    scopeMore() {
      this.scope = '';
    },
    // 收起
    scopeMore1() {
      this.scope = '123';
    },
    // 更多
    introductionMore() {
      this.introduction = '';
    },
    // 收起
    introductionMore1() {
      this.introduction = '123';
    },
    onSubmit() {
      this.$emit('onSubmit', this.detailInfo);
    },
    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/newlogin" 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.contact_user;
        }
        console.log(obj);
        let res = await this.create(obj);
        if (this.$checkRes(res)) {
          this.$set(this, `room`, res.data);
        }
      }
      this.dialogTableVisible = true;
    },
  },
};
</script>

<style lang="less" scoped>
p {
  padding: 0;
  margin: 0;
}
.textOver {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
// .textOver{}
// 	overflow: hidden;
// 	text-overflow: ellipsis;
// 	-webkit-line-clamp: 3;
// 	word-break: break-all;
// 	display: -webkit-box;
//   -webkit-box-orient: vertical;
//   }
.style {
  height: 100vh;
}
.style .info {
  position: relative;
  top: -450px;
}
.style .top {
  position: relative;
  top: 0;
  width: 100%;
  text-align: center;
  z-index: 999;
  height: 230px;
  margin: 0 0 20px 0;
}
.style .top p:first-child {
  font-size: 50px;
  color: #fff;
}
.style .top p:last-child {
  font-size: 30px;
  color: #fff;
  position: absolute;
  width: 100%;
  top: 170px;
}

.one {
  min-height: 550px;
  padding: 20px;
  .oneLeft {
    height: 210px;
    overflow: hidden;
  }
  .oneRight {
    padding: 0 15px;
    p {
      font-size: 16px !important;
      padding: 0 0 20px 0;
      span {
        display: inline-block;
        width: 50%;
      }
    }
    p:first-child {
      font-size: 18px;
      font-weight: bold;
      padding: 20px 0;
    }
    p:nth-child(2) span:last-child {
      color: red;
      font-weight: bold;
    }
  }
  .oneDown {
    border-top: 1px dashed #ccc;
    margin: 30px 0 0 0;
    padding: 30px 0 0 0;
    div {
      padding: 0 0 15px 0;
      p {
        font-size: 18px;
      }
      p:first-child {
        color: #333;
        font-weight: bold;
        padding: 0 0 10px 0;
      }
    }
    div:nth-child(2) p span:last-child {
      color: #409eff;
      padding: 0 10px;
    }
    div:nth-child(2) p span:last-child:hover {
      cursor: pointer;
    }
    div:nth-child(3) .moreScope {
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 6;
      word-break: break-all;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    div:nth-child(3) .moreScope1 {
      overflow: none;
    }
    div:nth-child(3) .el-button {
      float: right;
    }
    div:nth-child(5) .introduction {
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 6;
      word-break: break-all;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    div:nth-child(5) .introduction1 {
      overflow: none;
    }
    div:last-child .el-button {
      float: right;
    }
  }

  .newDown {
    border-top: 1px dashed #ccc;
    margin: 30px 0 0 0;
    padding: 30px 0 0 0;
    div {
      padding: 0 0 15px 0;
      p {
        font-size: 16px;
      }
      p:first-child {
        color: #333;

        padding: 0 0 10px 0;
      }
    }
    div:nth-child(2) p span:last-child {
      color: #409eff;
      padding: 0 10px;
    }
    div:nth-child(2) p span:last-child:hover {
      cursor: pointer;
    }
    div:nth-child(3) .moreScope {
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 6;
      word-break: break-all;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    div:nth-child(3) .moreScope1 {
      overflow: none;
    }
    div:nth-child(3) .el-button {
      float: right;
    }
    div:nth-child(5) .introduction {
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 6;
      word-break: break-all;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    div:nth-child(5) .introduction1 {
      overflow: none;
    }
    div:last-child .el-button {
      float: right;
    }
  }

  .mainDown {
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
}
.anniu {
  float: left;
  text-align: center;
}

/deep/.argsDialog .el-dialog__body {
  min-height: 120px;
  height: 0;
}

/deep/.el-dialog__body {
  padding: 15px 20px;
  color: #606266;
  font-size: 14px;
  height: 660px;
  word-break: break-all;
}
</style>
