<!--
 * @Descripttion: (接口管理/SAP交验单记录表/sap_deliver_record)
 * @version: (1.0)
 * @Author: (admin)
 * @Date: (2023-05-10)
 * @LastEditors: (admin)
 * @LastEditTime: (2023-05-10)
-->
<template>
  <div>
    <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent
      size="large">
      <el-row>
        <el-form-item label="物料名称" prop="materialName">
          <el-input v-model="queryParams.materialName" placeholder="请输入" class="z-el-input" clearable
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="物料编码" prop="materialCode">
          <el-input v-model="queryParams.materialCode" placeholder="请输入" class="z-el-input" clearable
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="物料类型" prop="category">
          <!-- <el-select v-model="queryParams.category" placeholder="请选择" clearable style="width:120px" @change="handleQuery">
            <el-option v-for="dict in options.materialTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue">
              <dict-tag :options="options.materialTypeOptions" :value="dict.dictValue" />
            </el-option>
          </el-select> -->
          <el-radio-group v-model="queryParams.category" @change="handleQuery">
            <el-radio-button>全部</el-radio-button>
            <el-radio-button v-for="dict in options.materialTypeOptions" :label="dict.dictValue">
              {{ dict.dictLabel }}
            </el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="规格型号 / 图号" prop="materialSpec">
          <el-input v-model="queryParams.materialSpec" placeholder="请输入" class="z-el-input" clearable
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="关键件标识" prop="keyFlag">
          <!-- <el-select v-model="queryParams.keyFlag" placeholder="请选择" clearable style="width:120px" @change="handleQuery">
            <el-option v-for="dict in options.keyFlagOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue">
              <dict-tag :options="options.keyFlagOptions" :value="dict.dictValue" />
            </el-option>
          </el-select> -->
          <el-radio-group v-model="queryParams.keyFlag" @change="handleQuery">
            <el-radio-button>全部</el-radio-button>
            <el-radio-button v-for="dict in options.keyFlagOptions" :label="dict.dictValue">
              {{ dict.dictLabel }}
            </el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="质检结果" prop="CheckResult">
          <!-- <el-select v-model="queryParams.CheckResult" placeholder="请选择" clearable style="width:120px"
            @change="handleQuery">
            <el-option v-for="dict in options.qaResultOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue">
              <dict-tag :options="options.qaResultOptions" :value="dict.dictValue" />
            </el-option>
          </el-select> -->
          <el-radio-group v-model="queryParams.CheckResult" @change="handleQuery">
            <el-radio-button>全部</el-radio-button>
            <el-radio-button v-for="dict in options.qaResultOptions" :label="dict.dictValue">
              {{ dict.dictLabel }}
            </el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="交验单号" prop="deliverNo">
          <el-input v-model="queryParams.deliverNo" placeholder="请输入" class="z-el-input" clearable
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="生产令号" prop="bomNo">
          <el-input v-model="queryParams.bomNo" placeholder="请输入" class="z-el-input" clearable
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker v-model="queryCreateTime" style="width: 400px" type="datetimerange" range-separator="-"
            @change="handleQuery" start-placeholder="开始时间" end-placeholder="结束时间"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
          <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
        </el-form-item>
      </el-row>
      <el-row>
      </el-row>
    </el-form>
    <!-- 工具区域 -->
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" v-hasPermi="['business:sapdeliverrecord:add']" plain icon="plus" @click="handleAdd">
          {{ $t('btn.add') }}
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="info" plain icon="Upload" @click="handleImport"
          v-hasPermi="['business:sapdeliverrecord:import']">导入</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['business:sapdeliverrecord:edit']" plain icon="edit"
          @click="handleUpdate">
          {{ $t('btn.edit') }}
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['business:sapdeliverrecord:delete']" plain
          icon="delete" @click="handleDelete">
          {{ $t('btn.delete') }}
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <!-- 数据区域 -->
    <el-table :data="dataList" v-loading="loading" ref="table" highlight-current-row @sort-change="sortChange"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="id" label="ID" align="center" v-if="columns.showColumn('id')" />
      <el-table-column prop="deliverNo" label="交验单号" align="center" :show-overflow-tooltip="true" width="150"
        v-if="columns.showColumn('deliverNo')" />
      <el-table-column prop="checkName" label="送检人员" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('checkName')" />
      <el-table-column prop="bomNo" label="生产令号" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('bomNo')" />
      <el-table-column prop="rowNo" label="行项目" align="center" v-if="columns.showColumn('rowNo')" />
      <el-table-column prop="category" label="物料类型" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('category')">
        <template #default="scope">
          <dict-tag :options="options.materialTypeOptions" :value="scope.row.category" />
        </template>
      </el-table-column>
      <el-table-column prop="materialCode" label="物料编码" align="center" :show-overflow-tooltip="true" width="150"
        v-if="columns.showColumn('materialCode')" />
      <el-table-column prop="materialName" label="物料名称" align="center" :show-overflow-tooltip="true" width="120"
        v-if="columns.showColumn('materialName')" />
      <el-table-column prop="materialSpec" label="规格型号/图号" align="center" :show-overflow-tooltip="true" width="120"
        v-if="columns.showColumn('materialSpec')" />
      <el-table-column prop="keyFlag" label="关键件" align="center" v-if="columns.showColumn('keyFlag')">
        <template #default="scope">
          <el-icon v-if="scope.row.keyFlag" size="large" color="red">
            <StarFilled />
          </el-icon>
          <el-icon v-else />
        </template>
      </el-table-column>
      <el-table-column prop="qty" label="交验单数量" align="center" v-if="columns.showColumn('qty')" />
      <el-table-column prop="spotCheckQty" label="抽检数量" align="center" v-if="columns.showColumn('spotCheckQty')" />
      <el-table-column prop="checkQty" label="质检数量" align="center" v-if="columns.showColumn('checkQty')" />
      <el-table-column prop="checkResult" label="质检结果" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('checkResult')">
        <template #default="scope">
          <dict-tag :options="options.qaResultOptions" :value="scope.row.checkResult" />
        </template>
      </el-table-column>
      <el-table-column prop="instoreQty" label="入库数量" align="center" v-if="columns.showColumn('instoreQty')" />
      <el-table-column prop="instoreResult" label="入库结果" align="center" v-if="columns.showColumn('instoreResult')">
        <template #default="scope">
          <dict-tag :options="options.operationResultOptions" :value="scope.row.instoreResult" />
        </template>
      </el-table-column>
      <el-table-column prop="createBy" label="创建人" align="center" v-if="columns.showColumn('createBy')" />
      <el-table-column prop="createTime" label="创建时间" align="center" width="160"
        v-if="columns.showColumn('createTime')" />
      <el-table-column prop="updateBy" label="更新人" align="center" v-if="columns.showColumn('updateBy')" />
      <el-table-column prop="updateTime" label="更新时间" align="center" width="160"
        v-if="columns.showColumn('updateTime')" />
      <el-table-column prop="remark" label="备注" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('remark')" />
      <el-table-column label="操作" align="center" width="160">
        <template #default="scope">
          <!-- <el-button v-hasPermi="['business:sapdeliverrecord:edit']" plain type="success" icon="edit" title="编辑"
            @click="handleUpdate(scope.row)"></el-button> -->
          <el-button v-hasPermi="['business:sapdeliverrecord:delete']" plain type="danger" icon="delete" title="删除"
            @click="handleDelete(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination class="mt10" background :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改接口管理/SAP交验单记录表对话框 -->
    <el-dialog :title="title" :lock-scroll="false" v-model="open">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">

          <el-col :lg="12">
            <el-form-item label="ID" prop="id">
              <el-input v-model="form.id" placeholder="请输入ID" :disabled="opertype != 1" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="交验单号" prop="deliverNo">
              <el-input v-model="form.deliverNo" placeholder="请输入交验单号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="送检人员" prop="checkName">
              <el-input v-model="form.checkName" placeholder="请输入送检人员" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="生产令号" prop="bomNo">
              <el-input v-model="form.bomNo" placeholder="请输入生产令号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="行项目" prop="rowNo">
              <el-input v-model="form.rowNo" placeholder="请输入行项目" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="物料类型" prop="category">
              <el-input v-model="form.category" placeholder="请输入物料类型" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="物料编码" prop="materialCode">
              <el-input v-model="form.materialCode" placeholder="请输入物料编码" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="物料名称" prop="materialName">
              <el-input v-model="form.materialName" placeholder="请输入物料名称" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="规格型号/图号" prop="materialSpec">
              <el-input v-model="form.materialSpec" placeholder="请输入规格型号/图号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="关键件标识" prop="keyFlag">
              <el-input v-model="form.keyFlag" placeholder="请输入关键件标识" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="交验单数量" prop="qty">
              <el-input v-model="form.qty" placeholder="请输入交验单数量" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="抽检数量" prop="spotCheckQty">
              <el-input v-model="form.spotCheckQty" placeholder="请输入抽检数量" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="质检数量" prop="checkQty">
              <el-input v-model="form.checkQty" placeholder="请输入质检数量" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="质检结果" prop="checkResult">
              <el-input v-model="form.checkResult" placeholder="请输入质检结果" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="入库数量" prop="instoreQty">
              <el-input v-model="form.instoreQty" placeholder="请输入入库数量" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="入库结果" prop="instoreResult">
              <el-input v-model="form.instoreResult" placeholder="请输入入库结果" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="创建者" prop="createBy">
              <el-input v-model="form.createBy" placeholder="请输入创建者" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="创建时间" prop="createTime">
              <el-date-picker v-model="form.createTime" type="datetime" :teleported="false"
                placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="更新者" prop="updateBy">
              <el-input v-model="form.updateBy" placeholder="请输入更新者" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="更新时间" prop="updateTime">
              <el-date-picker v-model="form.updateTime" type="datetime" :teleported="false"
                placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer v-if="opertype != 3">
        <el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
        <el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
      </template>
    </el-dialog>
    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body @close="dialogClose">
      <el-upload name="file" ref="uploadRef" :limit="1" accept=".xlsx,.xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :on-error="handleFileError"
        :on-exceed="handleExceed" :auto-upload="false" :data="uploadPara" drag>
        <el-icon class="el-icon--upload">
          <upload-filled />
        </el-icon>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
          <div class="el-upload__tip text-center">
            <!-- <div class="el-upload__tip">
                  <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
                </div> -->
            <span>仅允许导入xlsx和xls格式文件。</span>
            <br /><br />
            <span>限单次导入一个文件，再次选择将替换前一个文件。</span>
            <!-- <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
              @click="importTemplate">下载模板</el-link> -->
          </div>
        </template>
      </el-upload>
      <template #footer>
        <el-select v-model="uploadPara.category" placeholder="请选择" style="width:180px;margin-right: 15px;" size="large">
          <el-option v-for="dict in options.materialTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue">
            <dict-tag :options="options.materialTypeOptions" :value="dict.dictValue" />
          </el-option>
        </el-select>
        <el-button @click="upload.open = false" size="large">{{ $t('btn.cancel') }}</el-button>
        <el-button type="primary" @click="submitFileForm" size="large">{{ $t('btn.submit') }}</el-button>
        <el-row justify="center" style="margin-top:20px;" v-if="uploadPara.category == '外购件'">
          <el-text type="warning">【外购件】交验单中只导入关键件</el-text>
        </el-row>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="sapdeliverrecord">
