<template>
  <el-dialog
    title="查看"
    :visible.sync="dataObj.detailDialog"
    width="800px"
    :close-on-click-modal="false"
    @close="closedialog"
  >
    <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="申报表" name="first" v-if="applydataObj.param">
          <div class="content-box">
            <div class="content">
              <el-descriptions style="border:1px solid #ebebeb;padding:30px 20px;" :column="1">
                <el-descriptions-item label="专业合作社名称">{{dataObj.name}}</el-descriptions-item>
                <el-descriptions-item label="法人代表">{{dataObj.person}}</el-descriptions-item>
                <el-descriptions-item label="联系方式">{{applydataObj.param.tel}}</el-descriptions-item>
                <el-descriptions-item label="工商登记注册时间">{{applydataObj.param.create}}</el-descriptions-item>
                <el-descriptions-item label="专业合作社详细地址">{{applydataObj.param.coopaddr}}</el-descriptions-item>
                <el-descriptions-item label="获得何种奖励/称号">{{applydataObj.param.aware}}</el-descriptions-item>
                <el-descriptions-item label="成员数">{{applydataObj.param.numberper}} 人</el-descriptions-item>
                <el-descriptions-item label="农民成员数">{{applydataObj.param.nongmin}} 人</el-descriptions-item>
                <el-descriptions-item label="主营产品名称">{{applydataObj.param.mainpro}}</el-descriptions-item>
                <el-descriptions-item label="商标名称">{{applydataObj.param.mark}}</el-descriptions-item>
                <el-descriptions-item label="核心基地种植">{{applydataObj.param.plant}}</el-descriptions-item>
                <el-descriptions-item label="联结基地">{{applydataObj.param.area}}</el-descriptions-item>
                <el-descriptions-item label="带动非成员衣户数">{{applydataObj.param.cloth}} 人</el-descriptions-item>
                <el-descriptions-item label="成员采购供应比">{{applydataObj.param.common}} %</el-descriptions-item>
                <el-descriptions-item label="追溯方式">{{applydataObj.param.caiyong}}</el-descriptions-item>
                <el-descriptions-item label="基地/产品认证">{{applydataObj.param.renzheng}}</el-descriptions-item>
                <el-descriptions-item label="产品质量认证比">{{applydataObj.param.zhiliang}} %</el-descriptions-item>
                <el-descriptions-item label="上年度成员培训">{{applydataObj.param.peixun}} 人</el-descriptions-item>
                <el-descriptions-item label="上年度固定资产总额">{{applydataObj.param.guding}} 万元</el-descriptions-item>
                <el-descriptions-item label="上年度经营收入">{{applydataObj.param.jingying}} 万元</el-descriptions-item>
                <el-descriptions-item label="上年度盈余">{{applydataObj.param.yingkui}} 万元</el-descriptions-item>
                <el-descriptions-item label="盈余返还总额">{{applydataObj.param.fanhuizonge}} 万元</el-descriptions-item>
                <el-descriptions-item label="交易额返还比">{{applydataObj.param.jiaoyi}} %</el-descriptions-item>
                <el-descriptions-item label="股金返还比">{{applydataObj.param.gujin}} %</el-descriptions-item>
              </el-descriptions>
                <el-table :data="applydataObj.fileParam" style="width: 100%">
                  <el-table-column prop="name" label="附件" align="center">
                  </el-table-column>
                  <el-table-column prop="fileName" label="文件名" align="center">
                  </el-table-column>
                  <el-table-column prop="operate" align="center" label="操作">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="success"
                        @click="handleEdit(scope.$index, scope.row)">下载</el-button>
                    </template>
                  </el-table-column>
                </el-table>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="监测表" name="second">
          <div class="content-box">
            <div class="content">
              <!-- 监测表审核 -->
              <el-descriptions style="border:1px solid #ebebeb;padding:30px 20px;" :column="1">
                <el-descriptions-item v-for="(item,index) in checkdataObj.param" :key="index" :label="item.name">{{item.userSelfCheck}}</el-descriptions-item>
              </el-descriptions>
              <el-table :data="checkdataObj.fileParam" style="width: 100%">
                  <el-table-column prop="name" label="附件" align="center">
                  </el-table-column>
                  <el-table-column prop="fileName" label="文件名" align="center">
                  </el-table-column>
                  <el-table-column prop="operate" align="center" label="操作">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="success"
                        @click="handleEdit(scope.$index, scope.row)">下载</el-button>
                    </template>
                  </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>
    </el-tabs>
  </el-dialog>
</template>
<script>
import {
  getapplymsg,
  getcheckmsg
} from "../../../apis/modules/cooperative"
export default {
  props: ["dataObj"],
  data() {
    return {
        activeName: 'first',
        labelPosition:'right',
        applydataObj:{},
        checkdataObj:{}
    };
  },
  watch:{
    'dataObj.detailDialog':function(v) {
        if (v == true) {
          getapplymsg({},this.dataObj.userId).then((res)=>{
            if (res.data.length == 0) {
              return
            }
            if (res.status == 0) {
              this.applydataObj={
                param:JSON.parse(res.data[0].param),
                fileParam:res.data[0].fileParam
              }
            }
          })
          getcheckmsg({},this.dataObj.userId).then((res)=>{
            this.checkdataObj={}
            if (res.data.length == 0) {
              return
            }
            if (res.status == 0) {
              this.checkdataObj={
                param:JSON.parse(res.data[0].param),
                fileParam:res.data[0].fileParam
              }     
            }
          })
        }
    }
    
  },
  methods:{
    closedialog(){
      this.activeName = 'first'
    },
    // 申报表下载
    handleEdit(sort, row) {
      let _this = this
      this.applydataObj.fileParam.forEach((item,index) => {
        if (item.sort == (sort+1)) {
          _this.downLoad(item.fileUrl,item.fileName);
          this.$message({
            message: '下载成功',
            type: 'success'
          });
        }
      });
    },
    downLoad(content, fileName) {
      var aEle = document.createElement("a"); // 创建a标签
      aEle.download = fileName; // 设置下载文件的文件名
      aEle.href = content; // content为后台返回的下载地址
      aEle.click(); // 设置点击事件
    },
    handleClick(tab, event) {
    },
  },
};
</script>
<style lang="scss" scoped>
/* 弹框滚动条 */
/deep/ .el-dialog__body {
  max-height: 62vh;
  overflow: auto;
}
/deep/ .el-descriptions-item__label{
  display: inline-block;
  width: 300px;
}
</style>
