<template>
  <div class="app-container">
    <div class="search">
      <el-input
        v-model="table.getdataListParm.parammaps.rolename"
        placeholder="角色名称"
        style="width: 180px"
        class="filter-item"
        clearable
      />
      <el-input
        v-model="table.getdataListParm.parammaps.createmp"
        placeholder="创建人"
        style="width: 180px"
        class="filter-item"
        clearable
      />
      <el-select
        v-model="table.getdataListParm.parammaps.enable"
        placeholder="是否启用"
        class="filter-item"
        style="width: 120px"
        clearable
      >
        <el-option
          v-for="(item, index) in enableList"
          :key="index"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
      <el-date-picker
        ref="inputDatetime"
        v-model="table.getdataListParm.parammaps.inputDatetime"
        class="inputDatetime filter-item"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        style="width: 250px"
      />
      <el-button class="successBorder" @click="form_search">查询</el-button>
      <el-button class="successBorder" @click="form_clear">重置</el-button>
      <el-button class="success" @click="form_add">新增</el-button>
      <el-button class="danger" @click="handleDelete">删除</el-button>
    </div>

    <div class="table">
      <el-table
        :key="table.tableKey"
        v-loading="table.listLoading"
        element-loading-text="给我一点时间"
        :data="table.list"
        border
        fit
        highlight-current-row
        style="width: 100%"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        :max-height="myHeight"
        @selection-change="change_table_selection"
      >
        <el-table-column type="selection" align="center" width="50" />
        <el-table-column label="序号" align="center" type="index" width="50px">
          <template slot-scope="scope">
            <span>{{
              scope.$index + (table.pageNum - 1) * table.pageSize + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="角色名称" min-width="130px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.NoEdit">{{ scope.row.rolename }}</span>
            <el-input
              v-if="scope.row.Edit"
              v-model="scope.row.rolename"
              type="textarea"
              :autosize="{ minRows: 1.3, maxRows: 4 }"
              maxlength="32"
              style="width: 95%; padding: 10px 0"
            />
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="130px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
            <el-input
              v-if="scope.row.Edit"
              v-model="scope.row.remark"
              type="textarea"
              :autosize="{ minRows: 1.3, maxRows: 4 }"
              maxlength="32"
              style="width: 95%; padding: 10px 0"
            />
          </template>
        </el-table-column>
        <el-table-column label="创建时间" min-width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createdtime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" min-width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createmp }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否启用" min-width="110px" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.enable"
              :disabled="scope.row.NoEdit == true"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="1"
              :inactive-value="0"
              @change="change_enable(scope.$index, scope.row)"
            />
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          width="290"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <!-- 页面权限 -->
            <el-button class="miniSuccess" @click="handleMenu(row)"
              >菜单</el-button
            >
            <!-- <el-button  class="miniSuccess"  @click="handleDataRole(row)">数据</el-button> -->
            <el-button class="miniSuccess" @click="on_role_tap(row)"
              >数据</el-button
            >

            <!-- 页面权限 -->
            <!-- <el-button v-if="row.NoEdit && isRoleEdit" class="miniSuccess" @click="handleRole(row)">页面权限</el-button> -->
            <!-- 新增 -->
            <el-button
              v-if="row.isCreate"
              class="miniSuccess"
              :disabled="isokDisable"
              @click="add_dialog_save(row)"
              >保存</el-button
            >
            <el-button
              v-if="row.isCreate"
              class="minCancel"
              @click="add_cancel(row)"
              >取消</el-button
            >
            <!-- 编辑 -->
            <el-button
              v-if="row.isUpdate"
              class="miniSuccess"
              @click="form_edit(row)"
              >编辑</el-button
            >
            <el-button
              v-if="row.isUpdate"
              class="miniDanger"
              @click="form_delete(row)"
              >删除</el-button
            >
            <!-- 编辑保存 -->
            <el-button
              v-if="row.isUpdateSave"
              class="miniSuccess"
              :disabled="isokDisable"
              @click="form_edit_save(row)"
              >保存</el-button
            >
            <el-button
              v-if="row.isUpdateSave"
              class="minCancel"
              @click="edit_cancel(row)"
              >取消</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="table.total >= 0"
        :total="table.total"
        :page.sync="table.getdataListParm.offset"
        :limit.sync="table.getdataListParm.pagecount"
        @pagination="get_table_data"
      />
    </div>

    <el-dialog
      :title="textMap[role.dialogStatus]"
      :visible.sync="role.dialogFormVisible"
      :close-on-click-modal="false"
      width="70%"
    >
      <div class="role-details inside-base">
        <div class="inside-base-main clearfix">
          <div class="inside-base-cont">
            <div class="role-cont clearfix">
              <div>
                <el-table
                  ref="table"
                  :data="tableData"
                  style="width: 100%; margin-bottom: 20px"
                  row-key="id"
                  border
                  :indent="10"
                  :select-on-indeterminate="true"
                  :default-expand-all="false"
                  show-checkbox
                  :checked-keys="defaultCheckedKeys"
                  :tree-props="{
                    children: 'childList',
                    hasChildren: 'hasChildren',
                  }"
                >
                  <el-table-column prop="name" label="页面" />
                  <el-table-column
                    label="查看"
                    :render-header="renderSeeHeader"
                  >
                    <template slot-scope="scope">
                      <el-checkbox
                        v-model="scope.row.fnCheck.seebutton"
                        :indeterminate="scope.row.indeterminate.seebutton"
                        label="查看"
                        @change="fnCheckEv(scope, 'seebutton')"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="编辑"
                    :render-header="renderEditHeader"
                  >
                    <template slot-scope="scope">
                      <el-checkbox
                        v-model="scope.row.fnCheck.editbutton"
                        :indeterminate="scope.row.indeterminate.editbutton"
                        label="编辑"
                        @change="fnCheckEv(scope, 'editbutton')"
                      />
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div
        slot="footer"
        class="dialog-footer"
        style="right: 30px; position: absolute; bottom: 5px"
      >
        <el-button
          @click="
            role.dialogFormVisible = false;
            get_table_data();
          "
          >取消</el-button
        >
        <el-button
          v-if="role.dialogStatus === 'role'"
          type="success"
          :disabled="isokDisable"
          @click="roleData()"
          >确认</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :title="textMap['menu']"
      :visible.sync="dialogMenuVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :rules="rules"
        label-position="left"
        label-width="100px"
        style="width: 600px; margin-left: 50px"
      >
        <el-form-item label="菜单" prop="menuname">
          <div class="menu-header">
            <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand"
              >展开/折叠</el-checkbox
            >
            <el-checkbox
              v-model="menuNodeAll"
              @change="handleCheckedTreeNodeAll"
              >全选/全不选</el-checkbox
            >
            <el-checkbox
              v-model="menuCheckStrictly"
              @change="handleCheckedTreeConnect"
              >父子联动</el-checkbox
            >
          </div>
          <el-tree
            class="tree-border"
            :data="parentMenu"
            show-checkbox
            ref="menuTree"
            node-key="id"
            :check-strictly="!menuCheckStrictly"
            empty-text="加载中，请稍候"
            :props="defaultProps"
            :default-checked-keys="defaultCheckedKeys"
            :expand-on-click-node="false"
            @check="handleTreeCheck"
          ></el-tree>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="isokDisable" type="primary" @click="updateMenu()">
          确认
        </el-button>
        <el-button
          @click="
            dialogMenuVisible = false;
            close_update_menu_dialog();
          "
        >
          关闭
        </el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="数据权限"
      :visible.sync="dialogDataRoleVisible"
      :close-on-click-modal="false"
    >
      <el-form
        ref="dataRoleTemp"
        :rules="rules"
        label-position="left"
        :model="dataRoleTemp"
        label-width="100px"
        style="width: 600px; margin-left: 50px"
      >
        <el-form-item label="数据权限" prop="datarole">
          <el-radio-group v-model="dataRoleTemp.datarole">
            <el-radio :label="2">全部数据</el-radio>
            <el-radio :label="1">部门数据</el-radio>
            <el-radio :label="0">个人数据</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-if="dataRoleTemp.datarole == 1"
          label="部门"
          prop="deptNameList"
        >
          <el-select
            v-model="dataRoleTemp.deptNameList"
            style="width: 500px"
            multiple
            placeholder="部门"
          >
            <el-option
              v-for="item in findAllDepart"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateDataRole()"> 确认 </el-button>
        <el-button
          @click="
            dialogDataRoleVisible = false;
            get_table_data();
          "
        >
          关闭
        </el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="数据权限"
      :visible.sync="dialogRoleVisible"
      :close-on-click-modal="false"
    >
      <el-form
        ref="dataRoleTemp2"
        :rules="rules"
        label-position="left"
        :model="dataRoleTemp"
        label-width="100px"
        style="margin-left: 50px"
      >
        <!-- 表格 -->
        <div class="table">
          <el-table
            :key="tableObjLeft.tableKey"
            v-loading="tableObjLeft.listLoading"
            element-loading-text="给我一点时间"
            :data="tableObjLeft.list"
            border
            fit
            highlight-current-row
            style="width: 100%"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <!-- <el-table-column label="序号" align="center" type="index" width="50px"  fixed="left">
                        <template slot-scope="scope">
                          <span>{{ scope.$index + (tableObjLeft.pageNum-1) * tableObjLeft.pageSize + 1 }}</span>
                        </template>
                      </el-table-column> -->
            <el-table-column
              label="页面访问权限"
              min-width="120px"
              align="center"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="查看范围"
              min-width="120px"
              align="center"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-radio-group v-model="scope.row.typeId">
                  <el-radio :label="'2'">全部数据</el-radio>
                  <el-radio :label="'1'">部门数据</el-radio>
                  <el-radio :label="'0'">个人数据</el-radio>
                </el-radio-group>
              </template>
            </el-table-column>
          </el-table>
          <!-- <pagination v-show="tableObjLeft.total>0" :total="tableObjLeft.total" :page.sync="tableObjLeft.getdataListParm.offset" :limit.sync="tableObjLeft.getdataListParm.pagecount" @pagination="get_tableLeft_data" /> -->
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sure_role()"> 确认 </el-button>
        <el-button
          @click="
            dialogRoleVisible = false;
            get_table_data();
          "
        >
          关闭
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TreeSelect from "@/components/TreeSelect";
import {
  GetDataByName,
  PostDataByName,
  failproccess,
  transData,
  UpdateDataRelation,
  getRecuData,
  ExecDataByConfig,
  checkButtons,
  calculativeWidth,
} from "@/api/common";
import Cookies from "js-cookie";
import { parseTime } from "@/utils/index.js";
import { MessageBox } from "element-ui";
import Pagination from "@/components/Pagination";
export default {
  name: "Role",
  components: { Pagination, TreeSelect },
  data() {
    return {
      myHeight: document.documentElement.clientHeight - 85 - 160,
      isRoleEdit: [],
      enableList: [
        { id: 1, name: "是" },
        { id: 0, name: "否" },
      ], // 是否启用
      getMenuParm: {
        name: "getMenuandButtonRecuRule",
        idname: "id",
        params: [-1],
      },

      dialogMenuVisible: false,
      dialogDataRoleVisible: false,

      dialogRoleVisible: false,
      //权限里的树形数据
      parentMenu: [
        // {
        //   "children":[],"component":"dashboard/editor/index","enable":0,"icon":"首页","id":338,"menutype":"menu","method":"post","name":"首页","parentid":-1,"path":"Dashboard","redirect":"","sort":0,"title":"首页"
        // },
        // {
        //   "component":"Layout","enable":1,"icon":"报表管理","id":249,"menutype":"menu","method":"post","name":"报表管理","parentid":-1,"path":"report","redirect":"noredirect","sort":0,"title":"报表管理",
        //   "children":[
        //     {"children":[],"component":"report/equipmentIndex/index","enable":1,"icon":"集团设备指标","id":376,"menutype":"menu","method":"post","name":"设备指标","parentid":249,"path":"EquipmentIndex","redirect":"","sort":0,"title":"设备指标"},
        //     {"children":[],"component":"asset/standardAssetAllocation/index","enable":1,"icon":"资产标准配置","id":390,"menutype":"menu","method":"post","name":"资产标准配置","parentid":249,"path":"AssetStandardManagement","redirect":"","sort":0,"title":"资产标准配置"},
        //     {"children":[],"component":"report/purchaseScrap/index","enable":1,"icon":"设备购置报废统计","id":391,"menutype":"menu","method":"post","name":"设备购置报废统计","parentid":249,"path":"PurchaseScrap","redirect":"","sort":0,"title":"设备购置报废统计"}]
        // },
        // {
        //   "component":"Layout","enable":1,"icon":"资产管理","id":30,"menutype":"menu","method":"post","name":"资产管理","parentid":-1,"path":"asset","redirect":"noredirect","sort":1,"title":"资产管理",
        //   "children":[
        //     {
        //       "component":"asset/basics/index","enable":1,"icon":"设备基础信息","id":39,"menutype":"menu","method":"post","name":"设备基础信息","parentid":30,"path":"Basics","redirect":"","sort":1,"title":"设备基础信息",
        //       "children":[
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":283,"menutype":"button","method":"post","name":"设备基础信息界面","parentid":39,"path":"asset:basic:basic","redirect":"","sort":0,"title":"设备基础信息界面"
        //           },
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":284,"menutype":"button","method":"post","name":"审核界面","parentid":39,"path":"asset:basic:shjm","redirect":"","sort":0,"title":"审核界面"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":286,"menutype":"button","method":"post","name":"审核按钮","parentid":39,"path":"asset:basic:shenhe","redirect":"","sort":0,"title":"审核按钮"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":301,"menutype":"button","method":"post","name":"高级删除","parentid":39,"path":"asset:basics:del2","redirect":"","sort":0,"title":"高级删除"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":163,"menutype":"button","method":"post","name":"添加","parentid":39,"path":"asset:basics:add","redirect":"","sort":0,"title":"添加"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":164,"menutype":"button","method":"post","name":"卡片","parentid":39,"path":"asset:basics:kapian","redirect":"","sort":0,"title":"卡片"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":165,"menutype":"button","method":"post","name":"编辑","parentid":39,"path":"asset:basics:update","redirect":"","sort":0,"title":"编辑"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":166,"menutype":"button","method":"post","name":"审核-删除","parentid":39,"path":"asset:basics:del","redirect":"","sort":0,"title":"审核-删除"}
        //       ]
        //     },
        //     {"children":[],"component":"Layout","enable":0,"icon":"table","id":40,"menutype":"menu","method":"post","name":"设备管理文档","parentid":30,"path":"telvisit","redirect":"","sort":2,"title":"设备管理文档"},
        //     {"children":[],"component":"asset/statistics/index","enable":0,"icon":"设备变更","id":205,"menutype":"menu","method":"post","name":"设备统计","parentid":30,"path":"Statistics","redirect":"","sort":2,"title":"设备统计"},
        //     {"children":[],"component":"asset/template/index","enable":1,"icon":"设备模板","id":41,"menutype":"menu","method":"post","name":"设备模板","parentid":30,"path":"Template","redirect":"","sort":3,"title":"设备模板"},
        //     {"children":[],"component":"asset/equipmentAllocation/index","enable":1,"icon":"设备调拨","id":42,"menutype":"menu","method":"post","name":"设备调拨","parentid":30,"path":"EquipmentAllocation","redirect":"","sort":5,"title":"设备调拨"},
        //     {"children":[],"component":"form/index","enable":0,"icon":"文档上传","id":32,"menutype":"menu","method":"post","name":"文档上传","parentid":30,"path":"Form","redirect":"","sort":8,"title":"文档上传"}
        //   ],
        // },
        // {
        //   "component":"Layout","enable":1,"icon":"备件管理","id":35,"menutype":"menu","method":"post","name":"备件管理","parentid":-1,"path":"customs","redirect":"noredirect","sort":1,"title":"备件管理",
        //   "children":[
        //     {
        //       "component":"custom/basic/index","enable":1,"icon":"设备基础信息","id":203,"menutype":"menu","method":"post","name":"备件基础信息","parentid":35,"path":"Basic","redirect":"","sort":0,"title":"备件基础信息",
        //       "children":[
        //       {"children":[],"component":"Layout","enable":1,"icon":"","id":273,"menutype":"button","method":"post","name":"审核","parentid":203,"path":"customs:basic:shenhe","redirect":"","sort":0,"title":"审核"},
        //       {"children":[],"component":"Layout","enable":1,"icon":"","id":274,"menutype":"button","method":"post","name":"基础信息界面","parentid":203,"path":"customs:basic:basic","redirect":"","sort":0,"title":"基础信息界面"},
        //       {"children":[],"component":"Layout","enable":1,"icon":"","id":384,"menutype":"button","method":"post","name":"禁用","parentid":203,"path":"customs:basic:disable","redirect":"","sort":0,"title":"禁用"},
        //       {"children":[],"component":"Layout","enable":1,"icon":"","id":385,"menutype":"button","method":"post","name":"启用","parentid":203,"path":"customs:basic:enable","redirect":"","sort":0,"title":"启用"},
        //       ],
        //     },
        //     {
        //       "component":"custom/contractManagement/index","enable":1,"icon":"合同管理","id":206,"menutype":"menu","method":"post","name":"合同管理","parentid":35,"path":"ContractManagement","redirect":"","sort":1,"title":"合同管理",
        //       "children":[
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":287,"menutype":"button","method":"post","name":"办公室主任审核","parentid":206,"path":"customs:contract:examineZG","redirect":"","sort":0,"title":"办公室主任审核"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":289,"menutype":"button","method":"post","name":"设备中心审核","parentid":206,"path":"customs:contract:examineZX","redirect":"","sort":0,"title":"设备中心审核"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":220,"menutype":"button","method":"post","name":"新增","parentid":206,"path":"customs:contract:add","redirect":"","sort":0,"title":"新增"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":223,"menutype":"button","method":"post","name":"导出","parentid":206,"path":"customs:contract:export","redirect":"","sort":0,"title":"导出"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":225,"menutype":"button","method":"post","name":"查看","parentid":206,"path":"customs:contract:see","redirect":"","sort":0,"title":"查看"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":226,"menutype":"button","method":"post","name":"变更","parentid":206,"path":"customs:contract:change","redirect":"","sort":0,"title":"变更"},
        //           {"children":[],"component":"Layout","enable":1,"icon":"","id":227,"menutype":"button","method":"post","name":"审核—删除、编辑","parentid":206,"path":"customs:contract:delete","redirect":"","sort":0,"title":"审核—删除、编辑"}
        //         ],
        //     },
        //   ]
        // }
      ],
      defaultProps: { children: "children", label: "title" },
      nodeKey: "id",
      defaultCheckedKeys: [],
      selectedMenu: "",

      UpdateDataRelationParam: {
        name: "",
        dataname: "",
        datavalue: "",
        valuename: "",
        values: "",
      },
      dataform: {
        id: "",
        name: "",
        selectMenus: [],
        sort: "",
        enable: "",
        easInformationReception: "",
      },

      dataRoleTemp: {},
      findAllDepart: [],
      disabled: false,

      rules: {
        // name: [{ type: 'string', required: true, message: '名称必填', trigger: 'change' }],
        // sort: [{ validator: isIntegerZero, trigger: 'blur' }],
        // datarole: [{ required: true, message: '必填', trigger: 'blur' }]
      },

      isokDisable: false,

      table: {
        getdataListParm: {
          name: "getRoleList",
          page: 1,
          offset: 1,
          pagecount: 7,
          returntype: "Map",
          parammaps: {
            pastureid: Cookies.get("pastureid"),
            rolename: "",
            createmp: "",
            enable: "",
            startTime: "",
            stopTime: "",
            inputDatetime: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },
      requestParam: {},
      selectList: [],
      role: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {},
      },
      // parentType: [],
      getRecuListParm: {
        name: "getMenuByRole",
        parammaps: {
          pastureid: Cookies.get("pastureid"),
        },
      },
      tableData: [],
      defaultCheckedKeys: [],
      // tableData: [
      //   {
      //     id: 1, page: '配方计划', pageCheck: false,
      //     fnList: ['查看', '编辑'],
      //     fnCheck: { see: false, edit: false },
      //     childList: [
      //       { p_id: 1, id: 31, page: '配方模板', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }},
      //       { p_id: 1, id: 32, page: '栏舍配方', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }}
      //     ]
      //   }, {
      //     id: 2, page: '栏舍生产', pageCheck: false,
      //     fnList: ['查看', '编辑'],
      //     fnCheck: { see: false, edit: false },
      //     childList: [
      //       { p_id: 2, id: 33, page: '栏舍产奶量', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }},
      //       { p_id: 2, id: 34, page: '栏舍剩料量', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }}
      //     ]
      //   }
      // ],
      getDataRoleListParm: {
        name: "getDataRole",
        offset: 1,
        pagecount: "",
        returntype: "Map",
        parammaps: {},
      },
      getEchoDeptParm: {
        name: "getRoleDepartmentName",
        offset: 1,
        pagecount: "",
        returntype: "Map",
        parammaps: {},
      },
      requestParam2: {},
      requestParam3: {},

      typeNameList: [
        { name: "个人", id: 0 },
        { name: "部门", id: 1 },
        { name: "所有", id: 2 },
      ],

      //  表格 - 列表 - 查询
      tableObjLeft: {
        getdataListParm: {
          name: "getMenuDataTypeByRole",
          //请求的 page 无用参数  offset 第几页  pagecount 每页多少条
          page: 1,
          offset: 1,
          pagecount: 30,
          returntype: "Map",

          parammaps: {
            roleId: "",
          },
        },
        tableKey: 0,
        listLoading: false,
        //返回的 pageNum 第几页  pageSize 每页多少条 total 总条数
        pageNum: "",
        pageSize: "",
        total: 0,
        list: [
          // {id:1,weight:1,phone:2,typeId:1},
          // {id:1,weight:1,phone:2,typeId:2},
        ],
      },
      row_id: "",

      isokDisable: false,
      textMap: {
        role: "权限管理",
        update: "编辑",
        create: "新增",
        menu: "授权菜单",
        dataRole: "数据权限",
      },
      rowStyle: { maxHeight: 50 + "px", height: 45 + "px" },
      cellStyle: { padding: 0 + "px" },
      expandAll: false,
      checkAll: false,
      parentChild: true,
      selectedMenuIds: [],
      menuExpand: false,
      menuNodeAll: false,
      menuCheckStrictly: false, // 默认不联动
    };
  },

  created() {
    this.get_table_data();
    this.get_auto_buttons();
    this.getMenuList();

    this.getDepartDownList();
  },

  methods: {
    sure_role() {
      console.log(this.tableObjLeft.list);
      const roleId = this.row_id;
      this.tableObjLeft.list.forEach(function (item) {
        item.roleId = roleId;
      });
      var send_data = {
        common: { returnmap: "0" },
        data: [
          {
            name: "cleraMenuDataTypeByRole",
            type: "e",
            parammaps: { roleId: roleId },
          },
          {
            name: "insertMenuDataType",
            resultmaps: {
              list: this.tableObjLeft.list,
            },
            children: [
              {
                name: "insertMenuDataType",
                type: "e",
                parammaps: {
                  roleId: "@insertMenuDataType.roleId",
                  menuId: "@insertMenuDataType.menuId",
                  typeId: "@insertMenuDataType.typeId",
                },
              },
            ],
          },
        ],
      };

      ExecDataByConfig(send_data).then((response) => {
        console.log("通过发送参数", send_data);
        if (response.msg !== "fail") {
          this.$notify({
            title: "成功",
            message: "保存成功",
            type: "success",
            duration: 2000,
          });
          this.dialogRoleVisible = false;

          this.get_table_data();
        } else {
          this.$notify({
            title: "失败",
            message: "保存失败" + response.data,
            type: "error",
            duration: 2000,
          });
        }
      });
    },

    on_role_tap(row) {
      console.log(row);
      this.row_id = row.id;

      this.tableObjLeft.getdataListParm.parammaps.roleId = row.id;
      this.get_tableLeft_data();
      this.dialogRoleVisible = true;
    },
    get_tableLeft_data() {
      this.tableObjLeft.listLoading = true;
      GetDataByName(this.tableObjLeft.getdataListParm).then((response) => {
        console.log("table数据", response.data.list);
        if (response.data.list !== null) {
          this.tableObjLeft.list = response.data.list;
          this.tableObjLeft.pageNum = response.data.pageNum;
          this.tableObjLeft.pageSize = response.data.pageSize;
          this.tableObjLeft.total = response.data.total;
        } else {
          this.tableObjLeft.list = [];
        }

        setTimeout(() => {
          this.tableObjLeft.listLoading = false;
        }, 100);
      });
    },
    handleDataRole(row) {
      if (row.deptNameList == undefined) {
        this.$set(row, "deptNameList", []);
      }
      this.dataRoleTemp = Object.assign({}, row);
      this.$set(this.dataRoleTemp, "datarole", 0);
      this.dialogDataRoleVisible = true;
      this.getDataRoleListParm.parammaps.id = row.id;
      GetDataByName(this.getDataRoleListParm).then((response) => {
        this.dataRolelist = response.data.list;
        this.$set(
          this.dataRoleTemp,
          "datarole",
          response.data.list[0].datarole
        );
        if (this.dataRoleTemp.datarole == 1) {
          this.getEchoDeptParm.parammaps = {};
          this.getEchoDeptParm.parammaps.role_id = row.id;
          GetDataByName(this.getEchoDeptParm).then((response) => {
            var deptNameArr = [];
            for (let i = 0; i < response.data.list.length; i++) {
              deptNameArr.push(response.data.list[i].name);
            }
            this.$set(this.dataRoleTemp, "deptNameList", deptNameArr);
            this.$forceUpdate();
            console.log(this.dataRoleTemp.deptNameList);
          });
        }
      });
    },

    updateDataRole() {
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.$refs["dataRoleTemp"].validate((valid) => {
        if (valid) {
          if (this.dataRoleTemp.datarole == 1) {
            console.log("quanbu", this.dataRoleTemp.deptNameList);
            if (
              this.dataRoleTemp.deptNameList == undefined ||
              this.dataRoleTemp.deptNameList.length == 0
            ) {
              this.$message({ type: "warning", message: "请选择部门" });
              return false;
            }
            console.log(this.dataRoleTemp);
            this.requestParam2 = {};
            this.requestParam2.common = { returnmap: "0" };
            this.requestParam2.data = [];
            for (let i = 0; i < this.dataRoleTemp.deptNameList.length; i++) {
              this.requestParam2.data.push({
                name: "getDepartmentId",
                type: "sm",
                parammaps: { name: this.dataRoleTemp.deptNameList[i] },
              });
            }
            ExecDataByConfig(this.requestParam2).then((response) => {
              console.log("ID发送参数", this.requestParam2);
              if (response.msg == "fail") {
                this.$notify({
                  title: "保存失败",
                  message: response.data,
                  type: "warning",
                  duration: 2000,
                });
              } else {
                var arr = [];
                for (let i = 0; i < response.data.length; i++) {
                  for (let j = 0; j < response.data[i].resultmaps.length; j++) {
                    arr.push(response.data[i].resultmaps[j].id);
                  }
                }
                this.requestParam3.name = "role_department";
                this.requestParam3.dataname = "role_id";
                this.requestParam3.datavalue = this.dataRoleTemp.id;
                this.requestParam3.valuename = "department_id";
                this.requestParam3.values = arr;
                UpdateDataRelation(this.requestParam3).then((response) => {
                  if (response.msg == "fail") {
                    this.$notify({
                      title: "保存失败",
                      message: response.data,
                      type: "warning",
                      duration: 2000,
                    });
                  } else {
                    this.requestParam.name = "setDataRole";
                    this.requestParam.parammaps = {};
                    this.requestParam.parammaps.id = this.dataRoleTemp.id;
                    this.requestParam.parammaps.datarole =
                      this.dataRoleTemp.datarole;
                    PostDataByName(this.requestParam).then((response) => {
                      console.log(
                        "设置数据权限保存发送参数",
                        this.requestParam
                      );
                      if (response.msg !== "fail") {
                        this.get_table_data();
                        this.dialogDataRoleVisible = false;
                        this.$notify({
                          title: "成功",
                          message: "设置成功",
                          type: "success",
                          duration: 2000,
                        });
                      } else {
                        failproccess(response, this.$notify);
                      }
                    });
                  }
                });
              }
            });

            this.get_table_data();
          } else {
            this.requestParam.name = "setDataRole";
            this.requestParam.parammaps = {};
            this.requestParam.parammaps.id = this.dataRoleTemp.id;
            this.requestParam.parammaps.datarole = this.dataRoleTemp.datarole;
            PostDataByName(this.requestParam).then((response) => {
              console.log("设置数据权限保存发送参数", this.requestParam);
              if (response.msg !== "fail") {
                this.get_table_data();
                this.dialogDataRoleVisible = false;
                this.$notify({
                  title: "成功",
                  message: "设置成功",
                  type: "success",
                  duration: 2000,
                });
              } else {
                failproccess(response, this.$notify);
              }
            });
            this.get_table_data();
          }
        }
      });
    },

    getDepartDownList() {
      var data = { name: "getDepatmentOnlyName", offset: 0, pagecount: 0 };
      GetDataByName(data).then((response) => {
        this.findAllDepart = response.data.list;
      });
    },

    getMenuList() {
      getRecuData(this.getMenuParm).then((response) => {
        this.parentMenu = response.data;
      });
    },

    handleMenu(row) {
      // 重置复选框状态
      this.menuExpand = false; // 展开/折叠默认不选中
      this.menuNodeAll = false; // 全选/全不选默认不选中
      this.menuCheckStrictly = true; // 父子联动默认选中

      // 重新获取菜单数据，强制重置树状态
      this.getMenuList();

      // 等待 DOM 更新后重置树的状态
      this.$nextTick(() => {
        if (this.$refs.menuTree) {
          // 重置树的展开状态
          const nodes = this.$refs.menuTree.store.nodesMap;
          for (const key in nodes) {
            nodes[key].expanded = false;
          }

          // 设置初始状态
          this.$refs.menuTree.store.defaultExpandAll = false;
          this.$refs.menuTree.store.checkStrictly = !this.menuCheckStrictly;

          // 如果有初始选中的菜单ID，设置选中状态
          if (row.menuIds && row.menuIds !== "") {
            const menuArr = row.menuIds.split(",").map((id) => Number(id));
            this.selectedMenuIds = menuArr;
            this.defaultCheckedKeys = menuArr;
            this.UpdateDataRelationParam.values = menuArr;
            // 确保在设置选中状态前已经切换到正确的联动模式
            this.$refs.menuTree.setCheckedKeys(menuArr);
          } else {
            // 如果没有初始选中的菜单，清空选中状态
            this.selectedMenuIds = [];
            this.defaultCheckedKeys = [];
            this.UpdateDataRelationParam.values = [];
            this.$refs.menuTree.setCheckedKeys([]);
          }
        }
      });

      this.dataform.id = row.id;
      this.dialogMenuVisible = true;
    },
    close_update_menu_dialog() {
      this.get_table_data();
      this.dialogMenuVisible = false;
      // 清空选中数据
      this.selectedMenuIds = [];
      this.defaultCheckedKeys = [];
      this.UpdateDataRelationParam.values = [];
    },
    updateMenu() {
      this.UpdateDataRelationParam.name = "role_menu";
      this.UpdateDataRelationParam.dataname = "role_id";
      this.UpdateDataRelationParam.datavalue = this.dataform.id;
      this.UpdateDataRelationParam.valuename = "menu_id";
      this.UpdateDataRelationParam.values = this.selectedMenuIds;

      UpdateDataRelation(this.UpdateDataRelationParam).then(() => {
        this.dialogMenuVisible = false;
        this.$notify({
          title: "成功",
          message: "修改成功",
          type: "success",
          duration: 2000,
        });
        this.close_update_menu_dialog();
      });
    },

    get_auto_buttons() {
      const Edit = "Role";
      const isRoleEdit = checkButtons(
        JSON.parse(sessionStorage.getItem("buttons")),
        Edit
      );
      this.isRoleEdit = isRoleEdit;
    },
    get_table_data() {
      this.table.listLoading = true;
      GetDataByName(this.table.getdataListParm).then((response) => {
        console.log("table数据", response.data.list);
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.$set(response.data.list[i], "Edit", false); // 编辑
            this.$set(response.data.list[i], "NoEdit", true); // 不可编辑/输入
            this.$set(response.data.list[i], "isCreate", false); // 新增操作
            this.$set(response.data.list[i], "isUpdate", true); // 编辑操作
            this.$set(response.data.list[i], "isUpdateSave", false); // 编辑保存
          }
          this.table.list = response.data.list;
          this.table.pageNum = response.data.pageNum;
          this.table.pageSize = response.data.pageSize;
          this.table.total = response.data.total;
        } else {
          this.table.list = [];
        }

        setTimeout(() => {
          this.table.listLoading = false;
        }, 100);
      });
    },
    change_enable() {
      console.log("点击了是否启用");
    },
    handleConfirmStartChange() {
      console.log("点击了确认开始");
    },
    form_search() {
      console.log("点击了查询");
      if (
        this.table.getdataListParm.parammaps.inputDatetime !== "" &&
        this.table.getdataListParm.parammaps.inputDatetime !== null
      ) {
        this.table.getdataListParm.parammaps.startTime = parseTime(
          this.table.getdataListParm.parammaps.inputDatetime[0],
          "{y}-{m}-{d}"
        );
        this.table.getdataListParm.parammaps.stopTime = parseTime(
          this.table.getdataListParm.parammaps.inputDatetime[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.table.getdataListParm.parammaps.inputDatetime = "";
        this.table.getdataListParm.parammaps.startTime = "";
        this.table.getdataListParm.parammaps.stopTime = "";
      }
      this.table.getdataListParm.offset = 1;
      this.get_table_data();
    },
    form_clear() {
      console.log("点击了重置");
      this.table.getdataListParm.parammaps.rolename = "";
      this.table.getdataListParm.parammaps.createmp = "";
      this.table.getdataListParm.parammaps.enable = "";
      this.table.getdataListParm.parammaps.startTime = "";
      this.table.getdataListParm.parammaps.stopTime = "";
      this.table.getdataListParm.parammaps.inputDatetime = "";
      this.table.getdataListParm.offset = 1;
      this.get_table_data();
    },

    form_add() {
      console.log("点击了新增");
      // 编辑true/不可编辑false
      // 新增操true,编辑false，编辑保存false
      for (let i = 0; i < this.table.list.length; i++) {
        if (this.table.list[i].Edit == true) {
          this.$message({
            type: "error",
            message: "当前内容未保存，请点击取消或保存继续进行操作",
            duration: 2000,
          });
          return false;
        }
      }
      this.table.list.unshift({
        myId: new Date().valueOf(),
        Edit: true,
        NoEdit: false,
        isCreate: true,
        isUpdate: false,
        isUpdateSave: false,
        enable: 1,
        confirmStart: 1,
        createdtime: parseTime(new Date(), "{y}-{m}-{d}"),
        createmp: Cookies.get("employename"),
        rolename: "",
      });
    },
    add_dialog_save(row) {
      console.log("点击了新增保存", row);
      this.table.temp.pastureid = Cookies.get("pastureid");
      this.table.temp.empname = row.empname;
      this.table.temp.rolename = row.rolename;
      this.table.temp.enable = row.enable;
      this.table.temp.remark = row.remark;
      this.table.temp.createmp = row.createmp;
      // 检验角色名称/角色是否为空
      if (this.table.temp.rolename == "") {
        this.$message({
          type: "error",
          message: "角色名称不能为空",
          duration: 2000,
        });
        return false;
      }
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.requestParam.name = "createRole";
      this.requestParam.parammaps = this.table.temp;
      PostDataByName(this.requestParam).then((response) => {
        console.log("新增保存发送参数", this.requestParam);
        if (response.msg !== "fail") {
          this.$notify({
            title: "成功",
            message: "保存成功",
            type: "success",
            duration: 2000,
          });
          this.get_table_data();
        } else {
          const isRepeat = new RegExp("Duplicate entry");
          if (isRepeat.test(response.data)) {
            this.$message({
              type: "error",
              message: "角色名称不可重复",
              duration: 2000,
            });
          } else {
            failproccess(response, this.$notify);
          }
        }
      });
    },
    add_cancel(row) {
      console.log("点击了新增取消");
      for (let i = 0; i < this.table.list.length; i++) {
        if (row.myId === this.table.list[i].myId) {
          var listIndex = this.table.list.indexOf(this.table.list[i]);
        }
        if (listIndex > -1) {
          this.table.list.splice(listIndex, 1);
          return;
        }
      }
    },
    form_edit(row) {
      console.log("点击了编辑");
      for (let i = 0; i < this.table.list.length; i++) {
        if (this.table.list[i].Edit == true) {
          this.$message({
            type: "error",
            message: "当前内容未保存，请点击取消或保存继续进行操作",
            duration: 2000,
          });
          return false;
        }
      }
      // 编辑true,不可编辑false
      row.Edit = true;
      row.NoEdit = false;
      // 新增false,编辑false,编辑保存true
      row.isCreate = false;
      row.isUpdate = false;
      row.isUpdateSave = true;
    },
    form_edit_save(row) {
      console.log("点击了编辑保存", row);
      this.table.temp.pastureid = Cookies.get("pastureid");
      this.table.temp.id = row.id;
      this.table.temp.empname = row.empname;
      this.table.temp.rolename = row.rolename;
      this.table.temp.enable = row.enable;
      this.table.temp.remark = row.remark;
      // 检验角色名称/角色是否为空
      if (this.table.temp.rolename == "") {
        this.$message({
          type: "error",
          message: "角色名称不能为空",
          duration: 2000,
        });
        return false;
      }
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.requestParam.name = "updateRole";
      this.requestParam.parammaps = this.table.temp;
      PostDataByName(this.requestParam).then((response) => {
        console.log("新增保存发送参数", this.requestParam);
        if (response.msg !== "fail") {
          this.$notify({
            title: "成功",
            message: "保存成功",
            type: "success",
            duration: 2000,
          });
          this.get_table_data();
        } else {
          failproccess(response, this.$notify);
        }
      });
    },
    edit_cancel(row) {
      console.log("点击了编辑取消");
      // 编辑false,不可编辑true
      row.Edit = false;
      row.NoEdit = true;
      // 新增false,编辑true,编辑保存false
      row.isCreate = false;
      row.isUpdate = true;
      row.isUpdateSave = false;
      this.get_table_data();
    },
    form_delete(row) {
      console.log("点击了行内删除");
      MessageBox.confirm("是否确认删除此信息?", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          console.log(this.selectList);
          this.selectList = [];
          this.requestParam = {};
          this.requestParam.common = { returnmap: "0" };
          this.requestParam.data = [];
          this.requestParam.data[0] = {
            name: "checkroleuser",
            type: "v",
            parammaps: {
              pastureid: row.pastureid,
              roleid: row.id,
            },
          };
          this.requestParam.data[1] = {
            name: "deleteRole",
            type: "e",
            parammaps: {
              pastureid: row.pastureid,
              id: row.id,
            },
          };
          ExecDataByConfig(this.requestParam).then((response) => {
            console.log("删除保存发送参数", this.requestParam);
            if (response.msg === "fail") {
              this.$notify({
                title: "删除失败",
                message: response.data,
                type: "warning",
                duration: 2000,
              });
            } else {
              this.$notify({
                title: "",
                message: "删除成功",
                type: "success",
                duration: 2000,
              });
              this.get_table_data();
            }
          });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消删除" });
        });
    },
    change_table_selection(val) {
      console.log("勾选数据", val);
      this.selectList = val;
    },
    handleDelete() {
      console.log("点击了删除");
      if (this.selectList.length == 0) {
        this.$message({
          type: "error",
          message: "请选择角色信息",
          duration: 2000,
        });
      } else {
        MessageBox.confirm("是否确认删除此信息?", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          console.log(this.selectList);
          this.requestParam.common = { returnmap: "0" };
          this.requestParam.data = [];
          for (let i = 0; i < this.selectList.length; i++) {
            this.requestParam.data[i] = {
              name: "checkroleuser",
              type: "v",
              parammaps: {
                pastureid: this.selectList[i].pastureid,
                roleid: this.selectList[i].id,
              },
            };
          }
          this.requestParam.data[this.selectList.length] = {
            name: "insertSpotList",
            resultmaps: { list: this.selectList },
          };
          this.requestParam.data[this.selectList.length].children = [];
          this.requestParam.data[this.selectList.length].children[0] = {
            name: "deleteRole",
            type: "e",
            parammaps: {
              pastureid: "@insertSpotList.pastureid",
              id: "@insertSpotList.id",
            },
          };
          ExecDataByConfig(this.requestParam).then((response) => {
            console.log("删除保存发送参数", this.requestParam);
            if (response.msg === "fail") {
              this.$notify({
                title: "删除失败",
                message: response.data,
                type: "warning",
                duration: 2000,
              });
            } else {
              this.$notify({
                title: "",
                message: "删除成功",
                type: "success",
                duration: 2000,
              });
              this.get_table_data();
            }
          });
        });
      }
    },
    handleRole(row) {
      this.role.temp = Object.assign({}, row);
      console.log("点击了行内页面权限");
      this.role.dialogStatus = "role";
      this.role.dialogFormVisible = true;
      this.tableData = [];
      this.getRecuListParm.parammaps.roleid = row.id;
      this.getRoleList();
    },
    getRoleList() {
      GetDataByName(this.getRecuListParm).then((response) => {
        if (response.data.list !== null) {
          this.tableData = transData(
            response.data.list,
            "id",
            "pid",
            "children"
          );
          console.log(this.tableData);
          this.tableData.forEach((item, i) => {
            item.childList = item.children;
            this.$set(item, "fnCheck", {});
            this.$set(item, "indeterminate", {
              seebutton: false,
              editbutton: false,
            });
            if (item.seebutton == 1) {
              this.$set(item.fnCheck, "seebutton", true);
            } else if (item.seebutton == 0) {
              this.$set(item.fnCheck, "seebutton", false);
            } else if (item.seebutton == 2) {
              this.$set(item.indeterminate, "seebutton", true);
            } else if (item.seebutton == 3) {
              this.$set(item.indeterminate, "seebutton", false);
            }
            if (item.editbutton == 1) {
              this.$set(item.fnCheck, "editbutton", true);
            } else if (item.editbutton == 0) {
              this.$set(item.fnCheck, "editbutton", false);
            } else if (item.seebutton == 2) {
              this.$set(item.indeterminate, "editbutton", true);
            } else if (item.seebutton == 3) {
              this.$set(item.indeterminate, "editbutton", false);
            }
            if (item.seebutton == 2) {
              this.$set(item.indeterminate, "seebutton", true);
            } else if (item.seebutton == 0) {
              this.$set(item.indeterminate, "seebutton", false);
            }
            if (item.editbutton == 3) {
              this.$set(item.indeterminate, "editbutton", true);
            } else if (item.editbutton == 0) {
              this.$set(item.indeterminate, "editbutton", false);
            }
            if (item.childList !== undefined && item.childList.length > 0) {
              item.childList.forEach((item, i) => {
                this.$set(item, "fnCheck", {});
                this.$set(item, "indeterminate", {
                  seebutton: false,
                  editbutton: false,
                });
                if (item.seebutton == 1) {
                  this.$set(item.fnCheck, "seebutton", true);
                } else if (item.seebutton == 0) {
                  this.$set(item.fnCheck, "seebutton", false);
                }
                if (item.editbutton == 1) {
                  this.$set(item.fnCheck, "editbutton", true);
                } else if (item.editbutton == 0) {
                  this.$set(item.fnCheck, "editbutton", false);
                }
              });
            }
          });
          console.log(this.tableData);
        }
      });
    },
    // 查找父级函数
    getParent(data2, nodeId2) {
      var arrRes = [];
      if (data2.length === 0) {
        if (nodeId2) {
          arrRes.push(data2);
        }
        return arrRes;
      }
      const rev = (data, nodeId) => {
        for (var i = 0, length = data.length; i < length; i++) {
          const node = data[i];
          if (node.id === nodeId) {
            arrRes.push(node);
            rev(data2, node.pid);
            break;
          } else {
            if (node.childList) {
              rev(node.childList, nodeId);
            }
          }
        }
        return arrRes;
      };
      arrRes = rev(data2, nodeId2);
      return arrRes;
    },

    /**
     * 功能选择
     */
    // 子选框事件
    fnCheckEv(scope, type) {
      // 如果有子项，则子项的选框选择跟当前一致
      if (scope.row.childList) {
        console.log(scope.row);
        this.handleFnAll(
          scope.row,
          scope.row.fnCheck[type],
          scope.row.indeterminate[type],
          type
        );
      }
      // 查找父级选框
      this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
        // console.log(item)
        if (type == "seebutton") {
          if (!item.childList) {
            console.log(item);
            item.fnCheck[type] = scope.row.fnCheck[type];
          } else {
            let num = 0;
            item.childList.forEach((item, i) => {
              if (item.fnCheck[type] === true) {
                num += 1;
              }
            });
            if (num === item.childList.length) {
              console.log(item);
              item.fnCheck[type] = true;
              item.indeterminate[type] = false;
            } else {
              item.fnCheck[type] = false;
              item.fnCheck["editbutton"] = false;
              const childListArr = [];
              const childEditListArr = [];
              console.log(item.childList);
              item.childList.forEach((item, index) => {
                console.log(item); // d打印正常
                console.log(item.fnCheck); // d打印正常
                // console.log(item.fnCheck['editbutton'])//错误？
                console.log(item.fnCheck.editbutton); // 错误？
                childListArr.push(item.fnCheck[type]);
                childEditListArr.push(item.fnCheck["editbutton"]);
              });

              console.log(childEditListArr);
              if (childListArr.includes(true)) {
                item.indeterminate[type] = true;
                item.fnCheck["editbutton"] = false;
                console.log(childEditListArr);
                if (childEditListArr.includes(true)) {
                  // 判断编辑子级是否有true
                  item.indeterminate["editbutton"] = true;
                } else {
                  item.indeterminate["editbutton"] = false;
                }
                if (item.childList.length > 0) {
                  item.childList.forEach((item, i) => {
                    if (item.fnCheck["editbutton"] === false) {
                      item.fnCheck["editbutton"] = false;
                    } else {
                      item.fnCheck["editbutton"] = item.fnCheck[type];
                    }
                  });
                }
              } else {
                item.indeterminate[type] = false;
                console.log(item);
                // item.indeterminate['editbutton'] = false
                const editArr = [];
                if (item.childList.length > 0) {
                  item.childList.forEach((item, i) => {
                    item.fnCheck["editbutton"] = item.fnCheck[type];
                    editArr.push(item.fnCheck["editbutton"]);
                  });
                }
                if (editArr.includes(true)) {
                  // 判断编辑子级是否有true
                  item.indeterminate["editbutton"] = true;
                } else {
                  item.indeterminate["editbutton"] = false;
                }
              }
            }
          }
        } else if (type == "editbutton") {
          if (!item.childList) {
            item.fnCheck[type] = scope.row.fnCheck[type];
          } else {
            let num = 0;
            item.childList.forEach((item, i) => {
              if (item.fnCheck[type] === true) {
                num += 1;
              }
            });
            if (num === item.childList.length) {
              item.fnCheck[type] = true;
              item.fnCheck["seebutton"] = true;
              item.indeterminate[type] = false;
              item.indeterminate["seebutton"] = false;
              item.childList.forEach((item, i) => {
                // 编辑时，选中编辑的同时，选中查看
                console.log(item);
                if (item.fnCheck["seebutton"] === false) {
                  // 查看未选中时，选中编辑可控制查看
                  item.fnCheck["seebutton"] = item.fnCheck["editbutton"];
                }
              });
              console.log(item);
            } else {
              console.log(item);
              item.fnCheck[type] = false;
              console.log(item.fnCheck["seebutton"]);
              if (item.fnCheck["seebutton"] === false) {
                // 查看未选中时，选中编辑可控制查看
                item.fnCheck["seebutton"] = false;
              }
              const childListArr = [];
              for (let i = 0; i < item.childList.length; i++) {
                childListArr.push(item.childList[i].fnCheck[type]);
              }
              childListArr.includes(true);
              if (childListArr.includes(true)) {
                if (item.fnCheck["seebutton"] === false) {
                  item.indeterminate["seebutton"] = true;
                }
                item.indeterminate[type] = true;
              } else {
                // if (item.fnCheck['seebutton'] === false) {
                //    item.indeterminate['seebutton'] = false
                // }

                item.indeterminate[type] = false;
              }
              // item.indeterminate[type] = true
              item.childList.forEach((item, i) => {
                // 编辑时，选中编辑的同时，选中查看
                if (item.fnCheck["seebutton"] === false) {
                  item.fnCheck["seebutton"] = item.fnCheck["editbutton"];
                }
              });
              console.log(item);
            }
          }
        }
      });
    },
    handleFnAll(row, fnCheck, indeterminate, type) {
      console.log(row, fnCheck, indeterminate, type);
      row.fnCheck[type] = fnCheck;
      if (row.childList) {
        const that = this;
        row.childList.forEach((element, i) => {
          row.indeterminate[type] = false;
          console.log(fnCheck, indeterminate);
          // console.log(element, row.childList[i], fnCheck, indeterminate, type)
          that.handleFnAll(row.childList[i], fnCheck, indeterminate, type);
        });
      }
    },
    /**
     * 权限选择
     */
    // 权限：全部、自己
    // 子选框事件
    dataCheckEv(scope, type) {
      console.log(scope);
      const temp = scope.row.dataCheck[type];
      console.log(scope, type);
      for (const x in scope.row.dataCheck) {
        scope.row.dataCheck[x] = false;
      }
      scope.row.dataCheck[type] = temp;
      // 如果有子项，则子项的选框选择跟当前一致
      if (scope.row.childList) {
        this.handleDataAll(scope.row, scope.row.dataCheck[type], type);
      }
      // 查找父级选框
      this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
        console.log(item, "==============674");
        for (const x in item.dataCheck) {
          item.dataCheck[x] = false;
        }
        if (!item.childList) {
          console.log(item, "==============679");
          item.dataCheck[type] = temp;
        } else {
          var num = 0;
          item.childList.forEach((item, i) => {
            if (item.dataCheck[type] === true) {
              num += 1;
            }
          });
          if (num === item.childList.length) {
            console.log(item, "==============689");
            item.dataCheck[type] = true;
          } else {
            console.log(item, "==============691");
            item.dataCheck[type] = false;
          }
        }
      });
    },
    handleDataAll(row, dataCheck, type) {
      for (const x in row.dataCheck) {
        row.dataCheck[x] = false;
      }
      row.dataCheck[type] = dataCheck;
      if (row.childList) {
        console.log(row, dataCheck, type);
        const that = this;
        row.childList.forEach((element, i) => {
          that.handleDataAll(row.childList[i], dataCheck, type);
        });
      } else {
        console.log(row, dataCheck, type);
      }
    },
    renderSeeHeader(h, { column }) {
      return h("div", [
        h("span", column.label),
        h("el-checkbox", {
          style: "display:inline-flex;margin-left:5px;",
          on: {
            change: ($event, column) => this.selectSee($event, column, "see"), // 选中事件 $event, column，这里$event=true,column是input的dom当在select里打印的时候
          },
        }),
      ]);
    },
    renderEditHeader(h, { column }) {
      return h("div", [
        h("span", column.label),
        h("el-checkbox", {
          style: "display:inline-flex;margin-left:5px;",
          on: {
            change: ($event, column) => this.selectEdit($event, column, "edit"), // 选中事件 $event, column，这里$event=true,column是input的dom当在select里打印的时候
          },
        }),
      ]);
    },
    selectSee(obj, $event = this.targetEv, title) {
      const _this = this;
      if ($event) {
        this.targetEv = $event; // 这里是获取当前点击的input的dom元素赋值给this.targetEv，方便提交后初始化使用
      }
      if (obj === true) {
        this.flag = false;
      } else {
        this.flag = true;
      }
      this.targetEv.target.checked = obj;
      this.targetEv.target.parentNode.className = obj
        ? "el-checkbox__input is-checked"
        : "el-checkbox__input";
      _this.tableData.forEach((item, index) => {
        _this.$set(_this.tableData[index], "check", obj.toString());
        if (title === "see") {
          if (obj === true) {
            item.fnCheck["seebutton"] = true;
            if (item.childList.length > 0) {
              item.childList.forEach((item, index) => {
                item.fnCheck["seebutton"] = true;
              });
            }
          } else {
            item.fnCheck["seebutton"] = false;
            if (item.childList.length > 0) {
              item.childList.forEach((item, index) => {
                item.fnCheck["seebutton"] = false;
              });
            }
          }
        }
      });
    },
    selectEdit(obj, $event = this.targetEv, title) {
      const _this = this;
      if ($event) {
        this.targetEv = $event; // 这里是获取当前点击的input的dom元素赋值给this.targetEv，方便提交后初始化使用
      }
      console.log("进来就错了", obj);
      if (obj === true) {
        this.flag = false;
      } else {
        this.flag = true;
      }
      this.targetEv.target.checked = obj;
      this.targetEv.target.parentNode.className = obj
        ? "el-checkbox__input is-checked"
        : "el-checkbox__input";
      _this.tableData.forEach((item, index) => {
        _this.$set(_this.tableData[index], "check", obj.toString());
        if (title === "edit") {
          if (obj === true) {
            item.fnCheck["editbutton"] = true;
            if (item.fnCheck["seebutton"] === false) {
              item.fnCheck["seebutton"] = true;
            }
            if (item.childList.length > 0) {
              item.childList.forEach((item, index) => {
                item.fnCheck["editbutton"] = true;
                if (item.fnCheck["seebutton"] === false) {
                  item.fnCheck["seebutton"] = true;
                }
              });
            }
          } else {
            item.fnCheck["editbutton"] = false;
            if (item.childList.length > 0) {
              item.childList.forEach((item, index) => {
                item.fnCheck["editbutton"] = false;
              });
            }
          }
        }
      });
    },
    roleData(row) {
      console.log("点击了权限确认", this.tableData);
      // console.log('点击了权限确认', JSON.stringify(this.tableData))
      const dataAll = [];
      const dataArr = [];
      const dataArr2 = [];
      this.tableData.forEach((item, index) => {
        if (item.fnCheck.seebutton === true) {
          item.seebutton = 1;
        } else {
          item.seebutton = 0;
        }
        if (item.fnCheck.editbutton === true) {
          item.editbutton = 1;
        } else {
          item.editbutton = 0;
        }
        if (item.indeterminate.seebutton === true) {
          item.seebutton = 2;
        }
        if (item.indeterminate.editbutton === true) {
          item.editbutton = 3;
        }
        if (item.childList.length > 0) {
          item.childList.forEach((item, index) => {
            if (item.fnCheck.seebutton === true) {
              item.seebutton = 1;
            } else {
              item.seebutton = 0;
            }
            if (item.fnCheck.editbutton === true) {
              item.editbutton = 1;
            } else {
              item.editbutton = 0;
            }
            dataArr2.push({
              menuid: item.menu_id,
              seebutton: item.seebutton,
              editbutton: item.editbutton,
            });
          });
        }
        dataArr.push({
          menuid: item.menu_id,
          seebutton: item.seebutton,
          editbutton: item.editbutton,
        });
      });
      dataArr.forEach((item, index) => {
        dataAll.push({
          menuid: item.menuid,
          seebutton: item.seebutton,
          editbutton: item.editbutton,
        });
      });
      dataArr2.forEach((item, index) => {
        dataAll.push({
          menuid: item.menuid,
          seebutton: item.seebutton,
          editbutton: item.editbutton,
        });
      });

      this.requestParam.common = { returnmap: "0" };
      this.requestParam.data = [];
      this.requestParam.data[0] = {
        name: "insertSpotList",
        resultmaps: { list: dataAll },
      };
      this.requestParam.data[0].children = [];
      this.requestParam.data[0].children[0] = {
        name: "insertRolemenu",
        type: "e",
        parammaps: {
          pastureid: this.role.temp.pastureid,
          roleid: this.role.temp.id,
          menuid: "@insertSpotList.menuid",
          seebutton: "@insertSpotList.seebutton",
          editbutton: "@insertSpotList.editbutton",
        },
      };
      ExecDataByConfig(this.requestParam).then((response) => {
        console.log("权限菜单保存发送参数", this.requestParam);
        if (response.msg === "fail") {
          this.$notify({
            title: "保存失败",
            message: response.data,
            type: "warning",
            duration: 2000,
          });
        } else {
          this.$notify({
            title: "",
            message: "保存成功",
            type: "success",
            duration: 2000,
          });
          this.role.dialogFormVisible = false;
          this.get_table_data();
        }
      });
    },
    handleCheckedTreeExpand(value) {
      // 处理展开/折叠
      if (this.$refs.menuTree) {
        this.$nextTick(() => {
          const nodes = this.$refs.menuTree.store.nodesMap;
          for (const key in nodes) {
            const node = nodes[key];
            if (value) {
              // 展开时，仅展开一级（level=1）和二级（level=2）的父节点
              if (node.level <= 1) {
                this.$refs.menuTree.store.nodesMap[key].expanded = true;
              }
            } else {
              // 折叠所有节点
              this.$refs.menuTree.store.nodesMap[key].expanded = false;
            }
          }
        });
      }
    },
    handleCheckedTreeNodeAll(value) {
      // 处理全选/全不选
      if (this.$refs.menuTree) {
        const allMenuIds = this.getAllMenuIds(this.parentMenu);
        if (value) {
          // 全选
          this.$refs.menuTree.setCheckedKeys(allMenuIds);
          this.selectedMenuIds = allMenuIds;
        } else {
          // 取消全选
          this.$refs.menuTree.setCheckedKeys([]);
          this.selectedMenuIds = [];
        }
        // 更新相关数据
        this.defaultCheckedKeys = this.selectedMenuIds;
        this.UpdateDataRelationParam.values = this.selectedMenuIds;
      }
    },
    handleCheckedTreeConnect(value) {
      // 处理父子联动
      if (this.$refs.menuTree) {
        // 先获取当前选中的节点
        const checkedKeys = this.$refs.menuTree.getCheckedKeys();
        const halfCheckedKeys = this.$refs.menuTree.getHalfCheckedKeys();

        // 更新父子联动状态
        this.menuCheckStrictly = value;
        this.$refs.menuTree.checkStrictly = !value;

        // 重新设置选中状态
        this.$nextTick(() => {
          if (value) {
            // 父子联动模式，合并完全选中和半选中的节点
            const allCheckedKeys = [
              ...new Set([...checkedKeys, ...halfCheckedKeys]),
            ];
            this.$refs.menuTree.setCheckedKeys(allCheckedKeys);
            this.selectedMenuIds = allCheckedKeys;
          } else {
            // 严格模式，只保留完全选中的节点
            this.$refs.menuTree.setCheckedKeys(checkedKeys);
            this.selectedMenuIds = checkedKeys;
          }
          // 更新相关数据
          this.defaultCheckedKeys = this.selectedMenuIds;
          this.UpdateDataRelationParam.values = this.selectedMenuIds;
        });
      }
    },
    getAllMenuIds(menus) {
      // 获取所有菜单ID
      let ids = [];
      menus.forEach((menu) => {
        ids.push(menu.id);
        if (menu.children && menu.children.length > 0) {
          ids = ids.concat(this.getAllMenuIds(menu.children));
        }
      });
      return ids;
    },
    handleTreeCheck(data, checked, indeterminate) {
      // 获取当前所有选中的节点
      const checkedKeys = this.$refs.menuTree.getCheckedKeys();
      const halfCheckedKeys = this.$refs.menuTree.getHalfCheckedKeys();
      console.log("当前选中的节点：", checkedKeys, halfCheckedKeys);
      // 更新选中状态
      if (!this.menuCheckStrictly) {
        // 父子联动模式：包含全选和半选节点
        this.selectedMenuIds = [
          ...new Set([...checkedKeys, ...halfCheckedKeys]),
        ];
      } else {
        // 严格模式：只包含全选节点
        this.selectedMenuIds = [...checkedKeys];
      }

      console.log("当前选中的节点：", this.selectedMenuIds);

      // 更新相关数据
      this.defaultCheckedKeys = this.selectedMenuIds;
      this.UpdateDataRelationParam.values = this.selectedMenuIds;
    },
  },
};
</script>
<style lang="scss" scoped>
.search {
  margin-top: 10px;
}
.table {
  margin-top: 10px;
}
.inside-base {
  position: relative;
}