import {
  listSapDeliverRecord, addSapDeliverRecord, delSapDeliverRecord, updateSapDeliverRecord, getSapDeliverRecord,
} from '@/api/business/sapdeliverrecord.js'

import { getToken } from "@/utils/auth";
const { proxy } = getCurrentInstance()
// 选中id数组数组
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const loading = ref(false)
const showSearch = ref(true)
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  sort: '',
  sortType: 'asc',
})
const columns = ref([
  { visible: false, prop: 'id', label: 'ID' },
  { visible: true, prop: 'deliverNo', label: '交验单号' },
  { visible: true, prop: 'checkName', label: '送检人员' },
  { visible: true, prop: 'bomNo', label: '生产令号' },
  { visible: true, prop: 'rowNo', label: '行项目' },
  { visible: true, prop: 'category', label: '物料类型' },
  { visible: true, prop: 'materialCode', label: '物料编码' },
  { visible: true, prop: 'materialName', label: '物料名称' },
  { visible: true, prop: 'materialSpec', label: '规格型号/图号' },
  { visible: true, prop: 'keyFlag', label: '关键件标识' },
  { visible: true, prop: 'qty', label: '交验单数量' },
  { visible: false, prop: 'spotCheckQty', label: '抽检数量' },
  { visible: true, prop: 'checkQty', label: '质检数量' },
  { visible: false, prop: 'checkResult', label: '质检结果' },
  { visible: false, prop: 'instoreQty', label: '入库数量' },
  { visible: false, prop: 'instoreResult', label: '入库结果' },
  { visible: false, prop: 'createBy', label: '创建人' },
  { visible: false, prop: 'createTime', label: '创建时间' },
  { visible: false, prop: 'updateBy', label: '更新人' },
  { visible: false, prop: 'updateTime', label: '更新时间' },
  { visible: false, prop: 'remark', label: '备注' },
])
const total = ref(0)
const dataList = ref([])
const queryRef = ref()
const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])

