<template>
  <div class="sms-message-page">
    <Card>
      <div class="search-con">
        <Input placeholder="请输入消息编号" class="search-input" v-model="searchContent.keyWord" style="width: 200px"/>
        <Input placeholder="请输入消息关键字" class="search-input" v-model="searchContent.smsNo" style="width: 200px"/>
        <ButtonGroup class="search-btngroup">
          <Button type="primary" style="margin-left: 20px" @click="handleSearch">查找</Button>
          <Button type="primary" @click="handleRefresh">
            <Icon type="md-refresh" />
          </Button>
        </ButtonGroup>
        <Button type="info" style="margin-left: 20px" @click="handleAdd">+ 发送SMS</Button>
      </div>
      <tables
        ref="tables"
        editable
        pagable
        v-model="tableData"
        :columns="columns"
        :currentPage="searchContent.pageNum"
        :pageSize="searchContent.pageSize"
        :totalSize="totalSize"
        :loading="loading"
        @on-change="handleCurrentChange"
      />
    </Card>
  </div>
</template>
<script>
import Tables from '_c/tables'
import { formatTime } from '@/libs/tools'
export default {
  inject: ['reload'],
  components: {
    Tables
  },
  data () {
    return {
      searchContent: {
        keyWord: '',
        smsNo: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      columns: [
        { title: '编号', type: 'index', align: 'left', minWidth: 180 },
        { title: '消息', key: 'message', align: 'center', minWidth: 180 },
        { title: '收信人', key: 'index', align: 'center', minWidth: 150 },
        { title: '发送时间', key: 'index', align: 'center', minWidth: 150 },
        { title: '状态', key: 'index', align: 'center', minWidth: 100 },
        { title: '操作',
          key: 'index',
          align: 'center',
          minWidth: 120,
          render: (h, params) => {
            let sendNowBtn = h(
              'Button',
              {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                on: {
                  click: this.handleSendNow(params.row)
                },
                style: {
                  marginRight: '5px'
                }
              },
              '立即发送'
            )
            let reSendBtn = h(
              'Button',
              {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                on: {
                  click: this.handleReSend(params.row)
                },
                style: {
                  marginRight: '5px'
                }
              },
              '重 发'
            )
            let deleteBtn = h(
              'Button',
              {
                props: {
                  type: 'error',
                  size: 'small'
                },
                on: {
                  click: this.handleDelete(params.row)
                },
                style: {
                  marginRight: '5px'
                }
              },
              '删 除'
            )
            return h('div', [sendNowBtn, reSendBtn, deleteBtn])
          }
        }
      ],
      loading: false,
      totalSize: 0
    }
  },
  methods: {
    requestData () {
      this.loading = true
      this.api({
        apiName: 'getSmsList',
        postdata: this.searchContent,
        complete: () => {
          this.loading = false
        },
        success: (res) => {
          this.tableData = res.data.records
          this.totalSize = res.data.total
        }
      })
    },
    handleSearch () {
      this.reload()
    },
    handleAdd () {

    },
    handleCurrentChange () {

    },
    handleSendNow (row) {
      return () => {

      }
    },
    handleReSend (row) {
      return () => {

      }
    },
    handleDelete (row) {
      return () => {

      }
    }
  },
  created () {
    this.requestData()
  }
}
</script>
<style scoped lang="less">
.sms-message-page .search-con {
  display: flex;
  padding: 10px 0;
  .search-input {
    width: 300px;
    margin-right: 10px;
  }
}
</style>
