<template>
  <div>
    <el-container>

      <!-- <el-scrollbar height="550px">
        <el-aside>
          <div class="JKWTree-tree">
            <h3>工序大废品奖惩记录</h3>
            <el-tree
              :data="treeData"
              :props="defaultProps"
              @node-click="handleNodeClick"
            />
          </div>
        </el-aside>
      </el-scrollbar> -->
	  
	  <layout-sider
	    :resize-directions="['right']"
	    :width="220"
	    style="margin-right: 10px;"
	  >
	    <div
	      class="JKWTree-tree"
	      style="height: 70vh;"
	    >
	      <h3>工序大废品奖惩记录</h3>
	      <el-tree
	        :data="treeData"
	        highlight-current
	        @node-click="handleNodeClick"
	      />
	    </div>
	  </layout-sider>

      <el-container>
        <!--        <el-header>dd</el-header>-->
        <el-main>

          <div class="gva-search-box">
            <el-form
              ref="elSearchFormRef"
              :inline="true"
              :model="searchInfo"
              class="demo-form-inline"
              :rules="searchRule"
              @keyup.enter="onSubmit"
            >
              <el-form-item>
                <el-input
                  v-model="detailData.image"
                  :clearable="true"
                  placeholder="输入工单编号或产品名称"
                />
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  icon="search"
                  @click="onSubmit"
                >查询</el-button>
                <el-button
                  icon="refresh"
                  @click="onReset"
                >切换显示方式</el-button>
              </el-form-item>
            </el-form>
          </div>
          <div class="gva-table-box">
            <el-table
              ref="multipleTable"
              style="width: 100%"
              border
              tooltip-effect="dark"
              :data="tableData"
              row-key="ID"
              :show-overflow-tooltip="true"
              highlight-current-row
              :row-style="{ height: '20px' }"
              :cell-style="{ padding: '0px' }"
              :header-row-style="{ height: '20px' }"
              :header-cell-style="{ padding: '0px' }"
              @selection-change="handleSelectionChange"
              @row-dblclick="handleDoubleClick"
            >
              <el-table-column
                type="selection"
                width="55"
              />
              <el-table-column
                align="left"
                label="工单编号"
                prop="sczl_gdbh"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="印件名称"
                prop="yj_yjmc"
                width="210" sortable
              />
              <el-table-column
                align="left"
                label="日期"
                prop="sczl_rq"
                width="100" sortable
              />
              <el-table-column
                align="left"
                label="流程单备注"
                prop="sczl_numDesc"
                width="100" sortable
              />
              <el-table-column
                align="left"
                label="联数"
                prop="sczl_ls"
                width="70" sortable
              />
              <el-table-column
                align="left"
                label="责任部门"
                prop="责任部门"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="大废品数"
                prop="sczl_cl"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="废品类型"
                prop="sczl_fplxA"
                width="100" sortable
              />
              <el-table-column
                align="left"
                label="废品来源"
                prop="sczl_fplxB"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="奖励班组"
                prop="Jl_bzdh"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="检验员工"
                prop="JL_bh1"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="责任班组"
                prop="sczl_bzdh"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="责任员工1"
                prop="sczl_bh1"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="责任员工2"
                prop="sczl_bh2"
                width="90" sortable
              />
              <el-table-column
                align="left"
                label="创建用户"
                prop="sys_id"
                width="120" sortable
              />
              <el-table-column
                align="left"
                label="创建时间"
                prop="sys_rq"
                width="160" sortable
              />
              <el-table-column
                align="left"
                label="UNIQID"
                prop="UniqId"
                width="80" sortable
              />
            </el-table>
            <div class="gva-pagination">
              <el-pagination
                layout="total, sizes, prev, pager, next, jumper"
                :current-page="page"
                :page-size="pageSize"
                :page-sizes="[10, 30, 50, 100]"
                :total="total"
                @current-change="handleCurrentChange"
                @size-change="handleSizeChange"
              />
            </div>
          </div>
          <el-dialog
            v-model="dialogFormVisible"
            :before-close="closeDialog"
            title="详情"
            destroy-on-close
            style="width: 1020px;position: fixed; top: 35%; left: 50%; transform: translate(-50%, -50%);"
          >
            <el-scrollbar height="70vh">
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                style="margin-bottom: 0px;"
                label-position="right"
                :rules="rule"
                label-width="80px"
                aria-readonly="true"
              >
                <el-form-item
                  label="工单编号:"
                  prop="address"
                  style="margin-right: 120px;"
                >
                  <el-input
                    v-model="detailData.sczl_gdbh"
                    readonly
                    style="width: 120px;"
                  />
                </el-form-item>
                <el-form-item
                  label="产品名称:"
                  prop="image"
                >
                  <el-input
                    v-model="detailData.Gd_cpmc"
                    readonly
                    placeholder="请输入产品名称"
                    style="width: 450px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
                label-width="80px"
              >
                <el-form-item
                  label="印件号:"
                  prop="address"
                  style="margin-right: 120px;"
                >
                  <el-input
                    v-model="detailData.sczl_yjno"
                    readonly
                    style="width: 120px;"
                  />
                </el-form-item>
                <el-form-item
                  label="印件名称:"
                  prop="image"
                >
                  <el-input
                    v-model="detailData.yj_yjmc"
                    readonly
                    style="width: 450px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
                label-width="90px"
              >
                <el-form-item
                  label="工序名称:"
                  prop="address"
                >
                  <el-input
                    v-model="detailData.sczl_gxmc"
                    readonly
                    style="width: 300px;"
                  />
                </el-form-item>
                <el-form-item prop="image">
                  <el-input
                    v-model="detailData.sczl_gxh"
                    readonly
                    style="width: 50px;"
                  />
                </el-form-item>
                <el-form-item
                  label="流程单备注:"
                  prop="image"
                >
                  <el-input
                    v-model="detailData.sczl_numDesc"
                    readonly
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
                label-width="80px"
              >
                <el-form-item
                  label="日期:"
                  prop="address"
                  style="margin-right: 120px;"
                >
                  <el-input
                    v-model="detailData.sczl_rq"
                    readonly
                    style="width: 120px;"
                  />
                </el-form-item>
                <el-form-item
                  label="废品数量:"
                  prop="image"
                >
                  <el-input
                    v-model="detailData.sczl_cl"
                    readonly
                    style="width: 120px;"
                  />
                </el-form-item>
                <el-form-item
                  label="联数:"
                  prop="image"
                >
                  <el-input
                    v-model="detailData.sczl_ls"
                    readonly
                    style="width: 120px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
                label-width="90px"
              >
                <el-form-item
                  label="废品备注:"
                  prop="address"
                >
                  <el-input
                    v-model="detailData.sczl_fplxA"
                    readonly
                    style="width: 300px;"
                  />
                </el-form-item>
                <el-form-item>
                  <el-checkbox
                    v-model="detailData"
                    style="width: 30px;"
                  >制程废</el-checkbox>
                </el-form-item>
                <el-form-item
                  label="责任部门:"
                  prop="image"
                >
                  <el-input
                    v-model="detailData.责任部门"
                    readonly
                    style="width: 250px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div
                    class="sub-title"
                    style="width: 193px; height: 10px;"
                  />
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员1</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员2</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员3</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员4</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员5</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员6</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员7</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员8</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员9</div>
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div class="sub-title">奖励班组：</div>
                  <el-input
                    v-model="detailData.Jl_bzdh"
                    readonly
                    style="width: 45px;"
                  />
                  <el-input
                    v-model="detailData.jl_jtbh"
                    readonly
                    style="width: 65px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh1"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh2"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh3"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh4"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh5"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh6"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh7"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh8"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_bh9"
                    readonly
                    style="width: 85px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div
                    class="sub-title"
                    style="width: 182px;"
                  />
                  <el-input
                    v-model="detailData.jlname1"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname2"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname3"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname4"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname5"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname6"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname7"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname8"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.jlname9"
                    readonly
                    style="width: 85px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div
                    class="sub-title"
                    style="width: 182px;"
                  >奖励金额：</div>
                  <el-input
                    v-model="detailData.JL_Je1"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je2"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je3"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je4"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je5"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je6"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je7"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je8"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.JL_Je9"
                    readonly
                    style="width: 85px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div
                    class="sub-title"
                    style="width: 193px; height: 10px;"
                  />
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员1</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员2</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员3</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员4</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员5</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员6</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员7</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员8</div>
                  <div
                    class="sub-title"
                    style="width: 83.5px; height: 10px;"
                  >组员9</div>
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div class="sub-title">责任班组：</div>
                  <el-input
                    v-model="detailData.sczl_bzdh"
                    readonly
                    style="width: 45px;"
                  />
                  <el-input
                    v-model="detailData.sczl_jtbh"
                    readonly
                    style="width: 65px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh1"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh2"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh3"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh4"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh5"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh6"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh7"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh8"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_bh9"
                    readonly
                    style="width: 85px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div
                    class="sub-title"
                    style="width: 182px;"
                  />
                  <el-input
                    v-model="detailData.zrname1"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname2"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname3"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname4"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname5"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname6"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname7"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname8"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.zrname9"
                    readonly
                    style="width: 85px;"
                  />
                </el-form-item>
              </el-form>
              <el-form
                ref="elFormRef"
                :model="detailData"
                :inline="true"
                label-position="right"
                :rules="rule"
              >
                <el-form-item>
                  <div
                    class="sub-title"
                    style="width: 182px;"
                  >处罚金额：</div>
                  <el-input
                    v-model="detailData.sczl_je1"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je2"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je3"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je4"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je5"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je6"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je7"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je8"
                    readonly
                    style="width: 85px;"
                  />
                  <el-input
                    v-model="detailData.sczl_je9"
                    readonly
                    style="width: 85px;"
                  />
                </el-form-item>
              </el-form>
            </el-scrollbar>
            <template #footer>
              <div class="dialog-footer">
                <el-button @click="closeDialog">取 消</el-button>
                <el-button
                  type="primary"
                  @click="enterDialog"
                >确 定</el-button>
              </div>
            </template>
          </el-dialog>

          <el-dialog
            v-model="detailShow"
            style="width: 800px"
            lock-scroll
            :before-close="closeDetailShow"
            title="查看详情"
            destroy-on-close
          >
            <el-scrollbar height="550px">
              <el-descriptions
                column="1"
                border
              >
                <el-descriptions-item label="address字段">
                  {{ detailData.address }}
                </el-descriptions-item>
                <el-descriptions-item label="image字段">
                  {{ detailData.image }}
                </el-descriptions-item>
                <el-descriptions-item label="name字段">
                  {{ detailData.name }}
                </el-descriptions-item>
              </el-descriptions>
            </el-scrollbar>
          </el-dialog>

        </el-main>

      </el-container>
    </el-container>

  </div>
