<template>
  <div class="app-container home">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="机型" prop="aircraftTypeId">
        <el-select v-model="queryParams.aircraftTypeId" placeholder="请选择" @change="handleaircraftChange">
            <el-option
              v-for="item in typeOption"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="系统" prop="aircraftSystemId">
        <!-- <el-input
          v-model="queryParams.aircraftSystemId"
          placeholder="请输入系统"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.aircraftSystemId" placeholder="请选择" @change="handlesystemChange">
            <el-option
              v-for="item in systemOption"
              :key="item.id"
              :label="item.aircraftTypeName"
              :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>


      <el-form-item label="分系统" prop="aircraftSubsystemId">
        <!-- <el-input
          v-model="queryParams.aircraftSubsystemId"
          placeholder="请输入分系统"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.aircraftSubsystemId" placeholder="请选择">
            <el-option
              v-for="item in subSystemOption"
              :key="item.id"
              :label="item.aircraftTypeName"
              :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    
  </div>
</template>

<script>
import { listCase, getCase, delCase, addCase, updateCase } from "@/api/system/case";
import { getTypeOption } from "@/api/system/type";
import { getSystemOption } from "@/api/system/system";
import { getSubSystemOption } from "@/api/system/subsystem"
export default {
  name: "Case",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 故障案例管理表格数据
      caseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        aircraftTypeId: null,
        aircraftSystemId: null,
        aircraftSubsystemId: null,
        faultPhenomenon: null,
        faultCause: null,
        faultTreePath: null,
        faultPicturePath: null,
        troubleshootingMethodPath: null,
        viewCount: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      typeOption: [],
      systemOption:[],
      subSystemOption:[],
    };
  },
  created() {
    this.getList();
    this.getOption();

  },
  methods: {
    getOption() {
      getTypeOption().then(resp => {
        this.typeOption = resp.data
      })
    },

    /** 查询故障案例管理列表 */
    getList() {
      this.loading = true;
      listCase(this.queryParams).then(response => {
        this.caseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

        //机型变化后更新系统下拉框
        handleaircraftChange() {
      this.queryParams.aircraftSystemId = '';
      this.queryParams.aircraftSubsystemId = '';
      //alert(this.queryParams.aircraftTypeId)
      getSystemOption(this.queryParams.aircraftTypeId).then(resp => {
        this.systemOption = resp.data;
      });
    },

    //系统变化后更新分系统
    handlesystemChange(){
       this.queryParams.aircraftSubsystemId = '';
      getSubSystemOption(this.queryParams.aircraftSystemId).then(resp =>{
        this.subSystemOption = resp.data;
      })
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        aircraftTypeId: null,
        aircraftSystemId: null,
        aircraftSubsystemId: null,
        faultPhenomenon: null,
        faultCause: null,
        faultTreePath: null,
        faultPicturePath: null,
        troubleshootingMethodPath: null,
        viewCount: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加故障案例管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCase(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改故障案例管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除故障案例管理编号为"' + ids + '"的数据项？').then(function() {
        return delCase(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/case/export', {
        ...this.queryParams
      }, `case_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

