<template>
  <div>
    <!-- 表格数据 -->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left="row">
        <el-button type="primary" @click="handleAdd">新增</el-button>
      </template>
      <template #menu-right> </template>
      <template #menu="{ row }">
        <el-button type="text" @click="handleView(row)">详情</el-button>
      </template>
    </avue-crud>
    <assDialog :add-dialog="addDialog" @closeDialog="closeDialog" :id="id"></assDialog>
    <!-- 新增 -->
    <assayedContentDialog
      v-if="isAddOpen"
      :showDialog="isAddOpen"
      @closeDialog="closeDialog"
    ></assayedContentDialog>
  </div>
</template>

<script>
import { getList } from '@/api/productionManagement/assayedContent';
// import addDialog from '../addDialog.vue';
import coatingColumnData from '../../js/coatingColumnData';
import assayedContentDialog from './assayedContentDialog.vue';
import assDialog from '../assDialog.vue';
export default {
  components: {
 
    assayedContentDialog,
    assDialog
  },
  data() {
    return {
      id:null,
      searchForm: {},
      tabPosition: 'assayedContent',
      loading: false,
      data: [],
      form: {},
      addDialog: false,
      showDialog: false,
      materialDialog: false,
      approveForm: {},
      addQuantity: false,
      option: {
        columnSort: true,
        tip: false,
        height: 'auto',
        calcHeight: 32,
        simplePage: false,
        searchShow: true,
        searchMenuSpan: 12,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: false,
        selection: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        addBtn: false,
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 80,
        dialogWidth: 600,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: true,
        gridBtn: false,
        searchShowBtn: false,
        showOverflowTooltip: true,
        searchLabelPosition: 'left',
        filterBtn: true,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        align: 'center',
        column: [],
      },
      approveRules: {
        approveREsult: [{ required: true, message: '请选择审批结果', trigger: 'blur' }],
      },
      approveDialog: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      isAddOpen: false,
    };
  },
  mounted() {
    this.option.column = coatingColumnData[this.tabPosition];
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    // 待审核搜索
    pendingReviewFn() {
      this.$message.success('操作成功');
    },

    // 多选
    selectionChange(list) {
      this.selectionList = list;
    },
    // 点击详情
    handleView(row) {
      this.id=row.id
      this.addDialog = true;
    },
    deleteRow(row) {
      this.$confirm('确定删除此条数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {});
    },
    closeRow() {
      this.$confirm('确定删除此条数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {});
    },
    // 新增按钮点击
    handleAdd() {
      this.isAddOpen = true;
    },
    // 关闭弹窗
    closeDialog() {
      this.showDialog = false;
      this.materialDialog = false;
      this.addQuantity = false;
      this.addDialog = false;
      this.isAddOpen = false;
    },
    addQuantityClick() {
      if (this.selectionList.length == 0) {
        this.$message.error('请至少选择一条数据!');
      } else {
        this.addQuantity = true;
      }
    },
    approveRow() {
      this.approveDialog = true;
    },
    handleApprove() {
      if (this.selectionList.length != 0) {
        this.approveDialog = true;
      } else {
        this.$message.error('请至少选择一条数据!');
      }
    },
    submitApprove() {
      this.$refs.approveForm.validate(valid => {
        console.log('valid==============', valid);
        if (valid) {
          this.approveDialog = false;
        }
      });
    },
    async onLoad(page, params = {}) {
      // this.data = [
      //   {
      //     id: 1,
      //     requiredCode: '001',
      //     assayer: '张三',
      //     workCenter: '2025-10-20 11:20:32',
      //     status: 4,
      //   },
      //   {
      //     id: 2,
      //     requiredCode: '002',
      //     assayer: '李四',
      //     workCenter: '2025-10-21 11:20:32',
      //     status: 3,
      //   },
      // ];
      this.loading = true;
      try {
        const res = await getList({
          current:this.page.currentPage,
          size:this.page.pageSize,
          ...this.query
        });
        // if (res.code) {
        this.data = res.data.data.records;
        this.page.total = res.data.data.total;
        // this.selectionClear();
        this.loading = false;
        // }
      } catch (err) {
        console.log(err);
      }

      // this.page.total = this.data.length;
    },
  },
};
</script>

<style></style>