</template>

<script setup>
import { getRewardDetail, getRewardList, getRewardTab, getRewardTabByGd } from '@/api/mes/job'
import { createCompany, deleteCompany, deleteCompanyByIds, findCompany, updateCompany } from '@/api/company'
import { Layout, LayoutContent, LayoutHeader, LayoutSider } from '@arco-design/web-vue'
// 全量引入格式化工具 请按需保留
import { ElMessage, ElMessageBox } from 'element-plus'
import { reactive, ref } from 'vue'

defineOptions({
  name: 'Company'
})

const treeData = ref([])
const displayMod = ref('')
// 侧边栏
const RewardTab = async() => {
  const getRewardTabs = await getRewardTab()
  if (getRewardTabs.code === 0) {
    treeData.value = getRewardTabs.data.map((item) => ({
      label: `${item.date.replace(/-/g, '.')}【单据数: ${item.counts}张】`,
      params: {
        date: item.date.replace(/\./g, '-'),
      }
    }))
    displayMod.value = 'date'
  }
}
RewardTab()

const RewardTabByGd = async() => {
  const getRewardTabs = await getRewardTabByGd()
  if (getRewardTabs.code === 0) {
    treeData.value = getRewardTabs.data.map((item) => ({
      label: item.label,
      params: {
        date: item.sczl_gdbh
      }
    }))
    displayMod.value = 'gd'
  }
}

