<!--
 * @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="airportInfo-search">
      <Search title="航司信息维护" :isSearch="false">
        <button v-is="['ss_aim_add']" @click="handleAdd" class="newbut">
          新增
        </button>
      </Search>
    </div>
    <!--内容区域-->
    <div class="airportInfo-content">
      <el-row :gutter="24">
        <el-col
          v-for="(item, index) in arr"
          class="airportInfo-content-list"
          :key="index"
          :data="serachBox"
          :span="4"
        >
          <div class="grid-content box-public-shadow">
            <div class="flex list">
              <div class="ult flex-wrap er">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="item.Name"
                  placement="bottom"
                >
                  <div class="title">{{ item.Name }}</div>
                </el-tooltip>
                <!-- <div class="title fz16">{{ item.airCompanyName }}</div> -->
                <div
                  v-is="['ss_aim_cardEdit']"
                  @click="airEdit(item)"
                  class="edit_log"
                ></div>
              </div>
              <div class="close">
                <span
                  v-is="['ss_aim_cardDelete']"
                  @click.stop="handleMove(item, index)"
                  class="el-icon-close icon"
                ></span>
              </div>
            </div>
            <div class="list desc">{{ item.FullName }}</div>
          </div>
        </el-col>
      </el-row>
      <!-- <img v-if="!arr.length" src="../../../assets/logo/nodata.png" /> -->
    </div>
    <!--删除弹框-->
    <Dialog :flag="flag" :showFlag="true">
      <div class="airportInfoDialog">
        <div class="del-title">删除机场信息</div>
        <div class="content er">
          <div class="log"></div>
          是否确认删除
          <p style="color: #eb2f3b; margin-top: 0px; margin-bottom: 0px">
            {{ rmObj.name }}
          </p>
          ？
        </div>
        <div class="DelFoot right" style="margin-top: 24px">
          <el-button
            size="medium"
            @click="remove()"
            class="r25 buwitch"
            type="danger"
            >删除</el-button
          >
          <el-button size="medium" class="r26" @click="flag = false"
            >取消</el-button
          >
        </div>
      </div>
    </Dialog>
    <!--新增机场信息弹框-->
    <Dialog
      :flag="addFlag"
      @close="closeForm"
      :showFlag="true"
      v-if="addFlag"
      width="415px"
    >
      <div class="airportInfoDialog dialog-public-background">
        <div class="titleer">新增航司信息</div>
        <div class="content">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="120px"
            class="demo-ruleForm"
          >
            <el-form-item label="航司中文简称" prop="Name">
              <el-input
                size="medium"
                placeholder="请输入航司中文简称（必填）"
                v-model="ruleForm.Name"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司英文简称">
              <el-input
                size="medium"
                placeholder="请输入航司英文简称（必填）"
                v-model="ruleForm.name1"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司全称" prop="FullName">
              <el-input
                size="medium"
                placeholder="请输入航司全称（必填）"
                v-model="ruleForm.FullName"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司二字码" prop="Code2">
              <el-input
                size="medium"
                placeholder="请输入航司二字码（必填）"
                v-model="ruleForm.Code2"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司三字码" prop="">
              <el-input
                size="medium"
                placeholder="请输入航司三字码（必填）"
                v-model="ruleForm.name2"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司性质" prop="">
              <el-input
                size="medium"
                placeholder="请输入航司性质（必填）"
                v-model="ruleForm.name3"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="foot center t30">
          <el-button
            size="medium"
            type="primary"
            @click="addSubmit()"
            class="r25 r26"
            >提交</el-button
          >
          <el-button size="medium" class="r26" @click="resetForm()"
            >取消</el-button
          >
        </div>
      </div>
    </Dialog>
    <!--编辑机场信息弹框-->
    <Dialog :flag="EditFlag" @close="closeForm" :showFlag="true" width="415px">
      <div class="airportInfoDialog dialog-public-background">
        <div class="flx">编辑航司信息</div>
        <div class="content">
          <el-form
            :model="EditForm"
            :rules="rules"
            ref="ruleFormer"
            label-width="120px"
            class="demo-ruleForm"
          >
            <el-form-item label="航司中文简称" prop="Name">
              <el-input
                size="medium"
                placeholder="请输入航司中文简称（必填）"
                v-model="EditForm.Name"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司英文简称">
              <el-input
                size="medium"
                placeholder="请输入航司英文简称（必填）"
                v-model="EditForm.name1"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司全称" prop="FullName">
              <el-input
                size="medium"
                placeholder="请输入航司全称（必填）"
                v-model="EditForm.FullName"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司二字码" prop="Code2">
              <el-input
                size="medium"
                placeholder="请输入航司二字码（必填）"
                v-model="EditForm.Code2"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司三字码" prop="">
              <el-input
                size="medium"
                placeholder="请输入航司三字码（必填）"
                v-model="EditForm.name2"
              ></el-input>
            </el-form-item>
            <el-form-item label="航司性质" prop="">
              <el-input
                size="medium"
                placeholder="请输入航司性质（必填）"
                v-model="EditForm.name3"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="foot center t30">
          <div class="btnStyle">
            <el-button
              v-is="['ss_aim_cardEdit_submit']"
              size="medium"
              type="primary"
              @click="EditSubmit()"
              class="r25 r26"
              >提交</el-button
            >
            <el-button
              v-is="['ss_aim_cardEdit_cancel']"
              size="medium"
              class="r26"
              @click="resetForm()"
              >取消</el-button
            >
          </div>
        </div>
      </div>
    </Dialog>
  </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 {
  AirlinesInquiry,
  DelAirlines,
  AddAirlines,
} from "@/api/SystemSettings";
export default {
  name: "AirportInfo",
  components: { Search, Dialog },
  data() {
    return {
      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) {
          console.log("错误", 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) {
        console.log("错误", 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) {
          console.log("错误", 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) {
        console.log("错误", 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>
