<template>
  <div id="updateList">
    <!-- 头 -->
    <div class="app-top">
      <div class="app-titel" style="margin-top: 5px; padding: 0 10px">
        <div class="div-lab">
          <el-select
            v-model="selValue"
            @change="selChange"
            style="width: 100px"
            placeholder="请选择"
          >
            <el-option label="代理商" v-if="orgType == 0" value="1"></el-option>
            <el-option label="公司" v-if="orgType != 2" value="2"></el-option>
            <el-option label="项目" value="3"></el-option>
          </el-select>
        </div>

        <div class="div-lab">
          <div class="label">更新时间：</div>
          <el-date-picker
            v-model="time"
            type="daterange"
            class="div-inp"
            range-separator="-"
            start-placeholder="开始日期"
            :default-time="['00:00:00', '23:59:59']"
            value-format="yyyy-MM-dd"
            end-placeholder="结束日期"
            @change="timeChange"
          >
          </el-date-picker>
        </div>
      </div>
      <div class="app-titel" style="margin-top: 15px">
        <!-- <div class="label" style="color: #ffffff">筛选相关：</div> -->
        <div style="margin-left: 16px">
          <el-button type="primary" @click="add()" v-if="con_list_add">新增</el-button>
        </div>
        <div style="margin-left: 16px">
          <el-button type="primary" @click="noempty()">筛选</el-button>
        </div>
        <div style="margin-left: 20px">
          <el-button @click="empty()">清空筛选条件</el-button>
        </div>
      </div>
    </div>

    <!-- 表格 -->
    <div class="cen-tab">
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="title" label="标题" align="center"></el-table-column>
        <el-table-column prop="pageView" label="阅读数" align="center"></el-table-column>
        <el-table-column prop="createUser" label="发布人" align="center"></el-table-column>
        <el-table-column prop="createTime" label="发布时间" align="center"></el-table-column>
        <el-table-column label="操作" align="center" fixed="right" width="200">
          <template slot-scope="{ row }">
            <el-button type="text" @click="modify(row.id,row.orgType)" 
              v-if="con_list_modify">编辑</el-button>
            <el-button type="text" @click="remove(row.id)" 
              v-if="con_list_del">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="current"
          :page-sizes="[10, 30, 50]"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import axios from "axios"
export default {
  name: "updateList",
  data() {
    return {
      current: 1,
      size:10,
      total:0,
      selValue: "1",
      orgType: localStorage.getItem("orgType"),
      time: [],
      tableData:[]
    };
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  watch: {},
  created() {
    this.con_list_add = this.permissions["con_list_add"];
    this.con_list_modify = this.permissions["con_list_modify"];
    this.con_list_del = this.permissions["con_list_del"];
  },
  mounted(){
    if(this.$route.query.org!=undefined){
      this.selValue = this.$route.query.org
    }else{
      this.selValue = "1"
    }
    let data = {
        current:1, 
        size:10,
        orgType:this.selValue,
      }
    this.filefindByPage(data)
  },
  methods: {
    selChange() {
      let data = {
        current:1, 
        size:10,
        orgType:this.selValue,
        startTime:this.time[0],
        endTime:this.time[1],
      }
      this.filefindByPage(data)
    },
    timeChange() {},
    add() {
      this.$router.push(
        `/contentManage/updateRecord/update?pj=${this.selValue}`
      )
    },
    noempty() {
      let data = {
        current:1, 
        size:10,
        orgType:this.selValue,
        startTime:this.time[0],
        endTime:this.time[1]
      }
      this.filefindByPage(data);
    },
    empty() {
      let data = {
        current:1, 
        size:10,
        orgType:this.selValue,
        startTime:"",
        endTime:"",
      }
      this.time = [];
      this.current = 1;
      this.filefindByPage(data);
    },
    filefindByPage(data) {
      this.$api.http.updateListApi(data).then((res) => {
        this.tableData = res.data.records
        this.total = res.data.total
      });
    },
    modify(id,org){
      this.$router.push(
        `/contentManage/updateRecord/update?id=${id}&pj=${org}`
      )
    },
    remove(id){
      this.$api.http.updateDelApi({id}).then((res) => {
        if(res.code == 0){
          this.filefindByPage()
          this.$message.success("删除成功");
        }
      });
    },
    handleSizeChange(val) {
        this.size=val;
        let data = {
          current:1, 
          size:val,
          orgType:this.selValue,
        }
        this.filefindByPage(data)
    },
    handleCurrentChange(val) {
        this.current = val;
        let data = {
          current:val, 
          size:10,
          orgType:this.selValue,
        }
        this.filefindByPage(data)
    }
  },
};
</script>
<style lang="scss">
#updateList {
  width: 100%;
  min-height: 100%;
  padding: 15px;
  min-width: 1000px;
  padding-bottom: 100px;
  .app-top {
    width: 100%;
    background: #ffffff;
    box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.04);
    border-radius: 4px;
    padding-top: 15px;
    padding-bottom: 15px;
    .app-titel {
      width: 100%;
      display: flex;
      align-items: center;
      .div-lab {
        display: flex;
        margin: 5px;
      }
      .label {
        font-size: 14px;
        font-weight: 400;
        color: #32363d;
        line-height: 14px;
        margin-left: 15px;
        display: flex;
        align-items: center;
      }
      .toptimeqhuan {
        height: 30px;
        background: #ffffff;
        display: flex;
        align-items: center;
      }
      .toptimeqhuan div {
        padding-left: 20px;
        padding-right: 20px;
        text-align: center;
        line-height: 30px;
        font-size: 14px;
        margin-right: 15px;
        border-radius: 4px;
        border: 1px solid #e0e0e0;
      }
    }
  }
  .cen-tab{
  width: 100%;
  padding: 15px;
  background: #FFFFFF;
  margin-top: 15px;
}
}
</style>
