<template>
  <div class="container normal-panel">
    <!-- 表格搜索 -->
    <div class="flex-align-center  search-panel normal-margin">
      <el-input style="width:200px;margin-right:16px" 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>
      <time-select @clearSelect="clearTime" @timeChange="timeChange"></time-select>
    </div>
    <!-- 表格主题 -->
    <tableLayout v-if="tablecols && list" :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 == 'periodtype'">
            <span>
              {{scope.column.data.periodpoint | timer(scope.column.data[scope.column.columnname])}}
            </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>
      </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>
</template>

<script>
import TimeSelect from '@/SManagement/submitedit_one/components/TimeSelect'
export default {
  props:['mainData'],
  components:{
    TimeSelect
  },
  data () {
    return {
      params:{
        "id": 20220908134403,
        "version": 1,
        "content": {
          "nocache": true,
          "sa_salesforecastmodelid": "",
          "where": {
            "begindate": "",
            "enddate": "",
            "condition":""
          }
        }
      },
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,

    }
  },
  filters: {
    timer (val, type) {
      if (type == '月') {
        return '每月' + val.substr(1, val.length - 2) + '日'
      } else {
        return '每周' + val.substr(1, val.length - 2)
      }
    }
  },
  methods:{
    async listData (sa_salesforecastmodelid,pageNumber) {
      this.params.content.pageNumber = pageNumber
      this.params.content.sa_salesforecastmodelid = this.mainData.sa_salesforecastmodelid
      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(null,this.params.content.pageNumber)
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData(null,val)
    },
    /* 时间赛选改变 */
    timeChange (time) {
      this.params.content.where.begindate = time[0]
      this.params.content.where.enddate = time[1]
      this.listData()
    },
    /* 清除时间赛选 */
    clearTime () {
      this.params.content.where.begindate = ''
      this.params.content.where.enddate = ''
      this.listData()
    },
    rowClick (row) {
      this.$emit('tableRowClick',row)
    },
  },
  mounted () {
    this.listData()
    this.tablecols = this.tool.tabelCol(this.$route.name)['salesHistoryTable'].tablecols
  },
  created () {
  }
}

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