<template>
  <div class="app-container">
    <div class="search-form">
      <el-form ref="searchForm" :model="queryParams" inline :label-width="'100px'">
        <el-form-item label="openId" prop="openId">
          <el-input v-model="queryParams.openId" type="text" placeholder="openId" />
        </el-form-item>
        <el-form-item :label="$t('ec.sms.status')" prop="status">
          <el-select v-model="queryParams.status">
            <el-option
              v-for="dict in $dictUtils.getDictList('sendStatus')"
              :key="dict.value"
              :value="dict.value"
              :label="dict.label"
              style="padding-left: 10px;"
            >{{ dict.label }}
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="searchItem" :label-width="'50px'">
          <el-button type="primary" @click="toolbarButtonClickEvent({'code':'refresh'})">{{ $t('ec.table.query') }}</el-button>
          <el-button type="default" @click="handleReset">{{ $t('ec.table.reset') }}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <vxe-grid
      ref="vxe"
      highlight-hover-row
      border
      resizable
      sync-resize
      auto-resize
      class="vxe-table-element"
      :loading="loading"
      :start-index="(page.currentPage - 1) * page.pageSize"
      :pager-config="page"
      :columns="columns"
      :data="tableData"
      @toolbar-button-click="toolbarButtonClickEvent"
      @page-change="handlePageChange"
    >
      <template v-slot:status="{row}">
        <span>{{ $dictUtils.getDictLabel('sendStatus', row.status, row.status) }}</span>
      </template>
      <template v-slot:operation="{ row }">
        <el-button size="mini" type="danger" @click="remove(row.id)">{{ $t('ec.table.del') }}</el-button>
      </template>

    </vxe-grid>

  </div>
</template>

<script>
import mixin from 'ecip-web/utils/common-mixin'
import { getData, remove } from 'ecip-web/api/vue/wx/weixinSendLogApi'

export default {
  name: 'ModulesWeiXinSendLogView',
  components: {},
  mixins: [...mixin],
  data() {
    return {
      tableToolbar: {
        id: 'modules.wx.wxSendLogView-toolbar',
        // buttons: [
        //   { code: 'remove', name: this.$t('ec.table.delete'), visible: this.checkPermission(['smsSendLog:remove']) },
        //   { code: 'search', name: this.$t('ec.table.search') },
        //   { code: 'refresh', name: this.$t('ec.table.refresh') }
        // ],
        slots: {
        },
        export: true, // 导出按钮
        zoom: true, // 最大化按钮
        // 列宽操作记录
        resizable: {
          storage: true
        },
        // 列操作记录
        setting: {
          storage: true
        }
      },
      showSearch: false,
      loading: false,
      page: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
        align: 'left',
        pageSizes: [10, 20, 50, 100, 200, 500],
        layouts: ['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total'],
        perfect: true
      },
      tableData: [],
      columns: [
        { type: 'seq', width: 60, fixed: 'left', align: 'center' },
        { title: 'openId', key: 'openId', field: 'openId', minWidth: 100, showOverflow: true },
        { title: 'ec.wx.sendData', key: 'sendData', field: 'sendData', width: 400, showOverflow: true },
        { title: 'ec.sms.status', key: 'status', field: 'status', width: 80, showOverflow: true, slots: { default: 'status' }},
        { title: 'ec.sms.responseDate', key: 'updateDate', field: 'updateDate', minWidth: 100, showOverflow: true },
        { title: 'ec.table.createDate', key: 'createDate', field: 'createDate', minWidth: 100, showOverflow: true },
        { title: 'ec.table.remarks', key: 'remarks', field: 'remarks', minWidth: 200, showOverflow: true }
        /* { title: 'ec.table.actions', width: 150, fixed: 'right', align: 'center', slots: { default: 'operation' }}*/
      ],
      queryParams: {
        openId:'',
        status:''
      }
    }
  },
  created() {
    console.log(this.$dictUtils.getDictList('sendStatus'))
    this.getData()
  },
  methods: {
    toolbarButtonClickEvent({ code }, event) {
      switch (code) {
        case 'remove':
          this.remove()
          break
        case 'search':
          this.showSearch = !this.showSearch
          break
        case 'refresh':
          this.page.currentPage = 1
          this.getData()
          break
      }
    },
    getData() {
      this.loading = true
      getData(Object.assign({}, { size: this.page.pageSize, current: this.page.currentPage }),
        this.queryParams).then(res => {
        const data = res.data
        this.tableData = data.records
        this.page.total = data.total
        this.loading = false
      }).catch(e => {
        this.loading = false
      })
    },
    handlePageChange({ currentPage, pageSize }) {
      this.page.currentPage = currentPage
      this.page.pageSize = pageSize
      this.getData()
    },
    remove(id) {
      const deleteIds = []
      if (id) {
        deleteIds.push(id)
      } else {
        this.$refs.vxe.getSelectRecords().forEach(row => {
          const id = row.id
          deleteIds.push(id)
        })
      }
      if (deleteIds.length > 0) {
        this.$confirm(this.$t('ec.message.delConfirm'), this.$t('ec.message.prompt'), {
          confirmButtonText: this.$t('ec.message.confirm'),
          cancelButtonText: this.$t('ec.message.cancel'),
          type: 'warning'
        }).then(() => {
          remove(deleteIds).then(res => {
            this.getData()
            this.$notify.success(this.$t('ec.message.delSuccess'))
          })
        }
        )
      } else {
        this.$message({
          message: this.$t('ec.message.selectEmpty'),
          type: 'warning'
        })
      }
    },
    handleSearch() {
      this.getData()
    },
    handleReset() {
      this.$refs['searchForm'].resetFields()
      this.toolbarButtonClickEvent({'code': 'refresh'})
    }
  }
}
</script>

<style scoped>

</style>
