<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRefJSSJ"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      @row-update="updateRow"
      v-model:page="page"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
    >
      <template #menu="{ size, row, index }">
        <el-button type="text" size="mini" @click="lookData(row)">
          查看
        </el-button>
      </template>
    </avue-crud>
  </div>
  <el-dialog title="详细信息" v-model="dialogVisible">
    <el-table :data="tableData" class="tableView-cssj">
      <el-table-column prop="parameterName" label="测试项目" align="center" />
      <el-table-column prop="deviceCode" label="测试设备" align="center" />
      <el-table-column prop="value" label="测试值" align="center" />
      <el-table-column prop="flag" align="center" label="是否合格">
        <template #default="scope">
          <span
            :class="{
              'red-text': scope.row.flag == 0,
              'green-text': scope.row.writeData == 1,
            }"
          >
            {{ scope.row.flag == 1 ? "合格" : "不合格" }}
          </span>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import dictDataUtil from "@/common/configs/dictDataUtil";
import ButtonPermKeys from "@/common/configs/buttonPermission";
import {
  useCommonStoreHook,
  useDictionaryStore,
  useUserStoreHook,
} from "@/store";

// 数据字典相关
const { dicts } = useDictionaryStore();
const userStore = useUserStoreHook();

// 传入一个url，后面不带/
const {
  form,
  data,
  option,
  search,
  page,
  toDeleteIds,
  Methords,
  Utils,
  commonConfig,
} = useCrud({
  src: "/api/v1/testData/testData",
});
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
const onUserSelectedFinish = (selectedValue) => {
  form.value.operator = selectedValue.userName;
};
const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const userRef = ref(null);
const refreshTra = (row) => {
  commonConfig.value.params = {
    seqNo: row.seqNo,
    workOrderCode: row.workOrderCode,
  };
  dataList();
};
defineExpose({ refreshTra });
onMounted(() => {
  if (userStore.user.userId === 10000) {
    option.value.menu = true;
    option.value.editBtn = true;
  }
});

option.value = Object.assign(option.value, {
  // selection: false,
  // border: true,
  // index: false,
  // expandLevel: 3,
  // headerAlign: "center",
  // align: "center",
  // labelWidth: 100,
  // addBtn: false,
  // delBtn: false,
  // menuWidth: 0,
  // editBtn: false,
  // viewBtn: false,
  // // menu: false,
  header: false,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  column: [
    {
      label: "测试时间",
      prop: "created",
    },
    {
      label: "测试人",
      prop: "creator",
    },
    {
      label: "物料名称",
      prop: "materialName",
    },
    // {
    //   label: "操作",
    //   prop: "op",
    // },
  ],
});

// 查看相关代码
const dialogVisible = ref(false);
const tableData = ref([]);
const lookData = (row) => {
  tableData.value = JSON.parse(row.testData);
  console.log(tableData.value);
  dialogVisible.value = true;
};

const handleDialogCancel = () => {
  dialogVisible.value = false;
};
</script>
