<template>
  <div id="main" class="h-all">
    <el-container class="h-all">
      <el-header height="auto">
        <div class="header-button-box">
          <el-button v-if="createAndCopyCommand.visible" size='mini' icon="el-icon-circle-plus-outline" type="primary"
                     @click="createCollectTaskeInit">
            {{$t("common.createBtn")}}
          </el-button>
          <el-button v-if="deleteCommand.visible" size='mini' icon="el-icon-delete" type="danger"
                     @click="deleteCollectTaskInit">
            {{$t("common.deleteBtn")}}
          </el-button>
          <el-button v-if="createAndCopyCommand.visible" size='mini' icon="el-icon-video-play" type="success"
                     @click="startCollectTaskInit">
            {{$t("common.start")}}
          </el-button>
          <el-button v-if="createAndCopyCommand.visible" size='mini' icon="el-icon-video-pause" type="warning"
                     @click="stopCollectTaskInit">
            {{$t("common.stop")}}
          </el-button>
          <div class="search">
            <div class="search-div">
              <label>{{$t('CollectTask.taskName')}}：</label>
              <el-input size='mini' :placeholder="$t('common.placeholder')"
                        v-model="querySelectTaskName"
                        style="width: 180px"
                        clearable>
              </el-input>
            </div>
            <div class="search-div">
              <label>{{$t('CollectTask.taskStatus')}}：</label>
              <el-select v-model="querySelectStatus" size="mini" :placeholder="$t('common.selectOption')" :clearable="true">
                <el-option
                  v-for="item in StatusList"
                  :key="item.key"
                  :label="item.label"
                  :value="item.key">
                </el-option>
              </el-select>
            </div>
            <div class="search-div">
              <el-button icon="el-icon-search" type="primary" size = 'mini' @click="queryCollectTaskDataByCondition">{{$t('common.queryBtn')}}</el-button>
            </div>
          </div>
        </div>
      </el-header>
      <!-- table数据表格 -->
      <el-main class="adapt-height-box">
        <el-table
          :empty-text="$t('common.noData')"
          tooltip-effect="dark"
          ref="singleTable"
          :data="collectTaskList"
          stripe
          header-row-class-name="table-header"
          cell-class-name="table-cell"
          class="adapt-height"
          height="auto"
          border
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="28">
          </el-table-column>
          <el-table-column
            prop="performTaskName"
            :label="$t('CollectTask.taskName')">
          </el-table-column>
          <el-table-column
            prop="subnetName"
            :label="$t('CollectTask.subnet')">
          </el-table-column>
          <el-table-column
            prop="description"
            :show-overflow-tooltip="true"
            :label="$t('CollectTask.description')">
          </el-table-column>
          <el-table-column
            prop="performTemplateName"
            :label="$t('CollectTask.indexTemplate')">
          </el-table-column>
          <el-table-column
            prop="period"
            :label="$t('CollectTask.monitorPeriod1')">
          </el-table-column>
          <el-table-column
            prop="monitorType"
            :formatter="formatMonitorType"
            :label="$t('CollectTask.monitorType')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="monitorObjectName"
            :label="$t('CollectTask.monitorObject')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            width="75px"
            :label="$t('CollectTask.taskStatus')">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                :active-value=0
                :inactive-value=1
                @change="changeStatus(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column
            prop="startTime"
            width="140"
            :label="$t('CollectTask.startTime')"
            :formatter="formatterTime">
          </el-table-column>
          <el-table-column
            prop="endTime"
            width="140"
            :label="$t('CollectTask.endTime')"
            :formatter="formatterEndTime">
          </el-table-column>
          <el-table-column
            width="205px"
            v-if="createAndCopyCommand.visible"
            :label="$t('common.operation')">
            <template slot-scope="scope">
              <el-button
                size="mini"
                style="background: #53D214"
                :title="$t('common.viewHistoryData')"
                @click="handleViewHistoryData(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-chakan"></use>
                </svg>
              </el-button>
              <el-button
                size="mini"
                style="background: #53D214"
                :title="$t('common.viewIndexTemplateDetail')"
                @click="handleViewIndexTemplateDetail(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-chakan"></use>
                </svg>
              </el-button>
