<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="发票号码" prop="发票号码">
        <el-input
          v-model="queryParams.发票号码"
          placeholder="请输入发票号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票时间" prop="开票时间">
        <el-input
          v-model="queryParams.开票时间"
          placeholder="请输入开票时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票抬头" prop="发票抬头">
        <el-input
          v-model="queryParams.发票抬头"
          placeholder="请输入发票抬头"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票税号" prop="发票税号">
        <el-input
          v-model="queryParams.发票税号"
          placeholder="请输入发票税号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @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"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table :height="720" v-loading="loading" :data="发票管理List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="选择对账单" align="center" prop="选择对账单" />
      <el-table-column label="发票金额含税" align="center" prop="发票金额含税" />
      <el-table-column label="待开票金额含税元" align="center" prop="待开票金额含税元" />
      <el-table-column label="累计开票金额含税" align="center" prop="累计开票金额含税" />
      <el-table-column label="发票类型" align="center" prop="发票类型" />
      <el-table-column label="发票号码" align="center" prop="发票号码" />
      <el-table-column label="开票时间" align="center" prop="开票时间" />
      <el-table-column label="发票抬头" align="center" prop="发票抬头" />
      <el-table-column label="发票税号" align="center" prop="发票税号" />
      <el-table-column label="税种" align="center" prop="税种" />
      <el-table-column label="经办人" align="center" prop="经办人" />
      <el-table-column label="归属部门" align="center" prop="归属部门" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:发票管理:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:发票管理: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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="选择对账单" prop="选择对账单">
          <el-input v-model="form.选择对账单" placeholder="请输入选择对账单" />
        </el-form-item>
        <el-form-item label="发票金额含税" prop="发票金额含税">
          <el-input v-model="form.发票金额含税" placeholder="请输入发票金额含税" />
        </el-form-item>
        <el-form-item label="待开票金额含税元" prop="待开票金额含税元">
          <el-input v-model="form.待开票金额含税元" placeholder="请输入待开票金额含税元" />
        </el-form-item>
        <el-form-item label="累计开票金额含税" prop="累计开票金额含税">
          <el-input v-model="form.累计开票金额含税" placeholder="请输入累计开票金额含税" />
        </el-form-item>
        <el-form-item label="发票类型" prop="发票类型">
          <el-input v-model="form.发票类型" placeholder="请输入发票类型" />
        </el-form-item>
        <el-form-item label="发票号码" prop="发票号码">
          <el-input v-model="form.发票号码" placeholder="请输入发票号码" />
        </el-form-item>
        <el-form-item label="开票时间" prop="开票时间">
          <el-input v-model="form.开票时间" placeholder="请输入开票时间" />
        </el-form-item>
        <el-form-item label="发票抬头" prop="发票抬头">
          <el-input v-model="form.发票抬头" placeholder="请输入发票抬头" />
        </el-form-item>
        <el-form-item label="发票税号" prop="发票税号">
          <el-input v-model="form.发票税号" placeholder="请输入发票税号" />
        </el-form-item>
        <el-form-item label="税种" prop="税种">
          <el-input v-model="form.税种" placeholder="请输入税种" />
        </el-form-item>
        <el-form-item label="经办人" prop="经办人">
          <el-input v-model="form.经办人" placeholder="请输入经办人" />
        </el-form-item>
        <el-form-item label="归属部门" prop="归属部门">
          <el-input v-model="form.归属部门" placeholder="请输入归属部门" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { list发票管理, get发票管理, del发票管理, add发票管理, update发票管理 } from "@/api/system/发票管理";

export default {
  name: "发票管理",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      发票管理List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        选择对账单: null,
        发票金额含税: null,
        待开票金额含税元: null,
        累计开票金额含税: null,
        发票类型: null,
        发票号码: null,
        开票时间: null,
        发票抬头: null,
        发票税号: null,
        税种: null,
        经办人: null,
        归属部门: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      list发票管理(this.queryParams).then(response => {
        this.发票管理List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        选择对账单: null,
        发票金额含税: null,
        待开票金额含税元: null,
        累计开票金额含税: null,
        发票类型: null,
        发票号码: null,
        开票时间: null,
        发票抬头: null,
        发票税号: null,
        税种: null,
        经办人: null,
        归属部门: null
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.选择对账单)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const 选择对账单 = row.选择对账单 || this.ids
      get发票管理(选择对账单).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.选择对账单 != null) {
            update发票管理(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            add发票管理(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const 选择对账单s = row.选择对账单 || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + 选择对账单s + '"的数据项？').then(function() {
        return del发票管理(选择对账单s);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/发票管理/export', {
        ...this.queryParams
      }, `发票管理_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
