<template> 
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float:right"
          type="primary"
          @click="handleSearchList()"
          size="small">
          查询搜索
        </el-button>
        <el-button
          style="float:right;margin-right: 15px"
          @click="handleResetSearch()"
          size="small">
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input v-model="listQuery.productName" class="input-width" placeholder="产品名称" clearable></el-input>
          </el-form-item>
          <el-form-item label="供应商：">
            <el-select v-model="listQuery.compId" filterable placeholder="全部" clearable>
              <el-option
                v-for="item in compList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <el-table ref="roleTable"
                :data="list"
                style="width: 100%;"
                v-loading="listLoading" border>

        <el-table-column label="产品" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.productName}}</template>
        </el-table-column>
        <el-table-column label="品牌" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.productBrand}}</template>
        </el-table-column>
        <el-table-column label="公司名称" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.compName}}</template>
        </el-table-column>
        <el-table-column label="有意向者" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.memberNickname}}</template>
        </el-table-column>
        <el-table-column label="有意向时间" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.createDate | formatDateTime}}</template>
        </el-table-column>        
        
        <!-- <el-table-column label="操作" width="160" fixed="right" align="center">
          <template slot-scope="scope">
            <el-row>
            <el-button size="mini" v-if="originupdate"
                       type="text"
                       @click="handleUpdateorigin(scope.$index, scope.row)">
              编辑
            </el-button>             
            <el-button size="mini" v-if="intentiondelete"
                       type="text"
                       @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
            </el-row>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNo"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import {fetchList} from '@/api/intention';
  import {formatDate} from '@/utils/date';
  import {selectCompList} from '@/api/product';

  const defaultListQuery = {
    pageNo: 1,
    pageSize: 10,
    productName: null,
    compId:null,
  };

  export default {
    name: 'roleList',
    data() {
      return {
        listQuery: Object.assign({}, defaultListQuery),
        list: null,
        total: null,
        listLoading: false,
        dialogVisible: false,
        isEdit: false,
        compList:[],
      }
    },
    created() {
      this.getList();
      this.getcompList();
    },
    filters: {
      formatDateTime(time) {
        if (time == null || time === '') {
          return 'N/A';
        }
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      }
    },
    methods: {
      /** 获取供应商下拉列表 */
      getcompList() {
        selectCompList().then(response => {
          // console.log("获取供应商下拉列表",response);
          this.compList = response.data;
        });
      },
      handleResetSearch() {
        this.listQuery = Object.assign({}, defaultListQuery);
        this.getList();
      },
      handleSearchList() {
        this.listQuery.pageNo = 1;
        this.getList();
      },
      handleSizeChange(val) {
        this.listQuery.pageNo = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.pageNo = val;
        this.getList();
      },

      handleDelete(index, row) {
        this.$confirm('是否要删除该关注?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let id = [];
          id.push(row.id);
          let params=new URLSearchParams();
          params.append("id",id);
          console.log('del-params',params);
          deleteIntention(params).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList();
          });
        });
      },
      getList() {
        this.listLoading = true;
        fetchList(this.listQuery).then(response => {
          console.log('response',JSON.parse(JSON.stringify(response)));
          this.listLoading = false;
          this.list = response.data.list;
          this.total = response.data.total;
        }).catch(err => {
          this.listLoading = false;
        });
      }
    }
  }
</script>
<style></style>


