<template>
  <div class="app-container study-page">
    <div class="content-list" v-show="showType==='list'">
      <el-form :model="searchForm" ref="searchForm" :inline="true" class="search-box">
        <el-form-item :label="$t('page.business.study.nonTrial.sn')" prop="sn">
          <el-input v-model="searchForm.sn" :placeholder="$t('form.placeholderInput')" clearable style="width: 150px" @keyup.enter.native="search" />
        </el-form-item>
        <el-form-item :label="$t('page.business.study.nonTrial.name')" prop="name">
          <el-input v-model="searchForm.name" :placeholder="$t('form.placeholderInput')" clearable style="width: 150px" @keyup.enter.native="search" />
        </el-form-item>
        <el-form-item prop="status" :label="$t('page.business.study.nonTrial.status')">
          <el-select
            v-model="searchForm.status"
            :placeholder="$t('form.placeholderSelect')"
            clearable
            style="width: 100px"
            @change="search"
          >
            <el-option :label="$t('page.business.study.nonTrial.statusDgd')" :value="7" />
            <el-option :label="$t('page.business.study.nonTrial.statusGd')" :value="9" />
            <el-option :label="$t('page.business.study.nonTrial.statusDjd')" :value="10" />
          </el-select>
        </el-form-item>

        <div class="right-btn">
          <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>
        </div>
      </el-form>

      <div class="content-box">
        <el-table v-loading="loading" :data="list">
          <el-table-column :label="$t('page.business.study.nonTrial.sn')" prop="sn" />
          <el-table-column :label="$t('page.business.study.nonTrial.name')" prop="name" />
          <el-table-column :label="$t('page.business.study.nonTrial.leader')" align="center" prop="leaderName" width="100" />
          <el-table-column :label="$t('page.business.study.nonTrial.status')" prop="status" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.status===1"><span class="status-circle cg"></span>{{$t('page.business.study.nonTrial.statusCg')}}</span>
              <span v-if="scope.row.status===3"><span class="status-circle syz"></span>{{$t('page.business.study.nonTrial.statusSyz')}}</span>
              <span v-if="scope.row.status===5"><span class="status-circle ysd"></span>{{$t('page.business.study.nonTrial.statusYsd')}}</span>
              <span v-if="scope.row.status===7"><span class="status-circle"></span>{{$t('page.business.study.nonTrial.statusDgd')}}</span>
              <span v-if="scope.row.status===9"><span class="status-circle"></span>{{$t('page.business.study.nonTrial.statusGd')}}</span>
              <span v-if="scope.row.status===10"><span class="status-circle"></span>{{$t('page.business.study.nonTrial.statusDjd')}}</span>
            </template>
          </el-table-column>

          <el-table-column :label="$t('page.business.study.nonTrial.borrowStatus')" prop="borrowStatus" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.borrowStatus===1">{{$t('page.business.study.nonTrial.borrowStatusWjy')}}</span>
              <span v-if="scope.row.borrowStatus===5">{{$t('page.business.study.nonTrial.borrowStatusDjy')}}</span>
              <span v-if="scope.row.borrowStatus===10">{{$t('page.business.study.nonTrial.borrowStatusJyz')}}</span>
            </template>
          </el-table-column>

          <el-table-column :label="$t('page.business.study.nonTrial.sqgdsj')" align="center" prop="gdApplyTime" width="140" />

          <el-table-column :label="$t('form.operate')" fixed="right" align="center" width="200">
            <template slot-scope="scope">
              <!-- 同意归档 -->
              <el-button type="text" @click="gd(scope.row,9)" v-hasPermi="['business:archive:trial:tygd']" v-if="scope.row.status===7">{{$t('page.business.study.nonTrial.tygd')}}</el-button>
              <!-- 拒绝归档 -->
              <el-button type="text" @click="gd(scope.row,5)" v-hasPermi="['business:archive:trial:jjgd']" v-if="scope.row.status===7">{{$t('page.business.study.nonTrial.jjgd')}}</el-button>
              <!-- 同意解档 -->
              <el-button type="text" @click="jd(scope.row,5)" v-hasPermi="['business:archive:trial:tyjd']" v-if="scope.row.status===10">{{$t('page.business.study.nonTrial.tyjd')}}</el-button>
              <!-- 拒绝解档 -->
              <el-button type="text" @click="jd(scope.row,9)" v-hasPermi="['business:archive:trial:jjjd']" v-if="scope.row.status===10">{{$t('page.business.study.nonTrial.jjjd')}}</el-button>
              <!-- 同意借阅 -->
              <el-button type="text" @click="jy(scope.row,10)" v-hasPermi="['business:archive:trial:tyjy']" v-if="scope.row.status===9 && scope.row.borrowStatus===5">{{$t('page.business.study.nonTrial.tyjy')}}</el-button>
              <!-- 拒绝借阅 -->
              <el-button type="text" @click="jy(scope.row,1)" v-hasPermi="['business:archive:trial:jjjy']" v-if="scope.row.status===9 && scope.row.borrowStatus===5">{{$t('page.business.study.nonTrial.jjjy')}}</el-button>
              <!-- 确认归还 -->
              <el-button type="text" @click="gh(scope.row)" v-hasPermi="['business:archive:trial:qrgh']" v-if="scope.row.status===9 && scope.row.borrowStatus===10">{{$t('page.business.study.nonTrial.qrgh')}}</el-button>
              <!-- 详情 -->
              <el-button type="text" @click="detail(scope.row)" v-hasPermi="['business:archive:trial:xq']" >{{$t('page.business.study.nonTrial.detail')}}</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>

    <Detail ref="detail" v-show="showType==='detail'" @cancel="showType='list'" />
    <Sign ref="signRef" @callback="doSign" />
  </div>
