<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="custName">
        <el-input
          v-model="queryParams.custName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构号" prop="orgCode">
        <el-input
          v-model="queryParams.orgCode"
          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>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="workflowList">
      <el-table-column label="业务方流水号" align="center" prop="serialNum" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="客户名称" align="center" prop="custName" :show-overflow-tooltip="true" />
      <el-table-column label="客户类型" align="center" prop="custType" width="100" />
      <el-table-column label="担保方式" align="center" prop="guarType" width="100" />
      <el-table-column label="申请金额(元)" align="center" prop="applyAmt" width="120" />
      <el-table-column label="测算利率(%)" align="center" prop="calculateRate" width="100" />
      <el-table-column label="执行利率(%)" align="center" prop="executeRate" width="100" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createBy" width="120" />
      <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-view"
            @click="handleView(scope.row)"
          >查看</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"
    />

    <!-- 客户类型选择对话框 -->
    <customer-type-selector :visible.sync="showTypeSelector" @select="handleSelectType"/>

    <!-- 个人客户创建对话框 -->
    <personal-create-dialog :visible.sync="showPersonalDialog" @success="handleCreateSuccess"/>

    <!-- 企业客户创建对话框 -->
    <corporate-create-dialog :visible.sync="showCorporateDialog" @success="handleCreateSuccess"/>
  </div>
</template>

<script>
import {listWorkflow} from "@/api/loanPricing/workflow"
import CustomerTypeSelector from "./components/CustomerTypeSelector"
import PersonalCreateDialog from "./components/PersonalCreateDialog"
import CorporateCreateDialog from "./components/CorporateCreateDialog"

export default {
  name: "LoanPricingWorkflow",
  components: {
    CustomerTypeSelector,
    PersonalCreateDialog,
    CorporateCreateDialog
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 利率定价流程表格数据
      workflowList: [],
      // 是否显示客户类型选择弹出层
      showTypeSelector: false,
      // 是否显示个人客户创建弹出层
      showPersonalDialog: false,
      // 是否显示企业客户创建弹出层
      showCorporateDialog: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        custName: undefined,
        createBy: undefined,
        orgCode: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  activated() {
    this.getList()
  },
  methods: {
    /** 查询利率定价流程列表 */
    getList() {
      this.loading = true
      listWorkflow(this.queryParams).then(response => {
        this.workflowList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 查看详情操作 */
    handleView(row) {
      this.$router.push({
        name: 'LoanPricingWorkflowDetail',
        params: { serialNum: row.serialNum }
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.showTypeSelector = true
    },
    /** 选择客户类型回调 */
    handleSelectType(type) {
      if (type === 'personal') {
        this.showPersonalDialog = true
      } else if (type === 'corporate') {
        this.showCorporateDialog = true
      }
    },
    /** 创建成功回调 */
    handleCreateSuccess() {
      this.getList()
    }
  }
}
</script>
