<!--
 * @Author: your name
 * @Date: 2021-11-17 13:43:58
 * @LastEditTime: 2021-11-17 13:43:59
 * @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" tableHeight="685" :isStatuser="true" :isAuth="true" authAdd="special_baggage_information_add" authEdit="special_baggage_editing" authDel="special_baggage_deletion">
        <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 DataTable from "@/components/Table";
import { AirlinesInquiry, DelAirlines, AddAirlines } from "@/api/SystemSettings";
import { exceptiontype, exceptionadd, exceptiondel } from "@/api/acquisition";
import { GeneralDataReception, Query } from "@/api/dataIntegration";
export default {
  name: "AirportInfo",
  components: { Search, Dialog, DataTable },
  data () {
    return {
      dataId: DATACONTENT_ID.bagTableId,
      arr: [], //内容数据
      flag: false, //删除弹框开关
      addFlag: false, //新增机场信息弹框开关
      EditFlag: false,
      ids: null,
      idss: null,
      listDate: {},
      rmObj: {
        //删除内容
        name: "",
      },
      ruleForm: {
        //新增机场信息表单
        name: "",
        fullName: "",
        code: "",
      },
      EditForm: {
        name: "",
        fullName: "",
        code: "",
      },
      rules: {
        //新增机场信息表单验证
        TypeName: [{ required: true, message: "请输入航司简称", trigger: "blur" }],
        TypeNameEN: [{ required: true, message: "请输入航司全称", trigger: "blur" }],
        TypeCode: [{ required: true, message: "请输入航司二字码", trigger: "blur" }],
      },
      modid: "",
    };
  },
  created () {
    // this.getAirlines();
    // this.exceptionlist();
  },
  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: {
    //异常列表查询
    async exceptionlist () {
      let params = {
        id: "",
      };
      const result = await exceptiontype(params);
      if (result.code == 0) {
        this.arr = result.returnData;
      }
    },
    //搜索
    getSearchData (val) {
      let that = this;
      that.exceptionlist().then(function (data) {
        if (val) {
          that.arr = findarrays(that.arr, "typeName", val);
        } else {
          that.exceptionlist();
        }
      });
      //
    },
    //删除信息
    handleMove (item) {
      // this.ids = item.id;
      this.listDate = item;
      this.flag = true;
      this.rmObj = {
        name: item.TypeName,
      };
    },
    //编辑
    airEdit (item) {
      this.EditForm = item;
      this.EditFlag = true;
    },
    //编辑机场信息-弹框-提交
    async EditSubmit () {
      let arr = 0;
      this.$refs["ruleFormall"].validate((valid) => {
        if (valid) {
          arr = 1;
        } else {
          arr = 0;
          return false;
        }
      });
      if (arr == 1) {
        try {
          this.EditForm.operate = "2";
          const res = await GeneralDataReception({
            serviceId: "22",
            dataContent: JSON.stringify(this.EditForm),
          });
          if (res.code === "0") {
            this.$message.success(res.message ?? "成功");
            this.getAirlines();
          } else {
            this.$message.error(res.message ?? "失败");
          }
        } catch (error) {
          this.$message.error("失败");
        }
        this.EditForm = {};
        this.EditFlag = false;
      }
    },
    closeForm () {
      this.$refs.ruleForm.resetFields();
    },
    //获取航司信息列表
    async getAirlines () {
      try {
        const res = await Query({
          id: 78,
          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["ruleForms"].validate((valid) => {
        if (valid) {
          arr = 1;
        } else {
          arr = 0;
          return false;
        }
      });
      if (arr == 1) {
        try {
          const res = await GeneralDataReception({
            serviceId: "22",
            dataContent: JSON.stringify(this.ruleForm),
          });
          if (res.code === "0") {
            this.$message.success(res.message ?? "成功");
            this.getAirlines();
          } else {
            this.$message.error(res.message ?? "失败");
          }
        } catch (error) {
          this.$message.error("失败");
        }
        this.addFlag = false;
        this.ruleForm = {};
      }
    },
    //新增机场信息-弹框-取消
    resetForm () {
      this.addFlag = false;
      this.EditFlag = false;
      this.ruleForm.name = "";
      this.ruleForm.fullName = "";
      this.ruleForm = {};
      this.EditForm = {};
    },
    //删除
    async remove () {
      this.listDate.operate = "3";
      try {
        const res = await GeneralDataReception({
          serviceId: "22",
          dataContent: JSON.stringify(this.listDate),
        });
        if (res.code === "0") {
          this.$message.success(res.message ?? "成功");
          this.flag = false;
          this.listDate = {};
          this.getAirlines();
        } else {
          this.$message.error(res.message ?? "失败");
        }
      } catch (error) {
        this.$message.error("失败");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.airportInfo {
  ::v-deep .el-form-item {
    margin-bottom: 20px;
  }
  .log {
    width: 26px;
    height: 26px;
    background: #eb2f3b;
    border-radius: 50%;
    margin-right: 15px;
    background: url("../../../../assets/index/ic_close_hint.png") no-repeat;
    background-size: 100% 100%;
  }
  .er {
    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 {
      height: 144px;
      padding: 24px;
      margin-bottom: 24px;
      .title {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: #303133;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 150px;
      }
      .edit_log {
        position: relative;
        // top: -2px;
      }
      .icon {
        cursor: pointer;
      }
      .desc {
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #101116;
        margin-top: 60px;
      }
    }
  }
}
</style>