const queryCreateTime = ref([])

function getList() {
  loading.value = true
  listSapDeliverRecord(queryParams).then(res => {
    const { code, data } = res
    if (code == 200) {
      dataList.value = data.result
      total.value = data.totalNum
      loading.value = false
    }
  })
}

// 查询
function handleQuery() {
  queryParams.pageNum = 1
  if (queryCreateTime.value != null) {
    queryParams.beginTime = queryCreateTime.value[0]
    queryParams.endTime = queryCreateTime.value[1]
    // console.log(queryParams)
  }
  else {
    queryParams.beginTime = undefined
    queryParams.endTime = undefined
  }
  getList()
}

// 重置查询操作
function resetQuery() {
  queryCreateTime.value = []
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1
  multiple.value = !selection.length;
}

// 自定义排序
function sortChange(column) {
  var sort = undefined
  var sortType = undefined

  if (column.prop != null && column.order != null) {
    sort = column.prop
    sortType = column.order

  }
  queryParams.sort = sort
  queryParams.sortType = sortType
  handleQuery()
}
/*** 导入参数 */
const upload = reactive({
  // 是否显示弹出层
  open: false,
  // 弹出层标题
  title: '',
  // 是否禁用上传
  isUploading: false,
  // 是否更新已经存在的数据
  updateSupport: 0,
  // 设置上传的请求头部
  headers: { Authorization: 'Bearer ' + getToken() },
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + '/business/sapdeliverrecord/importData'
})
const uploadPara = reactive({
  category: ''
})
// 上传文件超限，替换文件
const handleExceed = (files, uploadFiles) => {
  // console.log(files)
  // console.log(uploadFiles)
  proxy.$refs['uploadRef'].clearFiles()
  proxy.$refs['uploadRef'].handleStart(files[0])
}
// 导入按钮操作
function handleImport() {
  upload.title = '交验单导入'
  upload.open = true
}
// 下载导入模板
function importTemplate() {
  proxy.download('/business/sapdeliverrecord/importTemplate', '交验单导入模板')
}
// 提交上传文件
function submitFileForm() {
  if (uploadPara.category == '') {
    console.log('上传物料类型是空的！')
    proxy.$modal.msgWarning('请选择物料类型')
  }
  else {
    proxy.$refs['uploadRef'].submit()
  }
}
/**文件上传中处理 */
const handleFileUploadProgress = (event, file, fileList) => {
  upload.isUploading = true
}
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
  upload.open = false
  upload.isUploading = false
  proxy.$refs['uploadRef'].clearFiles()
  console.log(response)
  proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.data + '</div>', '导入结果', {
    dangerouslyUseHTMLString: true
  })
  getList()
}
/** 文件上传服务器错误处理 */
const handleFileError = (Error, file, fileList) => {
  upload.isUploading = false
  proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>文件：【" + file.name + "】导入错误。<br/>请确认：<br/>交验单号<br/>采购订单<br/>生产令号<br/>行项目<br/>规格型号<br/>关键件标识<br/>交验单数量<br/>抽检数量<br/>以上内容在表格中正确无误。" + '</div>', '导入错误', {
    dangerouslyUseHTMLString: true
  })
}
/*************** form操作 ***************/
const formRef = ref()
const title = ref("")
// 操作类型 1、add 2、edit 3、view
const opertype = ref(0)
const open = ref(false)
const state = reactive({
  form: {},
  rules: {
    id: [{ required: true, message: "ID不能为空", trigger: "blur", type: "number" }],
    deliverNo: [{ required: true, message: "交验单号不能为空", trigger: "blur" }],
    bomNo: [{ required: true, message: "生产令号不能为空", trigger: "blur" }],
    rowNo: [{ required: true, message: "行项目不能为空", trigger: "blur", type: "number" }],
    category: [{ required: true, message: "物料类型不能为空", trigger: "blur" }],
    materialCode: [{ required: true, message: "物料编码不能为空", trigger: "blur" }],
    materialName: [{ required: true, message: "物料名称不能为空", trigger: "blur" }],
    materialSpec: [{ required: true, message: "规格型号/图号不能为空", trigger: "blur" }],
    keyFlag: [{ required: true, message: "关键件标识不能为空", trigger: "blur" }],
    qty: [{ required: true, message: "交验单数量不能为空", trigger: "blur", type: "number" }],
    spotCheckQty: [{ required: true, message: "抽检数量不能为空", trigger: "blur", type: "number" }],
    checkResult: [{ required: true, message: "质检结果不能为空", trigger: "blur" }],
    instoreResult: [{ required: true, message: "入库结果不能为空", trigger: "blur", type: "number" }],
  },
  options: {
    keyFlagOptions: [], // 关键件标识字典
    operationResultOptions: [],// 操作结果字典
    materialTypeOptions: [],// 物料类型字典
    qaResultOptions: [],//质检结果字典
  }
})

