<template>
  <div>
    <!-- 列表 -->
    <div>
      <div class="mjy" v-show="!showDetail">
        <el-form :model="queryParams" ref="queryForm" class="search-area" :inline="true" label-width="88px">
          <!-- 名称 -->
          <el-form-item :label="$t('page.business.resource.gsp.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.gsp.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.gsp.zjzt') + '：'">
            <el-select v-model="queryParams.zjzt" :placeholder="$t('form.placeholderSelect')" clearable
              @change="handleQuery">
              <el-option :label="$t('page.business.resource.resource.zjzt.rk')" :value="1" />
              <el-option :label="$t('page.business.resource.resource.zjzt.yff')" :value="3" />
              <el-option :label="$t('page.business.resource.resource.zjzt.ysd')" :value="5" />
              <el-option :label="$t('page.business.resource.resource.zjzt.dgd')" :value="7" />
              <el-option :label="$t('page.business.resource.resource.zjzt.gd')" :value="9" />
              <el-option :label="$t('page.business.resource.resource.zjzt.djd')" :value="11" />
            </el-select>
          </el-form-item>
          <!-- 有效日期 -->
          <el-form-item :label="$t('page.business.resource.gsp.yxq') + '：'">
            <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-table v-loading="loading" :data="list">
          <el-table-column :label="$t('page.business.resource.gsp.mc')" align="left" prop="mc"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.resource.gsp.bh')" align="center" prop="bh"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.resource.gsp.gg')" align="center">
            <template slot-scope="scope">
              {{ scope.row.gg }}{{ scope.row.ggdw }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.resource.gsp.yxq')" align="center" prop="yxq"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.resource.gsp.ph')" align="center" prop="ph"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.resource.gsp.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.gsp.sxrq')" align="center" prop="sxr" width="150px" />
          <el-table-column :label="$t('page.business.resource.gsp.zjzt')" align="center" width="100px" 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('form.operate')" fixed="right" align="center"
            class-name="small-padding fixed-width" width="250px">
            <template slot-scope="scope">
              <!-- 详情 -->
              <el-button type="text" @click="handleXq(scope.row)"
                v-hasPermi="['business:studyMjy:xq', 'business:nonTrialMjy:xq', 'business:drugMjy:xq']">{{
                  $t('page.business.resource.gsp.detail') }}</el-button>
              <template v-if="scope.row.syghzt == 1">
                <!-- 处置 -->
                <el-button type="text" @click="handleCz(scope.row)"
                  v-hasPermi="['business:studyMjy:czyj', 'business:nonTrialMjy:czyj', 'business:drugMjy:czyj']">{{
                    $t('page.business.resource.gsp.cz') }}</el-button>
                <!-- 编辑 -->
                <el-button type="text" @click="handleBj(scope.row)"
                  v-hasPermi="['business:studyMjy:bj', 'business:nonTrialMjy:bj', 'business:drugMjy:bj']">{{
                    $t('form.edit') }}</el-button>
                <!-- 修改库存 -->
                <el-button type="text" @click="handleXgkc(scope.row)"
                  v-hasPermi="['business:studyMjy:xgkc', 'business:nonTrialMjy:xgkc', 'business:drugMjy:xgkc']">{{
                    $t('page.business.resource.gsp.xgkc') }}</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>
      <!-- 编辑 -->
      <Bj key="Bj" ref="Bj" @callback="handleQuery" />
      <!-- 修改库存 -->
      <Xgkc key="Xgkc" ref="Xgkc" @callback="handleQuery" />
      <!-- 处置 -->
      <Cz key="Cz" ref="Cz" @callback="handleQuery" />
      <!-- 详情 -->
      <Xq v-show="showDetail" key="Xq" ref="Xq" @callback="closeXq" />
    </div>
  </div>
</template>

<script>
import { studyList } from "@/api/business/gsp/gsp"
import Xq from "@/views/business/resource/gsp/comps/gsp/Xq";
import Bj from "@/views/business/resource/gsp/comps/gsp/Bj";
import Xgkc from "@/views/business/resource/gsp/comps/gsp/Xgkc";
import Cz from "@/views/business/resource/gsp/comps/gsp/Cz";
import moment from "moment";

export default {
  name: "GspList",
  components: { Xq, Bj, Xgkc, Cz },
  data() {
    return {
      daterange: [],
      loading: true,
      single: true,
      multiple: true,
      showDetail: false,
      total: 0,
      list: [],
      //勾选列表
      selectList: [],
      //查询条件
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mc: null,
        jyzt: null,
        studyId: null,
        zjzt: null,
        bh: null,
        startDate: null,
        endDate: null,
      },
    }
  },
  created() {
  },
  props: {
    study: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
    study: {
      handler(newVal) {
        this.queryParams.studyId = newVal.id
        this.handleQuery()
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    //处置
    handleCzyj(row) {
      this.$refs.Cz.show(row)
    },
    //编辑
    handleBj(row) {
      this.$refs.Bj.show(row)
    },
    //修改库存
    handleXgkc(row) {
      this.$refs.Xgkc.show(row)
    },
    //归还
    handleGh(row) {
      this.$refs.Gh.show(row)
    },
    closeXq() {
      this.showDetail = false
      this.$emit('showDetail', this.showDetail)
      this.handleQuery()
    },
    //详情
    handleXq(row) {
      this.showDetail = true
      this.$emit('showDetail', this.showDetail)
      this.$refs.Xq.show(row)
    },
    //获取列表
    getList() {
      if (this.daterange != null && this.daterange.length > 0) {
        this.queryParams.startDate = this.daterange[0] + ' 00:00:00'
        this.queryParams.endDate = this.daterange[1] + ' 23:59:59'
      } else {
        this.queryParams.startDate = ''
        this.queryParams.endDate = ''
      }
      this.loading = true
      studyList(this.queryParams).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    //查询
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    //重置
    resetQuery() {
      this.daterange = []
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.mjy {
  background: #fff;
  padding: 10px 10px;
}
</style>