<template>
  <div class='main-content'>
    <baseTable
      ref='systemSmsLogTable'
      :tableHeader='tableHeader'
      :tableData='tableData'
      :searchParams='searchParams'
      @searchFn='searchFn'
      @resetFn='resetFn'
      :moreOperation='false'
      :addBtn='false'
    >
      <template slot='search'>
        <el-form-item label='手机号'>
          <el-input v-model.trim='searchParams.mobile' />
        </el-form-item>
        <el-form-item label='内容关键字'>
          <el-input v-model.trim='searchParams.content' />
        </el-form-item>
      </template>
    </baseTable>
  </div>
</template>

<script>
import {
  fetchSystemSmsLogPage
} from '@api/upms/sms-log';
import dateUtil from '@utils/dateUtil';

export default {
  name: 'SystemSmsLog',
  components: {},
  data() {
    return {
      tableHeader: [
        {
          label: '手机号',
          prop: 'mobile',
          width: 150,
          align: 'center'
        },
        {
          label: '发送内容',
          prop: 'content',
          align: 'center'
        },
        {
          label: '发送结果',
          prop: 'result',
          align: 'center'
        },
        {
          label: '发送时间',
          prop: 'createTime',
          align: 'center',
          type: 'render',
          render: (h, params) => {
            let date = dateUtil.stringToDate(params.row.createTime);
            return h('span', dateUtil.dateToString(date, 's', false));
          }
        }
      ],
      tableData: [],
      defaultSearch: {},
      searchParams: Object.assign({}, this.$search),
      uploadParams: {}
    };
  },
  methods: {
    searchFn(isReset = false) {
      let vm = this;
      if (isReset) {
        vm.searchParams = Object.assign(vm.searchParams, vm.$search);
      }
      fetchSystemSmsLogPage(vm.searchParams).then(
        (res) => {
          vm.tableData = res.data.records;
          vm.searchParams.total = res.data.total;
        },
        (error) => {
          vm.$notify.error({
            title: error.data.msg,
            message: error.data.data
          });
        }
      );
    },
    resetFn() {
      let vm = this;
      vm.searchParams = Object.assign({}, vm.defaultSearch, this.$search);
      vm.searchFn();
    }
  },
  created() {
    this.searchFn();
  }
};
</script>

<style scoped type='less'></style>
