<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税标识" prop="signboard">
        <el-select v-model="queryParams.signboard" placeholder="请选择单价含税不含税标识" clearable size="small">
          <el-option
            v-for="dict in dict.type.signboard"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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"
          v-hasPermi="['platform:exportmanage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['platform:exportmanage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['platform:exportmanage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['platform:exportmanage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="exportmanageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键ID" align="center" prop="id" />-->
      <el-table-column label="企业名称" align="center" prop="companyName" />
      <el-table-column label="单据编号" align="center" prop="receiptNumber" />
      <el-table-column label="客户名称/编码" align="center" prop="customerName" />
      <el-table-column label="客户税号" align="center" prop="customerTaxNumber" />
      <el-table-column label="客户地址" align="center" prop="customerAddress" />
      <el-table-column label="客户电话" align="center" prop="customerPhone" />
      <el-table-column label="开户银行" align="center" prop="bankName" />
      <el-table-column label="银行账号" align="center" prop="bankNumber" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="商品名称/编码" align="center" prop="productName" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="单价" align="center" prop="price" />
      <el-table-column label="数量" align="center" prop="num" />
      <el-table-column label="金额" align="center" prop="taxamt" />
      <el-table-column label="税率" align="center" prop="taxrate" />
      <el-table-column label="税额" align="center" prop="tax" />
      <el-table-column label="折扣" align="center" prop="discount" />
      <el-table-column label="扣除额" align="center" prop="deduction" />
      <el-table-column label="含税标识" align="center" prop="signboard">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.signboard" :value="scope.row.signboard"/>
        </template>
      </el-table-column>
      <el-table-column label="零税率标识" align="center" prop="zeroTaxRate" />
      <el-table-column label="编码简称" align="center" prop="encodingName" />
      <el-table-column label="编码版本号" align="center" prop="encodingVersion" />
      <el-table-column label="优惠政策类型" align="center" prop="discountsType" />
      <el-table-column label="税收分类编码" align="center" prop="taxClassificationCode" />
      <el-table-column label="是否享受优惠政策" align="center" prop="isornotDiscounts" />
      <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="['platform:exportmanage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['platform:exportmanage: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="80px">
<!--        <el-form-item label="企业名称" prop="companyName">-->
<!--          <el-input v-model="form.companyName" placeholder="请输入企业名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="单据编号" prop="receiptNumber">
          <el-input v-model="form.receiptNumber" placeholder="请输入单据编号" />
        </el-form-item>
        <el-form-item label="客户名称/编码" prop="customerName">
          <el-input v-model="form.customerName" placeholder="请输入客户名称/编码" />
        </el-form-item>
        <el-form-item label="客户税号" prop="customerTaxNumber">
          <el-input v-model="form.customerTaxNumber" placeholder="请输入客户税号" />
        </el-form-item>
        <el-form-item label="客户地址" prop="customerAddress">
          <el-input v-model="form.customerAddress" placeholder="请输入客户地址" />
        </el-form-item>
        <el-form-item label="客户电话" prop="customerPhone">
          <el-input v-model="form.customerPhone" placeholder="请输入客户电话" />
        </el-form-item>
        <el-form-item label="开户银行" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户银行" />
        </el-form-item>
        <el-form-item label="银行账号" prop="bankNumber">
          <el-input v-model="form.bankNumber" placeholder="请输入银行账号" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="商品名称/编码" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入商品名称/编码" />
        </el-form-item>
        <el-form-item label="规格型号" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="数量" prop="num">
          <el-input v-model="form.num" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="金额" prop="taxamt">
          <el-input v-model="form.taxamt" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="税率" prop="taxrate">
          <el-input v-model="form.taxrate" placeholder="请输入税率" />
        </el-form-item>
        <el-form-item label="税额" prop="tax">
          <el-input v-model="form.tax" placeholder="请输入税额" />
        </el-form-item>
        <el-form-item label="折扣" prop="discount">
          <el-input v-model="form.discount" placeholder="请输入折扣" />
        </el-form-item>
        <el-form-item label="扣除额" prop="deduction">
          <el-input v-model="form.deduction" placeholder="请输入扣除额" />
        </el-form-item>
        <el-form-item label="含税标识" prop="signboard">
          <el-select v-model="form.signboard" placeholder="请选择单价含税不含税标识">
            <el-option
              v-for="dict in dict.type.signboard"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="零税率标识" prop="zeroTaxRate">
          <el-input v-model="form.zeroTaxRate" placeholder="请输入零税率标识" />
        </el-form-item>
        <el-form-item label="编码简称" prop="encodingName">
          <el-input v-model="form.encodingName" placeholder="请输入编码简称" />
        </el-form-item>
        <el-form-item label="编码版本号" prop="encodingVersion">
          <el-input v-model="form.encodingVersion" placeholder="请输入编码版本号" />
        </el-form-item>
        <el-form-item label="优惠政策类型" prop="discountsType">
          <el-input v-model="form.discountsType" placeholder="请输入优惠政策类型" />
        </el-form-item>
        <el-form-item label="税收分类编码" prop="taxClassificationCode">
          <el-input v-model="form.taxClassificationCode" placeholder="请输入税收分类编码" />
        </el-form-item>
        <el-form-item label="是否享受优惠政策" prop="isornotDiscounts">
          <el-input v-model="form.isornotDiscounts" 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 { listExportmanage, getExportmanage, delExportmanage, addExportmanage, updateExportmanage } from "@/api/platform/exportmanage";

export default {
  name: "Exportmanage",
  dicts: ['signboard'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 导入设置表格数据
      exportmanageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        signboard: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        companyName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        receiptNumber: [
          { required: true, message: "单据编号不能为空", trigger: "blur" }
        ],
        customerName: [
          { required: true, message: "客户名称/编码不能为空", trigger: "blur" }
        ],
        productName: [
          { required: true, message: "商品名称/编码不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "单价不能为空", trigger: "blur" }
        ],
        num: [
          { required: true, message: "数量不能为空", trigger: "blur" }
        ],
        taxamt: [
          { required: true, message: "金额不能为空", trigger: "blur" }
        ],
        taxrate: [
          { required: true, message: "税率不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询导入设置列表 */
    getList() {
      this.loading = true;
      listExportmanage(this.queryParams).then(response => {
        this.exportmanageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyName: null,
        receiptNumber: null,
        customerName: null,
        customerTaxNumber: null,
        customerAddress: null,
        customerPhone: null,
        bankName: null,
        bankNumber: null,
        phone: null,
        email: null,
        remark: null,
        productName: null,
        specification: null,
        unit: null,
        price: null,
        num: null,
        taxamt: null,
        taxrate: null,
        tax: null,
        discount: null,
        deduction: null,
        signboard: null,
        zeroTaxRate: null,
        encodingName: null,
        encodingVersion: null,
        discountsType: null,
        taxClassificationCode: null,
        isornotDiscounts: null,
        source: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: 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 = "添加导入设置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExportmanage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改导入设置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateExportmanage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExportmanage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除导入设置编号为"' + ids + '"的数据项？').then(function() {
        return delExportmanage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('platform/exportmanage/export', {
        ...this.queryParams
      }, `exportmanage_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
