<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择服务类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.servicetype"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select
          v-model="queryParams.state"
          placeholder="请选择状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.usestate"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数据年份" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入数据年份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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:zyml:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
          >展开/折叠</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="zymlList"
      row-key="bsm"
      :default-expand-all="isExpandAll"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column label="名称" prop="name" />
      <el-table-column label="服务类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.servicetype" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="目录类型" align="center" prop="parent">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.catalogtype"
            :value="scope.row.parent"
          />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.usestate" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="数据年份" align="center" prop="year" />
      <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-s-cooperation"
            v-if="
              scope.row.parent == 0 && ['Vector'].indexOf(scope.row.type) > -1
            "
            @click="handleDict(scope.row)"
            >字典维护</el-button
          >
          <!-- scope.row.parent == 0 地图服务 1：目录 -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:zyml:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAdd(scope.row)"
            v-hasPermi="['system:zyml:add']"
            >新增</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:zyml:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改数据资源目录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        size="small"
        :inline="true"
      >
        <el-form-item label="父节点" prop="pbsm">
          <treeselect
            v-model="form.pbsm"
            :options="zymlOptions"
            :normalizer="normalizer"
            placeholder="请选择父节点"
          />
        </el-form-item>
        <el-form-item class="form_item" label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item class="form_item" label="服务类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择服务类型">
            <el-option
              v-for="dict in dict.type.servicetype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          class="form_item"
          label="地址"
          prop="url"
          style="position: relative"
        >
          <el-input v-model="form.url" placeholder="请输入地址" />
          <!-- :file-list="fileList" -->
          <el-upload
            ref="fileUpload"
            class="upload"
            :action="uploadFileUrl"
            :before-upload="handleBeforeUpload"
            :limit="limit"
            :on-exceed="handleExceed"
            :on-error="handleUploadError"
            :on-success="handleUploadSuccess"
            :show-file-list="false"
            :headers="headers"
            style="position: absolute; top: 0; right: -70px"
          >
            <el-button size="small" type="primary">上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item class="form_item" label="目录类型" prop="parent">
          <el-select v-model="form.parent" placeholder="请选择目录类型">
            <el-option
              v-for="dict in dict.type.catalogtype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="数据类型" prop="sjlx">
          <el-select v-model="form.sjlx" placeholder="请选择数据类型">
            <el-option
              v-for="dict in dict.type.datatype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="服务器类型" prop="serverType">
          <el-select v-model="form.serverType" placeholder="请选择服务器类型">
            <el-option
              v-for="dict in dict.type.servertype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="数管服务" prop="sde">
          <el-select
            v-model="form.sde"
            clearable
            filterable
            multiple
            placeholder="请选择数管服务"
          >
            <el-option
              v-for="dict in dict.type.dblayers"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="实体名称" prop="sde">
          <el-input v-model="form.sde" placeholder="请输入实体名称" />
        </el-form-item>
        <el-form-item class="form_item" label="标识码" prop="bsm">
          <el-input v-model="form.bsm" placeholder="请输入标识码" disabled />
        </el-form-item>
        <el-form-item class="form_item" label="图标" prop="icon">
          <el-input v-model="form.icon" placeholder="请输入图标" />
        </el-form-item>
        <el-form-item class="form_item" label="级别" prop="lev">
          <el-input v-model="form.lev" placeholder="请输入级别" />
        </el-form-item>
        <el-form-item class="form_item" label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item class="form_item" label="状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.usestate"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="历史数据" prop="sflssj">
          <el-select v-model="form.sflssj" placeholder="请选择历史数据">
            <el-option
              v-for="dict in dict.type.trueorfalse"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="对比分析" prop="sfdbfx">
          <el-select v-model="form.sfdbfx" placeholder="请选择对比分析">
            <el-option
              v-for="dict in dict.type.trueorfalse"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="卷帘" prop="sfjl">
          <el-select v-model="form.sfjl" placeholder="请选择卷帘">
            <el-option
              v-for="dict in dict.type.trueorfalse"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="要素查询" prop="sfcx">
          <el-select v-model="form.sfcx" placeholder="请选择要素查询">
            <el-option
              v-for="dict in dict.type.trueorfalse"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="要素统计" prop="sftj">
          <el-select v-model="form.sftj" placeholder="请选择要素统计">
            <el-option
              v-for="dict in dict.type.trueorfalse"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form_item" label="数据坐标系" prop="epsg">
          <el-input v-model="form.epsg" placeholder="请输入数据坐标系" />
        </el-form-item>
        <el-form-item class="form_item" label="数据年份" prop="year">
          <el-input v-model="form.year" placeholder="请输入数据年份" />
        </el-form-item>
        <el-form-item class="form_item" label="过滤条件" prop="gltj">
          <el-input v-model="form.gltj" placeholder="请输入过滤条件" />
        </el-form-item>
        <!-- <el-form-item class="form_item" label="数据来源" prop="sjly">
          <el-input v-model="form.sjly" placeholder="请输入数据来源" />
        </el-form-item> -->
        <!-- <el-form-item class="form_item" label="图例" prop="legend">
          <el-input v-model="form.legend" placeholder="请输入图例" />
        </el-form-item> -->
        <el-form-item class="form_item" label="数据来源" prop="sjly">
          <el-cascader
            size="small"
            :options="xzoptions"
            :props="{
              checkStrictly: true,
              emitPath: false,
            }"
            v-model="form.sjly"
            clearable
            ref="cascader"
            :filterable="true"
            @change="setXzqdm"
            :show-all-levels="false"
            style="width: 100%"
          ></el-cascader>
        </el-form-item>
        <el-form-item class="form_item" label="业务类型" prop="ywlx">
          <el-input v-model="form.ywlx" placeholder="请输入业务类型" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 字典配置表格弹窗 -->
    <el-dialog
      append-to-body
      :title="'【' + cur_server_name_dic + '】' + '字典配置'"
      :visible.sync="dialogDictVisible"
      width="800px"
      v-dialogDrag
      :before-close="closeDialogDict"
      :close-on-click-modal="false"
      v-loading="dic_loading"
    >
      <el-tabs v-model="tabActiveName" class="el_resourceListTab">
        <el-tab-pane
          v-for="(item, index) in tabelList"
          :key="index"
          :label="item.name"
          :name="item.name"
          style="width: 100%; height: 100%"
        >
          <el-table
            :ref="'table' + item.id"
            :id="'table' + item.id"
            :height="500"
            :data="item.tabelData"
            @cell-click="cellClick"
            :row-class-name="tableRowClassName"
            :cell-class-name="tableCellClassName"
            border
          >
            <el-table-column
              align="center"
              type="index"
              label="序号"
            ></el-table-column>
            <el-table-column align="center" label="字段名称" prop="fieldname">
            </el-table-column>
            <el-table-column prop="sort" label="字段别名" align="center">
              <template slot-scope="{ row, column }">
                <el-input
                  size="mini"
                  v-if="row.index == rowIndex && column.index == columnIndex"
                  v-model="row.fieldaliasname"
                  @blur="inputBlur(row)"
                ></el-input>
                <span v-else>{{ row.fieldaliasname }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmUpdateDict">确 定</el-button>
        <el-button @click="closeDialogDict">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listZyml,
  getZyml,
  delZyml,
  addZyml,
  updateZyml,
} from "@/api/system/zyml";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import request from "@/utils/requestServer";
import { getToken } from "@/utils/auth";
import { getXzq } from "@/api/system/user";
import { GetFieldValue, UpdateFieldValue } from "@/api/system/yztfield";
import axios from "axios";