<!--              <el-button-->
<!--                size="mini"-->
<!--                style="background: #53D214"-->
<!--                :title="$t('common.viewTaskDetail')"-->
<!--                @click="handleView(scope.row)">-->
<!--                <svg class="icon" aria-hidden="true">-->
<!--                  <use xlink:href="#icon-chakan"></use>-->
<!--                </svg>-->
<!--              </el-button>-->
              <el-button
                size="mini"
                style="background: #175BE3"
                :title="$t('common.copyBtn')"
                @click="handleCopy(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-fuzhi"></use>
                </svg>
              </el-button>
              <el-button
                size="mini"
                style="background: #008000"
                :title="$t('common.updateBtn')"
                @click="handleUpdate(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-bianji"></use>
                </svg>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-main>
    </el-container>
    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
  </div>
</template>

<script>
import CommandExecuteContext from '../../commands/CommandExecuteContext'
import CollectTaskCommands from '../../commands/CollectTaskCommands'
import CollectTaskService from '../../domain/services/CollectTaskService'
import DeviceService from '@/domain/services/DeviceService'
import SubnetService from '@/domain/services/SubnetService'
import HelperUtil from '../../utils/HelperUtil'
import loading from '../../utils/Loading'
import IndexTeplateService from '../../domain/services/IndexTeplateService'
import PerformanceDataQuaryService from "../../domain/services/PerformanceDataQuaryService";

