<!-- 试剂管理 -->
<template>
  <div>
    <!-- 列表 -->
    <div>
      <div class="app-container sj" v-show="!showDetail">
        <el-form :model="queryParams" ref="queryForm" class="search-area" :inline="true">
          <!-- 名称 -->
          <el-form-item :label="$t('page.business.resource.sj.mc') + '：'">
            <el-input v-model="queryParams.mc" clearable @change="handleQuery"
              :placeholder="$t('form.placeholderInput')" />
          </el-form-item>
          <!-- 编号 -->
          <el-form-item :label="$t('page.business.resource.sj.bh') + '：'">
            <el-input v-model="queryParams.bh" clearable @change="handleQuery"
              :placeholder="$t('form.placeholderInput')" />
          </el-form-item>
          <!-- 借阅状态 -->
          <el-form-item :label="$t('page.business.resource.sj.jyzt') + '：'">
            <el-select v-model="queryParams.jyzt" :placeholder="$t('form.placeholderSelect')" clearable
              @change="handleQuery">
              <el-option key="1" :label="$t('page.business.resource.resource.jyzt.wjy')" value="1" />
              <el-option key="3" :label="$t('page.business.resource.resource.jyzt.djy')" value="3" />
              <el-option key="5" :label="$t('page.business.resource.resource.jyzt.jyz')" value="5" />
            </el-select>
          </el-form-item>
          <!-- 制剂状态 -->
          <el-form-item :label="$t('page.business.resource.sj.zjzt') + '：'">
            <el-select v-model="queryParams.zjzt" :placeholder="$t('form.placeholderSelect')" clearable
              @change="handleQuery">
              <el-option key="7" :label="$t('page.business.resource.resource.zjzt.dgd')" value="7" />
              <el-option key="9" :label="$t('page.business.resource.resource.zjzt.gd')" value="9" />
              <el-option key="11" :label="$t('page.business.resource.resource.zjzt.djd')" value="11" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('form.search') }}</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('form.reset') }}</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="list">
          <el-table-column :label="$t('page.business.resource.sj.mc')" align="left" prop="mc"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.resource.sj.bh')" align="center" prop="bh"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.resource.sj.nd')" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.nd }}{{ scope.row.nddw }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.resource.sj.kcl')" align="center">
            <template slot-scope="scope">
              {{ scope.row.kc }}{{ scope.row.kcdw }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.resource.sj.sxrq')" align="center" prop="sxr" width="150px" />
          <el-table-column :label="$t('page.business.resource.sj.cctj')" align="center" prop="cctj" width="130px" />
          <el-table-column :label="$t('page.business.resource.sj.ccwz')" align="center" prop="ccwz" width="130px" />

          <el-table-column :label="$t('page.business.resource.sj.zjzt')" align="center" width="150px" >
            <template slot-scope="scope">
              <span v-if="scope.row.zjzt == 1">{{ $t('page.business.resource.resource.zjzt.rk') }}</span>
              <span v-if="scope.row.zjzt == 3">{{ $t('page.business.resource.resource.zjzt.yff') }}</span>
              <span v-if="scope.row.zjzt == 5">{{ $t('page.business.resource.resource.zjzt.ysd') }}</span>
              <span v-if="scope.row.zjzt == 7">{{ $t('page.business.resource.resource.zjzt.dgd') }}</span>
              <span v-if="scope.row.zjzt == 9">{{ $t('page.business.resource.resource.zjzt.gd') }}</span>
              <span v-if="scope.row.zjzt == 11">{{ $t('page.business.resource.resource.zjzt.djd') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.resource.sj.jyzt')" align="center" width="150px">
            <template slot-scope="scope">
              <span v-if="scope.row.jyzt == 1">{{ $t('page.business.resource.resource.jyzt.wjy') }}</span>
              <span v-if="scope.row.jyzt == 3">{{ $t('page.business.resource.resource.jyzt.djy') }}</span>
              <span v-if="scope.row.jyzt == 5">{{ $t('page.business.resource.resource.jyzt.jyz') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.resource.sj.gdsqsj')" align="center" prop="gdsqsj" width="130px" />

          <el-table-column :label="$t('form.operate')" fixed="right" align="center"
            class-name="small-padding fixed-width" width="250px">
            <template slot-scope="scope">
              <!-- 待归档 -->
              <template v-if="scope.row.zjzt == 7">
                <!-- 同意归档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.sj.tygd', false, 'tygd')">{{
                    $t('page.business.resource.sj.tygd') }}</el-button>
                <!-- 拒绝归档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.sj.jjgd', false, 'jjgd', true, true)">{{
                    $t('page.business.resource.sj.jjgd') }}</el-button>
              </template>
              <!-- 待解档 -->
              <template v-if="scope.row.zjzt == 11">
                <!-- 同意解档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.sj.tyjd', false, 'tyjd')">{{
                    $t('page.business.resource.sj.tyjd') }}</el-button>
                <!-- 拒绝解档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.sj.jjjd', false, 'jjjd', true, true)">{{
                    $t('page.business.resource.sj.jjjd') }}</el-button>
              </template>
              <!-- 归档 && 待借阅 -->
              <template v-if="scope.row.zjzt == 9 && scope.row.jyzt == 3">
                <!-- 同意借阅 -->
                <el-button type="text" @click="handleSign(scope.row, 'page.business.resource.sj.tyjy', true, 'tyjy')">{{
                  $t('page.business.resource.sj.tyjy') }}</el-button>
                <!-- 拒绝借阅 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.sj.jjjy', true, 'jjjy', true, true)">{{
                    $t('page.business.resource.sj.jjjy') }}</el-button>
              </template>
              <!-- 归档 && 借阅中 -->
              <template v-if="scope.row.zjzt == 9 && scope.row.jyzt == 5">
                <!-- 确认归还 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.sj.qrgh', false, 'qrgh')">{{
                    $t('page.business.resource.sj.qrgh') }}</el-button>
              </template>
              <!-- 详情 -->
              <el-button type="text" @click="handleXq(scope.row)">{{
                $t('page.business.resource.sj.detail') }}</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
      </div>
      <!-- 详情 -->
      <Xq v-show="showDetail" key="Xq" ref="Xq" @callback="closeXq" />
      <!-- 签名 -->
      <Sign ref="refSign" @callback="doSign" />
    </div>
  </div>
