<template>


  <div class="mainContentBox">
    <avue-form
      ref="formRef"
      v-model="form"
      :option="option"
      @submit="rowSave"
    >
    </avue-form>
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-save="createRow"
      @row-click="rowClick"
      @row-update="updateRow"
      @row-del="deleteRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      search-option="false"
    >


    </avue-crud>
    <div class="detail-footer">
      <el-button type="primary" @click="onSelected"> 确定 </el-button>
      <el-button @click="cancelWindow">取消</el-button>

    </div>
  </div>



</template>

<script setup>
  import { ref, getCurrentInstance } from "vue";
  import { useCrud } from "@/hooks/userCrud";
  import ButtonPermKeys from "@/common/configs/buttonPermission";
  import { useCommonStoreHook } from "@/store";

  const { isShowTable, tableType } = toRefs(useCommonStoreHook());
  import { useDictionaryStore } from "@/store";
  const test = () => {
    isShowTable.value = true;
    tableType.value = tableType.value == 1 ? 2 : 1;
  };

  // 传入一个url，后面不带/
  const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
    useCrud({
      src: "/api/v1/base/bomVersion",
    });
  const commonTableEmits = defineEmits(["selectedSure"]);
  const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
    Methords; //增删改查
  const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
  const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
  // checkBtnPerm(ButtonPermKeys.PLAN.BTNS.order_add) :permission="permission"
  // const permission = reactive({
  //   delBtn: checkPerm(buttonPermission.PLAN.BTNS.order_del),
  //   addBtn: checkPerm(buttonPermission.PLAN.BTNS.order_add),
  //   editBtn: checkPerm(buttonPermission.PLAN.BTNS.order_edit),
  //   menu: true,
  // });
  function rowSave(form2,done) {
    form.value.materialCode=props.materialCode;
    createRow(form,done,done);

  }



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

  onMounted(() => {
    console.log(props)
    search.value.materialCode=props.materialCode;
    dataList();
  });


  const uploadFinished = () => {
    // 上传完成后的刷新操作
    page.currentPage = 1;
    dataList();
  };




  // 设置表格列或者其他自定义的option
  option.value = Object.assign(option.value, {
    highlightCurrentRow: true,
    align:'center',
    menuAlign:'center',
    editBtn:false,
    column: [
      {
        label: "版本号",
        prop: "bomVersion",
        type:"number",
        controlsPosition: '',
        min:1.0,
        precision: 1,
      },
      { label: "物料编码", prop: "materialCode", width: 130,overHidden: true,display:false,hide:true},



      ],
    viewBtn: false,
    addBtn:false,
  });
  const props = defineProps({
    materialCode: {
      type: String,
      default: () => {
        return 0;
      }
    },
    dialog:{
      type:Object,
      default:()=>{
        return {};
      }
    }
  })
  const selectRowValue = ref({});
  const rowClick = (row) => {
    selectRowValue.value = row;
  };
  const onSelected = () => {
    commonTableEmits("selectedSure", selectRowValue.value);
    props.dialog.visible = false;
  };
  const cancelWindow=()=>{
    props.dialog.visible = false;
  }
</script>

<style>
  .detail-footer{
    float: right;
  }
</style>
