<!-- 试剂管理 -->
<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.ssbm') + '：'">
            <el-input v-model="queryParams.deptName" 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="1" :label="$t('page.business.resource.resource.zjzt.rk')" value="1" />
              <el-option key="3" :label="$t('page.business.resource.resource.zjzt.yff')" value="3" />
              <el-option key="5" :label="$t('page.business.resource.resource.zjzt.ysd')" value="5" />
              <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 :label="$t('page.business.resource.sj.sxrq') + '：'">
            <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="handleQuery" style="width: 250px;" />
          </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-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <!-- 更新试剂库 -->
            <el-button type="primary" v-hasPermi="['business:resource:sj:gxsjk']">{{
              $t('page.business.resource.sj.gxsjk') }}</el-button>
          </el-col>
          <el-col :span="1.5">
            <!-- 批量处置 -->
            <el-button type="primary" :disabled="multiple" @click="handlePlcz"
              v-hasPermi="['business:resource:sj:cz']">{{
                $t('page.business.resource.sj.plcz') }}</el-button>
          </el-col>
          <el-col :span="1.5">
            <!-- 批量锁定 -->
            <el-button type="primary" :disabled="multiple" @click="handlePlsd"
              v-hasPermi="['business:resource:sj:sd']">{{
                $t('page.business.resource.sj.plsd') }}</el-button>
          </el-col>
          <el-col :span="1.5">
            <!-- 批量归档 -->
            <el-button type="primary" :disabled="multiple" @click="handlePlgd"
              v-hasPermi="['business:resource:sj:gd']">{{
                $t('page.business.resource.sj.plgd') }}</el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" :selectable="checkSelectable" />
          <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.gg')" align="center" prop="gg" width="150px" />
          <el-table-column :label="$t('page.business.resource.sj.ly')" align="center" prop="ly" width="150px" />
          <el-table-column :label="$t('page.business.resource.sj.ssbm')" align="center" prop="deptName" width="150px" />
          <el-table-column :label="$t('page.business.resource.sj.sssy')" align="center" prop="studyName" width="150px" />
          <el-table-column :label="$t('page.business.resource.sj.ph')" align="center" prop="ph" width="150px" />
          <el-table-column :label="$t('page.business.resource.sj.yxzq')" align="center" prop="yxzq" width="150px" >
            <template slot-scope="scope">
              {{ scope.row.yxzq }}{{ scope.row.yxzqdw }}
            </template>
          </el-table-column>

          <el-table-column :label="$t('page.business.resource.mjy.sxrq')" align="center" prop="sxr" width="150px" />
          <el-table-column :label="$t('page.business.resource.mjy.cctj')" align="center" prop="cctj" width="130px" />
          <el-table-column :label="$t('page.business.resource.mjy.ccwz')" align="center" prop="ccwz" width="130px" />

          <el-table-column :label="$t('page.business.resource.mjy.zjzt')" align="center" width="150px" fixed="right">
            <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.mjy.jyzt')" align="center" width="150px" fixed="right">
            <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('form.operate')" fixed="right" align="center"
            class-name="small-padding fixed-width" width="250px">
            <template slot-scope="scope">
              <!-- 详情 -->
              <template
                v-if="scope.row.zjzt == 1 || scope.row.zjzt == 5 || (scope.row.zjzt == 9 && scope.row.jyzt == 5)">
                <el-button type="text" @click="handleXq(scope.row)" v-hasPermi="['business:resource:sj:xq']">{{
                  $t('page.business.resource.sj.detail') }}</el-button>
              </template>
              <!-- 处置 -->
              <template v-if="scope.row.zjzt == 1">
                <el-button type="text" @click="handleCz(scope.row)" v-hasPermi="['business:resource:sj:cz']">{{
                  $t('page.business.resource.sj.cz') }}</el-button>
              </template>
              <template v-if="scope.row.zjzt == 1">
                <!-- 编辑 -->
                <el-button type="text" @click="handleBj(scope.row)" v-hasPermi="['business:resource:sj:bj']">{{
                  $t('form.edit') }}</el-button>
                <!-- 修改库存 -->
                <el-button type="text" @click="handleXgkc(scope.row)" v-hasPermi="['business:resource:sj:xgkc']">{{
                  $t('page.business.resource.sj.xgkc') }}</el-button>
                <!-- 锁定 -->
                <el-button type="text" @click="handleSd(scope.row)" v-hasPermi="['business:resource:sj:sd']">{{
                  $t('page.business.resource.sj.lock') }}</el-button>
              </template>
              <template v-if="scope.row.zjzt == 5">
                <!-- 解锁 -->
                <el-button type="text" @click="handleJs(scope.row)" v-hasPermi="['business:resource:sj:js']">{{
                  $t('page.business.resource.sj.unlock') }}</el-button>
                <!-- 归档 -->
                <el-button type="text" @click="handleGd(scope.row)" v-hasPermi="['business:resource:sj:gd']">{{
                  $t('page.business.resource.sj.guidang') }}</el-button>
              </template>
              <template v-if="scope.row.zjzt == 9 && scope.row.jyzt == 1">
                <!-- 解档 -->
                <el-button type="text" @click="handleJd(scope.row)" v-hasPermi="['business:resource:sj:jd']">{{
                  $t('page.business.resource.sj.jiedang') }}</el-button>
                <!-- 借阅 -->
                <el-button type="text" @click="handleJy(scope.row)" v-hasPermi="['business:resource:sj:jy']">{{
                  $t('page.business.resource.sj.jieyue') }}</el-button>
              </template>

            </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" />
      <!-- 锁定 -->
      <Sd ref="Sd" @callback="handleQuery" />
      <!-- 解锁 -->
      <Js ref="Js" @callback="handleQuery" />
      <!-- 归档 -->
      <Gd ref="Gd" @callback="handleQuery" />
      <!-- 解档 -->
      <Jd ref="Jd" @callback="handleQuery" />
      <!-- 编辑 -->
      <Bj ref="Bj" @callback="handleQuery" />
      <!-- 修改库存 -->
      <Xgkc ref="Xgkc" @callback="handleQuery" />
      <!-- 借阅 -->
      <Jy ref="Jy" @callback="handleQuery" />
      <!-- 处置 -->
      <Cz ref="Cz" @callback="handleQuery" />
      <!-- 批量处置 -->
      <CzBatch ref="CzBatch" />
    </div>
  </div>
