<template>
  <div class="view-carrierFlightMission">
    <!-- 通用代码 左侧按钮 右侧输入框 下拉框 -->
    <div class="view-common-header">
      <div class="view-common-header-left"></div>
      <div class="view-common-header-right">
        <!-- width-137 在style/excel.js 定义宽度 -->
        <div class="input-with-select width-137">
          <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>
    <LTable ref="table" :defaultFetch="false" :columns="columns" :dataSource="tableData" :options="options" :fetch="fetchTableData"></LTable>
  </div>
</template>

<script>
import { columns, options } from './index'
import { statusList } from '@/utils/status'
import { queryFlyTaskTree, updateFlyTask } from '@/api/task/carrierFlightMission'
export default {
  name: 'carrierFlightMission',
  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) {
      let postData = {
        status: this.statusValue,
        queryParam: this.searchValue
      }
      const { code, data } = await queryFlyTaskTree(postData)
      if (code == 200) {
        this.tableData = data
      }
    },
    toCompile(row) {
      this.$router.push(`/carrierStandard/carrierListShipping/compile/${row.taskId}`)
    },
    look(row) {
      this.$router.push(`/carrierStandard/carrierListShipping/look/${row.taskId}`)
    },
    completion(row) {
      this.$confirm('是否完成该任务', '提示', {
        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: '7'
            }
            const { code, data } = await updateFlyTask(postData)
            if (code == 200) {
              this.fetchTableData()
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
            }
          } else {
            let postData = {
              taskId: row.taskId,
              status: '7'
            }
            const { code, data } = await updateFlyTask(postData)
            if (code == 200) {
              this.fetchTableData()
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
            }
          }
        })
        .catch(() => {})
    }
  }
}
</script>

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