<template>
  <div>
    <div class="container normal-panel normal-margin">
      <slot name="add"></slot>
    </div>
    <div class="container normal-panel">
      <!-- 表格搜索 -->
      <div class="flex-align-center  search-panel normal-margin">
        <p>搜索:</p>
        <el-input style="width:200px" size="small" placeholder="标题" @keyup.native.enter="listData('search')"
          @clear="listData('search')" v-model="params.content.where.condition" prefix-icon="el-icon-search" clearable>
        </el-input>
      </div>
      <!-- 表格 -->
      <tableLayout :layout="tablecols" :data="list" :custom="true" :height="tableHieght">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname === 'status'">
            <span :style="scope.column.data.status === '发布' ? 'color:#52C41A' : ''">{{ scope.column.data.status
            }}</span>
          </div>
          <div v-else-if="scope.column.columnname === 'onceonly'">
            <span>{{ scope.column.data.onceonly === 1 ? '一事一报' : '一事多报' }}</span>
          </div>
          <p v-else>{{ scope.column.data[scope.column.columnname] }}</p>
        </template>
        <template v-slot:opreation="scope">
          <slot name="detail" :data="scope"></slot>
          <slot name="edit" :data="scope"></slot>
          <slot name="release" :data="scope"></slot>
          <slot name="data_statistics" :data="scope"></slot>
          <slot name="del" :data="scope"></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>
export default {
  data() {
    return {
      params: {
        "classname": "webmanage.saletool.submitedit.submitedit",
        "method": "selectsubmitlist",
        "content": {
          "pageNumber": 1,
          "pageSize": 10,
          "where": {
            "condition": "",
          }
        }
      },
      tablecols: [],
      list: [],
      total: 0,
      currentPage: 0
    }
  },
  methods: {
    async listData() {
      const res = await this.$api.requested(this.params)
      let deteleList = [];
      res.data.forEach(v => {
        if (v.notes == '初始化数据' + JSON.parse(sessionStorage.getItem('active_account')).userid && v.title == '' && v.status == '新建') {
          deteleList.push(v.sat_submiteditmodelid)
          this.$api.requested({
            "classname": "webmanage.saletool.submitedit.submitedit",
            "method": "delete",
            "content": {
              "sat_submiteditmodelid": v.sat_submiteditmodelid
            }
          })
        }
      })
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      if (deteleList.length != 0) this.listData();
    },
    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()
  },
  created() {
    //获取表结构
    this.tablecols = this.tool.tabelCol(this.$route.name)['tableSubmitlist'].tablecols
  }
}

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