<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="searchDate"
        :picker-options="pickerOptions"
        class="filter-item"
        type="daterange"
        format="yyyy年MM月dd日"
        value-format="yyyy-MM-dd"
        align="left"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
       <el-input v-model="receiveNumber" placeholder="请输入接收号码" class="filter-item"></el-input>
       <el-input v-model="name" placeholder="请输入批次名称" class="filter-item"></el-input>
      <el-button type='primary' @click="btn_search">搜索</el-button>
    </div>
    <el-table v-loading="loading" :data="dataLists" border stripe >
      <el-table-column type="index" label="编号" align="center" fixed width="80" />
      <el-table-column prop="F_Name" label="批次名称" align="center" min-width="140" />
      <el-table-column prop="F_Content" label="短信内容" align="center" min-width />
      <el-table-column prop="F_Tel" label="接收号码" align="center" />
      <el-table-column label="发送状态" align="center" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.F_State==1" type="success">成功</el-tag>
          <el-tag v-else-if="scope.row.F_State==2" type="danger">失败</el-tag>
          <el-tag v-else>未发送</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="F_AddTime" label="添加时间" align="center" />
      <el-table-column prop="F_AddUserName" label="添加人" align="center" />
      <!-- <el-table-column label="操作" width="120" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button v-permission="'HY_delete'" size="mini" plain type="danger" @click="btn_delete(scope.row.F_Id)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getSMSLists,deleteSMS } from "@/api/noteManagement/noteList";
import { pickerOptions } from "@/utils";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装

export default {
  components: {
    Pagination
  },
  filters: {
    OrderTextFilter(status) {
      const statusMap = {
        0: "暂时",
        1: "永久",
        2: "已取消"
      };
      return statusMap[status];
    }
  },
  data() {
    return {
      loading: false,
      searchDate: "", // 日期
      pickerOptions, // 日期数据
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      receiveNumber: '', // 接收号码
      name: '', // 批次名称
    };
  },
  created() {
    this.getList();
    document.onkeyup = e => {
      if (e.keyCode === 13) {
        this.getList();
      }
    };
  },
  methods: {
    getList() {
      this.loading = true;
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize, // int 每页几条信息
          F_Name: this.name, 
          F_Tel: this.receiveNumber, 
          SearchStartTime: this.searchDate && this.searchDate[0], // 开始时间
          SearchEndTime: this.searchDate && this.searchDate[1], // 结束时间
        };
        getSMSLists(params).then(response => {
          this.loading = false;
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.data.Totals;
            this.dataLists = response.data.Rows;
          }
        });
        resolve();
      });
    },
    btn_search() {
      this.pageParams.pageindex = 1;
      this.getList();
    },
     btn_delete(editId) {
      this.$confirm('您确定要将此短信信息删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteSMS(editId).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    handleChange(value) {
      console.log(value);
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
span{
  font-size: 14px;
}

</style>
