<template>
  <div>
    <!--        头部操作模块 start -->
    <div>
      <div style="width:200px;margin:0 15px;float:left;">
        <el-input v-model="solutionTitle" placeholder="搜索标题" @keyup.enter.native="searchList"></el-input>
      </div>
      <div style="width:200px;margin:0 15px;float:left;">
        <el-select v-model="is_choice" clearable placeholder="是否优选">
          <el-option
            v-for="item in choice"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </div>
      <div style="width:200px;margin:0 15px;float:left;">
        <el-select v-model="solutionStatus" clearable placeholder="状态">
          <el-option
            v-for="item in statusData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </div>
      <div style="width:100px;margin:0 15px;float:left;">
        <el-button type="primary" @click="searchList">搜索</el-button>
      </div>
      <div style="clear: both;"></div>
    </div>
    <!--        头部操作模块 end -->
    <div class="count-list" v-if="record">
      <div class="count-item">总数：{{record.sum}}</div>
      <div class="count-item">待审核：{{record.wait_check}}</div>
      <div class="count-item">已通过：{{record.approve}}</div>
      <div class="count-item">拒绝：{{record.deny}}</div>
      <router-link to='/main/kaifawu_contact'><el-button type="primary" size="mini">解决方案需求</el-button></router-link>
    </div>
    <div class="content" v-if="solutionData">
      <el-table :data="solutionData" border style="width: 100%">
        <el-table-column prop="title" label="方案名称"></el-table-column>
        <el-table-column prop="login_mobile" label="联系方式"></el-table-column>
        <el-table-column prop="updated_at" label="入驻时间"></el-table-column>
        <el-table-column prop="checked_at" label="操作时间"></el-table-column>
        <el-table-column prop="nickname" label="客户经理"></el-table-column>
        <el-table-column prop="status" label="当前状态"></el-table-column>
        <el-table-column label="是否优选">
          <template slot-scope="scope">
            <p v-if="scope.row['is_choice'] == 1">是</p>
            <p v-else>否</p>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-checkbox label="1" @change="contact(scope.row.id)" name="type">联系他</el-checkbox>
            <el-button type="text" @click="detail(scope.row.id)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      class="order-footer"
      background
      layout="prev, pager, next"
      :page-size="20"
      :total="Number(record.sum)"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      page: 1,
      solutionData: [],
      form: {
        reason: ""
      },
      record: [],
      isDialogShow: false,
      solutionTitle:'',
      is_choice:'',
      choice:[
        {'id':'1',name:'是'},
        {'id':'0',name:'否'},
      ],
      solutionStatus:'',
      statusData:[
        {'id':'0',name:'草稿'},
        {'id':'1',name:'审核'},
        {'id':'2',name:'通过'},
        {'id':'3',name:'拒绝'},
      ]
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    async searchList(){
      let data = {
        page:1,
        size:20,
        title:'',
        is_choice :'',
        status:'',
      }
      if(this.solutionTitle){
        data.title = this.solutionTitle;
      }
      if(this.is_choice){
        data.is_choice = this.is_choice;
      }
      console.log(this.solutionStatus);
      if(this.solutionStatus){
        data.status = this.solutionStatus;
      }
      let res = await this.$post("/api/admin/kaifawu/getProviders", data);
      this.solutionData = res.data.list;
      this.record = res.data.record;
    },
    async detail(id) {
      window.open(`/main/solution_detail?id=${id}`, "_self");
    },
    async getList() {
      const page = this.page;
      const size = 20;
      const data = {
        page,
        size
      };
      let res = await this.$post("/api/admin/kaifawu/getProviders", data);
      this.solutionData = res.data.list;
      this.record = res.data.record;
    },
    async contact(id) {
      const data = {
        id
      };
      let res = await this.$post("/api/admin/kaifawu/contact", data);
      this.$message({
        message: res.info,
        type: "success"
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.count-list {
  padding-bottom: 10px;
  display: flex;
  align-items: center;
}

.count-item {
  margin-right: 20px;
  font-size: 16px;
}

.content {
  white-space: nowrap;
  overflow-x: scroll;
  height: calc(100vh - 150px);
}

.btn {
  width: 80px;
}

.order-footer {
  margin-top: 10px;
}
</style>