</template>

<script>
import { sj_list } from "@/api/business/sj/sj"
import Sd from "./comps/Sd";
import Js from "./comps/Js";
import Gd from "./comps/Gd";
import Jd from "./comps/Jd";
import Xq from "./comps/Xq";
import Bj from "./comps/Bj";
import Xgkc from "./comps/Xgkc";
import Jy from "./comps/Jy";
import Cz from "./comps/Cz";
import CzBatch from "./comps/CzBatch";

export default {
  name: "Sj",
  components: { Sd, Js, Gd, Xq, Jd, Bj, Xgkc, Jy, Cz, CzBatch },
  data() {
    return {
      showDetail: false,
      daterange: [],
      loading: true,
      single: true,
      multiple: true,
      total: 0,
      list: [],
      //勾选列表
      selectList: [],
      //查询条件
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mc: null,
        jyzt: null,
        zjzt: null,
        bh: null,
        startDate: null,
        endDate: null,
      },
    }
  },
  created() {
    this.handleQuery()
  },
  methods: {
    //处置
    handleCz(row) {
      this.$refs.Cz.show(row)
    },
    //批量处置
    handlePlcz() {
      this.$refs.CzBatch.showBatch(this.selectList)
    },
    //编辑
    handleBj(row) {
      this.$refs.Bj.show(row)
    },
    //修改库存
    handleXgkc(row) {
      this.$refs.Xgkc.show(row)
    },
    //借阅
    handleJy(row) {
      this.$refs.Jy.show(row)
    },
    //归还
    handleGh(row) {
      this.$refs.Gh.show(row)
    },
    //关闭详情
    cancelXq() {
      this.showDetail = false
    },
    //是否可勾选
    checkSelectable(row) {
      return true;
    },
    //详情
    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()
    },
    //批量解锁
    handlePljs() {
      this.$refs.Js.showBatch(this.selectList)
    },
    //解锁
    handleJs(row) {
      this.$refs.Js.show(row)
    },
    //批量归档
    handlePlgd() {
      this.$refs.Gd.showBatch(this.selectList)
    },
    //归档
    handleGd(row) {
      this.$refs.Gd.show(row)
    },
    //解档
    handleJd(row) {
      this.$refs.Jd.show(row)
    },
    //批量锁定
    handlePlsd() {
      this.$refs.Sd.showBatch(this.selectList)
    },
    //锁定
    handleSd(row) {
      this.$refs.Sd.show(row)
    },
    //获取列表
    getList() {
      if (this.daterange != null && this.daterange.length > 0) {
        this.queryParams.startDate = this.daterange[0]
        this.queryParams.endDate = moment().add(this.daterange[1], 'days').format('YYYY-MM-DD');
      } else {
        this.queryParams.startDate = ''
        this.queryParams.endDate = ''
      }
      this.loading = true
      sj_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()
    },
    //勾选回调
    handleSelectionChange(selection) {
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.selectList = selection
    }
  }
}
</script>

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