const handleNodeClick = (node, check) => {
  // 存放当前节点的nodeId
  // console.log(node, check)
  if (node.params) {
    params.date = node.params.date
    getTableData()
  }
}

// 切换显示方式
const onReset = () => {
  if (displayMod.value === 'date') {
    RewardTabByGd()
  } else {
    RewardTab()
  }
}

// 验证规则
const rule = reactive({
})

const searchRule = reactive({
  createdAt: [
    { validator: (rule, value, callback) => {
      if (searchInfo.value.startCreatedAt && !searchInfo.value.endCreatedAt) {
        callback(new Error('请填写结束日期'))
      } else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
        callback(new Error('请填写开始日期'))
      } else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
        callback(new Error('开始日期应当早于结束日期'))
      } else {
        callback()
      }
    }, trigger: 'change' }
  ],
})

const elFormRef = ref()
const elSearchFormRef = ref()

// =========== 表格控制部分 ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})
const params = {
  date: '',
  page: page.value.toString(),
  limit: pageSize.value.toString(),
}

// 搜索
const onSubmit = () => {
  elSearchFormRef.value?.validate(async(valid) => {
    if (!valid) return
    page.value = 1
    pageSize.value = 10
    getTableData()
  })
}

// 分页
const handleSizeChange = (val) => {
  pageSize.value = val
  params.limit = val.toString()
  getTableData()
}

