<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <catalogue-tree @callback="catalogueCallBack" catalogueType="share" />
      </el-col>
      <el-col :span="20" :xs="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="68px"
          :class="showSearch ? '' : ' hide'"
        >
          <el-form-item label="数据名称" prop="dataName">
            <el-input
              v-model="queryParams.dataName"
              placeholder="请输入数据名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="" prop="syncFlag">
            <el-checkbox
              label="是否有更新"
              v-model="queryParams.syncFlag"
            ></el-checkbox>
          </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="['system/integration:data:add']"
              >新增</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              @click="handleMount"
              v-hasPermi="['system/integration:data:add']"
              >挂载</el-button
            >
          </el-col>
          <el-col :span="6">
            <el-alert
              type="warning"
              :title="`有 ${updateCount} 条共享数据有更新`"
              :closable="false"
              v-if="updateCount > 0"
            ></el-alert>
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dataList">
          <el-table-column label="编号" align="center" prop="id" width="80" />
          <el-table-column label="数据名称" prop="dataName" />
          <el-table-column label="表名" prop="tableName" />
          <el-table-column label="标签" prop="tag" />
          <el-table-column label="申请数量" prop="applyCount" align="center"></el-table-column>
          <el-table-column label="审核状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sys_audit_status"
                :value="scope.row.status"
                v-if="scope.row.status !== '2'"
              />
              <el-tooltip
                :content="'驳回原因：' + scope.row.auditRemark"
                placement="top"
                v-else
              >
                <dict-tag
                  :options="dict.type.sys_audit_status"
                  :value="scope.row.status"
                />
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="有更新" prop="syncFlag" align="center">
            <template slot-scope="scope">
              <el-tooltip
                content="当前共享数据对应的字段有更新，点击修改查看"
                placement="top"
              >
                <el-tag v-if="scope.row.syncFlag === '1'"
                  >是</el-tag
                ></el-tooltip
              >
            </template>
          </el-table-column>
          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="更新时间"
            align="center"
            prop="updateTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.updateTime, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            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="['system/integration:data:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system/integration:data: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-col>
    </el-row>

    <!-- 添加或修改共享数据对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="目录" prop="catalogueId" required>
              <treeselect
                v-model="form.catalogueId"
                :options="treeList"
                :show-count="true"
                placeholder="请选择目录"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数据名称" prop="dataName">
              <el-input v-model="form.dataName" placeholder="请输入数据名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="整合数据" prop="dataId">
              <el-select
                v-model="form.dataId"
                placeholder="请选择整合数据"
                @change="changeData"
                filterable
                v-if="!form.id"
              >
                <el-option
                  :label="`【${
                    db.isMetadata === 'Y' ? '元数据' : '整合数据'
                  }】${db.dataName}（${db.tableName}）`"
                  :value="db.id"
                  v-for="(db, i) in integrationList"
                  :key="i"
                ></el-option>
              </el-select>
              <span v-else>{{ form.dataName }}（{{ form.tableName }}）</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开放类型" prop="publishType">
              <el-select
                v-model="form.publishType"
                placeholder="请选择开放类型"
              >
                <el-option
                  v-for="dict in dict.type.sys_publish_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="增量字段" prop="addField">
              <el-input v-model="form.addField" placeholder="请输入增量字段" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="信息标识符" prop="infoId">
              <el-input v-model="form.infoId" placeholder="请输入信息标识符" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提供机构" prop="provideOrganization">
              <el-select
                v-model="form.provideOrganization"
                placeholder="请选择提供机构"
                filterable
              >
                <el-option
                  v-for="dict in dict.type.sys_provide_organization"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标签" prop="tag">
              <el-select
                v-model="form.tag"
                placeholder="请选择"
                multiple
                style="width: 100%"
                filterable
              >
                <el-option
                  v-for="(tag, i) in tagList"
                  :label="tag.tagName"
                  :value="tag.tagName"
                  :key="i"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="描述" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-col
          :span="form.syncFlag === '1' ? 20 : 24"
          style="margin-bottom: 10px; padding-left: 10px"
        >
          <span content-position="left">
            <b style="margin-right: 10px">数据项</b>
            <el-tag
              type="danger"
              v-if="form.id > 0 && form.syncFlag === '1'"
              size="mini"
            >
              有更新
            </el-tag>
            <el-tag
              type="info"
              v-if="form.id > 0 && form.syncFlag !== '1'"
              size="mini"
            >
              无更新
            </el-tag>
          </span>
        </el-col>
        <el-col :span="4" v-if="form.id > 0 && form.syncFlag === '1'">
          <el-button
            type="primary"
            size="mini"
            style="float: right"
            @click="handleBatchConfirm"
            v-if="form.id > 0 && form.syncFlag === '1'"
            >批量确认变更</el-button
          >
        </el-col>
      </el-row>

      <el-table
        :data="columnList"
        max-height="350"
        :row-class-name="tableRowClassName"
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
        ></el-table-column>
        <el-table-column
          label="英文名称"
          prop="columnName"
          show-overflow-tooltip=""
        >
          <template slot-scope="scope">
            <span v-if="!scope.row.newData">{{ scope.row.columnName }}</span>
            <span
              v-else-if="scope.row.columnName === scope.row.newData.columnName"
              >{{ scope.row.columnName }}</span
            >
            <span v-else>
              <div>{{ scope.row.columnName }}</div>
              <div>
                <span style="color: red"
                  >新值：{{ scope.row.newData.columnName }}</span
                >
              </div>
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="中文名称"
          prop="columnComment"
          show-overflow-tooltip=""
        >
          <template slot-scope="scope">
            <span v-if="!scope.row.newData">{{ scope.row.columnComment }}</span>
            <span
              v-else-if="
                scope.row.columnComment === scope.row.newData.columnComment
              "
              >{{ scope.row.columnComment }}</span
            >
            <span v-else>
              <div>{{ scope.row.columnComment }}</div>
              <div>
                <span style="color: red"
                  >新值：{{ scope.row.newData.columnComment }}</span
                >
              </div>
            </span>
          </template>
        </el-table-column>
        <el-table-column label="数据格式" prop="columnType" width="150">
          <template slot-scope="scope">
            <span v-if="!scope.row.newData">{{ scope.row.columnType }}</span>
            <span
              v-else-if="scope.row.columnType === scope.row.newData.columnType"
              >{{ scope.row.columnType }}</span
            >
            <span v-else>
              <div>{{ scope.row.columnType }}</div>
              <div>
                <span style="color: red"
                  >新值：{{ scope.row.newData.columnType }}</span
                >
              </div>
            </span>
          </template>
        </el-table-column>
        <!-- <el-table-column
          label="是否必填"
          prop="isRequired"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isRequired"
              active-value="Y"
              inactive-value="N"
              size="mini"
            ></el-switch>
          </template>
        </el-table-column> -->
        <el-table-column
          label="是否可见"
          prop="isVisable"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isVisable"
              active-value="Y"
              inactive-value="N"
              size="mini"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          label="是否搜索"
          prop="isSearchable"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isSearchable"
              active-value="Y"
              inactive-value="N"
              size="mini"
              :disabled="scope.row.isVisable !== 'Y'"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          label="脱敏"
          prop="desensitizationRuleId"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-select
              v-model="scope.row.desensitizationRuleId"
              placeholder="请选择规则"
              clearable
              size="mini"
              :disabled="scope.row.isVisable !== 'Y'"
              filterable
            >
              <el-option
                :label="rule.ruleName"
                :value="rule.id"
                v-for="(rule, i) in desensitizationRuleList"
                :key="i"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          label="变更类型"
          prop="businessType"
          show-overflow-tooltip=""
          align="center"
          v-if="form.id > 0 && form.syncFlag === '1'"
        >
          <template slot-scope="scope">
            <el-tag
              type="info"
              size="mini"
              v-if="
                scope.row.businessType === 'DELETE' && scope.row.confirm === 0
              "
              >移除</el-tag
            >
            <el-tag
              type="success"
              size="mini"
              v-if="
                scope.row.businessType === 'DELETE' && scope.row.confirm === 1
              "
              >确认移除</el-tag
            >
            <el-tag
              size="mini"
              v-if="
                scope.row.businessType === 'UPDATE' && scope.row.confirm === 0
              "
              >变更</el-tag
            >
            <el-tag
              type="success"
              size="mini"
              v-if="
                scope.row.businessType === 'UPDATE' && scope.row.confirm === 1
              "
              >确认变更</el-tag
            >
            <el-tag
              type="danger"
              size="mini"
              v-if="
                scope.row.businessType === 'INSERT' && scope.row.confirm === 0
              "
              >新增</el-tag
            >
            <el-tag
              type="success"
              size="mini"
              v-if="
                scope.row.businessType === 'INSERT' && scope.row.confirm === 1
              "
              >确认新增</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          v-if="form.id > 0 && form.syncFlag === '1'"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-if="scope.row.businessType && scope.row.confirm !== 1"
              @click="handleConfirm(scope.row, 1)"
            >
              <span v-if="scope.row.businessType === 'INSERT'">共享</span>
              <span v-if="scope.row.businessType === 'UPDATE'">更新</span>
              <span v-if="scope.row.businessType === 'DELETE'">移除</span>
            </el-button>

            <el-button
              size="mini"
              type="text"
              icon="el-icon-refresh-right"
              v-if="scope.row.businessType && scope.row.confirm === 1"
              @click="handleConfirm(scope.row, 0)"
            >
              取消
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="submitting"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 挂载 -->
    <el-dialog
      title="挂载"
      :visible="true"
      width="800px"
      append-to-body
      v-if="mount"
      @close="cancel"
    >
      <el-form
        ref="mountForm"
        :model="queryIntegrationParam"
        :rules="rules"
        label-width="120px"
        :inline="true"
      >
        <el-form-item label="整合数据名称" prop="data_id">
          <el-input
            v-model="queryIntegrationParam.tableName"
            placeholder="请输入整合数据名称/表名"
            clearable
          />
        </el-form-item>
        <el-form-item label="未挂载" prop="isBind">
          <el-checkbox label="" v-model="queryIntegrationParam.isBind"></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleIntegrationQuery"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        :data="integrationPageList"
        @selection-change="handleSelectionChange"
        :height="500"
        v-loading="loading"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="数据名称" prop="dataName"></el-table-column>
        <el-table-column label="表名" prop="tableName"></el-table-column>
        <el-table-column label="来源" prop="isMetadata">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isMetadata === 'Y'" size="mini"
              >元数据</el-tag
            >
            <el-tag
              v-if="scope.row.isMetadata === 'N'"
              type="success"
              size="mini"
              >整合数据</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="描述" prop="remark"></el-table-column>
      </el-table>
      <pagination
        v-show="integrationTotal > 0"
        :total="integrationTotal"
        :page.sync="queryIntegrationParam.pageNum"
        :limit.sync="queryIntegrationParam.pageSize"
        @pagination="getIntegrationPageList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitMountForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listData as listIntegrationData,
  getDataItem as getIntegrationDataItem,
} from "@/api/system/integration/data";
import {
  listData,
  getData,
  delData,
  addData,
  updateData,
  getDataItem,
  mountData,
} from "@/api/system/share/data";
import { listCatalogue } from "@/api/system/integration/catalogue";
import { listTag } from "@/api/system/base/tag";
import { listDesensitization } from "@/api/system/quality/desensitization";
import CatalogueTree from "@/components/CatalogueTree";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Data",
  dicts: [
    "sys_provide_organization",
    "sys_yes_no",
    "sys_audit_status",
    "sys_publish_type",
  ],
  components: { CatalogueTree, Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      submitting: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 共享数据表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 挂载弹出层
      mount: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        catalogueId: null,
        databaseId: null,
        tableId: null,
        tableName: null,
        infoId: null,
        tag: null,
        provideOrganization: null,
        status: null,
        isMetadata: null,
        repetitionField: null,
        syncFlag: null,
        dataName: null,
      },
      queryIntegrationParam: {
        pageNum: 1,
        pageSize: 10,
        tableName: null,
        isBind: null
      },
      // 目录树
      treeList: [],
      // 标签
      tagList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dataId: [
          { required: true, message: "整合数据不能为空", trigger: "change" },
        ],
        dataName: [
          { required: true, message: "数据名称不能为空", trigger: "change" },
        ],
        publishType: [
          { required: true, message: "开放类型不能为空", trigger: "change" },
        ],
        catalogueId: [
          { required: true, message: "请选择目录", trigger: "change" },
        ],
        addField: [
          { required: true, message: "请填写增量字段", trigger: "change" },
        ],
      },
      integrationList: [], // 下拉选择的整合数据
      selectedIntegrationList: [], // 选择的共享数据列表
      columnList: [],
      mountForm: {},
      integrationPageList: [],
      integrationTotal: 0,
      updateCount: 0,
      desensitizationRuleList: [], // 脱敏规则
    };
  },
  created() {
    this.getUpdateCount();
    this.getCatalogueList();
    this.getIntegrationList();
    this.getTagList();
    this.getList();
    this.getDesensitizationRuleList();
  },
  methods: {
    tableRowClassName(row, rowIndex) {
      if (row.row.confirm !== 1) {
        return "warning-row";
      }
    },
    catalogueCallBack(data) {
      this.queryParams.catalogueId = data.id;
      this.handleQuery();
    },
    getDesensitizationRuleList() {
      // 获取脱敏规则列表
      listDesensitization({ pageNum: 1, pageSize: 10000 }).then((response) => {
        this.desensitizationRuleList = response.rows;
      });
    },
    getUpdateCount() {
      listData({ pageNum: 1, pageSize: 10000, syncFlag: 1 }).then(
        (response) => {
          this.updateCount = response.total;
        }
      );
    },
    /** 查询目录列表 */
    getCatalogueList() {
      listCatalogue({
        pageNum: 1,
        pageSize: 100000,
        catalogueType: "share",
      }).then((response) => {
        let treeList = [];
        if (response.rows && response.rows.length > 0) {
          response.rows.forEach((p) => {
            treeList.push({
              id: p.id,
              parentId: p.parentId,
              label: p.catalogueName,
              children: [],
            });
          });
        }
        this.treeList = this.handleTree(treeList);
      });
    },
    /** 查询共享数据列表 */
    getList() {
      this.loading = true;
      const params = JSON.parse(JSON.stringify(this.queryParams));
      if (this.queryParams.syncFlag) {
        params.syncFlag = 1;
      } else {
        params.syncFlag = null;
      }
      listData(params).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getIntegrationList() {
      this.loading = true;
      listIntegrationData({ status: 1, pageSize: 100000, pageNum: 1, isBind: true }).then(
        (response) => {
          this.integrationList = response.rows;
          this.loading = false;
        }
      );
    },
    getIntegrationPageList() {
      this.loading = true;
      listIntegrationData(this.queryIntegrationParam).then((response) => {
        this.integrationPageList = response.rows;
        this.integrationTotal = response.total;
        this.loading = false;
      });
    },
    getTagList() {
      listTag({}).then((response) => {
        this.tagList = response.rows;
      });
    },
    changeData(e) {
      //   console.log(e);
      // 查询整合数据对应的数据字段
      getIntegrationDataItem(e).then((response) => {
        // 新增的数据全部确认
        if (response.data) {
          response.data.forEach((p) => {
            p.confirm = 1;
          });
        }
        this.columnList = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.mount = false;
      this.columnList = [];
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        catalogueId: null,
        databaseId: null,
        tableId: null,
        dataName: null,
        infoId: null,
        tag: null,
        provideOrganization: null,
        status: null,
        isMetadata: null,
        repetitionField: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      };
      this.resetForm("form");

      this.mountForm = {
        databaseId: null,
      };
      this.resetForm("mountForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleIntegrationQuery() {
      this.queryIntegrationParam.pageNum = 1;
      this.getIntegrationPageList();
    },
    /** 重置按钮操作 */
    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.columnList = [];
      this.reset();
      this.open = true;
      this.title = "添加共享数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.columnList = [];
      this.reset();
      const id = row.id || this.ids;
      this.selectedIntegrationList = [];
      this.columnList = [];
      getData(id, 1).then((response) => {
        this.form = response.data;
        if (this.form.tag && this.form.tag.length > 0) {
          this.form.tag = this.form.tag.split(",");
        }

        if (this.form.syncFlag) {
          getDataItem(id, 1).then((res) => {
            if (res.data.dataItems) {
              res.data.dataItems.forEach((p) => {
                if (!p.businessType) {
                  p.confirm = 1;
                } else {
                  p.confirm = 0;
                }
              });
            }

            // 排序
            res.data.dataItems.sort(function (a, b) {
              const aV = a.businessType ? a.businessType.length : 0;
              const bV = b.businessType ? b.businessType.length : 0;
              return bV - aV;
            });
            this.columnList = res.data.dataItems;
          });
        } else {
          getDataItem(id, 0).then((res) => {
            if (res.data) {
              res.data.forEach((p) => {
                p.confirm = 1;
              });
            }

            this.columnList = res.data;
          });
        }

        this.open = true;
        this.title = "修改共享数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const form = JSON.parse(JSON.stringify(this.form));
          if (form.tag) {
            form.tag = form.tag.join(",");
          } else {
            form.tag = null;
          }
          if (!this.columnList || this.columnList.length === 0) {
            this.$modal.msgError("数据项不能为空");
            return;
          }
          const dateItems = JSON.parse(JSON.stringify(this.columnList));
          const submitDataItems = [];
          dateItems.forEach((p) => {
            if (!p.confirm) {
              // 未确认的新增不加入提交数据
              if (p.businessType !== "INSERT") {
                submitDataItems.push(p);
              }
            } else {
              // 确认后，编辑使用新数据
              if (p.businessType === "UPDATE") {
                p = p.newData;
                delete p.newData;
              }

              // 确认后，非删除加入
              if (p.businessType !== "DELETE") {
                submitDataItems.push(p);
              }
            }
          });
          form.dataItems = submitDataItems;
          console.log(form);
          this.submitting = true;
          if (form.id != null) {
            updateData(form).then((response) => {
              this.submitting = false;
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.getUpdateCount();
            }).catch(() => {
              this.submitting = false;
            });
          } else {
            addData(form).then((response) => {
              this.submitting = false;
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.getUpdateCount();
            }).catch(() => {
              this.submitting = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除共享数据编号为"' + ids + '"的数据项？')
        .then(function () {
          return delData(ids);
        })
        .then(() => {
          this.getList();
          this.getUpdateCount();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/integration/data/export",
        {
          ...this.queryParams,
        },
        `data_${new Date().getTime()}.xlsx`
      );
    },
    handleMount() {
      this.getIntegrationPageList();
      this.selectedIntegrationList = [];
      this.columnList = [];
      this.mount = true;
    },
    handleSelectionChange(selection) {
      this.selectedIntegrationList = selection;
    },
    submitMountForm() {
      this.$refs["mountForm"].validate((valid) => {
        if (valid) {
          const param = {
            dataIds: this.selectedIntegrationList.map((p) => p.id),
          };
          mountData(param).then((response) => {
            this.getList();
            this.getUpdateCount();
            this.$modal.msgSuccess("挂载成功");
            this.cancel();
          });
        }
      });
    },
    handleConfirm(row, confirm) {
      row.confirm = confirm;
    },
    handleBatchConfirm() {
      this.columnList.forEach((p) => {
        p.confirm = 1;
      });
    },
  },
};
</script>