<!-- 报故记录 -->
<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef2"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-update="updateRow"
    />
    <CommonTable
      ref="ctableRef"
      tableTitle="人员选择"
      tableType="USERS"
      @selected-sure="onSelectedFinish"
    />
  </div>
</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();

// 传入一个url，后面不带/
const {
  form,
  data,
  option,
  search,
  page,
  toDeleteIds,
  Methords,
  Utils,
  commonConfig,
} = useCrud({
  src: "/api/v1/process/web/traceability/escalationRecordInfo",
});
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具

const crudRef = ref(null); //crudRef.value 获取avue-crud对象

const refreshTra = (row) => {
  commonConfig.value.params = { seqNo: row.seqNo,workOrderCode: row.workOrderCode};
  dataList();
};
const userStore = useUserStoreHook();
const onSelectedFinish = (selectValue) => {
  form.value.creator = selectValue.userName;
};
defineExpose({ refreshTra });
onMounted(() => {
  if (userStore.user.userId === 10000) {
    option.value.menu = true;
    option.value.editBtn = true;
  }
});
const ctableRef = ref(null);
option.value = Object.assign(option.value, {
  selection: false,
  border: true,
  index: false,
  expandLevel: 3,
  headerAlign: "center",
  align: "center",
  labelWidth: 100,
  addBtn: false,
  viewBtn: false,
  delBtn: false,
  menu: false,
  header: false,
  column: [
    {
      label: "冻结状态",
      prop: "state",
      dicData: dicts.escalation_fault_state,
      display: false,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "报故人",
      prop: "creator",
      search: false,
      click: ({ value, column }) => {
        ctableRef.value.startSelect();
      },
      change: ({ value, column }) => {
        if (value != form.value.creator) {
          ctableRef.value.startSelect();
        }
      },

      rules: [
        {
          required: true,
          message: "请选择上传人员",
          trigger: "blur",
        },
      ],
    },
    {
      label: "报故工位",
      prop: "stationName",
      search: false,
      display: false,
    },
    {
      label: "报故时间",
      prop: "created",
      search: false,
      format: "YYYY-MM-DD HH:mm:ss",
      valueFormat: "YYYY-MM-DD HH:mm:ss",
      type: "datetime",
    },
    {
      label: "处理结果",
      prop: "currentState",
      dicData: dicts.fault_current_state,
      type: "select",
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      display: false,
      search: false,
    },
    {
      label: "备注",
      prop: "remark",
      search: false,
      type: "textarea",
      span: 24,
    },
  ],
});
</script>
