<template>
  <div>
    <el-dialog title="放箱号信息" :visible.sync="dialogVisible" append-to-body width="60%" :before-close="handleClose">
      <avue-crud
        v-if="dialogVisible"
        :option="option"
        :table-loading="loading"
        :data="data"
        ref="crud"
        :search.sync="query"
        :page.sync="page"
        @current-row-change="handleCurrentRowChange"
        :header-cell-class-name="headerClassName"
        @search-change="searchChange"
        @search-reset="searchReset"
        @current-change="currentChange"
        @size-change="sizeChange"
        @on-load="onLoad"
      >
      </avue-crud>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submit" size="mini">导 入</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from "@/api/boxManagement/containerNumber/index.js";
import { head } from "lodash";
export default {
  props: {},
  data() {
    return {
      quotationObj: null,
      data: [],
      dialogVisible: false,
      loading: false,
      option: {
        height: 500,
        calcHeight: 30,
        border: true,
        index: true,
        addBtn: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        menu: false,
        header: false,
        highlightCurrentRow: true,
        searchShow: true,
        searchIndex: 3,
        searchMenuSpan: 6,
        headr: false,
        column: [
          {
            label: "箱东",
            prop: "boxEastName",
            width: 150,
            overHidden: true
          },
          {
            label: "系统号",
            prop: "sysNo",
            width: 100,
            overHidden: true
          },
          {
            label: "放箱号",
            prop: "containerNumber",
            width: 100,
            search: true,
            overHidden: true
          },
          {
            label: "箱号",
            prop: "code",
            width: 100,
            overHidden: true
          },
          {
            label: "内部放箱号",
            prop: "internalContainerNumber",
            width: 100,
            overHidden: true
          },
          {
            label: "放箱号类型",
            prop: "boxClass",
            width: 100,
            overHidden: true
          },
          {
            label: "来源类型",
            prop: "srcType",
            width: 100,
            overHidden: true
          },
          {
            label: "来源系统号",
            prop: "srcNo",
            width: 100,
            overHidden: true
          },
          {
            label: "来源放箱号",
            prop: "srcContainerNumber",
            width: 100,
            overHidden: true
          },
          {
            label: "箱属",
            prop: "boxBelongsTo",
            width: 80,
            overHidden: true
          },
          {
            label: "代理名称",
            prop: "agentName",
            width: 90,
            overHidden: true
          },
          {
            label: "起运港提/送箱场站",
            prop: "polStationCname",
            width: 140,
            overHidden: true
          },
          {
            label: "目的港提/还箱场站",
            prop: "podStationCname",
            width: 140,
            overHidden: true
          },
          {
            label: "起运港",
            prop: "polCname",
            width: 90,
            search: true,
            type: "select",
            filterable: true,
            remote: true,
            dicUrl: "/api/blade-los/bports/list?status=0&size=5&current=1&cnName={{key}}",
            props: {
              label: "cnName",
              value: "cnName",
              desc: "code",
              res: "data.records"
            },
            overHidden: true
          },
          {
            label: "目的港",
            prop: "podCname",
            width: 90,
            search: true,
            type: "select",
            filterable: true,
            remote: true,
            dicUrl: "/api/blade-los/bports/list?status=0&size=5&current=1&code={{key}}",
            props: {
              label: "code",
              value: "code",
              desc: "code",
              res: "data.records"
            },
            overHidden: true
          },
          {
            label: "箱型",
            prop: "boxType",
            width: 80,
            overHidden: true
          },
          {
            label: "可用箱量",
            prop: "remainingNum",
            width: 100,
            overHidden: true
          },
          {
            label: "操作占用",
            prop: "occupyNum",
            width: 100,
            overHidden: true
          },
          {
            label: "场地盘存",
            prop: "storageNum",
            width: 100,
            overHidden: true
          },
          {
            label: "内部放箱号类型",
            prop: "internalBoxClass",
            width: 120,
            overHidden: true
          },
          {
            label: "箱况",
            prop: "boxCondition",
            width: 80,
            overHidden: true
          },
          {
            label: "有效日期起",
            prop: "effectiveStartDate",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            width: 100,
            overHidden: true
          },
          {
            label: "有效日期止",
            prop: "effectiveEndDate",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            width: 100,
            overHidden: true
          },
          {
            label: "舱位类型",
            prop: "cabinType",
            width: 100,
            overHidden: true
          },
          {
            label: "舱位数",
            prop: "shippingSpaceNumber",
            width: 90,
            overHidden: true
          },
          {
            label: "航线",
            prop: "airlineCname",
            width: 100,
            overHidden: true
          },
          {
            label: "是否合营舱位",
            prop: "whetherJointVentureCabin",
            width: 100,
            overHidden: true
          },
          {
            label: "LOLO-POL",
            prop: "loloPol",
            width: 90,
            overHidden: true
          },
          {
            label: "LOLO-POD",
            prop: "loloPod",
            width: 90,
            overHidden: true
          },
          {
            label: "目的港场站地址",
            prop: "podCyAddress",
            width: 120,
            overHidden: true
          },
          {
            label: "目的港场站联系人",
            prop: "podCyContact",
            width: 120,
            overHidden: true
          },
          {
            label: "目的港场站邮箱",
            prop: "podCyEmail",
            width: 120,
            overHidden: true
          },
          {
            label: "目的港场站电话",
            prop: "podCyTel",
            width: 120,
            overHidden: true
          }
        ]
      },
      query: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      }
    };
  },
  async created() {
    // this.option = await this.getColumnData(this.getColumnName(309.6), this.optionBack);
  },
  methods: {
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    searchReset() {
      this.query = this.$options.data().query;
      this.onLoad(this.page);
    },
    // 搜索按钮点击
    searchChange(params, done) {
      this.page.currentPage = 1;
      this.onLoad(this.page, this.query);
      done();
    },
    onLoad(page, params = {}) {
      let obj = {};
      obj = {
        ...Object.assign(params, this.query),
        whetherDeactivate:0
      };
      if (obj.effectiveDateList && obj.effectiveDateList.length > 0) {
        obj.effectiveStartDate = obj.effectiveDateList[0];
        obj.effectiveEndDate = obj.effectiveDateList[1];
      }
      this.loading = true;
      getList(page.currentPage, page.pageSize, obj)
        .then(res => {
          this.data = res.data.data.records;
          this.page.total = res.data.data.total;
          this.$nextTick(() => {
            this.$refs.crud.doLayout();
            this.$refs.crud.dicInit();
          });
        })
        .finally(() => {
          this.loading = false;
        });
    },
    openDialog(val, form) {
      this.dialogVisible = true;
      this.quotationObj = null;
      this.query = {};
      // this.query.containerNumber = val;
    },
    handleCurrentRowChange(val) {
      this.quotationObj = val;
    },
    submit() {
      if (!this.quotationObj) {
        return this.$message.error("请选择数据");
      }
      let obj = {
        polId: this.quotationObj.polId,
        polCode: this.quotationObj.polCode,
        polEname: this.quotationObj.polEname,
        polCname: this.quotationObj.polCname,
        polStationId: this.quotationObj.polStationId,
        polStationCode: this.quotationObj.polStationCode,
        polStationCname: this.quotationObj.polStationCname,
        polStationEname: this.quotationObj.polCnpolStationEnameame,
        boxTypeQuantityOne: this.quotationObj.boxType,
        boxNumber: this.quotationObj.remainingNum,
        containerNumber: this.quotationObj.containerNumber
      };
      this.$emit("importData", obj);
      this.dialogVisible = false;
    },
    //自定义列保存
    async saveColumn(ref, option, optionBack, code) {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs[ref].$refs.dialogColumn.columnBox = false;
        this.searchReset();
      }
    },
    //自定义列重置
    async resetColumn(ref, option, optionBack, code) {
      this[option] = this[optionBack];
      const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs[ref].$refs.dialogColumn.columnBox = false;
      }
    },

    // 更改表格颜色
    headerClassName(tab) {
      //颜色间隔
      let back = "";
      if (tab.columnIndex >= 0 && tab.column.level === 1) {
        if (tab.columnIndex % 2 === 0) {
          back = "back-one";
        } else if (tab.columnIndex % 2 === 1) {
          back = "back-two";
        }
      }
      return back;
    }
  }
};
</script>

<style scoped>
::v-deep#out-table .back-one {
  background: #ecf5ff !important;
  text-align: center;
  padding: 4px 0;
}

::v-deep#out-table .back-two {
  background: #ecf5ff !important;
  text-align: center;
  padding: 4px 0;
}
</style>
