<template>
  <div>
    <div>
      <!-- 入库记录列表 -->
      <div class="ffjl" v-show="!showDetail">
        <el-form :model="queryParams" ref="queryForm" class="search-area" :inline="true" label-width="88px">
          <el-row>
            <el-col :span="24">
              <!-- 名称 -->
              <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.gg') + '：'">
                <el-input v-model="queryParams.gg" clearable @change="handleQuery"
                  :placeholder="$t('form.placeholderInput')" />
              </el-form-item>
              <!-- 记录状态 -->
              <el-form-item :label="$t('page.business.resource.gsp.jlzt') + '：'">
                <el-select v-model="queryParams.jlzt" :placeholder="$t('form.placeholderSelect')" clearable
                  @change="handleQuery">
                  <el-option :label="$t('page.business.resource.resource.jlzt.dgd')" :value="5" />
                  <el-option :label="$t('page.business.resource.resource.jlzt.gd')" :value="7" />
                  <el-option :label="$t('page.business.resource.resource.jlzt.djd')" :value="9" />
                </el-select>
              </el-form-item>
              <!-- 借阅状态 -->
              <el-form-item :label="$t('page.business.resource.gsp.jyzt') + '：'">
                <el-select v-model="queryParams.jyzt" :placeholder="$t('form.placeholderSelect')" clearable
                  @change="handleQuery">
                  <el-option :label="$t('page.business.resource.resource.jyzt.wjy')" :value="1" />
                  <el-option :label="$t('page.business.resource.resource.jyzt.djy')" :value="3" />
                  <el-option :label="$t('page.business.resource.resource.jyzt.jyz')" :value="5" />
                </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-col>
          </el-row>
        </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.ph')" align="center" prop="ph"
            :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.gdsqr')" align="center" prop="gdsqrMc" width="150px"
            :show-overflow-tooltip="true" />

          <el-table-column :label="$t('page.business.resource.gsp.jlzt')" align="center" width="100px" >
            <template slot-scope="scope">
              <span v-if="scope.row.jlzt == 1">{{ $t('page.business.resource.resource.jlzt.wsd') }}</span>
              <span v-if="scope.row.jlzt == 3">{{ $t('page.business.resource.resource.jlzt.ysd') }}</span>
              <span v-if="scope.row.jlzt == 5">{{ $t('page.business.resource.resource.jlzt.dgd') }}</span>
              <span v-if="scope.row.jlzt == 7">{{ $t('page.business.resource.resource.jlzt.gd') }}</span>
              <span v-if="scope.row.jlzt == 9">{{ $t('page.business.resource.resource.jlzt.djd') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.resource.gsp.jyzt')" align="center" width="100px">
            <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.gsp.gdsqsj')" align="center" prop="gdsqsj" width="150px"
            :show-overflow-tooltip="true" />
          <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.jlzt == 5">
                <!-- 同意归档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.tygd', false, 'tygd')">{{
                    $t('page.business.resource.gsp.tygd') }}</el-button>
                <!-- 拒绝归档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.jjgd', false, 'jjgd', true, true)">{{
                    $t('page.business.resource.gsp.jjgd') }}</el-button>
              </template>
              <!-- 待解档 -->
              <template v-if="scope.row.zjzt == 9">
                <!-- 同意解档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.tyjd', false, 'tyjd')">{{
                    $t('page.business.resource.gsp.tyjd') }}</el-button>
                <!-- 拒绝解档 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.jjjd', false, 'jjjd', true, true)">{{
                    $t('page.business.resource.gsp.jjjd') }}</el-button>
              </template>
              <!-- 归档 && 待借阅 -->
              <template v-if="scope.row.zjzt == 7 && scope.row.jyzt == 3">
                <!-- 同意借阅 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.tyjy', true, 'tyjy')">{{
                    $t('page.business.resource.gsp.tyjy') }}</el-button>
                <!-- 拒绝借阅 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.jjjy', true, 'jjjy', true, true)">{{
                    $t('page.business.resource.gsp.jjjy') }}</el-button>
              </template>
              <!-- 归档 && 借阅中 -->
              <template v-if="scope.row.zjzt == 7 && scope.row.jyzt == 5">
                <!-- 确认归还 -->
                <el-button type="text"
                  @click="handleSign(scope.row, 'page.business.resource.gsp.qrgh', false, 'qrgh')">{{
                    $t('page.business.resource.gsp.qrgh') }}</el-button>
              </template>
              <!-- 详情 -->
              <el-button type="text" @click="handleXq(scope.row)">{{
                $t('page.business.resource.gsp.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 key="Xq" v-show="showDetail" 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/gsp/gspRkjlArchive"

import Xq from "@/views/business/resource/gsp/comps/rkjl/Xq";
import Sign from "@/views/business/comps/common/sign";
import { deepClone } from "@/utils/index";
export default {
  name: "FfjlList",
  components: { Xq, Sign },
  data() {
    return {
      daterangeCk: [],
      daterangeRk: [],
      loading: true,
      showDetail: false,
      single: true,
      multiple: true,
      total: 0,
      list: [],
      //勾选列表
      selectList: [],
      //查询条件
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mc: null,
        mdId: null,
        jlzt: null,
        jyzt: null,
        bh: null,
        startDateCk: null,
        endDateCk: null,
        startDateRk: null,
        endDateRk: null,
      },
      form: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleSign(row, qmyy, showDate, type, isReson, reasonRequired) {
      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()
        })
      }
    },
    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() {
      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">
.ffjl {
  background: #fff;
  padding: 10px 10px;
}
</style>