<template>
  <div>
    <div class="mt-10">
      <label class="search__label">项目类型:</label>
      <el-select v-model="type" placeholder="请选择" class="inline-24" size="small" @change="search" clearable>
        <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
        </el-option>
      </el-select>
      <el-input style="width:200px" suffix-icon="el-icon-search" size="small" placeholder="项目编号 / 项目名称" v-model="param.content.where.condition" @keyup.native.enter="search" @clear="search" clearable></el-input>
    </div>
    <el-table
      :data="list"
      style="width: 100%"
      size="mini"
      border
      @row-click="rowClick">
      <el-table-column
        prop="projectnum"
        label="项目编号">
      </el-table-column>
      <el-table-column
        prop="projectname"
        label="项目名称">
      </el-table-column>
      <el-table-column
          prop="projecttype"
          label="项目类型">
      </el-table-column>
      <el-table-column
        prop="address"
        label="项目地址">
      </el-table-column>
      <el-table-column
        prop="sumprojectamount"
        label="预测金额(元)">
      </el-table-column>
      <el-table-column
        label="操作"
        width="100">
        <template slot-scope="scope">
          <product class="inline-16" :id="scope.row.sa_projectid" :sa_salesforecastbillid="param.content.sa_salesforecastbillid" :data="scope.row"></product>
        </template>
      </el-table-column>
    </el-table>
    <div class="container normal-panel flex-align-center flex-between">
      <p v-if="list[0]">预测金额(元):{{list[0].sumamount}}</p>
      <p v-else>预测金额(元): 0</p>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[20, 50, 100, 200]"
        layout="total,sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import product from './product.vue'
export default {
  components:{
    product
  },
  data () {
    return {
      param:{
        "id": 20220916115203,
        "version":1,
        "content": {
          "pageNumber":1,
          "pageSize":20,
          "sa_salesforecastbillid":'',
          "where":{
            "condition":"",
            "projecttype":""
          }
        }
      },
      list:[],
      currentPage:0,
      total:0,
      type:'',
      typeList:[]
    }
  },
  methods:{
    async search () {
      this.param.content.pageNumber = 1
      this.param.content.where.projecttype = this.type
      this.listData(this.param.content.sa_salesforecastbillid)
    },
    async listData (id) {
      this.queryType()
      this.param.content.sa_salesforecastbillid = id
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    rowClick (row) {
      this.$emit('queryProduct',row.sa_projectid)
    },
    async queryType(){
      let param = {
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 90,
          "typename": "projecttype",
          "parameter": {
          }
        }
      }
      const res = await this.$api.requested(param)
      this.typeList = res.data
    }
  },
  mounted () {
    this.queryType()
  }
}

</script>
<style>
</style>