<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-click="rowClick"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="handleSelectionChange"
    >
      <template #footer>
        <div style="float: right; margin-top: 10px">
          <el-button type="primary" @click="onSelected"> 确定 </el-button>
        </div>
      </template>
    </avue-crud>
  </div>
</template>
<script setup>
import { defineProps, ref } from "vue";
import { useCrud } from "@/hooks/userCrud";

import { useCommonStoreHook } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());

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

const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const emit = defineEmits(["orderInfo"]);
const onSelected = () => {
  const array = ref([]);
  selectedRows.value.forEach((item) => {
    array.value.push(item.seqNo);
  });
  emit("orderInfo", array.value);
};

const props = defineProps({
  workOrderCode: {
    type: String,
  },
  state: {
    type: String,
  },
  semiFinishedStock: {
    type: String,
  },
});
const selectedRows = ref([]);
const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  selection: true,
  searchBtn: false,
  addBtn: false,
  menu: false,
  deleteBtn: false,
  column: [
    {
      label: "工单编号",
      prop: "workOrderCode",
      display: false,
      overHidden: true,
    },
    {
      label: "订单编号",
      prop: "orderCode",
      overHidden: true,
    },
    {
      label: "流转卡号",
      prop: "seqNo",
      disabled: true,
      overHidden: true,
    },
    // {
    //   label: "状态",
    //   prop: "workOrderState",
    //   width: "80",
    //   display: false,
    //   type: "select", //类型为下拉选择框
    //   dicUrl:
    //     dictDataUtil.request_url + dictDataUtil.TYPE_CODE.plan_work_order_state,
    //   props: {
    //     label: "dictLabel",
    //     value: "dictValue",
    //   },
    // },
    {
      label: "创建时间",
      prop: "created",
      width: 180,
      overHidden: true,
      display: false,
    },
  ],
});

onMounted(() => {
  search.value.workOrderCode = props.workOrderCode;
  if (props.semiFinishedStock) {
    search.value.semiFinishedStock = props.semiFinishedStock;
  }

  search.value.state = props.state;
  dataList();
});
watch(
  () => props.workOrderCode,
  () => {
    if (props.state) {
      search.value.state = props.state;
    }
    search.value.workOrderCode = props.workOrderCode;
    dataList();
  }
);
</script>
