<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="核心企业授信额度ID(zc_finance_pro_com_rel.zfpcr_id)" prop="zfsqCoreQuotaId">
        <el-input
          v-model="queryParams.zfsqCoreQuotaId"
          placeholder="请输入核心企业授信额度ID(zc_finance_pro_com_rel.zfpcr_id)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商ID(sys_company.scy_id)" prop="zfsqCompanyId">
        <el-input
          v-model="queryParams.zfsqCompanyId"
          placeholder="请输入供应商ID(sys_company.scy_id)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="授信额度" prop="zfsqAmount">
        <el-input
          v-model="queryParams.zfsqAmount"
          placeholder="请输入授信额度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原授信额度" prop="zfsqOldAmount">
        <el-input
          v-model="queryParams.zfsqOldAmount"
          placeholder="请输入原授信额度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="利率" prop="zfsqRate">
        <el-input
          v-model="queryParams.zfsqRate"
          placeholder="请输入利率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="已使用额度" prop="zfsqUsedAmount">
        <el-input
          v-model="queryParams.zfsqUsedAmount"
          placeholder="请输入已使用额度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="可用额度" prop="zfsqAvailableAmount">
        <el-input
          v-model="queryParams.zfsqAvailableAmount"
          placeholder="请输入可用额度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有效期(0:长期, 1:定期)" prop="zfsqDateType">
        <el-select v-model="queryParams.zfsqDateType" placeholder="请选择有效期(0:长期, 1:定期)" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="开始日期" prop="zfsqStartDate">
        <el-input
          v-model="queryParams.zfsqStartDate"
          placeholder="请输入开始日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到期日期" prop="zfsqEndDate">
        <el-input
          v-model="queryParams.zfsqEndDate"
          placeholder="请输入到期日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态(00:有效 01:失效)" prop="zfsqStatus">
        <el-select v-model="queryParams.zfsqStatus" placeholder="请选择状态(00:有效 01:失效)" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="备用字段1" prop="zfsqProfitSpare1">
        <el-input
          v-model="queryParams.zfsqProfitSpare1"
          placeholder="请输入备用字段1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段2" prop="zfsqProfitSpare2">
        <el-input
          v-model="queryParams.zfsqProfitSpare2"
          placeholder="请输入备用字段2"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段3" prop="zfsqProfitSpare3">
        <el-input
          v-model="queryParams.zfsqProfitSpare3"
          placeholder="请输入备用字段3"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段4" prop="zfsqProfitSpare4">
        <el-input
          v-model="queryParams.zfsqProfitSpare4"
          placeholder="请输入备用字段4"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段5" prop="zfsqProfitSpare5">
        <el-input
          v-model="queryParams.zfsqProfitSpare5"
          placeholder="请输入备用字段5"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段6" prop="zfsqProfitSpare6">
        <el-input
          v-model="queryParams.zfsqProfitSpare6"
          placeholder="请输入备用字段6"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段7" prop="zfsqProfitSpare7">
        <el-input
          v-model="queryParams.zfsqProfitSpare7"
          placeholder="请输入备用字段7"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段8" prop="zfsqProfitSpare8">
        <el-input
          v-model="queryParams.zfsqProfitSpare8"
          placeholder="请输入备用字段8"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段9" prop="zfsqProfitSpare9">
        <el-input
          v-model="queryParams.zfsqProfitSpare9"
          placeholder="请输入备用字段9"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" 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"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:quota:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:quota:edit']"
        >修改</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="['system:quota:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:quota:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="quotaList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="zfsqId" />
      <el-table-column label="核心企业授信额度ID(zc_finance_pro_com_rel.zfpcr_id)" align="center" prop="zfsqCoreQuotaId" />
      <el-table-column label="供应商ID(sys_company.scy_id)" align="center" prop="zfsqCompanyId" />
      <el-table-column label="授信额度" align="center" prop="zfsqAmount" />
      <el-table-column label="原授信额度" align="center" prop="zfsqOldAmount" />
      <el-table-column label="利率" align="center" prop="zfsqRate" />
      <el-table-column label="已使用额度" align="center" prop="zfsqUsedAmount" />
      <el-table-column label="可用额度" align="center" prop="zfsqAvailableAmount" />
      <el-table-column label="有效期(0:长期, 1:定期)" align="center" prop="zfsqDateType" />
      <el-table-column label="开始日期" align="center" prop="zfsqStartDate" />
      <el-table-column label="到期日期" align="center" prop="zfsqEndDate" />
      <el-table-column label="状态(00:有效 01:失效)" align="center" prop="zfsqStatus" />
      <el-table-column label="备用字段1" align="center" prop="zfsqProfitSpare1" />
      <el-table-column label="备用字段2" align="center" prop="zfsqProfitSpare2" />
      <el-table-column label="备用字段3" align="center" prop="zfsqProfitSpare3" />
      <el-table-column label="备用字段4" align="center" prop="zfsqProfitSpare4" />
      <el-table-column label="备用字段5" align="center" prop="zfsqProfitSpare5" />
      <el-table-column label="备用字段6" align="center" prop="zfsqProfitSpare6" />
      <el-table-column label="备用字段7" align="center" prop="zfsqProfitSpare7" />
      <el-table-column label="备用字段8" align="center" prop="zfsqProfitSpare8" />
      <el-table-column label="备用字段9" align="center" prop="zfsqProfitSpare9" />
      <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:quota:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:quota: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="核心企业授信额度ID(zc_finance_pro_com_rel.zfpcr_id)" prop="zfsqCoreQuotaId">
          <el-input v-model="form.zfsqCoreQuotaId" placeholder="请输入核心企业授信额度ID(zc_finance_pro_com_rel.zfpcr_id)" />
        </el-form-item>
        <el-form-item label="供应商ID(sys_company.scy_id)" prop="zfsqCompanyId">
          <el-input v-model="form.zfsqCompanyId" placeholder="请输入供应商ID(sys_company.scy_id)" />
        </el-form-item>
        <el-form-item label="授信额度" prop="zfsqAmount">
          <el-input v-model="form.zfsqAmount" placeholder="请输入授信额度" />
        </el-form-item>
        <el-form-item label="原授信额度" prop="zfsqOldAmount">
          <el-input v-model="form.zfsqOldAmount" placeholder="请输入原授信额度" />
        </el-form-item>
        <el-form-item label="利率" prop="zfsqRate">
          <el-input v-model="form.zfsqRate" placeholder="请输入利率" />
        </el-form-item>
        <el-form-item label="已使用额度" prop="zfsqUsedAmount">
          <el-input v-model="form.zfsqUsedAmount" placeholder="请输入已使用额度" />
        </el-form-item>
        <el-form-item label="可用额度" prop="zfsqAvailableAmount">
          <el-input v-model="form.zfsqAvailableAmount" placeholder="请输入可用额度" />
        </el-form-item>
        <el-form-item label="有效期(0:长期, 1:定期)" prop="zfsqDateType">
          <el-select v-model="form.zfsqDateType" placeholder="请选择有效期(0:长期, 1:定期)">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="开始日期" prop="zfsqStartDate">
          <el-input v-model="form.zfsqStartDate" placeholder="请输入开始日期" />
        </el-form-item>
        <el-form-item label="到期日期" prop="zfsqEndDate">
          <el-input v-model="form.zfsqEndDate" placeholder="请输入到期日期" />
        </el-form-item>
        <el-form-item label="状态(00:有效 01:失效)">
          <el-radio-group v-model="form.zfsqStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备用字段1" prop="zfsqProfitSpare1">
          <el-input v-model="form.zfsqProfitSpare1" placeholder="请输入备用字段1" />
        </el-form-item>
        <el-form-item label="备用字段2" prop="zfsqProfitSpare2">
          <el-input v-model="form.zfsqProfitSpare2" placeholder="请输入备用字段2" />
        </el-form-item>
        <el-form-item label="备用字段3" prop="zfsqProfitSpare3">
          <el-input v-model="form.zfsqProfitSpare3" placeholder="请输入备用字段3" />
        </el-form-item>
        <el-form-item label="备用字段4" prop="zfsqProfitSpare4">
          <el-input v-model="form.zfsqProfitSpare4" placeholder="请输入备用字段4" />
        </el-form-item>
        <el-form-item label="备用字段5" prop="zfsqProfitSpare5">
          <el-input v-model="form.zfsqProfitSpare5" placeholder="请输入备用字段5" />
        </el-form-item>
        <el-form-item label="备用字段6" prop="zfsqProfitSpare6">
          <el-input v-model="form.zfsqProfitSpare6" placeholder="请输入备用字段6" />
        </el-form-item>
        <el-form-item label="备用字段7" prop="zfsqProfitSpare7">
          <el-input v-model="form.zfsqProfitSpare7" placeholder="请输入备用字段7" />
        </el-form-item>
        <el-form-item label="备用字段8" prop="zfsqProfitSpare8">
          <el-input v-model="form.zfsqProfitSpare8" placeholder="请输入备用字段8" />
        </el-form-item>
        <el-form-item label="备用字段9" prop="zfsqProfitSpare9">
          <el-input v-model="form.zfsqProfitSpare9" placeholder="请输入备用字段9" />
        </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 { listCreditLine, getCreditLine, delCreditLine, addCreditLine, updateCreditLine,changeStatus} from "@/api/service/creditLine/creditLine";

