<template>
  <div class="view-carrierFlightMission">
    <div class="view-carrierFlightMission-FlightMission-btn-mc">
      <div class="view-carrierFlightMission-FlightMission-btn-right">
        <div class="input-with-select">
          <span>状态</span>
          <el-select v-model="statusValue" placeholder="请选择" @change="fetchTableData('search')">
            <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </div>
        <el-input @keyup.enter.native="fetchTableData('search')" placeholder="请输入任务名称/代号/带队领导" v-model="searchValue" class="input-select">
          <el-button @click="fetchTableData('search')" slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </div>
    </div>
    <div class="view-carrierFlightMission-FlightMission-table">
      <LTable ref="table" :defaultFetch="false" :columns="columns" :dataSource="tableData" :options="options" :fetch="fetchTableData"></LTable>
    </div>
  </div>
</template>

<script>
import { columns, options } from './index'
import { queryFlyTaskTree, updateFlyTask } from '@/api/task/carrierFlightMission'
import { statusList } from '@/utils/status'
export default {
  name: 'carrierAllAudit',
  data() {
    // 这里存放数据
    return {
      statusList: statusList,
      statusValue: null,
      searchValue: '',
      activeName: 'flightMission',
      columns: columns(this),
      options,
      tableData: [],
      tableRequset: {
        searchValue: ''
      },

      flightEnvironmentOptions: [
        { label: '沙漠', value: '沙漠' },
        { label: '暴雨', value: '暴雨' },
        { label: '狂风', value: '狂风' }
      ]
    }
  },

  mounted() {
    this.fetchTableData()
  },
  methods: {
    async fetchTableData(search) {
      // search ? (this.tableRequset.pageIndex = 1) : (this.tableRequset.pageIndex = this.tableRequset.pageIndex)
      let postData = {
        status: this.statusValue,
        queryParam: this.searchValue
      }
      const { code, data } = await queryFlyTaskTree(postData)
      if (code == 200) {
        this.tableData = data
      }
    },
    audit(row, type) {
      this.$confirm(`是否确认${type}该任务`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          if (row.children != null) {
            const childIdList = row.children.map((item) => item.taskId)
            let postData = {
              taskId: row.taskId,
              childIdList: childIdList,
              status: type == '审核' ? '5' : '1'
            }
            const { code, data } = await updateFlyTask(postData)
            if (code == 200) {
              this.fetchTableData()
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
            }
          } else {
            let postData = {
              taskId: row.taskId,
              status: type == '审核' ? '5' : '1'
            }
            const { code, data } = await updateFlyTask(postData)
            if (code == 200) {
              this.fetchTableData()
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
            }
          }
        })
        .catch(() => {})
    },
    look(row) {
      //   this.$router.push(`/carrierStandard/carrierAllAudit/look/${row.taskId}`)
      this.$router.push(`/carrierStandard/carrierListMachineryPreparation/look/${row.taskId}`)
    }
  }
}
</script>

<style lang="scss">
@import './index.scss';
</style>
