<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="SPD商机" name="0">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="商机名称" prop="boName">
            <el-input
              v-model="queryParams.boName"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="客户" prop="customerName">
            <el-input
              v-model="queryParams.customerName"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="负责人" prop="principalName">
            <el-input
              v-model="queryParams.principalName"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="商机来源" prop="boSource">
            <el-input
              v-model="queryParams.boSource"
              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 :data="boList" >
          <el-table-column label="客户" align="center" prop="customerName" />
          <el-table-column label="部门" align="center" prop="deptName" />
          <el-table-column label="负责人" align="center" prop="principalName" />
          <el-table-column label="商机名称" align="center" prop="boName" />
          <el-table-column label="商机编码" align="center" prop="boCode" />
          <el-table-column label="创建日期" align="center" prop="createTime" />
          <el-table-column label="商机挖掘" align="center" prop="b000">
            <template slot-scope="scope">
              <dev v-if="scope.row.b000">
                <el-button size="medium" type="text" icon="el-icon-s-flag" />
                {{scope.row.b000}}
              </dev>
            </template>
          </el-table-column>
          <el-table-column label="商机审核" align="center" prop="b001" >
            <template slot-scope="scope">
              <dev v-if="scope.row.b001">
                <el-button size="medium" type="text" icon="el-icon-s-flag" />
                {{scope.row.b001}}
              </dev>
            </template>
          </el-table-column>
          <el-table-column label="项目立项" align="center" prop="b002" >
            <template slot-scope="scope">
              <dev v-if="scope.row.b002">
                <el-button size="medium" type="text" icon="el-icon-s-flag" />
                {{scope.row.b002}}
              </dev>
            </template>
          </el-table-column>
          <el-table-column label="解决方案" align="center" prop="b007" >
            <template slot-scope="scope">
              <dev v-if="scope.row.b007">
                <el-button size="medium" type="text" icon="el-icon-s-flag" />
                {{scope.row.b007}}
              </dev>
            </template>
          </el-table-column>
          <el-table-column label="投标与签合同" align="center" prop="b008" >
            <template slot-scope="scope">
              <dev v-if="scope.row.b008">
                <el-button size="medium" type="text" icon="el-icon-s-flag" />
                {{scope.row.b008}}
              </dev>
            </template>
          </el-table-column>
          <el-table-column label="完成" align="center" prop="b099" >
            <template slot-scope="scope">
              <dev v-if="scope.row.b099">
                <el-button size="medium" type="text" icon="el-icon-s-flag" />
                {{scope.row.b099}}
              </dev>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="耗材集采商机" name="1">功能开发中</el-tab-pane>
      <el-tab-pane label="耗材集采商机" name="2">功能开发中</el-tab-pane>
      <el-tab-pane label="医疗设备商机" name="3">功能开发中</el-tab-pane>
      <el-tab-pane label="军队医疗设备商机" name="4">功能开发中</el-tab-pane>
    </el-tabs>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>


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

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      //查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        boType: null,
        boName: null,
        customerName: null,
        principalName: null,
        boSource: null,
      },
      // 显示搜索条件
      showSearch: true,
      //列表数据
      boList:[],
      //当前页签
      activeName: '0',
      //分页参数
      total:0,
    };
  },
  created() {
    var e = {
      name: '0',
    }
    this.handleClick(e);
  },
  methods: {
    /** 查询任务列表 */
    getList() {
      var e = {
        name: '0',
      }
      this.handleClick(e);
    },
    handleClick(e) {
      console.log('e',e);
      this.queryParams.boType = e.name;
      switch (e.name) {
        case "0":
          listBasic(this.queryParams).then(response => {
            this.boList = response.rows;
            console.log('this.boList',this.boList);
            for(var i = 0;i < this.boList.length;i++){
              var nodes = this.boList[i].boNodeFlowList;
              console.log('nodes',nodes);
              var nodesfilter = nodes.filter(n => n.code == '0-00');
              if(nodesfilter.length > 0){
                this.boList[i].b000 = nodesfilter[0].day;
              }
              nodesfilter = nodes.filter(n => n.code == '0-01');
              if(nodesfilter.length > 0){
                this.boList[i].b001 = nodesfilter[0].day;
              }
              nodesfilter = nodes.filter(n => n.code == '0-02');
              if(nodesfilter.length > 0){
                this.boList[i].b002 = nodesfilter[0].day;
              }
              nodesfilter = nodes.filter(n => n.code == '0-07');
              if(nodesfilter.length > 0){
                this.boList[i].b007 = nodesfilter[0].day;
              }
              nodesfilter = nodes.filter(n => n.code == '0-08');
              if(nodesfilter.length > 0){
                this.boList[i].b008 = nodesfilter[0].day;
              }
              nodesfilter = nodes.filter(n => n.code == '0-99');
              if(nodesfilter.length > 0){
                this.boList[i].b099 = nodesfilter[0].day;
              }
            }
            console.log('this.boList',this.boList);
            this.total = response.total;
            this.loading = false;
          });
          break;
        case "1":
          break;
        case "2":
          break;
        case "3":
          break;
        case "4":
          break;
        default:
          break;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
