<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="录单单位名称">
        <el-input v-model="queryParams.lddwmc"></el-input>
      </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>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:BONDEDUPPLY:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:BONDEDUPPLY:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:BONDEDUPPLY:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:BONDEDUPPLY:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table :data="BONDEDUPPLYList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="录单单位名称 " align="center" prop="lddwmc">
      </el-table-column>
      <el-table-column label="进出口标志 " align="center" prop="jckbz">
      </el-table-column>
      <el-table-column label="进出口日期 " align="center" prop="jckrq">
      </el-table-column>
      <el-table-column label="净重 " align="center" prop="jz">
      </el-table-column>
      <el-table-column label="净值 " align="center" prop="jingzhi">
      </el-table-column>
      <el-table-column label="件数 " align="center" prop="js">
      </el-table-column>
      <el-table-column label="境内收发货人编号 " align="center" prop="jnsfhrbh">
      </el-table-column>
      <el-table-column label="境内收发货人名称 " align="center" prop="jnsfhrmc">
      </el-table-column>
      <el-table-column label="境外发货人代码 " align="center" prop="jwfhrdm">
      </el-table-column>
      <el-table-column label="境外收发货人名称 " align="center" prop="jwsfhrmc">
      </el-table-column>
      <el-table-column label="境外收发货人地址 " align="center" prop="jwsfhrdz">
      </el-table-column>
      <el-table-column label="启运日期 " align="center" prop="qyrq">
      </el-table-column>
      <el-table-column label="卸毕日期 " align="center" prop="xbrq">
      </el-table-column>
      <el-table-column label="供应链主键" align="center" prop="id">
      </el-table-column>
      <el-table-column label="保税区主键" align="center" prop="deptId">
      </el-table-column>
      <el-table-column label="报关单币种统计 " align="center" prop="bgdbztj">
      </el-table-column>
      <el-table-column label="申报单位名称 " align="center" prop="sbdwmc">
      </el-table-column>
      <el-table-column label="录单单位编码名称 " align="center" prop="lddwbmmc">
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:BONDEDUPPLY:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:BONDEDUPPLY:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改保税区供应链数据对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      :close-on-click-modal="false"
      width="35%"
      append-to-body
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="基本信息" name="first">
          <el-form ref="forms" :model="form" :rules="rules" label-width="140px">
            <el-form-item label="录单单位名称" prop="lddwmc">
              <el-input v-model="form.lddwmc"></el-input>
            </el-form-item>
            <el-form-item label="进出口标志" prop="jckbz">
              <el-input v-model="form.jckbz"></el-input>
            </el-form-item>
            <el-form-item label="进出口日期" prop="jckrq">
              <el-date-picker
                v-model="form.jckrq"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="净重" prop="jz">
              <el-input v-model="form.jz"></el-input>
            </el-form-item>
            <el-form-item label="净值" prop="jingzhi">
              <el-input v-model="form.jingzhi"></el-input>
            </el-form-item>
            <el-form-item label="件数" prop="js">
              <el-input v-model="form.js"></el-input>
            </el-form-item>

            <el-form-item label="启运日期  " prop="qyrq">
              <el-date-picker
                v-model="form.qyrq"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="卸毕日期   " prop="xbrq">
              <!-- <el-input v-model="form.xbrq"></el-input> -->
              <el-date-picker
                v-model="form.xbrq"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item label="报关单币种统计   " prop="bgdbztj">
              <el-input v-model="form.bgdbztj"></el-input>
            </el-form-item>
            <el-form-item label="申报单位名称   " prop="sbdwmc">
              <el-input v-model="form.sbdwmc"></el-input>
            </el-form-item>
            <el-form-item label="录单单位编码名称   " prop="lddwbmmc">
              <el-input v-model="form.lddwbmmc"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="境内外信息" name="second">
          <el-form ref="form" :model="form" :rules="rules" label-width="140px">
            <el-form-item label="境内收发货人标号" prop="jnsfhrbh">
              <el-input v-model="form.jnsfhrbh"></el-input>
            </el-form-item>
            <el-form-item label="境内收发货人名称 " prop="jnsfhrmc">
              <el-input v-model="form.jnsfhrmc"></el-input>
            </el-form-item>
            <el-form-item label="境外发货人代码 " prop="jwfhrdm">
              <el-input v-model="form.jwfhrdm"></el-input>
            </el-form-item>
            <el-form-item label="境外收发货人名称   " prop="jwsfhrmc">
              <el-input v-model="form.jwsfhrmc"></el-input>
            </el-form-item>
            <el-form-item label="境外收发货人地址   " prop="jwsfhrdz">
              <el-input v-model="form.jwsfhrdz"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBONDEDUPPLY,
  getBONDEDUPPLY,
  delBONDEDUPPLY,
  addBONDEDUPPLY,
  updateBONDEDUPPLY,
} from "@/api/portal/BONDEDUPPLY/BONDEDUPPLY";