.inside-base-main {
  width: 100%;
  background: #ffffff;
  box-shadow: 0px 0px 10px 0px rgba(231, 232, 238, 1);
  border-radius: 4px;
  margin-bottom: 30px;
}

// 中间内容
.inside-base-cont {
  margin: 0 20px;
}

.role-cont {
  position: relative;
  font-size: 16px;
  color: #333333;
  line-height: 40px;
  > span {
    width: 90px;
    height: 40px;
    text-align: right;
    float: left;
    margin-right: 10px;
    margin-bottom: 20px;
  }
  > div {
    position: relative;
    width: 100%;
    float: left;
    margin-bottom: 20px;
    >>> .el-input__inner {
      width: 320px;
    }
  }
}
.check-page-all {
  position: absolute;
  top: 13px;
  left: 11px;
  z-index: 99;
}

/* element-ui css */
.inside-base {
  >>> .el-input__inner {
    font-size: 16px;
    color: #333333;
  }
}
.menu-control {
  margin-bottom: 10px;
}

.menu-header {
  padding: 10px;
  border-bottom: 1px solid #ebeef5;
  background-color: #f5f7fa;
  .el-checkbox {
    margin-right: 20px;
    &:last-child {
      margin-right: 0;
    }
  }
}

.menu-tree-container {
  height: 400px;
  overflow-y: auto;
  border: 1px solid #dcdfe6;
  border-radius: 4px;

  .el-tree {
    background: transparent;
  }
}

.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}

.tree-border {
  margin-top: 5px;
  border: 1px solid #e5e6e7;
  background: #ffffff none;
  border-radius: 4px;
  width: 100%;
}

.menu-header {
  border-bottom: 1px solid #dfe4ed;
  padding: 8px;
  background-color: #f5f7fa;

  .el-checkbox {
    margin-right: 15px;
    &:last-child {
      margin-right: 0;
    }
  }
}
</style>
