<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-message__smslog}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="dataForm.mobile" placeholder="手机号" clearable></el-input>
      </el-form-item>
          <el-form-item label="发送状态" prop="status">
            <el-select v-model="dataForm.status" placeholder="发送状态" clearable>
              <el-option v-for="item in statusArr" :key="item.dictValue" :label="item.dictName" :value="item.dictValue" >
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="平台类型" prop="platform">
            <el-select v-model="dataForm.platform" placeholder="平台类型" clearable>
              <el-option v-for="item in platformArr" :key="item.dictValue" :label="item.dictName" :value="item.dictValue" >
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <!-- <el-button v-if="$hasPermission('message:smslog:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button> -->
          <el-button v-if=false type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if=false type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="mobile" label="手机号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="params1" label="参数1" header-align="center" align="center"></el-table-column>
        <el-table-column prop="params2" label="参数2" header-align="center" align="center"></el-table-column>
        <el-table-column prop="params3" label="参数3" header-align="center" align="center"></el-table-column>
        <el-table-column prop="params4" label="参数4" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="发送状态" header-align="center" align="center" :formatter="showStatus"></el-table-column>
        <el-table-column prop="platform" label="平台类型" header-align="center" align="center" :formatter="showPlatform"></el-table-column>
        <el-table-column prop="createdTime" label="创建时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updatedTime" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="smslogDetailHandle(scope.row.id)">查看</el-button>
            <el-button v-if="$hasPermission('message:smslog:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('message:smslog:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <!--查看-->
      <smslog-detail v-if="smslogDetailVisible" ref="smslogDetail" @refreshDataList="getDataList"></smslog-detail>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './smslog-add-or-update'
import smslogDetail from './smslog-detail'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/message/smslog/page',
        getDataListIsPage: true,
        deleteURL: '/message/smslog',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      },
      statusArr: [
        { dictValue: 1, dictName: '成功' },
        { dictValue: 0, dictName: '失败' }
      ],
      platformArr: [
        { dictValue: 1, dictName: '阿里云' },
        { dictValue: 2, dictName: '腾讯云' }
      ],
      smslogDetailVisible: false
    }
  },
  components: {
    AddOrUpdate,
    smslogDetail
  },
  methods: {
    showStatus (row, column) {
      if (row.status === 0) {
        return '失败'
      } else {
        return '成功'
      }
    },
    showPlatform (row, column) {
      if (row.platform === 1) {
        return '阿里云'
      } else {
        return '腾讯云'
      }
    },
    smslogDetailHandle (smslogId) {
      this.smslogDetailVisible = true
      this.$nextTick(() => {
        this.$refs.smslogDetail.dataForm.id = smslogId
        this.$refs.smslogDetail.init()
      })
    }
  }
}
</script>