export default {
  name: "BONDEDUPPLY",
  data() {
    return {
      activeName: "first",
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 保税区供应链数据表格数据
      BONDEDUPPLYList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lddwmc: null,
        jckbz: null,
        jckrq: null,
        jz: null,
        jingzhi: null,
        js: null,
        jnsfhrbh: null,
        jnsfhrmc: null,
        jwfhrdm: null,
        jwsfhrmc: null,
        jwsfhrdz: null,
        qyrq: null,
        xbrq: null,
        id: null,
        deptId: null,
        bgdbztj: null,
        sbdwmc: null,
        lddwbmmc: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        lddwmc: [
          { required: true, message: "录单单位名称 不能为空", trigger: "blur" },
        ],
        jckbz: [
          { required: true, message: "进出口标志 不能为空", trigger: "blur" },
        ],
        jckrq: [
          { required: true, message: "进出口日期 不能为空", trigger: "blur" },
        ],
        jz: [{ required: true, message: "净重 不能为空", trigger: "blur" }],
        jingzhi: [
          { required: true, message: "净值 不能为空", trigger: "blur" },
        ],
        js: [{ required: true, message: "件数 不能为空", trigger: "blur" }],
        jnsfhrbh: [
          {
            required: true,
            message: "境内收发货人编号 不能为空",
            trigger: "blur",
          },
        ],
        jnsfhrmc: [
          {
            required: true,
            message: "境内收发货人名称 不能为空",
            trigger: "blur",
          },
        ],
        jwfhrdm: [
          {
            required: true,
            message: "境外发货人代码 不能为空",
            trigger: "blur",
          },
        ],
        jwsfhrmc: [
          {
            required: true,
            message: "境外收发货人名称 不能为空",
            trigger: "blur",
          },
        ],
        jwsfhrdz: [
          {
            required: true,
            message: "境外收发货人地址 不能为空",
            trigger: "blur",
          },
        ],
        qyrq: [
          { required: true, message: "启运日期 不能为空", trigger: "blur" },
        ],
        xbrq: [
          { required: true, message: "卸毕日期 不能为空", trigger: "blur" },
        ],
        id: [
          { required: true, message: "供应链主键不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "保税区主键不能为空", trigger: "blur" },
        ],
        bgdbztj: [
          {
            required: true,
            message: "报关单币种统计 不能为空",
            trigger: "blur",
          },
        ],
        sbdwmc: [
          { required: true, message: "申报单位名称 不能为空", trigger: "blur" },
        ],
        lddwbmmc: [
          {
            required: true,
            message: "录单单位编码名称 不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询保税区供应链数据列表 */
    getList() {
      this.loading = true;
      listBONDEDUPPLY(this.queryParams).then((response) => {
        this.BONDEDUPPLYList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        lddwmc: null,
        jckbz: null,
        jckrq: null,
        jz: null,
        jingzhi: null,
        js: null,
        jnsfhrbh: null,
        jnsfhrmc: null,
        jwfhrdm: null,
        jwsfhrmc: null,
        jwsfhrdz: null,
        qyrq: null,
        xbrq: null,
        id: null,
        deptId: null,
        bgdbztj: null,
        sbdwmc: null,
        lddwbmmc: 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);
      console.log(this.ids);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加保税区供应链数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row.lddwmc);
      this.reset();
      let lddwmc = row.id || this.ids;
      getBONDEDUPPLY(lddwmc).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改保税区供应链数据";
        console.log(this.form, "form");
      });
    },
    /** 提交按钮 */
    submitForm() {
      let is;
      this.$refs["forms"].validate((valid) => {
        if (!valid) {
          this.$message.error("请补全基本信息");
          is = true;
          return;
        }
      });
      if (is) return;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id == null) {
            addBONDEDUPPLY(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.reset();
            });
          } else {
            updateBONDEDUPPLY(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.reset();
            });
          }
        }else{
          this.$message.error("请补全境内外信息");
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const lddwmcs = row.id || this.ids;
      console.log(lddwmcs);
      this.$modal
        .confirm(
          '是否确认删除保税区供应链数据编号为"' + lddwmcs + '"的数据项？'
        )
        .then(function () {
          return delBONDEDUPPLY(lddwmcs);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/BONDEDUPPLY/export",
        {
          ...this.queryParams,
        },
        `BONDEDUPPLY_new Date().getTme()}.xlsx`
      );
    },
  },
};
</script>
