<template>
  <div class="study-syxx">
    <div class="syxx-top" v-show="!showDetail" style="margin-bottom: 10px;">
      <div class="syxx-operate">
        <div class="operate-img"></div>
        <div class="operate-left">{{ $t('page.business.study.studyFormPlan.syxx') }}</div>
      </div>
      <el-form ref="form" label-width="150px">
        <el-row>
          <el-col :span="6">
            <el-form-item :label="$t('page.business.study.studyFormPlan.symc')">
              {{ studyInfo.name }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('page.business.study.studyFormPlan.sybh')">
              {{ studyInfo.sn }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('page.business.study.studyFormPlan.syfzr')">
              {{ studyInfo.leaderName }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('page.business.study.studyFormPlan.cjsj')">
              {{ studyInfo.createTime }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('page.business.study.studyFormPlan.syjj')">
              {{ studyInfo.remark }}
            </el-form-item>
          </el-col>
          <el-col>
            <el-button type="primary" @click="sdsy" v-hasPermi="['business:study:sd']" v-if="(studyInfo.leader==id || checkRole(['TFM'])) && studyInfo.status!=5 && studyInfo.formCount===studyInfo.formFinishCount">{{ $t('page.business.study.studyFormPlan.sdsy') }}</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div class="syxx-operate" style="margin-top: 10px;">
        <div class="operate-img"></div>
        <div class="operate-left">{{ $t('page.business.study.studyFormPlan.syxkxx') }}</div>
      </div>
      <div style="display: flex;">
        <div style="margin-right: 30px;" v-for="(item, index) in subjectList" :key="index">
          {{ item.deptName }}（{{ item.leaderName }}）
        </div>
      </div>
    </div>
    <div class="syxx-content">
      <jhbdList :study="studyInfo" @showDetail="showDetailCallback" />
    </div>

    <Sign ref="syxxSignRef" @callback="doSign" />
  </div>
</template>

<script>
import { checkPermi, checkRole } from "@/utils/permission";
import Sign from './sign.vue'
import jhbdList from './jhbdList.vue'
import { study_info,study_checkSd,study_sd } from "@/api/business/study/study"
import { studySubject_listByStudyId } from '@/api/business/study/studySubject'
import { mapGetters } from 'vuex'
export default {
  name: 'StudyTbbd',
  props: {
    study: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
    study: {
      immediate: true,
      deep:true,
      handler(v) {
        this.studyId = v.id
        this.getStudyInfo()
      }
    },
  },
  components: { jhbdList,Sign },
  computed: {
    ...mapGetters([
      'id'
    ]),
  },
  data() {
    return {
      showDetail: false,
      studyId: '',
      studyInfo:{},
      subjectList: []
    }
  },
  created() {
  },
  methods: {
    checkPermi,
    checkRole,
    getstudySubject() {
      studySubject_listByStudyId({ studyId: this.studyId }).then(response => {
        this.subjectList = response.data;
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    getStudyInfo() {
      this.$modal.loading()
      study_info({ id: this.studyId }).then(response => {
        this.studyInfo = response.data
        this.getstudySubject()
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    sdsy() {
      this.$modal.loading()
      study_checkSd({
        study:{id:this.studyId},
      }).then(() => {
        this.$refs.syxxSignRef.show(this.$t('page.business.study.study.sdsy'),this.$t('page.business.study.study.sdsy'))
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    doSign(val){
      this.doSd(val)
    },
    doSd(sign){
      this.$modal.loading()
      study_sd({
        study:{id:this.studyId},
        sign:sign
      }).then(() => {
        this.$refs.syxxSignRef.cancel()
        this.getStudyInfo()
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    showDetailCallback(val) {
      this.showDetail = val
      this.$emit('showDetail', val)
    }
  }
}
</script>
<style lang="scss" scoped>
.study-syxx {

  .syxx-top {
    background: #fff;
    padding: 20px;
    width: 100%;

    .syxx-operate {
      margin: 0px 0 10px 0;
      display: flex;
      flex-direction: row;
      align-items: center;
      color: #409eff;

      .operate-img {
        flex-shrink: 0;
        height: 15px;
        background: #409eff;
        width: 3px;
      }

      .operate-left {
        flex-shrink: 0;
        font-weight: bold;
        padding-left: 10px;
      }

      .operate-right {
        flex-grow: 1;
        text-align: right;

        .operate-icon {
          cursor: pointer;
        }
      }
    }
  }

  .syxx-content {
    
  }
}
</style>
