<template>
  <div id="stockDetail">
    <el-row>
      <el-col :span="24" class="debt">
        <el-col :span="24" class="top">
          <topInfo :topTitle="topTitle" :display="display"></topInfo>
        </el-col>
        <el-col :span="24" class="main">
          <el-col :span="24" class="back">
            <detailTop @goBack="goBack"></detailTop>
          </el-col>
          <el-col :span="24" class="info">
            <stockForm :ruleForm="stockForm" :saw="saw" @fallow="fallow"></stockForm>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import detailTop from '@/layout/common/detailTop.vue';
import stockForm from '@/layout/businessneed/stockForm.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: stockneed } = createNamespacedHelpers('stockneed');
const { mapActions: claimneed } = createNamespacedHelpers('claimneed');
export default {
  name: 'stockDetail',
  props: {},
  components: {
    topInfo, //头部导航
    detailTop, //头部返回
    stockForm, //股权需求详情
  },
  data: () => ({
    display: 'none',
    topTitle: '股权信息详情',
    stockForm: {},
    charList: {
      name: '10',
    },
    saw: '1',
  }),
  created() {
    this.searchInfo();
    this.safollow();
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  methods: {
    ...stockneed(['followstock', 'one']),
    ...claimneed(['beforFollow']),
    async searchInfo() {
      if (this.id) {
        const res = await this.one({ id: this.id });
        this.$set(this, `stockForm`, res.data);
      }
    },
    async safollow() {
      if (this.id) {
        var userid = this.user.userid;
        const ress = await this.beforFollow({ finceId: this.id, userid: userid });
        if (ress.data.finstatus == 'SUCCESS') {
          this.$set(this, `saw`, '0');
        } else {
          this.$set(this, `saw`, '1');
        }
      }
    },
    // 关注
    async fallow({ data }) {
      var finceId = data._id;
      var userid = this.user.userid;
      const res = await this.beforFollow({ finceId: finceId, userid: userid });
      if (res.data.finstatus == 'SUCCESS') {
        this.$message({
          message: '您已经关注成功',
          type: 'success',
        });
      } else {
        const followres = await this.followstock({ finceId: finceId, userid: userid });
        if (followres.errcode === 0) {
          this.$message({
            message: '关注成功',
            type: 'success',
          });
        } else {
          this.$message({
            message: '关注失败',
            type: 'error',
          });
        }
      }
    },
    // 返回
    goBack() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.debt {
  padding: 20px;
}
.top {
  border-bottom: 1px solid #ccc;
}
.main {
  border-radius: 10px;
  margin: 20px 0 0 0;
  box-shadow: 0 0 3px #666;
}
.main .back {
  padding: 10px 0 10px 15px;
}
</style>
