<template>
  <div>
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-save="createRow"
      @row-update="updateRow"
      @row-del="deleteRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange"
    >
    </avue-crud>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { useDictionaryStore } from "@/store";
import { useRoute } from "vue-router";
const value1 = ref([]);
const options = ref([]);
const route = useRoute();
// 数据字典相关
const { dicts } = useDictionaryStore();

const props = defineProps({
  operationId: {
    default: "0",
    type: String,
  },
  routeId: {
    default: "0",
    type: String,
  },
});
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/opExcelForm",
  });
const setValue1 = () => {
  value1.value = [];
  data.value.forEach((el) => {
    value1.value.push(el.formCode);
  });
};
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对象
onMounted(() => {
  search.value.operationId = props.operationId + ""
  dataList();
});
watch(
  () => data.value,
  (val) => {
    setValue1();
  },
  {
    immediately: true,
  }
);

option.value = Object.assign(option.value, {
  searchEnter: true,
  selection: false,
  addBtn: false,
  menu: true,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  searchMenuSpan: 8,
  column: [
    {
      label: "工序id",
      prop: "operationId",
      display: false,
      hide: true,
    },
    {
      label: "模版名称",
      prop: "formName",
      addDisabled: true,
      editDisabled: true,
    },
    {
      label: "模版类型",
      prop: "formType",
      addDisabled: true,
      editDisabled: true,
      dicData: dicts.excel_type,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "修改时间",
      prop: "updated",
      addDisabled: true,
      editDisabled: true,
    },
    {
      label: "操作人",
      prop: "updator",
      addDisabled: true,
      editDisabled: true,
    },
  ],
});
</script>
<style lang="scss" scoped>
.dialog {
  width: 100%;
  height: 120px;
  position: relative;
  .btns {
    position: absolute;
    right: 0;
    bottom: 0;
  }
}
</style>