export default {
  name: "Zyml",
  dicts: [
    "servertype",
    "trueorfalse",
    "usestate",
    "servicetype",
    "catalogtype",
    "datatype",
    "dblayers",
  ],
  components: {
    Treeselect,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 数据资源目录表格数据
      zymlList: [],
      // 数据资源目录树选项
      zymlOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        name: null,
        type: null,
        state: null,
        year: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pbsm: [{ required: true, message: "父节点不能为空", trigger: "blur" }],
        name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
        parent: [
          { required: true, message: "目录类型不能为空", trigger: "change" },
        ],
        state: [{ required: true, message: "状态不能为空", trigger: "change" }],
      },
      oldServerUrl: "",
      // 上传附件
      number: 0,
      uploadList: [],
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传文件服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      fileType: [
        "png",
        "jpg",
        "jpeg",
        "doc",
        "docx",
        "xls",
        "xlsx",
        "ppt",
        "pptx",
        "txt",
        "pdf",
      ],
      fileSize: 100,
      limit: 1,
      fileList: [],
      // 行政区选项
      xzoptions: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 字典维护弹窗显隐
      dialogDictVisible: false,
      cur_server_name_dic: "", // 维护的服务名称
      // 字典维护表格数据
      tabelList: [],
      tabActiveName: "",
      rowIndex: -1, //行索引
      columnIndex: -1, //列索引
      cellClickRow: {},
      dic_loading: false,
      tempRowData: undefined,
    };
  },
  created() {
    this.getXzq();
    this.getList();
  },
  methods: {
    /** 查询数据资源目录列表 */
    getList() {
      this.loading = true;
      listZyml(this.queryParams).then((response) => {
        this.zymlList = this.handleTree(response.data, "bsm", "pbsm");
        this.loading = false;
      });
    },
    /** 转换数据资源目录数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.bsm,
        label: node.name,
        children: node.children,
      };
    },
    /** 查询数据资源目录下拉树结构 */
    getTreeselect() {
      listZyml().then((response) => {
        this.zymlOptions = [];
        const data = { bsm: 0, name: "根节点", children: [] };
        data.children = this.handleTree(response.data, "bsm", "pbsm");
        this.zymlOptions.push(data);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pbsm: "",
        name: "",
        type: "",
        url: "",
        parent: "",
        sjlx: "",
        serverType: "",
        sde: "",
        bsm: "",
        icon: "",
        lev: "",
        sort: "",
        state: "",
        sflssj: "",
        sfdbfx: "",
        sfjl: "",
        sfcx: "",
        sftj: "",
        epsg: "",
        year: "",
        gltj: "",
        sjly: "",
        legend: "",
        ywlx: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.bsm) {
        this.form.pbsm = row.bsm;
      } else {
        this.form.pbsm = 0;
      }
      this.open = true;
      this.title = "添加数据资源目录";
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      if (row != null) {
        this.form.pbsm = row.bsm;
      }
      getZyml(row.bsm).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据资源目录";
        this.oldServerUrl = response.data.url;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          for (let key in this.form) {
            if (this.form[key] != "0" && !this.form[key]) {
              this.form[key] = "";
            }
          }
          if (this.form.sde) {
            if (typeof this.form.sde != "string") {
              //if (this.form.sde.length > 0) {
              this.form.sde = this.form.sde.join(",");
              //}
            }
          }
          if (this.form.bsm != null) {
            // && this.oldServerUrl != this.form.url
            if (
              this.form.url &&
              this.form.type != "TILE" &&
              this.form.serverType === "Arcgis" &&
              this.form.parent == "0"
            ) {
              // 若修改服务地址-重新调用地址获取图例
              request({
                method: "get",
                url: this.form.url + "/legend?f=pjson",
              })
                .then((res) => {
                  this.form.legend = JSON.stringify(res.layers[0].legend);
                  // 调用接口修改服务
                  updateZyml(this.form).then((response) => {
                    this.$modal.msgSuccess("修改成功");
                    this.open = false;
                    this.getList();
                  });
                })
                .catch(() => {
                  this.form.legend = "";
                });
            } else {
              // 调用接口修改服务
              updateZyml(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            // 注册服务-调用地址获取图例
            if (
              this.form.url &&
              this.form.type != "TILE" &&
              this.form.serverType === "Arcgis" &&
              this.form.parent == "0"
            ) {
              request({
                method: "get",
                url: this.form.url + "/legend?f=pjson",
              })
                .then((res) => {
                  this.form.legend = JSON.stringify(res.layers[0].legend);
                  // 调用接口注册服务
                  addZyml(this.form).then((response) => {
                    this.$modal.msgSuccess("新增成功");
                    this.open = false;
                    this.getList();
                  });
                })
                .catch(() => {
                  this.form.legend = "";
                });
            } else {
              // 调用接口注册服务
              addZyml(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除数据资源目录编号为"' + row.bsm + '"的数据项？')
        .then(function () {
          return delZyml(row.bsm);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 上传前校检格式和大小 */
    handleBeforeUpload(file) {
      // 校检文件类型
      if (this.fileType) {
        const fileName = file.name.split(".");
        const fileExt = fileName[fileName.length - 1];
        const isTypeOk = this.fileType.indexOf(fileExt) >= 0;
        if (!isTypeOk) {
          this.$modal.msgError(
            `文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`
          );
          return false;
        }
      }
      // 校检文件大小
      if (this.fileSize) {
        const isLt = file.size / 1024 / 1024 < this.fileSize;
        if (!isLt) {
          this.$modal.msgError(`上传文件大小不能超过 ${this.fileSize} MB!`);
          return false;
        }
      }
      this.$modal.loading("正在上传文件，请稍候...");
      this.number++;
      return true;
    },
    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传失败
    handleUploadError(err) {
      this.$modal.msgError("上传文件失败，请重试");
      this.$modal.closeLoading();
    },
    // 上传成功回调
    handleUploadSuccess(res, file) {
      if (res.code === 200) {
        // this.uploadList.push({ name: res.data.url, url: res.data.url });
        this.form.url = res.data.url;
        this.form.name = file.name;
        // this.form.name = !this.form.name ? file.name : this.form.name
        this.$refs.fileUpload.handleRemove(file);
        this.$modal.closeLoading();
      } else {
        this.number--;
        this.$modal.closeLoading();
        this.$modal.msgError(res.msg);
        this.$refs.fileUpload.handleRemove(file);
        this.form.url = "";
        // this.uploadedSuccessfully();
      }
    },
    // 构建行政区tree
    resetTree(data) {
      data.forEach((item) => {
        if (!item.isparent && item.children.length == 0) {
          delete item.children;
        }
        if (item.isparent && item.children.length > 0) {
          this.resetTree(item.children);
        }
      });
      return data;
    },
    // 获取行政区
    getXzq() {
      getXzq({ city: true }).then((res) => {
        if (res.success) {
          this.xzoptions = this.resetTree(res.data);
        }
      });
    },
    // 获取行政区数据
    setXzqdm() {
      if (typeof this.$refs.cascader.getCheckedNodes()[0] !== "undefined") {
        this.form.sjly = this.$refs.cascader.getCheckedNodes()[0].value;
      }
    },
    /** 字典维护 */
    async handleDict(row) {
      this.tempRowData = row;
      this.tabelList = [];
      this.tempTableData = [];
      //默认选中
      this.tabActiveName = row.name;
      // console.log(row.url, row);
      let indexss = row.url.lastIndexOf("/");
      var resolvess = row.url.substring(0, indexss);
      let url1 = resolvess.replace("map-", "data-");
      let url3 = row.sde.substring(0, row.sde.indexOf(":")) + "/datasets/";
      let url2 = url1.replace("maps", "data/datasources/" + url3);
      let reqName = row.sde.substring(row.sde.indexOf(":") + 1, row.sde.length)
      if (row.legend == "" && row.url != "") {
        //从iserver中获取数据地址
        let newUrl = url2 + reqName + "/fields.json";
        request({
          method: "get",
          url: newUrl,
        }).then((res) => {
          console.log(res);
          if (res.fieldNames.length > 0) {
            //处理数据
            res.fieldNames.forEach((item) => {
              this.tempTableData.push({
                fieldname: item,
                fieldaliasname: item,
              });
            });

            this.tabelList.push({
              bsm: row.bsm,
              name: row.name,
              tabelData: this.tempTableData,
              servicename: row.name,
            });
          }
        });
      } else {
        //如果lenged中存在字段修正数据，则直接使用
        this.tabelList.push({
          bsm: row.bsm,
          name: row.name,
          tabelData: JSON.parse(row.legend),
          servicename: row.name,
        });
      }

      this.cur_server_name_dic = row.name;
      this.dialogDictVisible = true;
    },
    //确定字典维护的修改
    confirmUpdateDict() {
      if (this.tabelList.length > 0) {
        //将数据转化为字符串存储
        this.tempRowData.legend = JSON.stringify(this.tabelList[0].tabelData);
        updateZyml(this.tempRowData).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.dialogDictVisible = false;
          //关闭弹窗时还原编辑状态
          this.columnIndex = -1;
          this.getList();
        });
      }
    },
    /** 字典维护—— 关闭弹窗 */
    closeDialogDict() {
      this.resetDict();
      this.dialogDictVisible = false;
      //关闭弹窗时还原编辑状态
      this.columnIndex = -1;
    },
    resetDict() {
      this.cur_server_name_dic = "";
      this.tabelList = [];
    },
    // 字典维护—— 把每一行的索引放到row里
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex;
    },
    // 字典维护—— 把每一列的索引放到column里
    tableCellClassName({ column, columnIndex }) {
      column.index = columnIndex;
    },
    // 字典维护—— 单击单元格
    cellClick(row, column) {
      this.rowIndex = row.index;
      this.columnIndex = column.index;
      this.cellClickRow = Object.assign({}, row);
    },
    // 字典维护—— 编辑单元格失去焦点
    inputBlur(row) {
      this.rowIndex = -1;
      this.columnIndex = -1;
      console.log(row);
    },
    // 字典维护—— 字段浏览设置
    // handleStatusChange(row) {
    //     console.log(row)
    // },
  },
};
</script>
<style scoped>
.form_item {
  width: calc(50% - 20px);
}
</style>
