<!--
 * @Author: your name
 * @Date: 2021-11-17 13:43:58
 * @LastEditTime: 2022-03-02 09:48:58
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \CABaggageData\src\views\dashboard\views\info.vue
-->
<template>
  <div class="airportInfo">
    <div class="wrap">
      <DataTable :data-id="dataId" :rows="12" labelWidth="100px" :minHeight="70" width="800px" :isStatuser="true" :isAuth="true" authAdd="ss_aim_add" authEdit="ss_aim_cardEdit" authDel="ss_aim_cardDelete" tableHeight="685">
        <template v-slot:header>
          <div class="status flex-wrap">
            <div class="manageTitle">航司信息维护</div>
          </div>
        </template>
      </DataTable>
    </div>
  </div>
</template>

<script>
import Search from "@/layout/components/Search/index.vue";
import Dialog from "@/layout/components/Dialog/index.vue";
import { findarrays } from "@/utils/validate";
import { GeneralDataReception, Query } from "@/api/dataIntegration";
import DataTable from "@/components/Table";
import { AirlinesInquiry, DelAirlines, AddAirlines } from "@/api/SystemSettings";
export default {
  name: "AirportInfo",
  components: { Search, Dialog, DataTable },
  data () {
    return {
      dataId: DATACONTENT_ID.airlineTableId,
      arr: [], //内容数据
      flag: false, //删除弹框开关
      addFlag: false, //新增机场信息弹框开关
      EditFlag: false,
      ids: null,
      idss: null,
      Turnoff: false,
      rmObj: {
        //删除内容
        name: "",
      },
      ruleForm: {
        //新增机场信息表单
        Name: "",
        FullName: "",
        Code2: "",
        operate: "1",
      },
      EditForm: {
        //编辑机场信息表单
        ID: "",
        Name: "",
        FullName: "",
        Code2: "",
        operate: "2",
      },
      eleForm: {
        //删除机场信息表单
        ID: "",
        Name: "",
        FullName: "",
        Code2: "",
      },
      rules: {
        //新增机场信息表单验证
        Name: [{ required: true, message: "请输入航司简称", trigger: "blur" }],
        FullName: [{ required: true, message: "请输入航司全称", trigger: "blur" }],
        Code2: [{ required: true, message: "请输入航司二字码", trigger: "blur" }],
      },
    };
  },
  mounted () {
    // this.getAirlines();
  },
  computed: {
    serachBox () {
      if (this.searchInfo) {
        return this.arr.filter((data) => {
          return Object.keys(data).some((key) => {
            return String(data[key]).toLowerCase().indexOf(this.searchInfo) > -1;
          });
        });
      }
      return this.arr;
    },
  },
  methods: {
    //删除信息
    handleMove (item) {
      this.eleForm = item;
      this.eleForm["operate"] = "3";
      this.ids = item.id;
      this.flag = true;
      this.rmObj = {
        name: item.Name,
      };
    },
    //编辑-航司信息（存储信息）
    airEdit (item) {
      this.EditForm.ID = item.ID;
      this.EditForm.Name = item.Name;
      this.EditForm.FullName = item.FullName;
      this.EditForm.Code2 = item.Code2;
      this.EditFlag = true;
    },
    //编辑机场信息-弹框-提交
    async EditSubmit () {
      let arr = 0;
      this.$refs["ruleFormer"].validate((valid) => {
        if (valid) {
          arr = 1;
        } else {
          arr = 0;
          return false;
        }
      });
      if (arr == 1) {
        try {
          const res = await GeneralDataReception({
            serviceId: "15",
            dataContent: JSON.stringify(this.EditForm),
          });
          if (res.code === "0") {
            this.getAirlines();
            this.$message.success(res.message ?? "成功");
            this.resetForm();
          } else {
            this.$message.error(res.message ?? "失败");
          }
        } catch (error) {
this.$message.error("失败");
        }
      }
    },
    //清空内容
    closeForm () {
      this.$refs.ruleForm.resetFields();
    },
    //获取航司信息列表
    async getAirlines () {
      try {
        const res = await Query({
          id: 22,
          dataContent: [],
        });
        if (res.code === "0") {
          this.arr = res.returnData;
        } else {
          this.$message.error(res.message ?? "失败");
        }
      } catch (error) {
        this.$message.error("失败");
      }
    },

    //新增机场信息-弹框
    handleAdd () {
      this.addFlag = true;
    },
    //新增机场信息-弹框-提交
    async addSubmit () {
      let arr = 0;
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          arr = 1;
        } else {
          arr = 0;
          return false;
        }
      });
      if (arr == 1) {
        try {
          const res = await GeneralDataReception({
            serviceId: "15",
            dataContent: JSON.stringify(this.ruleForm),
          });
          if (res.code === "0") {
            this.$message.success(res.message ?? "成功");
            this.getAirlines();
            this.resetForm();
          } else {
            this.$message.error(res.message ?? "失败");
          }
        } catch (error) {
          this.$message.error("失败");
        }
        this.closeForm();
      }
    },
    //新增机场信息-弹框-取消
    resetForm () {
      this.addFlag = false;
      this.EditFlag = false;
      this.EditForm.Name = null;
      this.ruleForm.FullName = "";
      this.ruleForm.Code2 = "";
      this.ruleForm.code = "";
    },
    //删除
    async remove () {
      try {
        const res = await GeneralDataReception({
          serviceId: "15",
          dataContent: JSON.stringify(this.eleForm),
        });
        if (res.code === "0") {
          this.$message.success(res.message ?? "成功");
          this.flag = false;
          this.getAirlines();
        } else {
          this.$message.error(res.message ?? "失败");
        }
      } catch (error) {
        this.$message.error("失败");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.airportInfo {
  .log {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    margin-right: 15px;
    background: url("../../../../assets/index/ic_close_hint.png") no-repeat;
    background-size: 100% 100%;
  }
  ::v-deep .el-form-item__content {
    margin-left: 120px !important;
  }
  ::v-deep .el-form-item__label {
    width: 120px !important;
  }
  ::v-deep .el-form-item {
    margin-bottom: 20px;
  }
  .title {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #101116;
    max-width: calc(100% - 3px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .er {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #101611;
    display: flex;
    align-items: center;
  }
  .airportInfo-search {
    margin: 40px 0 30px 0;
  }
  .airportInfo-content {
    img {
      margin: 0 auto;
      margin-top: 10%;
      display: -webkit-box;
      -webkit-box-pack: center;
      -webkit-box-align: center;
      -webkit-box-orient: vertical;
      text-align: center;
    }
    .grid-content {
      padding: 24px;
      margin-bottom: 24px;
      height: 144px;
      .edit_log {
        position: relative;
        // top: -2px;
      }
      .icon {
        cursor: pointer;
      }
      .desc {
        margin-top: 60px;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #101116;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
  .er {
    display: flex;
    align-items: center;
  }
  .list {
    width: 100%;
  }
  .titleers {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #101116;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .titleer {
    width: 100%;
    padding: 10px 0px 10px 20px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    height: 36px;
    background: #2d67e3;
    color: #ffffff;
    margin-bottom: 28px;
  }
  .title {
    // width: 40%;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .btnStyle {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #303133;
    // margin-right: 20px;
    display: flex;
    align-items: center;
  }
}
</style>
