<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <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:ENTERPRISETRADEPERFORMANCE: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:ENTERPRISETRADEPERFORMANCE: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:ENTERPRISETRADEPERFORMANCE: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:ENTERPRISETRADEPERFORMANCE:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      :data="ENTERPRISETRADEPERFORMANCEList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="企业贸易绩效数据" align="center" prop="id">
      </el-table-column> -->
      <!-- <el-table-column label="部门id" align="center" prop="deptId">
      </el-table-column> -->
      <el-table-column label="部门名称" align="center" prop="deptName">
      </el-table-column>
      <el-table-column label="规模以上工业产值" align="center" prop="gmysgycz">
      </el-table-column>
      <el-table-column label="固定资产投资" align="center" prop="gdzctz">
      </el-table-column>
      <el-table-column label="资产分类 " align="center" prop="zcfl">
      </el-table-column>
      <el-table-column label="主要贸易国家 " align="center" prop="zymygj">
      </el-table-column>
      <el-table-column label="电子账册分类 " align="center" prop="dzzcfl">
      </el-table-column>
      <el-table-column label="进、出口总值" align="center" prop="jckzz">
      </el-table-column>
      <el-table-column label="进口总值" align="center" prop="jkzz">
      </el-table-column>
      <el-table-column label="出口总值" align="center" prop="ckzz">
      </el-table-column>
      <el-table-column label="加工贸易进出口值 " align="center" prop="jgmyjckz">
      </el-table-column>
      <el-table-column label="物流货物进出口值 " align="center" prop="wlhwjckz">
      </el-table-column>
      <el-table-column label="一般贸易进出口值 " align="center" prop="ybmyjckz">
      </el-table-column>
      <el-table-column label="海关税收" align="center" prop="hgss">
      </el-table-column>
      <el-table-column label="税务部门税收" align="center" prop="swbmss">
      </el-table-column>
      <el-table-column label="期末企业从业人员" align="center" prop="qmqycyry">
      </el-table-column>
      <el-table-column label="实际使用外资金额" align="center" prop="sjsywzje">
      </el-table-column>
      <el-table-column label="维修业务进出口值 " align="center" prop="wxyejckz">
      </el-table-column>
      <el-table-column label="研发业务进出口值 " align="center" prop="yfywjckz">
      </el-table-column>
      <el-table-column label="租赁贸易进出口值 " align="center" prop="zlmyjckz">
      </el-table-column>
      <el-table-column
        label="跨境电商业务进出口值 "
        align="center"
        prop="kjdsywjckz"
      >
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy">
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime">
      </el-table-column>
      <el-table-column label="更信任" align="center" prop="updateBy">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:ENTERPRISETRADEPERFORMANCE:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:ENTERPRISETRADEPERFORMANCE: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="40%"
      append-to-body
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="基本信息" name="first">
          <el-form ref="forms" :model="form" :rules="rules" label-width="180px">
            <el-form-item label="部门" prop="deptName">
              <el-select
                v-model="form.deptName"
                @change="deptSelect"
                placeholder="请选择"
              >
                <el-option
                  v-for="(item, index) in deptList"
                  :key="index"
                  :label="item.deptName"
                  :value="index"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="固定资产投资" prop="gdzctz">
              <el-input
                v-model="form.gdzctz"
                placeholder="请输入固定资产投资"
              ></el-input>
            </el-form-item>
            <el-form-item label="资产分类 " prop="zcfl">
              <el-input
                v-model="form.zcfl"
                placeholder="请输入资产分类 "
              ></el-input>
            </el-form-item>
            <el-form-item label="主要贸易国家 " prop="zymygj">
              <el-input
                v-model="form.zymygj"
                placeholder="请输入主要贸易国家 "
              ></el-input>
            </el-form-item>
            <el-form-item label="电子账册分类 " prop="dzzcfl">
              <el-input
                v-model="form.dzzcfl"
                placeholder="请输入电子账册分类 "
              ></el-input>
            </el-form-item>

            <el-form-item label="海关税收" prop="hgss">
              <el-input
                v-model="form.hgss"
                placeholder="请输入海关税收"
              ></el-input>
            </el-form-item>
            <el-form-item label="税务部门税收" prop="swbmss">
              <el-input
                v-model="form.swbmss"
                placeholder="请输入税务部门税收"
              ></el-input>
            </el-form-item>
            <el-form-item label="期末企业从业人员" prop="qmqycyry">
              <el-input
                v-model="form.qmqycyry"
                placeholder="请输入期末企业从业人员"
              ></el-input>
            </el-form-item>
            <el-form-item label="实际使用外资金额" prop="sjsywzje">
              <el-input
                v-model="form.sjsywzje"
                placeholder="请输入实际使用外资金额"
              ></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="180px">
            <el-form-item label="规模以上工业产值" prop="gmysgycz">
              <el-input
                v-model="form.gmysgycz"
                placeholder="请输入规模以上工业产值"
              ></el-input>
            </el-form-item>

            <el-form-item label="进出口总值" prop="jckzz">
              <el-input
                v-model="form.jckzz"
                placeholder="请输入进出口总值"
              ></el-input>
            </el-form-item>
            <el-form-item label="进口总值" prop="jkzz">
              <el-input
                v-model="form.jkzz"
                placeholder="请输入进口总值"
              ></el-input>
            </el-form-item>
            <el-form-item label="出口总值" prop="ckzz">
              <el-input
                v-model="form.ckzz"
                placeholder="请输入出口总值"
              ></el-input>
            </el-form-item>
            <el-form-item label="加工贸易进出口值 " prop="jgmyjckz">
              <el-input
                v-model="form.jgmyjckz"
                placeholder="请输入加工贸易进出口值 "
              ></el-input>
            </el-form-item>
            <el-form-item label="物流货物进出口值 " prop="wlhwjckz">
              <el-input
                v-model="form.wlhwjckz"
                placeholder="请输入物流货物进出口值 "
              ></el-input>
            </el-form-item>
            <el-form-item label="一般贸易进出口值 " prop="ybmyjckz">
              <el-input
                v-model="form.ybmyjckz"
                placeholder="请输入一般贸易进出口值 "
              ></el-input>
            </el-form-item>
            <el-form-item label="维修业务进出口值 " prop="wxyejckz">
              <el-input
                v-model="form.wxyejckz"
                placeholder="请输入维修业务进出口值 "
              ></el-input>
            </el-form-item>
            <el-form-item label="研发业务进出口值 " prop="yfywjckz">
              <el-input
                v-model="form.yfywjckz"
                placeholder="请输入研发业务进出口值 "
              ></el-input>
            </el-form-item>
            <el-form-item label="租赁贸易进出口值 " prop="zlmyjckz">
              <el-input
                v-model="form.zlmyjckz"
                placeholder="请输入租赁贸易进出口值 "
              ></el-input>
            </el-form-item>
            <el-form-item label="跨境电商业务进出口值 " prop="kjdsywjckz">
              <el-input
                v-model="form.kjdsywjckz"
                placeholder="请输入跨境电商业务进出口值 "
              ></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 {
  listENTERPRISETRADEPERFORMANCE,
  getDeptList,
  getENTERPRISETRADEPERFORMANCE,
  delENTERPRISETRADEPERFORMANCE,
  addENTERPRISETRADEPERFORMANCE,
  updateENTERPRISETRADEPERFORMANCE,
} from "@/api/portal/ENTERPRISETRADEPERFORMANCE/ENTERPRISETRADEPERFORMANCE";