const { form, rules, options } = toRefs(state)

var dictParams = [
  { dictType: 'my_key_flag', columnName: 'keyFlagOptions' },
  { dictType: 'my_operation_result', columnName: 'operationResultOptions' },
  { dictType: 'my_material_type', columnName: 'materialTypeOptions' },
  { dictType: 'my_qa_result', columnName: 'qaResultOptions' },
]
proxy.getDicts(dictParams).then((response) => {
  response.data.forEach((element) => {
    state.options[element.columnName] = element.list
  })
})
// 关闭dialog
function cancel() {
  open.value = false
  reset()
}
function dialogClose() {
  uploadPara.category = ''
}
// 重置表单
function reset() {
  form.value = {
    id: undefined,
    deliverNo: undefined,
    checkName: undefined,
    bomNo: undefined,
    rowNo: undefined,
    category: undefined,
    materialCode: undefined,
    materialName: undefined,
    materialSpec: undefined,
    keyFlag: undefined,
    qty: undefined,
    spotCheckQty: undefined,
    checkQty: undefined,
    checkResult: undefined,
    instoreQty: undefined,
    instoreResult: undefined,
    createBy: undefined,
    createTime: undefined,
    updateBy: undefined,
    updateTime: undefined,
    remark: undefined,
  };
  proxy.resetForm("formRef")
}

// 添加按钮操作
function handleAdd() {
  reset();
  open.value = true
  title.value = '添加'
  opertype.value = 1
}

// 修改按钮操作
function handleUpdate(row) {
  reset()
  const id = row.id || ids.value
  getSapDeliverRecord(id).then((res) => {
    const { code, data } = res
    if (code == 200) {
      open.value = true
      title.value = "修改数据"
      opertype.value = 2

      form.value = {
        ...data,
      }
    }
  })
}

// 添加&修改 表单提交
function submitForm() {
  proxy.$refs["formRef"].validate((valid) => {
    if (valid) {
      if (form.value.id != undefined && opertype.value === 2) {
        updateSapDeliverRecord(form.value).then((res) => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
          .catch(() => { })
      } else {
        addSapDeliverRecord(form.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
          .catch(() => { })
      }
    }
  })
}

// 删除按钮操作
function handleDelete(row) {
  const Ids = row.id || ids.value

  proxy
    .$confirm('是否确认删除选中数据？')
    .then(function () {
      return delSapDeliverRecord(Ids)
    })
    .then(() => {
      getList()
      proxy.$modal.msgSuccess("删除成功")
    })
    .catch(() => { })
}


handleQuery()
</script>
