<template>
  <div>
    <div class="container normal-panel normal-margin">
      <slot name="add"></slot>
    </div>
    <div class="container normal-panel">
      <el-form size="small" inline label-position="left" label-width="50px" :model="search">
        <el-form-item label="搜索">
          <el-input v-model="search.condition" prefix-icon="el-icon-search" placeholder="年度" @clear="listData(params.content.pageNumber = 1)" @keyup.native.enter="listData(params.content.pageNumber = 1)" clearable></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="search.status" placeholder="请选择" @change="listData(params.content.pageNumber = 1)" clearable>
            <el-option
              v-for="item in sys_options"
              :key="item.index"
              :label="item.value"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <tableLayout :layout="tablecols" :data="list" :custom="true" :height="tableHieght">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname === 'status'">
            <span v-if="scope.column.data.status === '已下达'" style="color:#52C41A">{{scope.column.data.status}}</span>
            <span v-else>{{scope.column.data.status}}</span>
          </div>
          <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
        </template>
        <template v-slot:opreation="scope">
          <slot name="detail" :data="scope.data"></slot>
          <slot name="edit" :data="scope.data"></slot>
          <slot name="issue" :data="scope.data"></slot>
          <slot name="adjustment" :data="scope.data"></slot>
        </template>
      </tableLayout>
      <div style="margin-top:16px;text-align:right">
        <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="params.content.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'

export default {
  data () {
    return {
      params:{
        "id": 20220903170002,
        "content": {
          "where": {
            "condition": "",
            "status": ""
          },
          "pageNumber": 1,
          "pageSize": 20
        },
      },
      search:{},
      tablecols:[],
      list:[],
      total:0,
      currentPage:0
    }
  },
  computed:{
    ...mapGetters({
      sys_options:'sys_options'
    })
  },
  methods:{
    async listData () {
      this.params.content.where = this.search
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
  },
  mounted () {
    this.listData()
    this.$store.dispatch('optiontypeselect','targettype')
  },
  created () {
    this.tablecols = this.tool.tabelCol(this.$route.name)['projectTarget'].tablecols
  }
}

</script>
<style>
</style>