<template>
  <div class="check-safe-list">
    <el-collapse  v-model="riskPointDetail.cIndex2" v-if="checkSafeList.length > 0">
      <el-collapse-item v-for="(i,index) in checkSafeList" :key="index" :name="index.toString()+'0'">
        <template slot="title">
          危险源: <span>{{i.rootName}}</span>
        </template>
        <el-collapse  >
          <el-collapse-item v-for="(j,index) in i.list" :key="'nub'+index" :name="index.toString()+'1'">
            <template slot="title">
              {{j.riskName}}
            </template>
            <div class="risk-detail-table">
              <el-table
                :data="j.sysRiskMeasureTypeList"
                height="400"
                style="width: 100%">
                <el-table-column
                  type="index"
                  min-width="5%"
                >
                </el-table-column>
                <el-table-column
                  prop="type"
                  min-width="20%"
                  label="风险管控措施类型">
                </el-table-column>
                <el-table-column
                  prop = "info"
                  min-width="75%"
                  label="管控措施内容">
                  <!--<template slot-scope="scope">
                    <ul class="gkcs-list">
                      <li v-for="(itemV,index1) in scope.row.sysRiskMeasureList" :key="index1">
                        <span>{{index1+1+'、'}}</span>
                        <span>{{itemV.riskMeasureContent}}</span>
                      </li>
                    </ul>
                  </template>-->
                </el-table-column>
              </el-table>
            </div>
          </el-collapse-item>
        </el-collapse>
      </el-collapse-item>
    </el-collapse>
    <div v-else style="text-align: center;">
      暂无数据
    </div>

  </div>
</template>

<script>
  import {mapState, mapGetters} from 'vuex'

  export default {
	name: "CheckList",
	data(){
		return{
      checkSafeList: []
		}
	},
    computed:{
      ...mapGetters([
        'getRiskPointId'
      ]),
      ...mapState(['riskPointDetail', 'riskPointId'])
    },
    watch:{
      getRiskPointId(val) {
        console.log('riskPointId', val)
        this.getRiskMeasureList()
      }
    },
    mounted(){
      console.log('riskPointId', this.$store.state.riskPointId)
      this.getRiskMeasureList()
    },
    methods: {
      getRiskMeasureList(){
        let _this = this
        let obj = {
          gId:this.$route.query.gId,
          cId:this.$route.query.cId,
          // riskPointId: 7759,
          riskPointId: this.$store.state.riskPointId

        };
        this.$axios.AxiosMethods("get",this.$api.getRiskMeasureList,obj,function (res) {
          console.log(res);
          // _this.checkSafeList = res.data
          var msg = res.data
          for(var i=0; i<msg.length; i++){
            for(var j=0; j<msg[i].list.length; j++){
              if(msg[i].list[j].riskMeasureContent){
                var myArr = msg[i].list[j].riskMeasureContent.split(',')
                console.log(myArr)
                if(myArr.length > 0){
                  var item = [];
                  for(var k=0; k<myArr.length; k++){
                    if(myArr[k]){
                      var myType = parseInt(myArr[k].split('#')[0])
                      // console.log(myType)
                      switch(myType)
                      {
                        case 1:
                          myType = '工程技术';
                          break;
                        case 2:
                          myType = '管理';
                          break;
                        case 3:
                          myType = '教育';
                          break;
                        case 4:
                          myType = '个体防护';
                          break;
                        default:
                          myType = '应急';
                      }
                      // console.log(myType)

                      let myjson = {
                        type: myType,
                        info: myArr[k].split('#')[1]
                      }
                      item.push(myjson)
                    }

                  }
                  msg[i].list[j].sysRiskMeasureTypeList = item
                }
              }

            }
          }
          _this.checkSafeList = msg
          console.log(_this.checkSafeList)
        })
      }
    }
  }
</script>

<style scoped>

</style>