export default {
  name: 'CollectTask',

  components: {
    CommandExecuteContext
  },
  created: function () {
    this.getAllSubnetInit()
    this.getAllDeviceModel()
    this.getAllIndexTemplate()
    this.queryInit()
  },
  // 存放数据
  data: function () {
    return {
      // 命令
      commandContext: {},
      // 为修改传参数
      multipleSelection: [],
      createAndCopyInitList: {},
      deleteList: [],
      copyInitList: {},
      updateInitList: {},
      showInitList: {},

      collectTaskList: [],
      performList: [],

      // form参数
      formLabelWidth: '120px',
      labelPosition: 'right',
      querySelectTaskName: '',
      querySelectStatus: '',
      selectList: [],
      deviceModelList: [],
      StatusList: [
        {
          key: '0',
          label: this.$t('common.inUse')
        },
        {
          key: '1',
          label: this.$t('common.outUse')
        }
      ],
      // 双向绑定展示数据
      subnetList: [],
      indexTemplateList: [],
      beginItem: 1,
      endItem: 100,
      total: 100,
      currentPage: 1,
      pageSize: 100
    }
  },

  computed: {
    createAndCopyCommand () {
      return CollectTaskCommands.createAndCopyCommand(this.createAndCopyTitle, this.createAndCopyInitList, this.commandContext)
    },
    copyCommand () {
      return CollectTaskCommands.copyCommand(this.copyInitList, this.commandContext)
    },
    deleteCommand () {
      return CollectTaskCommands.deleteCollecTaskCommand(this.deleteList, this.commandContext)
    },
    updateCommand () {
      return CollectTaskCommands.updateCollectTaskCommand(this.updateInitList, this.commandContext)
    },
    viewCommand () {
      return CollectTaskCommands.showCollectTaskDetailCommand(this.showList, this.commandContext)
    },
    openTab () {
      return this.$store.state.openTab
    },
    activeIndex: {
      get () {
        return this.$store.state.activeIndex
      },
      set (val) {
        this.$store.commit('set_active_index', val)
      }
    }
  },

  methods: {
    /**
     * @Description  : chuangjian
     * @author       : ls
     * @date         : 2020/5/26 14:41
     * @param        :
     * @return       :
     */
    createCollectTaskeInit () {
      this.createAndCopyTitle = this.$t('CollectTaskCommands.createCollectTask')
      this.createAndCopyCommand.execute()
    },
    /**
     * @Description  : shanchu
     * @author       : ls
     * @date         : 2020/4/26 15:01
     * @param        :
     * @return       :
     */
    deleteCollectTaskInit () {
      if (this.multipleSelection.length === 0) {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.DELETE_SELECT_CODE))
      } else {
        if (this.multipleSelection.some(item => {
          return item.status === 0
        })) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.STOP_TASK_CODE))
          this.$refs.singleTable.clearSelection()
          return
        }
        this.deleteList = []
        for (var i = 0; i < this.multipleSelection.length; i++) {
          this.deleteList.push(this.multipleSelection[i].performTaskKey)
        }
        this.deleteCommand.execute()
      }
    },
    /**
     * @Description  : 启用
     * @author       : ls
     * @date         : 2020/4/27 16:15
     * @param        :
     * @return       :
     */
    startCollectTaskInit () {
      if (this.multipleSelection.length === 0) {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.START_SELECT_CODE))
      } else {
        this.deleteList = []
        for (var i = 0; i < this.multipleSelection.length; i++) {
          if (this.multipleSelection[i].status === 0) { continue }
          this.deleteList.push(this.multipleSelection[i]['performTaskKey'])
        }
        let _this = this
        let loadingInstance = _this.Loading.openLoading()
        CollectTaskService.startCollectTask(this.deleteList).then(result => {
          // this.queryCollectTaskDataByCondition()
          for (var j = 0; j < _this.collectTaskList.length; j++) {
            for (let t = 0; t < _this.deleteList.length; t++) {
              if (_this.collectTaskList[j].performTaskKey === _this.deleteList[t]) {
                _this.collectTaskList[j].status = 0
              }
            }
          }
          _this.Loading.closeLoading(loadingInstance)
          _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.ENABLE_CODE))
        }).catch(err => {
          _this.Loading.closeLoading(loadingInstance)
          this.InfoTip.errorTip(this, err)
        })
        this.cancel()
      }
    },
    /**
     * @Description  : 停用
     * @author       : ls
     * @date         : 2020/4/27 16:14
     * @param        :
     * @return       :
     */
    stopCollectTaskInit () {
      if (this.multipleSelection.length === 0) {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.STOP_SELECT_CODE))
      } else {
        this.deleteList = []
        for (var i = 0; i < this.multipleSelection.length; i++) {
          if (this.multipleSelection[i].status === 1) { continue }
          this.deleteList.push(this.multipleSelection[i]['performTaskKey'])
        }
        let _this = this
        let loadingInstance = _this.Loading.openLoading()
        CollectTaskService.startCollectTask(this.deleteList).then(result => {
          // this.queryCollectTaskDataByCondition()
          for (var j = 0; j < _this.collectTaskList.length; j++) {
            for (let t = 0; t < _this.deleteList.length; t++) {
              if (_this.collectTaskList[j].performTaskKey === _this.deleteList[t]) {
                _this.collectTaskList[j].status = 1
              }
            }
          }
          _this.Loading.closeLoading(loadingInstance)
          _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.DISABLE_CODE))
        }).catch(err => {
          _this.Loading.closeLoading(loadingInstance)
          this.InfoTip.errorTip(this, err)
        })
        this.cancel()
      }
    },
    /**
     * @Description  : 启用停用
     * @author       : ls
     * @date         : 2020/5/26 9:34
     * @param        :
     * @return       :
     */
    changeStatus: function (val) {
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      CollectTaskService.updateCollectTask(val).then(result => {
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.MODIFY_CODE))
      }).catch(err => {
        _this.Loading.closeLoading(loadingInstance)
        this.InfoTip.errorTip(this, err)
      })
    },
    /**
     * @Description  : 取消
     * @author       : ls
     * @date         : 2020/4/29 18:25
     * @param        :
     * @return       :
     */
    cancel: function () {
      this.$refs.singleTable.clearSelection()
    },
    /**
     * @Description  : fuzhi
     * @author       : ls
     * @date         : 2020/4/27 10:54
     * @param        :
     * @return       :
     */
    handleCopy: function (row) {
      this.copyInitList = row
      this.copyCommand.execute()
    },
    /**
     * @Description  : xiugai
     * @author       : ls
     * @date         : 2020/4/27 10:55
     * @param        :
     * @return       :
     */
    handleUpdate: function (row) {
      if (row.status === 0) {
        this.$alert('采集任务在启用状态下不可修改！', '提示', {
          confirmButtonText: '确定',
          type: 'warning'
        })
        return
      }
      this.updateInitList = row
      this.updateCommand.execute()
    },
    /**
     * @Description  :
     * @author       : ls
     * @date         : 2020/4/27 16:07
     * @param        :
     * @return       :
     */
    handleView: function (row) {
      let flag = false
      for (let item of this.openTab) {
        if (item.name === '任务详情') {
          this.$store.commit('delete_keepAliveRouter', 'TaskDetail')
          this.$store.commit('delete_tabs', '/TheLayout/TaskDetail')
          this.$store.commit('add_tabs', {route: '/TheLayout/TaskDetail', name: '任务详情', title: 'TheLayoutHeader.TaskDetail'})
          this.$store.commit('set_active_index', '/TheLayout/TaskDetail')
          this.$store.commit('add_keepAliveRouter', 'TaskDetail')
          this.$router.push({path: '/TheLayout/TaskDetail', query: {performTemplateKey: row}})
          flag = true
          break
        }
      }
      if (!flag) {
        this.$store.commit('add_tabs', {route: '/TheLayout/TaskDetail', name: '任务详情', title: 'TheLayoutHeader.TaskDetail'})
        this.$store.commit('add_keepAliveRouter', 'TaskDetail')
        this.$store.commit('set_active_index', '/TheLayout/TaskDetail')
        this.$router.push({path: '/TheLayout/TaskDetail', query: {performTemplateKey: row}})
      }
    },
    /**
     * @Description  : handleViewHistoryData
     * @author       : ls
     * @date         : 2021/3/29 16:18
     * @param        :
     * @return       :
     */
    handleViewHistoryData: function (row) {
      if (row.status === 1) {
        var a = {
          message: '请先启用该采集任务'
        }
        this.InfoTip.warningTip_alarm(this, a)
        return
      }

      let _this = this
      PerformanceDataQuaryService.queryPerformTaskData(row).then(result => {
        _this.performList = Object.values(result)
        if (_this.performList.length === 0) {
          this.InfoTip.warningTip_alarm(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
        } else {
          this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.QUERY_CODE))
        }
        let flag = false
        for (let item of this.openTab) {
          if (item.name === '性能查询') {
            this.$store.commit('delete_keepAliveRouter', 'PerformanceDataQuery')
            this.$store.commit('delete_tabs', '/TheLayout/PerformanceDataQuery')
            this.$store.commit('add_tabs', {route: '/TheLayout/PerformanceDataQuery', name: '性能查询', title: 'TheLayoutHeader.performanceQuery'})
            this.$store.commit('set_active_index', '/TheLayout/PerformanceDataQuery')
            this.$store.commit('add_keepAliveRouter', 'PerformanceDataQuery')
            // this.$router.push({path: '/TheLayout/PerformanceDataQuery', query: {collectTask: this.performList}})
            this.$router.push({name: '性能查询', params: {performList: _this.performList}})
            flag = true
            break
          }
        }
        if (!flag) {
          this.$store.commit('add_tabs', {route: '/TheLayout/PerformanceDataQuery', name: '性能查询', title: 'TheLayoutHeader.performanceQuery'})
          this.$store.commit('add_keepAliveRouter', 'PerformanceDataQuery')
          this.$store.commit('set_active_index', '/TheLayout/PerformanceDataQuery')
          this.$router.push({name: '性能查询', params: {performList: _this.performList}})
          // this.$router.push({path: '/TheLayout/PerformanceDataQuery', query: {collectTask: this.performList}})
        }
      }).catch(err => {
        this.InfoTip.errorTip(_this, err)
      })
    },
    /**
     * @Description  : 查看指标模板
     * @author       : ls
     * @date         : 2020/4/29 13:19
     * @param        :
     * @return       :
     */
    handleViewIndexTemplateDetail (row) {
      let flag = false
      for (let item of this.openTab) {
        if (item.name === '指标模板管理') {
          this.$store.commit('delete_keepAliveRouter', 'IndexTemplate')
          this.$store.commit('delete_tabs', '/TheLayout/IndexTemplate')
          this.$store.commit('add_tabs', {route: '/TheLayout/IndexTemplate', name: '指标模板管理', title: 'TheLayoutHeader.IndexTemplate'})
          this.$store.commit('set_active_index', '/TheLayout/IndexTemplate')
          this.$store.commit('add_keepAliveRouter', 'IndexTemplate')
          this.$router.push({path: '/TheLayout/IndexTemplate', query: {performTemplateName: row.performTemplateName}})
          flag = true
          break
        }
      }
      if (!flag) {
        this.$store.commit('add_tabs', {route: '/TheLayout/IndexTemplate', name: '指标模板管理', title: 'TheLayoutHeader.IndexTemplate'})
        this.$store.commit('add_keepAliveRouter', 'IndexTemplate')
        this.$store.commit('set_active_index', '/TheLayout/IndexTemplate')
        this.$router.push({path: '/TheLayout/IndexTemplate', query: {performTemplateName: row.performTemplateName}})
      }
    },
    /**
     * @Description  : shezhitiaojian
     * @author       : ls
     * @date         : 2020/4/27 10:05
     * @param        :
     * @return       :
     */
    setSelectList: function () {
      this.selectList = []
      if (this.querySelectTaskName !== null && this.querySelectTaskName !== '') {
        this.selectList.push({
          quaryAttribute: 'performTaskName',
          compareSymbol: 'like',
          compareValue: this.querySelectTaskName
        })
      }
      if (this.querySelectStatus !== '' && this.querySelectStatus !== null) {
        this.selectList.push({
          quaryAttribute: 'status',
          compareSymbol: '=',
          compareValue: this.querySelectStatus
        })
      }
    },
    /**
     * @Description  : chaxun
     * @author       : ls
     * @date         : 2020/4/27 10:04
     * @param        :
     * @return       :
     */
    queryCollectTaskByCondition: function () {
      let _this = this
      _this.setSelectList()
      let loadingInstance = _this.Loading.openLoading()
      CollectTaskService.queryCollectTask(_this.selectList).then(result => {
        _this.collectTaskList = Object.values(result)
        _this.Loading.closeLoading(loadingInstance)
        if (_this.indexTemplateList.length === 0) {
          this.InfoTip.warningTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
        } else {
          this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.QUERY_CODE))
        }
      }).catch(err => {
        this.Loading.closeLoading(loadingInstance)
        this.InfoTip.errorTip(_this, err)
      })
    },
    /**
     * @Description  : 获取网元型号
     * @author       : ls
     * @date         : 2020/4/27 9:57
     * @param        :
     * @return       :
     */
    getAllDeviceModel: function () {
      let _this = this
      DeviceService.getAllDeviceModelCollection().then(result => {
        _this.deviceModelList = Object.values(result)
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /**
     * @Description  : 获取所有
     * @author       : ls
     * @date         : 2020/4/26 15:05
     * @param        :
     * @return       :
     */
    getAllSubnetInit: function () {
      let _this = this
      let loadingInstance = loading.openLoading()
      SubnetService.getAllSubnetCollection().then(result => {
        _this.subnetList = Object.values(result)
        loadingInstance.close()
      }).catch(err => {
        this.InfoTip.errorTip(this, err)
        loadingInstance.close()
      })
    },
    /**
     * @Description  : 获取指标模板
     * @author       : ls
     * @date         : 2020/5/25 10:13
     * @param        :
     * @return       :
     */
    getAllIndexTemplate: function () {
      let _this = this
      let loadingInstance = loading.openLoading()
      IndexTeplateService.getAllIndexTemplateCollection().then(result => {
        _this.indexTemplateList = result
        loadingInstance.close()
      }).catch(err => {
        this.InfoTip.errorTip(this, err)
        loadingInstance.close()
      })
    },
    /**
     * @Description  : huoqusuoyou
     * @author       : ls
     * @date         : 2020/4/27 9:36
     * @param        :
     * @return       :
     */
    getAllCollectTask: function () {
      let _this = this
      let loadingInstance = loading.openLoading()
      CollectTaskService.getAllCollectTaskCollection().then(result => {
        _this.collectTaskList = Object.values(result)
        loadingInstance.close()
      }).catch(err => {
        this.InfoTip.errorTip(this, err)
        loadingInstance.close()
      })
    },
    /**
     * @Description  : 格式化子网
     * @author       : ls
     * @date         : 2020/4/29 12:06
     * @param        :
     * @return       :
     */
    formatSubnetKey: function (row, column) {
      for (var i = 0; i < this.subnetList.length; i++) {
        if (this.subnetList[i]['subnetKey'] === row.subnetKey) {
          return this.subnetList[i]['subnetName']
        }
      }
    },
    /**
     * @Description  : 格式化指标模板
     * @author       : ls
     * @date         : 2020/5/25 17:41
     * @param        :
     * @return       :
     */
    formatPerformTemplateKey: function (val) {
      return this.indexTemplateList[val.performTemplateKey].performTemplateName
    },
    /**
     * @Description  : 格式化时间
     * @author       : ls
     * @date         : 2020/5/26 9:44
     * @param        :
     * @return       :
     */
    formatterTime: function (val) {
      if (val.startTime === '') {
        return ''
      } else {
        return HelperUtil.timeTran(val.startTime)
      }
    },
    /**
     * @Description  : 格式化时间
     * @author       : ls
     * @date         : 2020/5/26 9:48
     * @param        :
     * @return       :
     */
    formatterEndTime: function (val) {
      if (val.endTime === '') {
        return ''
      } else {
        return HelperUtil.timeTran(val.endTime)
      }
    },
    formatMonitorType: function (val) {
      var ret = ''
      switch (val.monitorType) {
        case 0:
          ret = this.$t('DeviceConfigurationManagement.nodeType')
          break
        case 1:
          ret = this.$t('DeviceConfigurationManagement.nodeModel')
          break
        case 2:
          ret = this.$t('DeviceConfigurationManagement.nodeName')
          break
      }
      return ret
    },
    /**
     * @Description  : 选中数据
     * @author       : ls
     * @date         : 2020/4/29 12:06
     * @param        :
     * @return       :
     */
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    /**
     * @Description  : 初始化
     * @author       : ls
     * @date         : 2020/5/26 14:42
     * @param        :
     * @return       :
     */
    handleCurrentChange (val) {
      this.currentPage = val
      this.beginItem = ((val - 1) * 100) + 1
      this.endItem = this.beginItem + 99
      if (this.endItem > this.total) {
        this.endItem = this.total
      }
      this.queryCollectTaskDataByConditionCurrentPage()
    },
    /**
     * @Description  : 分页
     * @author       : ls
     * @date         : 2020/5/26 14:44
     * @param        :
     * @return       :
     */
    queryCollectTaskDataByConditionCurrentPage: function () {
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      CollectTaskService.queryCollectTaskListPaging(this.beginItem, this.endItem, this.selectList).then(result => {
        _this.collectTaskList = Object.values(result)
        _this.Loading.closeLoading(loadingInstance)
      }).catch(err => {
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /**
     * @Description  : 查询
     * @author       : ls
     * @date         : 2020/6/10 15:32
     * @param        :
     * @return       :
     */
    queryInit: function () {
      this.beginItem = 1
      this.setSelectList()
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      CollectTaskService.getCollectTaskTotalCounts(this.selectList).then(result => {
        _this.total = result
        _this.Loading.closeLoading(loadingInstance)
        if (this.total === 0 || this.total < 0) {
          _this.collectTaskList = []
        } else {
          if (this.total < 100 && this.total > 0) {
            this.endItem = this.total
          } else {
            this.endItem = 100
          }
          this.queryCollectTaskDataByConditionCurrentPage()
        }
      }).catch(err => {
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /**
     * @Description  : 条件查询
     * @author       : ls
     * @date         : 2020/5/26 14:47
     * @param        :
     * @return       :
     */
    queryCollectTaskDataByCondition: function () {
      this.beginItem = 1
      this.setSelectList()
      this.collectTaskDataTotalNumber()
    },
    /**
     * @Description  : 查询总数
     * @author       : ls
     * @date         : 2020/5/26 15:04
     * @param        :
     * @return       :
     */
    collectTaskDataTotalNumber: function () {
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      CollectTaskService.getCollectTaskTotalCounts(this.selectList).then(result => {
        _this.total = result
        _this.Loading.closeLoading(loadingInstance)
        if (this.total === 0 || this.total < 0) {
          _this.InfoTip.warningTip_alarm(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
          _this.collectTaskList = []
        } else {
          if (this.total < 100 && this.total > 0) {
            this.endItem = this.total
          } else {
            this.endItem = 100
          }
          _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.QUERY_CODE))
          this.queryCollectTaskDataByConditionCurrentPage()
        }
      }).catch(err => {
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    }
  },

  watch: {
    commandContext (newVal, oldVal) {
      if (JSON.stringify(newVal) === '{}') {
        this.queryInit()
        this.$refs.singleTable.clearSelection()
      }
      deep: true
    }
  }
}
</script>

<style scoped>
</style>
