<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-news__checkrecords}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataListSearch()">
          <el-form-item label="用户名" prop="name" label-width="90px">
            <el-input v-model="dataForm.name" placeholder="用户名" clearable maxlength="10" @keyup.native="btKeyUpName" style="width:200px"></el-input>
          </el-form-item>
          <el-form-item label="内容" prop="content" label-width="90px">
            <el-input v-model="dataForm.content" placeholder="内容" clearable maxlength="20" @keyup.native="btKeyUpContent" style="width:200px"></el-input>
          </el-form-item>
          <el-form-item label="功能模块" prop="module" label-width="90px">
            <el-input v-model="dataForm.module" placeholder="功能模块" clearable maxlength="10" @keyup.native="btKeyUpModule" style="width:200px"></el-input>
          </el-form-item>
          <el-form-item label="手机号" prop="mobile" label-width="90px">
            <el-input v-model="dataForm.mobile" placeholder="手机号" clearable maxlength="10" @keyup.native="btKeyUpMobile" style="width:200px"></el-input>
          </el-form-item>
          <el-form-item label="审核状态" prop="suggestion" label-width="90px">
            <el-select v-model="dataForm.suggestion" placeholder="请选择" clearable style="width:200px">
              <el-option v-for="item in suggestionList" :key="item.code" :label="item.description" :value="item.code" >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="系统状态" prop="decision" label-width="90px">
            <el-select v-model="dataForm.systemStatus" placeholder="请选择" clearable>
              <el-option label="正常" value="0"> </el-option>
              <el-option label="异常" value="1"> </el-option>
            </el-select>
          </el-form-item>

        <el-form-item label="时间"
                      prop="startTime" label-width="90px">
          <el-date-picker v-model="dataForm.startTime"
                          type="date"
                          :picker-options="pickerBeginDateBefore"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="至"
                      label-width="25px"
                      prop="endTime">
          <el-date-picker v-model="dataForm.endTime"
                          type="date"
                          :picker-options="pickerBeginDateAfter"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getDataListSearch()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('news:checkrecords:save')" type="success" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('news:checkrecords:delete')" 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 label="序号" header-align="center" align="center" width="50px">
          <template slot-scope="scope">
            {{scope.$index+1}}
          </template>
        </el-table-column>
<!--        <el-table-column prop="id" label="ID" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="userId" label="用户ID" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="name" label="用户名称" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mobile" label="手机号" header-align="center" align="center" width="120"></el-table-column>
        <el-table-column prop="category" label="工作类别" header-align="center" align="center"></el-table-column>
       <el-table-column prop="module" label="功能模块" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="content" label="内容" header-align="center" align="center" min-width=400 show-overflow-tooltip></el-table-column>
        <el-table-column prop="suggestion" label="审核状态" header-align="center" align="center"></el-table-column>
        <el-table-column prop="label" label="检测结果分类" header-align="center" align="center" width="120"></el-table-column>
        <el-table-column prop="system" label="系统状态" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createdTime" label="提交时间" header-align="center" align="center" width=180></el-table-column>
        <el-table-column prop="auditTime" label="审核时间" header-align="center" align="center" width=180></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="scope.row.suggestionCode==='review'" type="text" size="small" @click="openHandle(scope.row.id)">{{ '审核' }}</el-button>
            <el-button  type="text" size="small" @click="selectDetails(scope.row.id)">{{ '查看详情' }}</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>
      <checkrecords-handle v-if="handleVisible" ref="checkrecordsHandle" @refreshDataList="getDataList"></checkrecords-handle>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './checkrecords-add-or-update'
import CheckrecordsHandle from './checkrecords-handle'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/contentSecurity/checkrecords/page',
        getDataListIsPage: true,
        deleteURL: '/contentSecurity/checkrecords',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        content:'',
        name:'',
        module:'',
        startTime:'',
        endTime:'',
        suggestionCode:'',
        systemStatus:''
      },
      suggestionList:[],
      handleVisible:false,
      pickerBeginDateBefore: {
        disabledDate: (time) => {
          let beginDateVal = this.dataForm.endTime;
          if (beginDateVal) {
            return time.getTime() > new Date(beginDateVal + ' 00:00:00').getTime()
          }
        }
      },
      pickerBeginDateAfter: {
        disabledDate: (time) => {
          let EndDateVal = this.dataForm.startTime;
          if (EndDateVal) {
            return time.getTime() < new Date(EndDateVal + ' 00:00:00').getTime()
          }
        }
      }
    }
  },
  components: {
    AddOrUpdate,
    CheckrecordsHandle
  },
  created: function () {
    this.getDataList()
    this.getSuggestionInfo('check_state')
  },
  methods:{
    btKeyUpName (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '');
      this.dataForm.name = e.target.value
    },
    btKeyUpMobile (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '');
      this.dataForm.mobile = e.target.value
    },
    btKeyUpModule (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '');
      this.dataForm.module = e.target.value
    },
    btKeyUpContent (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '');
      this.dataForm.content = e.target.value
    },
    selectDetails (id) {
      this.$parent.selectComponent = 'CheckrecordsDetail'
      this.$router.push({ path: '/contentSecurity-checkrecordsroute', query: { id: id} })
    },
    // 获取审核状态下拉信息
    getSuggestionInfo (type) {
      this.$http.get(`/contentSecurity/checkcode/getResourcesByType?type=` + type).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.suggestionList = res.data
      }).catch(() => {})
    },
    openHandle (id) {
      this.handleVisible = true
      this.$nextTick(() => {
        this.$refs.checkrecordsHandle.dataForm.id = id
        this.$refs.checkrecordsHandle.init()
      })
    }
  }
}
</script>