export default {
  name: "ENTERPRISETRADEPERFORMANCE",
  data() {
    return {
      // 部门列表
      deptList: [],
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业贸易绩效数据（每个月填报）表格数据
      ENTERPRISETRADEPERFORMANCEList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      activeName: "first",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        deptId: null,
        gmysgycz: null,
        gdzctz: null,
        zcfl: null,
        zymygj: null,
        dzzcfl: null,
        jckzz: null,
        jkzz: null,
        ckzz: null,
        jgmyjckz: null,
        wlhwjckz: null,
        ybmyjckz: null,
        hgss: null,
        swbmss: null,
        qmqycyry: null,
        sjsywzje: null,
        wxyejckz: null,
        yfywjckz: null,
        zlmyjckz: null,
        kjdsywjckz: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          {
            required: true,
            message: "企业贸易绩效数据不能为空",
            trigger: "blur",
          },
        ],
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" },
        ],
        gmysgycz: [
          {
            required: true,
            message: "规模以上工业产值不能为空",
            trigger: "blur",
          },
        ],
        deptName: [
          { required: true, message: "部门信息不能为空", trigger: "blur" },
        ],
        gdzctz: [
          { required: true, message: "固定资产投资不能为空", trigger: "blur" },
        ],
        zcfl: [
          { required: true, message: "资产分类 不能为空", trigger: "blur" },
        ],
        zymygj: [
          { required: true, message: "主要贸易国家 不能为空", trigger: "blur" },
        ],
        dzzcfl: [
          { required: true, message: "电子账册分类 不能为空", trigger: "blur" },
        ],
        jckzz: [
          { required: true, message: "进、出口总值不能为空", trigger: "blur" },
        ],
        jkzz: [
          { required: true, message: "进口总值不能为空", trigger: "blur" },
        ],
        ckzz: [
          { required: true, message: "出口总值不能为空", trigger: "blur" },
        ],
        jgmyjckz: [
          {
            required: true,
            message: "加工贸易进出口值 不能为空",
            trigger: "blur",
          },
        ],
        wlhwjckz: [
          {
            required: true,
            message: "物流货物进出口值 不能为空",
            trigger: "blur",
          },
        ],
        ybmyjckz: [
          {
            required: true,
            message: "一般贸易进出口值 不能为空",
            trigger: "blur",
          },
        ],
        hgss: [
          { required: true, message: "海关税收不能为空", trigger: "blur" },
        ],
        swbmss: [
          { required: true, message: "税务部门税收不能为空", trigger: "blur" },
        ],
        qmqycyry: [
          {
            required: true,
            message: "期末企业从业人员不能为空",
            trigger: "blur",
          },
        ],
        sjsywzje: [
          {
            required: true,
            message: "实际使用外资金额不能为空",
            trigger: "blur",
          },
        ],
        wxyejckz: [
          {
            required: true,
            message: "维修业务进出口值 不能为空",
            trigger: "blur",
          },
        ],
        yfywjckz: [
          {
            required: true,
            message: "研发业务进出口值 不能为空",
            trigger: "blur",
          },
        ],
        zlmyjckz: [
          {
            required: true,
            message: "租赁贸易进出口值 不能为空",
            trigger: "blur",
          },
        ],
        kjdsywjckz: [
          {
            required: true,
            message: "跨境电商业务进出口值 不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    getDeptList().then((res) => {
      this.deptList = res.data;
    });
  },
  methods: {
    /** 查询企业贸易绩效数据（每个月填报）列表 */
    getList() {
      this.loading = true;
      listENTERPRISETRADEPERFORMANCE(this.queryParams).then((response) => {
        this.ENTERPRISETRADEPERFORMANCEList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptId: null,
        gmysgycz: null,
        gdzctz: null,
        zcfl: null,
        zymygj: null,
        dzzcfl: null,
        jckzz: null,
        jkzz: null,
        ckzz: null,
        jgmyjckz: null,
        wlhwjckz: null,
        ybmyjckz: null,
        hgss: null,
        swbmss: null,
        qmqycyry: null,
        sjsywzje: null,
        wxyejckz: null,
        yfywjckz: null,
        zlmyjckz: null,
        kjdsywjckz: 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);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业贸易绩效数据（每个月填报）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getENTERPRISETRADEPERFORMANCE(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业贸易绩效数据（每个月填报）";
      });
    },

    deptSelect(index) {
      this.form.deptId = this.deptList[index].deptId;
      this.form.deptName = this.deptList[index].deptName;
    },
    /** 提交按钮 */
    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) {
            updateENTERPRISETRADEPERFORMANCE(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addENTERPRISETRADEPERFORMANCE(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }else{
          this.$message.error("请补全进出口信息");
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm(
          '是否确认删除企业贸易绩效数据（每个月填报）编号为"' +
            ids +
            '"的数据项？'
        )
        .then(function () {
          return delENTERPRISETRADEPERFORMANCE(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "business/ENTERPRISETRADEPERFORMANCE/export",
        {
          ...this.queryParams,
        },
        `ENTERPRISETRADEPERFORMANCE_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