</template>

<script>
import { list, tygd, jjgd, tyjd, jjjd, tyjy, jjjy, qrgh } from "@/api/business/sj/sjArchive"
import Xq from "@/views/business/resource/sj/comps/Xq";
import Sign from "@/views/business/comps/common/sign";
export default {
  name: "Sj",
  components: { Xq, Sign },
  data() {
    return {
      showDetail: false,
      daterange: [],
      loading: true,
      single: true,
      multiple: true,
      total: 0,
      list: [],
      //勾选列表
      selectList: [],
      form: {},
      //查询条件
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mc: null,
        jyzt: null,
        zjzt: null,
        bh: null,
        startDate: null,
        endDate: null,
      },
    }
  },
  created() {
    this.handleQuery()
  },
  methods: {
    handleSign(row, qmyy, showDate, type, isReson, reasonRequired) {
      console.log(row)
      this.form.id = row.id
      let title = this.$t(qmyy)
      this.type = type
      this.$refs.refSign.show(title, title, showDate, (type == 'jjjy' || type == 'tyjy') ? [row.jyksrq, row.jyjsrq] : [], isReson, reasonRequired)
    },
    doSign(val) {
      let params = _.merge({}, this.form, val)
      this.$modal.loading()
      if (this.type == 'tygd') {
        tygd(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      } else if (this.type == 'jjgd') {
        jjgd(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      } else if (this.type == 'tyjd') {
        tyjd(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      } else if (this.type == 'jjjd') {
        jjjd(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      } else if (this.type == 'tyjy') {
        params.startDate = params.jyksrq
        params.endDate = params.jyjsrq
        tyjy(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      } else if (this.type == 'jjjy') {
        params.startDate = params.jyksrq
        params.endDate = params.jyjsrq
        jjjy(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      } else if (this.type == 'qrgh') {
        qrgh(params).then(response => {
          this.handleQuery()
        }).finally(() => {
          this.$modal.closeLoading()
        })
      }
    },
    //详情
    handleXq(row) {
      this.showDetail = true
      this.$emit('showDetail', this.showDetail)
      this.$refs.Xq.show(row)
    },
    closeXq() {
      this.showDetail = false
      this.$emit('showDetail', this.showDetail)
      this.handleQuery()
    },

    //获取列表
    getList() {

      this.loading = true
      list(this.queryParams).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    //查询
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    //重置
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },

  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.sj {}
</style>