export default {
  name: "Quota",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商授信额度表格数据
      quotaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zfsqCoreQuotaId: null,
        zfsqCompanyId: null,
        zfsqAmount: null,
        zfsqOldAmount: null,
        zfsqRate: null,
        zfsqUsedAmount: null,
        zfsqAvailableAmount: null,
        zfsqDateType: null,
        zfsqStartDate: null,
        zfsqEndDate: null,
        zfsqStatus: null,
        zfsqProfitSpare1: null,
        zfsqProfitSpare2: null,
        zfsqProfitSpare3: null,
        zfsqProfitSpare4: null,
        zfsqProfitSpare5: null,
        zfsqProfitSpare6: null,
        zfsqProfitSpare7: null,
        zfsqProfitSpare8: null,
        zfsqProfitSpare9: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        zfsqCoreQuotaId: [
          { required: true, message: "核心企业授信额度ID(zc_finance_pro_com_rel.zfpcr_id)不能为空", trigger: "blur" }
        ],
        zfsqCompanyId: [
          { required: true, message: "供应商ID(sys_company.scy_id)不能为空", trigger: "blur" }
        ],
        zfsqAmount: [
          { required: true, message: "授信额度不能为空", trigger: "blur" }
        ],
        zfsqRate: [
          { required: true, message: "利率不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询供应商授信额度列表 */
    getList() {
      this.loading = true;
      listQuota(this.queryParams).then(response => {
        this.quotaList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        zfsqId: null,
        zfsqCoreQuotaId: null,
        zfsqCompanyId: null,
        zfsqAmount: null,
        zfsqOldAmount: null,
        zfsqRate: null,
        zfsqUsedAmount: null,
        zfsqAvailableAmount: null,
        zfsqDateType: null,
        zfsqStartDate: null,
        zfsqEndDate: null,
        zfsqStatus: "0",
        zfsqProfitSpare1: null,
        zfsqProfitSpare2: null,
        zfsqProfitSpare3: null,
        zfsqProfitSpare4: null,
        zfsqProfitSpare5: null,
        zfsqProfitSpare6: null,
        zfsqProfitSpare7: null,
        zfsqProfitSpare8: null,
        zfsqProfitSpare9: 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.zfsqId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加供应商授信额度";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const zfsqId = row.zfsqId || this.ids
      getQuota(zfsqId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改供应商授信额度";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.zfsqId != null) {
            updateQuota(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQuota(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const zfsqIds = row.zfsqId || this.ids;
      this.$confirm('是否确认删除供应商授信额度编号为"' + zfsqIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delQuota(zfsqIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/quota/export', {
        ...this.queryParams
      }, `system_quota.xlsx`)
    }
  }
};
</script>