<template>
  <div class="list_container">
    <apass-list
      ref="list"
      :list-header="listHeader"
      :list-data="listData"
      :list-total="listTotal"
      :hide-search="true"
      :list-padding-left="0"
      @list-action="initList"
    >
      <el-breadcrumb separator="/" slot="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/message' }">
          {{ $t("lang.message") }}
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          {{ $t("lang.banner") }}
        </el-breadcrumb-item>
      </el-breadcrumb>

      <template slot="top">
        <div class="top_fliter">
          <div class="filter_list">
            <div class="filter_item">
              <span class="filter_title">banner搜索：</span>
              <el-input
                v-model="topFilter.name"
                placeholder="请输入banner关键词"
              ></el-input>
            </div>
            <div class="filter_item">
              <span class="filter_title">状态：</span>
              <el-select v-model="topFilter.state" placeholder="请选择">
                <el-option label="全部" value=""> </el-option>
                <el-option label="已上架" value="1"> </el-option>
                <el-option label="已下架" value="0"> </el-option>
                <el-option label="已过期" value="-1"> </el-option>
              </el-select>
            </div>
            <div class="filter_item">
              <span class="filter_title">上架时间：</span>
              <el-date-picker
                v-model="topFilter.up_time"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </div>
            <div class="filter_item">
              <span class="filter_title">下架时间：</span>
              <el-date-picker
                v-model="topFilter.down_time"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </div>
          </div>
          <div class="filter_action apass_button">
            <el-button type="primary" @click="topFilterAction">
              查询
            </el-button>
            <el-button type="defalut" @click="topFilterClear">
              重置
            </el-button>
          </div>
        </div>
      </template>

      <el-button type="primary" @click="addNew" slot="header-left">
        新建
      </el-button>
    </apass-list>

    <apass-dialog
      ref="dialog"
      :msg="dialogInfo.msg"
      :submit="dialogInfo.submit"
    ></apass-dialog>
  </div>
</template>

<script>
import helper from "@/services/helper.js";
import apassList from "@/components/apass-list";
import apassDialog from "@/components/apass-dialog";

export default {
  components: {
    apassList,
    apassDialog,
  },
  data: () => ({
    listHeader: [],
    listData: [],
    listTotal: 0,
    dialogInfo: {
      msg: "",
      submit: null,
    },
    topFilter: {
      name: "",
      state: "",
      up_time: "",
      down_time: "",
    },
    tempFilter: null,
  }),
  created() {
    this.listHeader = [
      {
        label: "",
        prop: "state",
        type: "image-tooltip",
        getImage(item) {
          return [
            require("@/assets/imgs/ic_guoqi.png"),
            require("@/assets/imgs/ic_failed.png"),
            require("@/assets/imgs/ic_true.png"),
          ][item.state + 1];
        },
        getTooltip(item) {
          return ["已过期", "已下架", "已上架"][item.state + 1];
        },
        align: "center",
        width: 60,
      },
      {
        label: "排序",
        prop: "index",
        width: 60,
        align: "center",
      },
      {
        label: "banner编码",
        prop: "code",
        width: 180,
      },
      {
        label: "banner名称",
        prop: "name",
        type: "button",
        callback: this.detailAction,
        width: 240,
      },
      {
        label: "链接地址",
        prop: "url",
      },
      {
        label: "图片大小",
        prop: "size",
        getText(item) {
          let value = item.size || 0;
          return (value / 1024).toFixed(2) + "KB";
        },
        width: 100,
      },
      {
        label: "上架时间",
        prop: "up_time",
        getText(item) {
          let date = item.up_time || "";
          return helper.dateStringTransform(date);
        },
        align: "center",
        width: 180,
      },
      {
        label: "下架时间",
        prop: "down_time",
        getText(item) {
          let date = item.down_time || "";
          return helper.dateStringTransform(date);
        },
        align: "center",
        width: 180,
      },
      {
        label: "操作",
        type: "buttons",
        align: "center",
        width: 320,
        actionList: [
          {
            label: "编辑",
            callback: this.editAction,
          },
          {
            label: "上架",
            callback: this.upAction,
          },
          {
            label: "下架",
            callback: this.downAction,
          },
          {
            label: "删除",
            class: "warn",
            callback: this.deleteAction,
          },
        ],
      },
    ];
  },
  methods: {
    initList(filter) {
      let fullFilter = {
        ...filter,
        ...this.topFilter,
      };

      this.tempFilter = filter; // filter存档，用于页面刷新

      console.log(fullFilter);

      this.listTotal = 55;
      this.listData = [
        {
          state: 1,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: -1,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: -1,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 1,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: -1,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: -1,
          index: "01",
          code: "BN202004542001",
          name: "多元数据可视化分析宣传图片",
          url: "https://apaasgis.wodcloud.com/portal",
          size: 131072,
          up_time: "2020-07-18T14:25:09+08:00",
          down_time: "2020-07-18T14:25:09+08:00",
        },
      ];

      /* this.$http
        .get("/apaas/service/v3/resource/apply/approveList", {
          params: {
            search: filter.keyword,
            page: filter.page,
            limit: filter.size,
            state: filter.state,
          },
        })
        .then(({ data }) => {
          if (data.success == 1) {
            this.listTotal = data.total;
            this.listData = data.data;
          } else {
            this.$message({
              message: data.errMsg || "获取列表失败",
              type: "warning",
            });
          }
        })
        .catch((error) => {
          console.log(error);
        }); */
    }, // TODO: 列表待调试
    topFilterAction() {
      this.initList(this.tempFilter);
    },
    topFilterClear() {
      this.topFilter = {
        name: "",
        state: "",
        up_time: "",
        down_time: "",
      };

      this.initList(this.tempFilter);
    },
    showDialog() {
      this.$refs.dialog.show();
    },
    addNew() {
      console.log("新建模板");
    },
    editAction(item) {
      console.log(`编辑${item.name}`);
    },
    upAction(item) {
      console.log(`上架${item.name}`);
    },
    downAction(item) {
      console.log(`下架${item.name}`);
    },
    deleteAction(item) {
      console.log(`删除${item.name}`);
    },
  },
};
</script>

<style scoped>
.list_container {
  height: 100%;
}
</style>
