<template>
  <div>
    <!-- 表格搜索 -->
    <div class="flex-align-center  search-panel normal-margin">
      <label class="search__label">提报时间:</label>
      <el-date-picker
          size="small"
          v-model="date"
          style="margin-right: 24px !important;"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="selectChange">
      </el-date-picker>
      <el-input class="inline-16" style="width:200px" size="small" placeholder="单号 / 提报人" @keyup.native.enter="listData(null,1)" @clear="listData(null,1)" v-model="params.content.where.condition" prefix-icon="el-icon-search" clearable></el-input>
    </div>
    <!-- 表格主题 -->
    <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true" :fixedName="'operation'" height="300px" @rowClick="rowClick">
      <template v-slot:customcol="scope">
<!--        <div v-if="scope.column.columnname === 'baseonproject'">
          <span>{{scope.column.data.baseonproject === 1?'按项目预测':'无'}}</span>
        </div>
        <div v-else-if="scope.column.columnname === 'taskdays'">
          <span>提前{{scope.column.data.taskdays}}天</span>
        </div>-->
        <div v-if="scope.column.columnname === 'begdate'">
          <div>
            <span>{{scope.column.data.taskdayschange.length !== 0?scope.column.data.periodstart.split(' ')[0]:scope.column.data.begdate.split(' ')[0]}}</span>
          </div>
        </div>
        <div v-else-if="scope.column.columnname === 'periodpoint'">
<!--          <span v-for="i in scope.column.data.periodpointchange" :key="i.index">
            {{scope.column.data.periodtype === '周'?'周'+ `${i===7?'日':i}`:i+'日'}},
          </span>-->
          <div>
<!--            <span v-for="(i,index) in scope.column.data.taskdayschange" :key="index">
              <span v-if="index === scope.column.data.taskdayschange.length -1">
                {{ i + '天' }}
              </span>
              <span v-else>
                {{ i + '天,' }}
              </span>

            </span>-->
            <span>{{scope.column.data.taskdayschange.length !== 0?scope.column.data.periodend.split(' ')[0]:scope.column.data.enddate.split(' ')[0]}}</span>
          </div>
<!--          <div v-else>
            <span v-for="i in scope.column.data.periodpointchange" :key="i.index">
              {{scope.column.data.periodtype === '周'?'周'+ `${i===7?'日':i}`:i+'日'}},
            </span>
          </div>-->

        </div>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <slot name="detail" :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 style="height: 35px;margin-top: 20px">
      <div style="float: left;margin-left: 15px">提报人数:{{ total }}</div>
      <div style="float: right">
        <el-pagination
            background
            small
            style="text-align: right;"
            @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>

export default {
  components:{
  },
  data () {
    return {
      params:{
        "id": 20220906150403,
        "content": {
          "pageNumber":1,
          "pageSize":10,
          "sa_salesforecastmodelid":0,
          "where":{
            "condition":"",
            'begindate':"",
            'enddate':""
          }
        }
      },
      tablecols:{},
      list:[],
      total:0,
      currentPage:0,
      date:[]
    }
  },
  methods:{
    async listData () {
      this.params.content.sa_salesforecastmodelid = this.$route.query.id
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      res.data.length > 0 ?this.$emit('tableRowClick',res.data[0]):''
    },
    handleSizeChange(val) {
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      this.params.content.pageNumber = val
      this.listData()
    },
    rowClick (row) {
      this.$emit('tableRowClick',row)
    },
    selectChange(val){
      console.log(val)
      this.params.content.where.begindate = val[0]
      this.params.content.where.enddate = val[1]
      this.listData()
    }
  },
  mounted () {
    this.tablecols = this.tool.tabelCol(this.$route.name)['forecastTable'].tablecols
     this.listData()
  }
}

</script>
<style>
</style>
<style scoped>
.search-panel p{
  width:40px;
  font-size:14px
}
</style>