<!--
  @description: 短信日志
  @Modifier: 苏志刚
  @routerPath: /systemManagement/smsLog
  @date: 2020/9/1 13:45
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />短信日志
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <section :class="{ SearchContent_show: toggleSearchStatus }" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form ref="searchForm" :model="searchForm" inline>
            <!-- 短信号码 -->
            <el-form-item ref="phoneNumbers" label="短信号码" prop="phoneNumbers">
              <el-input v-model="searchForm.phoneNumbers" placeholder="请输入短信号码" />
            </el-form-item>
            <!-- 短信内容 -->
            <el-form-item ref="content" label="短信内容" prop="content">
              <el-input v-model="searchForm.content" placeholder="请输入短信内容" />
            </el-form-item>
            <!--发送状态-->
            <el-form-item ref="sendStatus" label="发送状态" prop="sendStatus">
              <el-select v-model="searchForm.sendStatus" placeholder="请选择">
                <el-option
                  v-for="item in sendStatusList"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <!--发送时间-->
            <el-form-item ref="date" label="发送时间" prop="date">
              <el-date-picker
                v-model="searchForm.sendStartTime"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="开始时间"
                style="width:15vw"
              />~
              <el-date-picker
                v-model="searchForm.sendEndTime"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="结束时间"
                style="width:15vw"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" size="small" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" size="small" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </section>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <section>
        <el-table ref="smallTable" v-loading="loading" :data="tableData">
          <el-table-column type="index" label="序号" width="60px" align="center" />
          <!-- 短信号码 template-->
          <el-table-column prop="phoneNumbers" header-align="center" align="left" label="短信号码" width="300" />
          <!-- 短信内容-->
          <el-table-column prop="content" align="left" header-align="center" label="短信内容" min-width="300" />
          <!-- 发送时间-->
          <el-table-column prop="sendTime" align="center" label="发送时间" width="200" />
          <!-- 发送状态 -->
          <el-table-column
            header-align="center"
            prop="useStatus"
            label="使用状态"
            align="center"
            width="150"
          >
            <template slot-scope="scope">
              <span
                v-for="(item, index) in sendStatusList"
                v-if="scope.row.sendStatus === item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
  </div>
</template>
<script>
/* 接口*/
import {
  getSmsList
} from '@/api/procurement/procurementCommonTools.js' // 短信配置模块接口文件
/* 公用方法*/
import { filterObj } from '@/assets/js/utils' // 常用方法
import { commonMxin } from '@/mixins/commonMxin'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'
import { procurementSmsMaintainGrounpMixins } from '../mixins/procurementSmsMaintainGrounpMixins'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
export default {
  name: 'SmsLogList',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin, procurementSmsMaintainGrounpMixins, commonMxin],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        sendStartTime: '', // 开始时间
        sendEndTime: '', // 结束时间
        sendStatus: '', // 发送状态 0成功 1失败
        phoneNumbers: '', // 短信号码
        content: '' // 短信内容
      },
      tableData: [] // 数据集合
    }
  },
  watch: {
  },
  created() {
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = this.getQueryParams() // 查询条件
      getSmsList(params)
        .then(response => {
          this.loading = false
          this.tableData = response.data.records
          this.paginationData.total = response.data.total
        })
        .catch(() => {})
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.searchForm.sendStartTime = ''
      this.searchForm.sendEndTime = ''
      this.$refs[formName].resetFields()
      // 获取列表信息
      this.loadData()
    }
  }
}
</script>
<style lang="less" scoped>
  .SearchContent_leftInput {
    width: calc(100% - 300px) !important;
  }
</style>