</template>

<script>
import { nonTrial_archiveList,nonTrial_doGd,nonTrial_doJd,nonTrial_doJy,nonTrial_gh} from "@/api/business/form/nonTrial";
import Detail from '@/views/business/form/nonTrial/comp/detail.vue'
import Sign from '@/views/business/study/comp/sign.vue'
export default {
  name: "ArchiveNonTrial",
  props:{
  },
  components:{
    Detail,
    Sign
  },
  computed: {
  },
  filters:{
  },
  data() {
    return {
      userId:this.$store.getters.id,
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        sn:'',
        name:'',
        status:'',
      },

      loading: true,
      total: 0,
      list: [],
      //线上类型list,edit。。。。
      showType:'list',

      operate:'',
      operateRow:{},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      nonTrial_archiveList(this.searchForm).then(response => {
        this.list = response.rows;
        this.total = response.total;
      }).finally(()=>{
        this.loading = false;
      })
    },
    search() {
      this.searchForm.pageNum = 1;
      this.getList();
    },
    reset(){
      this.searchForm = {
        pageNum: 1,
        pageSize: 10,
        sn:'',
        name:'',
        status:'',
      }
      this.search()
    },
    detail(row){
      this.saveSimpleLog({name:row.name+'('+row.sn+')',nameEn:row.name+'('+row.sn+')',jcmc:'非试验档案详情',jcmcEn:'Non-study Archive Detail'})
      this.showType = 'detail'
      this.$refs.detail.show(row)
    },
    gd(row,status) {
      this.operate = 'gd'
      this.operateRow = _.cloneDeep(row)
      this.operateRow.status = status
      this.$refs.signRef.show(
        status==9?this.$t('page.business.study.nonTrial.tygd'):this.$t('page.business.study.nonTrial.jjgd'),
        status==9?this.$t('page.business.study.nonTrial.tygd'):this.$t('page.business.study.nonTrial.jjgd'),
        false,
        null,
        true,
        status!=9
      )
    },
    doGd(signInfo) {
      this.$modal.loading()
      let postData = {
        study: this.operateRow,
        sign:signInfo
      }
      nonTrial_doGd(postData).then(() => {
        this.$refs.signRef.cancel()
        this.getList()
      })
      .finally(() => {
        this.$modal.closeLoading()
      })
    },
    jd(row,status) {
      this.operate = 'jd'
      this.operateRow = _.cloneDeep(row)
      this.operateRow.status = status
      this.$refs.signRef.show(
        status==5?this.$t('page.business.study.nonTrial.tyjd'):this.$t('page.business.study.nonTrial.jjjd'),
        status==5?this.$t('page.business.study.nonTrial.tyjd'):this.$t('page.business.study.nonTrial.jjjd'),
        false,
        null,
        true,
        status!=5
      )
    },
    doJd(signInfo) {
      this.$modal.loading()
      let postData = {
        study:this.operateRow,
        sign:signInfo
      }
      nonTrial_doJd(postData).then(() => {
        this.$refs.signRef.cancel()
        this.getList()
      })
      .finally(() => {
        this.$modal.closeLoading()
      })
    },

    jy(row,status) {
      this.operate = 'jy'
      this.operateRow = _.cloneDeep(row)
      this.operateRow.borrowStatus = status
      this.$refs.signRef.show(
        status==10?this.$t('page.business.study.nonTrial.tyjy'):this.$t('page.business.study.nonTrial.jjjy'),
        status==10?this.$t('page.business.study.nonTrial.tyjy'):this.$t('page.business.study.nonTrial.jjjy'),
        true,
        [row.borrowStartDate,row.borrowEndDate],
        true,
        status!=10
      )
    },
    doJy(signInfo) {
      this.$modal.loading()
      let postData = {
        study:this.operateRow,
        sign:signInfo
      }
      nonTrial_doJy(postData).then(() => {
        this.$refs.signRef.cancel()
        this.getList()
      })
      .finally(() => {
        this.$modal.closeLoading()
      })
    },

    gh(row) {
      this.operate = 'gh'
      this.operateRow = row
      this.$refs.signRef.show(
        this.$t('page.business.study.nonTrial.qrgh'),
        this.$t('page.business.study.nonTrial.qrgh'),
        false,
        null,
        false,
        false
      )
    },
    doGh(signInfo) {
      this.$modal.loading()
      let postData = {
        study:this.operateRow,
        sign:signInfo
      }
      nonTrial_gh(postData).then(() => {
        this.$refs.signRef.cancel()
        this.getList()
      })
      .finally(() => {
        this.$modal.closeLoading()
      })
    },

    doSign(val){
      if(this.operate==='gd'){
        this.doGd(val)
      }
      if(this.operate==='jd'){
        this.doJd(val)
      }
      if(this.operate==='jy'){
        this.doJy(val)
      }
      if(this.operate==='gh'){
        this.doGh(val)
      }
    },
  }
};
</script>
<style lang="scss" scoped>
.study-page{
  background: #f5f5f5;
  padding: 0;
  .content-list{
    .search-box{
      background: #fff;
      padding: 20px 20px 2px 20px;
      margin-bottom: 10px;
      .right-btn{
        text-align:right
      }
    }
    .content-box{
      background: #fff;
      padding: 20px;
      .add-box{
        margin-bottom: 10px;
      }
    }
  }
}
</style>