<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.message_alert") }}
        </el-breadcrumb-item>
      </el-breadcrumb>

      <template slot="top">
        <div class="top_fliter">
          <show-more-filter class="filter_list">
            <div class="filter_item">
              <span class="filter_title">消息模板名称：</span>
              <el-input
                v-model="topFilter.name"
                placeholder="请输入消息模板名称"
              ></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-select>
            </div>
            <div class="filter_item">
              <span class="filter_title">推送时间：</span>
              <el-date-picker
                v-model="topFilter.push_time"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </div>
          </show-more-filter>
          <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";
import showMoreFilter from "@/components/show-more-filter";

export default {
  components: {
    apassList,
    apassDialog,
    showMoreFilter,
  },
  data: () => ({
    listHeader: [],
    listData: [],
    listTotal: 0,
    dialogInfo: {
      msg: "",
      submit: null,
    },
    topFilter: {
      name: "",
      state: "",
      push_time: "",
    },
    tempFilter: null,
  }),
  created() {
    this.listHeader = [
      {
        label: "",
        prop: "state",
        type: "image-tooltip",
        getImage(item) {
          return item.state == 1
            ? require("@/assets/imgs/ic_true.png")
            : require("@/assets/imgs/ic_failed.png");
        },
        getTooltip(item) {
          return item.state == 1 ? "推送成功" : "推送失败";
        },
        align: "center",
        width: 60,
      },
      {
        label: "推送流水号",
        prop: "push_num",
        width: 240,
      },
      {
        label: "消息模板名称",
        prop: "name",
        type: "button",
        callback: this.detailAction,
        width: 300,
      },
      {
        label: "消息详情",
        prop: "detail",
      },
      {
        label: "接收用户",
        prop: "users",
        getText(item) {
          let users = item.users || [];

          return users.join("，");
        },
        width: 300,
      },
      {
        label: "推送时间",
        prop: "push_time",
        getText(item) {
          let date = item.push_time || "";
          return helper.dateStringTransform(date);
        },
        align: "center",
        width: 180,
      },
    ];
  },
  methods: {
    initList(filter) {
      let fullFilter = {
        ...filter,
        ...this.topFilter,
      };

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

      console.log(fullFilter);

      this.listTotal = 55;
      this.listData = [
        {
          state: 1,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["张三", "李四", "王五"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 1,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["杨过", "小龙女", "冯宝宝"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 1,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["张三", "李四", "王五"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["杨过", "小龙女", "冯宝宝"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["杨过", "小龙女", "冯宝宝"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 1,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["张三", "李四", "王五"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 1,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["杨过", "小龙女", "冯宝宝"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 1,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["张三", "李四", "王五"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["杨过", "小龙女", "冯宝宝"],
          push_time: "2020-07-18T14:25:09+08:00",
        },
        {
          state: 0,
          push_num: "propelling2020001",
          name: "服务定向推送的消息",
          detail:
            "亲爱的用户，根据您的服务调用情况，我们向您推荐地图视频融合服务，欢迎使用！",
          users: ["杨过", "小龙女", "冯宝宝"],
          push_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: "",
        push_time: "",
      };

      this.initList(this.tempFilter);
    },
    showDialog() {
      this.$refs.dialog.show();
    },
    addNew() {
      console.log("新建模板");
    },
    detailAction(item) {
      console.log(`查看${item.name}`);
    },
  },
};
</script>

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