<template>
  <basic-container>
    <!-- 添加量填报 -->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @row-save="rowSave"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left>
        <el-button type="primary" @click="handleAdd">新增</el-button>
      </template>

      <template #menu="scope"> </template>
    </avue-crud>
 
    <!-- 新增 -->
    <addQuantityDialog
      v-if="showDialog"
      :showDialog="showDialog"
      @closeDialog="closeDialog"
      :moldAddMore="moldAddMore"
    ></addQuantityDialog>
  </basic-container>
</template>

<script>
import { getList, add, remove, update } from '@/api/processManagement/addQuantity.js';

import addQuantityDialog from './components/addQuantityDialog.vue';

export default {
  components: { addQuantityDialog },
  data() {
    return {
      moldAddMore:false,
      query: {},
      loading: false,
      title: '新增',
      tableData: [],
      showDialog: false,
      data: [],
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: 'auto',
        calcHeight: 32,
        rowKey: 'keyValue',
        tip: false,
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: true,
        addBtn: false,
        editBtn: true,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 140,
        dialogWidth: 1200,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        showOverflowTooltip: true,
        menuAlign: 'left',
        gridBtn: false,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        searchMenuPosition: 'right',
        align: 'center',
        column: [
          {
            label: '作业中心',
            prop: 'wcId',
            type: 'select',
            filterable:true,
            clearable: true,
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            dicUrl: '/blade-desk/bsWorkCenter/getList',
            props: {
              label: 'wcName',
              value: 'id',
            },
          },
          {
            label: '作业槽',
            prop: 'batchNo',
            search: false,
            sortable: true,
            overHidden: true,
            type: 'select',
            filterable:true,
            clearable: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            rules: [
              {
                required: true,
                message: '请输入作业槽',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '添加量',
            prop: 'addValue',
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '添加时间',
            prop: 'addTime',
            search: true,
            sortable: true,
            headerAlign: 'center',
            align: 'center',
            type: 'date',
              format: 'YYYY-MM-DD HH:mm:ss',
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
            // display: false,
            searchRange: true,

            searchLabelWidth: 80,
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    handleAdd() {
      this.title = '新增';
      this.tableData = [];
      this.showDialog = true;
      this.moldAddMore=true
    },
    closeDialog() {
      this.showDialog = false;
      this.onLoad(this.page);
    },
    insertEvent() {
      const record = { bsWorkCenter: { wcId: '' }, _select: false };
      this.tableData.push(record);
    },
    selectChange(list, row) {
      row._select = !row._select;
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          window.console.log(error);
          loading();
        }
      );
    },
    //删除所选行
    remove() {},
    handleSave() {
      this.showDialog = false;
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        this.data = res.data.data.records;
        this.loading = false;
        this.page.total = res.data.data.total;
      });
    },
  },
};
</script>

<style></style>
