<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="auto"
    >
      <!-- <el-form-item label="打印id" prop="printId">
        <el-input
          v-model="queryParams.printId"
          placeholder="请输入打印id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="打印文件名称" prop="printName">
        <el-input
          v-model="queryParams.printName"
          placeholder="请输入打印文件名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="打印份数" prop="printNumber">
        <el-input
          v-model="queryParams.printNumber"
          placeholder="请输入打印份数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否需要归还(0否1是)" prop="isReturn">
        <el-input
          v-model="queryParams.isReturn"
          placeholder="请输入是否需要归还(0否1是)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件打印人" prop="printfileName">
        <el-input
          v-model="queryParams.printfileName"
          placeholder="请输入文件打印人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打印时间" prop="printTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.printTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择打印时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item label="归还状态" prop="statusG">
        <el-select v-model="queryParams.statusG" clearable placeholder="请选择归还状态">
          <el-option
            v-for="dict in statusGlist"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="归还份数" prop="returnNumber">
        <el-input
          v-model="queryParams.returnNumber"
          placeholder="请输入归还份数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!-- <el-form-item label="原文件路径" prop="primaryPath">
        <el-input
          v-model="queryParams.primaryPath"
          placeholder="请输入原文件路径"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现文件路径" prop="presentPath">
        <el-input
          v-model="queryParams.presentPath"
          placeholder="请输入现文件路径"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="btn" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="btr" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['PrintsLog:printlog:add']"
          >新增</el-button
        >
      </el-col>-->
      <el-col :span="1.5">
        <el-button type="primary" @click="handleUpdate" style="width:76px;height:36px;">归还</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['PrintsLog:printlog:remove']"
        >删除</el-button>
      </el-col>-->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['PrintsLog:printlog:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :header-cell-style="{ background: '#003C69', color: 'white' }"
      :data="printlogList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" />
      <!-- <el-table-column label="现文件路径" align="center" prop="id" />
      <el-table-column label="打印id" align="center" prop="printId" />-->
      <el-table-column label="打印文件名称" align="center" prop="printName" />
      <el-table-column label="打印份数" align="center" prop="printNumber" />
      <!-- <el-table-column
        label="是否需要归还(0否1是)"
        align="center"
        prop="isReturn"
      />-->
      <!-- <el-table-column label="是否需要归还" align="center" prop="isReturn">
        <template slot-scope="scope">
          <div v-if="scope.row.isReturn == 0">无需归还</div>
          <div v-if="scope.row.isReturn == 1">归还</div>
        </template>
      </el-table-column>-->
      <!-- <el-table-column label="归还状态" align="center" prop="statusG" /> -->
      <el-table-column label="文件打印人" align="center" prop="printfileName" />
      <el-table-column label="打印时间" align="center" prop="printTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.printTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="归还状态" align="center" prop="statusG">
        <template slot-scope="scope">
          <!-- <dict-tag :options="dict.type.sys_statusG" :value="scope.row.statusG" /> -->
          <div
            style="color:#E6A23C;"
            v-if="scope.row.statusG=='0'"
          >未归还</div>
          <div
            style="color:#57b764;"
            v-if="scope.row.statusG=='1'"
          >已归还</div>
        </template>
      </el-table-column>
      <el-table-column label="归还份数" align="center" prop="returnNumber">
        <template slot-scope="scope">
          <span>{{ scope.row.returnNumber?scope.row.returnNumber:0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="归还时间" align="center" prop="returnTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.returnTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="打印编码信息" align="center" prop="printCode" />
      <el-table-column label="原文件路径" align="center" prop="primaryPath" />
      <el-table-column label="现文件路径" align="center" prop="presentPath" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="btk" type="text" @click="handlesee(scope.row)">查看</el-button>
          <!-- <el-button size="mini" type="text" v-if="scope.row.statusG==1||scope.row.statusG==2">已归还</el-button> -->
          <!-- <el-button
            size="btd"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['PrintsLog:printlog:remove']"
          >删除</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"
    />

    <!-- 添加或修改集中文印记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1030px" append-to-body>
      <el-form ref="form" :model="form" :inline="true" :rules="rules" label-width="120px">
        <!-- <el-form-item label="打印id" prop="printId">
          <el-input v-model="form.printId" placeholder="请输入打印id" />
        </el-form-item>-->
        <div class="jiben">打印编码</div>
        <el-form-item label="打印编码" prop="printCode">
          <el-input v-model="form.printCode" @blur="printCodeblur" placeholder="请输入打印编码" />
          <!-- <el-select v-model="form.printCode" filterable @change="printCodechange" clearable placeholder="请选择打印编码">
          <el-option
            v-for="dict in printlogList"
            :key="dict.printId"
            :label="dict.printCode"
            :value="dict"
          ></el-option>
          </el-select>-->
          <!-- <el-input v-model="form.printCode" placeholder="请输入打印编码" /> -->
        </el-form-item>
        <div class="jiben">基本信息</div>
        <!-- <el-form-item label="单位名称" prop="unitName">
          <el-input v-model="form.unitName" placeholder="请输入单位名称" />
        </el-form-item>-->
        <el-form-item label="打印文件名称" prop="printName">
          <el-input v-model="form.printName" placeholder="请输入打印文件名称" />
        </el-form-item>
        <!-- <el-form-item label="打印份数" prop="printNumber">
          <el-input v-model="form.printNumber" type="Number" placeholder="请输入打印份数" />
        </el-form-item>
        <el-form-item label="是否需要归还" prop="isReturn">
          <el-radio-group v-model="form.isReturn" size="mini" style="width:200px;">
            <el-radio label="1">归还</el-radio>
            <el-radio label="0">无需归还</el-radio>
          </el-radio-group>
        </el-form-item>-->
        <!-- <el-form-item label="归还状态" prop="statusG">
          <el-select v-model="form.statusG" clearable placeholder="请选择归还状态">
            <el-option
              v-for="dict in statusGlist"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <!-- <el-form-item label="归还状态(1 已归还  0未归还)" prop="statusG">
          <el-input v-model="form.statusG" placeholder="请输入归还状态(1 已归还  0未归还)" />
        </el-form-item>-->
        <!-- <el-form-item label="是否需要归还(0否1是)" prop="isReturn">
          <el-input v-model="form.isReturn" placeholder="请输入是否需要归还(0否1是)" />
        </el-form-item>-->
        <el-form-item label="归还份数" prop="returnNumber">
          <el-input v-model="form.returnNumber" @blur="returnNumberblur" placeholder="请输入打印份数" />
        </el-form-item>
        <el-form-item label="文件打印人" prop="printfileName">
          <el-input v-model="form.printfileName" placeholder="请输入文件打印人" />
          <!-- <el-select v-model="form.printfileName" filterable clearable placeholder="请选择文件打印人">
            <el-option v-for="item in rylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>-->
        </el-form-item>
        <!-- <el-form-item label="备注说明" prop="prize">
          <el-input v-model="form.prize" type="textarea" placeholder />
        </el-form-item>-->
        <!-- <el-form-item label="文件打印人" prop="printfileName">
          <el-input v-model="form.printfileName" placeholder="请输入文件打印人" />
        </el-form-item>-->
        <!-- <el-form-item label="打印时间" prop="printTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.printTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择打印时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="归还份数" prop="returnNumber">
          <el-input v-model="form.returnNumber" placeholder="请输入归还份数" />
        </el-form-item>
        <el-form-item label="原文件路径" prop="primaryPath">
          <el-input v-model="form.primaryPath" placeholder="请输入原文件路径" />
        </el-form-item>
        <el-form-item label="现文件路径" prop="presentPath">
          <el-input v-model="form.presentPath" placeholder="请输入现文件路径" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="flg!=1">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPrintlog,
  getPrintlog,
  delPrintlog,
  addPrintlog,
  updatePrintlog,
  exportPrintlog,
  listPeople
} from "@/api/PrintsLog/printlog";

export default {
  name: "Printlog",
  dicts: ["sys_statusG"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 集中文印记录表格数据
      printlogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        printId: null,
        printName: null,
        printNumber: null,
        isReturn: null,
        printfileName: null,
        printTime: null,
        statusG: null,
        returnNumber: null,
        printCode: null,
        primaryPath: null,
        presentPath: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        returnNumber: [
          { required: true, message: "归还份数不能为空", trigger: "blur" }
        ]
      },
      statusGlist: [],
      rylist: [],
      returnNumber: null,
      flg: null
    };
  },
  created() {
    this.getList();
    //检查类型
    this.getDicts("sys_statusG").then(response => {
      this.statusGlist = response.data;
    });
  },
  methods: {
    //获取人员
    getrylist() {
      listPeople().then(res => {
        if (res.code == 200) {
          this.rylist = res.rows;
        }
      });
    },
    /** 查询集中文印记录列表 */
    getList() {
      this.loading = true;
      listPrintlog(this.queryParams).then(response => {
        this.printlogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.flg = null;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        printId: null,
        printName: null,
        printNumber: null,
        isReturn: null,
        printfileName: null,
        printTime: null,
        statusG: null,
        returnNumber: null,
        printCode: null,
        primaryPath: null,
        presentPath: null,
        unitName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加集中文印记录";
      this.getrylist();
    },
    /** 查看按钮操作 */
    handlesee(row) {
      getPrintlog(row.id).then(res => {
        if (res.code == 200) {
          this.form = res.data;
          if (res.data.returnNumber) {
            this.form.returnNumber = res.data.returnNumber;
          } else {
            this.form.returnNumber = 0;
          }
          this.title = "归还记录";
          this.open = true;
          this.flg = 1;
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdate() {
      this.reset();
      this.title = "归还记录";
      this.open = true;
      // const id = row.id || this.ids;
      // getPrintlog(id).then(response => {
      //   if (!response.data.returnNumber) {
      //     this.returnNumber = 0;
      //   } else {
      //     this.returnNumber = response.data.returnNumber;
      //   }

      //   this.form = response.data;
      //   this.form.isReturn = this.form.isReturn + "";
      //   this.open = true;
      //   // if(this.form.returnNumber==this.form.printNumber){
      //   //      this.form.statusG = 1;
      //   // }else{
      //   //   this.form.statusG=this.form.statusG;
      //   // }

      //   this.form.returnNumber = response.data.printNumber;
      //   this.title = "修改集中文印记录";
      // });
    },
    returnNumberblur() {
      if (
        Number(this.form.returnNumber) + Number(this.returnNumber) >
        Number(this.form.printNumber)
      ) {
        this.$modal.msgSuccess(
          `应归还${Number(this.form.printNumber) - Number(this.returnNumber)}份`
        );
        this.form.returnNumber = null;
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.returnNumber =
            Number(this.form.returnNumber) + Number(this.returnNumber);
          if (this.form.returnNumber == this.form.printNumber) {
            this.form.statusG = 1;
          }
          if (this.form.id != null) {
            updatePrintlog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPrintlog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否删除该记录？")
        .then(function() {
          return delPrintlog(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有集中文印记录数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportPrintlog(queryParams);
        })
        .then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    //打印编号
    printCodeblur() {
      if (this.form.printCode) {
        listPrintlog({ printCode: this.form.printCode }).then(response => {
          this.form = response.rows[0];
          if (this.form.returnNumber) {
            this.form.returnNumber = this.form.returnNumber;
          } else {
            this.form.returnNumber = 0;
          }
        });
      }
    }
  }
};
</script>
<style scoped>
::v-deep .el-dialog {
  background-color: #004d86;
}

::v-deep .el-dialog__header {
  border-bottom: 1px solid #718a9d;
}
::v-deep .el-dialog__title {
  color: #fff;
  font: 18px;
}
::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
.el-form-item ::v-deep .el-input__inner {
  width: 200px;
  height: 36px;
  background: #004d86;
  color: #fff;
  border: 1px solid #fff !important;
}
::v-deep .el-date-editor.el-input {
  width: 200px;
  height: 36px;
}

.pictureUploading-img img {
  width: 60px;
  height: 210px;
  margin-right: 10px;
}

::v-deep .el-upload--picture-card {
  height: 210px;
  width: 170px;
  line-height: 210px;
  background-image: url("../../../assets/images/头像.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
::v-deep .el-upload--picture-card .el-icon-plus {
  display: none;
}
.el-upload--picture-card /deep/ .el-upload--picture-card i {
  font-size: 48px;
}
::v-deep .el-upload__tip {
  display: none;
}
::v-deep .el-textarea__inner {
  width: 200px;
  height: 64px;
}
.jiben span {
  width: 25px;
  height: 25px;
  display: inline-block;
  background-color: #1c86e1;
  line-height: 25px;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
  /* margin-left: 851px; */
  position: absolute;
  right: 20px;
}
.el-select-dropdown__item:hover {
  color: #1c86e1;
}
.el-select-dropdown__item {
  color: #fff;
}
.el-tree {
  background-color: #00365f;
  color: #fff;
}
::v-deep .el-tree-node__content:hover {
  color: #1c86e1;
}
::v-deep .el-upload-list--picture-card .el-upload-list__item {
  height: 210px;
  width: 170px;
}
.dadui {
  height: 40px;
  background: #003156;
  /* border-bottom: 1px solid #718A9D ; */
  background-image: url(../../../images/矩形底部边框.png);
  background-repeat: no-repeat;
  background-position: 0px 39px;
  font-size: 16px;
  color: #1d96ff;
}
.dadui img {
  margin: 10px 10px 0px 10px;
}

.data {
  height: 40px;
  background: #003156;
  margin-bottom: 12px;
  color: #fff;
  display: flex;
  font-size: 13px;
  line-height: 25px;
  position: relative;
}
.el-tree {
  padding: 10px;
  background: #003156;
  color: #fff;
}

.data p {
  position: absolute;
  top: -5px;
  left: 15px;
}
.data .a1 {
  width: 128px;
  height: 26px;
  background: rgba(23, 74, 112, 0.4);
  border-radius: 13px;
  position: absolute;
  top: 7px;
  left: 60px;
}
::v-deep .data .el-date-editor.el-input {
  width: 100%;
  border: none;
}
::v-deep .data .el-input__inner {
  width: 100% !important;
  border: none;
}
::v-deep .data .el-input--medium .el-input__icon {
  line-height: 36px;
  position: absolute;
  right: -223px;
  top: 2px;
}
::v-deep .data .el-input__inner {
  background-color: transparent;
  color: #fff;
  text-align: center;
  margin-top: 2px;
}
::v-deep .data .el-input__suffix {
  position: absolute;
  right: 281px;
}
::v-deep
  .el-tree--highlight-current
  .el-tree-node.is-current
  > .el-tree-node__content {
  color: #00365f !important;
  /* background-color: #003156 !important; */
}
</style>
