<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="code">
        <el-date-picker
          type="month"
          v-model="queryParams.yearMonth"
          placeholder="选择月份"
          >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="商机类型" prop="boType">
        <el-select
          v-model="queryParams.boType"
          @change="boTypeChange"
          clearable
        >
          <el-option
            v-for="dict in dict.type.mk_bo_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商机来源" prop="boSource">
        <el-select
          v-model="queryParams.boSource"
          clearable
        >
          <el-option
            v-for="dict in dict.type.mk_bo_source"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商机部门" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          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-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column label="中心部门" align="center" prop="deptName" />
      <el-table-column label="当月新增商机数（个）" align="center" prop="sumTotal" />
      <el-table-column label="当月审核通过数（个）" align="center" prop="passAudit" />
      <el-table-column label="当月审核通过率%" align="center" prop="passAuditRate" />
      <el-table-column label="当月立项成功数（个）" align="center" prop="approveInitiateProject" />
      <el-table-column label="当月立项成功率%" align="center" prop="approveInitiateProjectRate" />
      <el-table-column label="当月挂网数(个)" align="center" prop="hanging" />
      <el-table-column label="当月挂网率%" align="center" prop="hangingRate" />
      <el-table-column label="当月合同签订数（个）" align="center" prop="contractSigning" />
      <el-table-column label="当月合同签订率%" align="center" prop="contractSigningRate" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listProportion } from "@/api/business/spd/bo/statement";

export default {
  name: "proportion",
  dicts: [
    "mk_bo_type",
    "mk_bo_source",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 职责表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        yearMonth: null,
        boType: null,
        boSource: null,
        deptName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询职责列表 */
    getList() {
      this.loading = true;
      listProportion(this.queryParams).then(response => {
        this.list = response.rows;
        for(let item of this.list) {
          if(item.passAuditRate){item.passAuditRate = (item.passAuditRate * 100) + '%';}
          if(item.approveInitiateProjectRate){item.approveInitiateProjectRate = (item.approveInitiateProjectRate * 100) + '%';}
          if(item.hangingRate){item.hangingRate = (item.hangingRate * 100) + '%';}
          if(item.contractSigningRate){item.contractSigningRate = (item.contractSigningRate * 100) + '%';}
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        name: null,
        boType: null,
        tenantId: null,
        revision: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log('this.queryParams',this.queryParams);
      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
      getJob(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) {
            updateJob(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJob(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 delJob(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pu/job/export', {
        ...this.queryParams
      }, `job_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