// 修改页面容量
const handleCurrentChange = (val) => {
  page.value = val
  params.page = val.toString()
  getTableData()
}

// 查看详情
const detailData = reactive({})
const handleDoubleClick = async(row) => {
  const { UniqId } = row
  console.log(UniqId)
  const res = await getRewardDetail({ UniqId })
  console.log(res)
  if (res.code === 0) {
    console.log(res)
    Object.assign(detailData, res.data[0])
    dialogFormVisible.value = true
  }
}

// 查询
const getTableData = async() => {
  const table = await getRewardList(params)
  if (table.code === 0) {
    tableData.value = table.data.rows
    total.value = table.data.total
  }
}

// getTableData()

// ============== 表格控制部分结束 ===============

// 获取需要的字典 可能为空 按需保留
const setOptions = async() => {
}

// 获取需要的字典 可能为空 按需保留
setOptions()

// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
  multipleSelection.value = val
}

// 删除行
const deleteRow = (row) => {
  ElMessageBox.confirm('确定要删除吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    deleteCompanyFunc(row)
  })
}

// 批量删除控制标记
const deleteVisible = ref(false)

// 多选删除
const onDelete = async() => {
  const ids = []
  if (multipleSelection.value.length === 0) {
    ElMessage({
      type: 'warning',
      message: '请选择要删除的数据'
    })
    return
  }
  multipleSelection.value &&
        multipleSelection.value.map(item => {
          ids.push(item.ID)
        })
  const res = await deleteCompanyByIds({ ids })
  if (res.code === 0) {
    ElMessage({
      type: 'success',
      message: '删除成功'
    })
    if (tableData.value.length === ids.length && page.value > 1) {
      page.value--
    }
    deleteVisible.value = false
    getTableData()
  }
}

// 行为控制标记（弹窗内部需要增还是改）
const type = ref('')

// 删除行
const deleteCompanyFunc = async(row) => {
  const res = await deleteCompany({ ID: row.ID })
  if (res.code === 0) {
    ElMessage({
      type: 'success',
      message: '删除成功'
    })
    if (tableData.value.length === 1 && page.value > 1) {
      page.value--
    }
    getTableData()
  }
}

// 弹窗控制标记
const dialogFormVisible = ref(false)

// 查看详情控制标记
const detailShow = ref(false)

// 打开详情弹窗
const openDetailShow = () => {
  detailShow.value = true
}

// 打开详情
const getDetails = async(row) => {
  // 打开弹窗
  const res = await findCompany({ ID: row.ID })
  if (res.code === 0) {
    detailData.value = res.data.recompany
    openDetailShow()
  }
}

// 关闭详情弹窗
const closeDetailShow = () => {
  detailShow.value = false
  detailData.value = {
    address: '',
    image: '',
    name: '',
  }
}

// 打开弹窗
const openDialog = () => {
  type.value = 'create'
  dialogFormVisible.value = true
}

// 关闭弹窗
const closeDialog = () => {
  dialogFormVisible.value = false
  detailData.value = {
    address: '',
    image: '',
    name: '',
  }
}
// 弹窗确定
const enterDialog = async() => {
  elFormRef.value?.validate(async(valid) => {
    if (!valid) return
    let res
    switch (type.value) {
      case 'create':
        res = await createCompany(detailData.value)
        break
      case 'update':
        res = await updateCompany(detailData.value)
        break
      default:
        res = await createCompany(detailData.value)
        break
    }
    if (res.code === 0) {
      ElMessage({
        type: 'success',
        message: '创建/更改成功'
      })
      closeDialog()
      getTableData()
    }
  })
}

</script>

<style scoped>

:deep(.el-table td .cell) {
  line-height: 30px !important;
}

.JKWTree-container {
  display: flex;
}

/* 选中某行时的背景色 */
:deep(.el-table__body tr.current-row) > td {
  background: #ff80ff !important;
}

.JKWTree-tree {
  width: 300px;
  background-color: #fff;
  padding: 10px;
  margin-right: 20px;
}

.JKWTree-tree h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 10px 0;
}

.JKWTree-content {
  flex: 1;
}

</style>
