<!-- 试验方法列表 -->
<template>
  <div>
    <div class="tbbd-list" v-show="!showDetail">
      <div class="tbbd-search">
        <el-form :model="searchForm" ref="searchForm" class="search-area" :inline="true" label-width="88px">
          <el-row>
            <el-col :span="24">
              <!-- 方法名称 -->
              <el-form-item :label="$t('page.business.study.studyMethod.ffmc')" prop="ffmc">
                <el-input v-model="searchForm.ffmc" :placeholder="$t('form.placeholderInput')" clearable
                  @keyup.enter.native="search" />
              </el-form-item>
              <!-- 创建人 -->
              <el-form-item :label="$t('page.business.study.studyMethod.cjr')" prop="cjr">
                <el-input v-model="searchForm.cjr" :placeholder="$t('form.placeholderInput')" clearable
                  @keyup.enter.native="search" />
              </el-form-item>
              <!-- 创建时间 -->
              <el-form-item :label="$t('page.business.study.studyMethod.cjsj') + '：'">
                <el-date-picker v-model="daterange" class="chat-histogram-daterange" type="daterange"
                  range-separator="-" :start-placeholder="$t('form.startDate')" :end-placeholder="$t('form.endDate')"
                  value-format="yyyy-MM-dd" @change="search" style="width: 250px;" />
              </el-form-item>
              <!-- 状态 -->
              <el-form-item :label="$t('page.business.study.studyMethod.zt') + '：'" prop="zt">
                <el-select v-model="searchForm.zt" :placeholder="$t('form.placeholderSelect')" clearable
                  @change="search">
                  <el-option :label="$t('page.business.study.studyMethod.yidu')" :value="1" />
                  <el-option :label="$t('page.business.study.studyMethod.weidu')" :value="0" />
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="search">{{ $t('form.search') }}</el-button>
                <el-button icon="el-icon-refresh" @click="reset">{{ $t('form.reset') }}</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

      </div>
      <div class="tbbd-content">
        <el-row class="add-box">
          <el-col>
            <el-button type="primary" icon="el-icon-plus" @click="add()" v-hasPermi="['business:studyMethod:upload']">{{
              $t('page.business.study.studyMethod.scff') }}</el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="list">
          <el-table-column :label="$t('page.business.study.studyMethod.ffmc')" prop="ffmc" />
          <el-table-column :label="$t('page.business.study.studyMethod.cjsj')" prop="createTime" />
          <el-table-column :label="$t('page.business.study.studyMethod.cjr')" prop="userMc" />
          <el-table-column :label="$t('page.business.study.studyMethod.zt')" prop="status" align="center" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.zt != 0">{{ $t('page.business.study.studyMethod.yidu') }}</span>
              <span v-if="scope.row.zt === 0">{{ $t('page.business.study.studyMethod.weidu') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('form.operate')" align="left" fixed="right" width="200">
            <template slot-scope="scope">
              <!-- 阅读 -->
              <el-button type="text" @click="detail(scope.row)" v-hasPermi="['business:studyMethod:read']">{{
                $t('page.business.study.studyMethod.yuedu') }}</el-button>
              <!-- 导出 -->
              <el-button type="text" @click="showExport(scope.row)" v-hasPermi="['business:studyMethod:download']">{{
                $t('page.business.study.studyMethod.daochu') }}</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize"
          @pagination="getList" />
      </div>
    </div>
    <!-- 新增 -->
    <Xz key="Xz" ref="Xz" @callback="search" />
    <!-- 详情 -->
    <Xq key="Xq" ref="Xq" v-show="showDetail"  @close="xqClose" />
  </div>

</template>

<script>
import { studyMethod_list } from '@/api/business/study/studyMethod'
import Xz from "./syff/Xz";
import Xq from "./syff/Xq";
import { mapGetters } from 'vuex'
import moment from "moment";
export default {
  name: 'SyffList',
  props: {
    study: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ]),
  },
  watch: {
    study: {
      handler(newVal) {
        this.searchForm.studySn = newVal.sn
        this.searchForm.studyMc = newVal.name
        this.searchForm.studyId = newVal.id
        this.searchForm.studySubjectId = newVal.studySubjectId
        this.leader = newVal.leader
        this.search()
      },
      immediate: true,
      deep: true
    }
  },
  components: { Xz, Xq },
  data() {
    return {
      showDetail: false,
      daterange: [],
      showFh: false,
      daterange: [],
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        studyId: '',
        syjh: '',
        syqy: '',
        qyr: '',
        jsr: '',
        startDate: '',
        endDate: ''
      },
      loading: false,
      total: 0,
      list: [],
      currentRow: null
    }
  },
  created() { },
  methods: {

    search() {
      this.searchForm.pageNum = 1
      this.getList()
    },
    reset() {
      this.resetForm("searchForm")
      this.search()
    },
    getList() {
      if (this.daterange != null && this.daterange.length > 0) {
        this.searchForm.startDate = this.daterange[0] + " 00:00:00"
        this.searchForm.endDate = this.daterange[1] + " 23:59:59"
      } else {
        this.searchForm.startDate = ''
        this.searchForm.endDate = ''
      }
      this.loading = true
      studyMethod_list(this.searchForm).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    add() {
      this.$refs.Xz.show(this.study);
    },
    detail(row) {
      this.showDetail = true
      this.$emit('showDetail', this.showDetail)
      this.$refs.Xq.show(row)
    },
    showExport(row) {
      this.showDetail = true
      this.$emit('showDetail', this.showDetail)
      this.$refs.Xq.showExport(row)
    },
    xqClose() {
      this.showDetail = false
      this.$emit('showDetail', this.showDetail)
      this.search()
    },
  }
}
</script>
<style lang="scss" scoped>
.tbbd-list {
  .tbbd-search {
    background: #fff;
    padding: 20px;
    margin-bottom: 10px;

    .right-btn {
      text-align: right
    }
  }

  .tbbd-content {
    padding: 20px;
    background: #fff;

    .add-box {
      margin-bottom: 10px;
    }
  }
}
</style>
