<template>
  <basic-container>
    <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 #leCode="{ row }">{{ row.stLend.leCode }}</template> -->
      <!-- <template #goodsCode="{ row }">{{ row.stLend.stRealtimeStock.coGoods.goodsCode }}</template>
            <template #goodsName="{ row }">{{ row.stLend.stRealtimeStock.coGoods.goodsName }}</template>
            <template #piNo="{ row }">{{ row.stLend.stRealtimeStock.piNo }}</template>
            <template #shName="{ row }">{{ row.stLend.stRealtimeStock.coStorehouse.shName }}</template>
            <template #location="{ row }">{{ row.stLend.stRealtimeStock.storageLocation.location }}</template>
            <template #quantity="{ row }">{{ row.stLend.quantity }}</template>
            <template #returnQty="{ row }">{{ row.stLend.returnQty }}</template>
            <template #unitName="{ row }">{{ row.stLend.stRealtimeStock.coGoods.unitName }}</template>
            <template #leDate="{ row }">{{ row.stLend.leDate }}</template>
            <template #leReturnDate="{ row }">{{ row.stLend.leReturnDate }}</template>
            <template #deptName="{ row }">{{ row.stLend.pfDepartment.deptName }}</template>
            <template #userName="{ row }">{{ row.stLend.leMan.userName }}</template>
            <template #createMan="{ row }">{{ row.createMan.userName }}</template>
            <template #curStatus="{ row }">
                {{ row.stLend.curStatus == 20 ? '已借出' : row.stLend.curStatus == 24 ?
                    '部分归还' : row.stLend.curStatus == 25 ? '已归还' : "新建" }}
            </template> -->
      <template #menu-left>
        <el-input v-model="input" style="width: 240px;  margin-right: 24px" placeholder="请扫描条形码"  @keyup.enter.native="handleEnter"/>
        <el-button type="primary" @click="handleAdd">新增</el-button>
        <el-button type="primary" @click="jichu()">批量借出</el-button>
        <el-button type="primary" @click="handleReturn">批量归还</el-button>
      </template>
      <template #menu="scope">
        <el-button type="text" @click="handleEdit(scope.row)" v-if="scope.row.curStatus === 1">修改</el-button>
        <el-button type="text" @click="rowDel(scope.row)" v-if="scope.row.curStatus === 1">删除</el-button>
      </template>
    </avue-crud>

    <el-dialog title="批量归还" append-to-body v-model="returnDialog" width="50%">
      <el-button plain type="danger" @click="remove">删除选择行</el-button>
      <!-- <el-button type="primary" @click="handleSave">保存</el-button> -->
      <el-table :data="returnData" style="margin-top: 10px">
        <el-table-column type="selection"></el-table-column>
        <el-table-column
          label="物料编码"
          prop="goodsCode"
          align="center"
        ></el-table-column>
        <el-table-column label="合格数" prop="passQty">
          <template #default="scope">
            <el-input-number
              v-model="num"
              :min="1"
              :max="10"
              controls-position="right"
              @change="handleChange"
            />
          </template>
        </el-table-column>
        <el-table-column label="丢失数" prop="loseQty" align="center">
          <template #default="scope">
            <el-input-number
              v-model="num"
              :min="1"
              :max="10"
              controls-position="right"
              @change="handleChange"
            />
          </template>
        </el-table-column>
        <!-- 如果有报废数量，自动生成一条报废记录 然后发送给工艺员（角色）审批  待报废  已报废(审批通过) -->
        <el-table-column label="报废数" prop="loseQty" align="center">
          <template #default="scope">
            <el-input-number
              v-model="num"
              :min="1"
              :max="10"
              controls-position="right"
              @change="handleChange"
            />
          </template>
        </el-table-column>
        <el-table-column label="使用次数" prop="useNumber" align="center">
          <template #default="scope">
            <el-input-number
              v-model="num"
              :min="1"
              :max="10"
              controls-position="right"
              @change="handleChange"
            />
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="submit">确 定</el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 借出 -->
    <borrowDialog
      v-if="isOpen"
      :showDialog="isOpen"
      @closeDialog="closeDialog"
      :moldAddMore="moldAddMore"
    >
    </borrowDialog>
  </basic-container>
</template>
<script>
import borrowDialog from "./components/borrowDialog.vue";
export default {
  components: {
    borrowDialog,
  },
  data() {
    return {
      loading: false,
      data: [],
      form: {},
      returnDialog: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      returnData: [
        {
          goodsCode: "9898989",
        },
      ],
      option: {
        height: "auto",
        calcHeight: 32,
        tip: false,
        size: "medium",
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: true,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        editBtnText: "修改",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        viewBtnText: "详情",
        labelWidth: 150,
        menuWidth: 120,
        dialogWidth: 1500,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        index: false,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "left",
        gridBtn: false,
        searchMenuPosition: "right",
        align: "center",
        column: [
          {
            label: "单据号",
            prop: "leCode",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 12,
            search: true,
            searchOrder: 20,
            rules: [
              {
                required: true,
                message: "请输入单据号",
                trigger: "click",
              },
            ],
          },
          {
            label: "物料编号",
            prop: "goodsCode",
            addDisplay: true,
            editDisplay: false,
            order: 11,
            span: 6,
            width: 200,
            search: true,
            searchOrder: 18,
            rules: [
              {
                required: true,
                message: "请输入物料编号",
                trigger: "click",
              },
            ],
          },
          {
            label: "物料名称",
            prop: "goodsName",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 8,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入物料名称",
                trigger: "click",
              },
            ],
          },
          {
            label: "库房",
            prop: "shName",
            addDisplay: false,
            editDisplay: false,
            span: 6,
            width: 200,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入库房号",
                trigger: "click",
              },
            ],
          },
          {
            label: "库位",
            prop: "location",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入库位号",
                trigger: "click",
              },
            ],
          },
           {
            label: "型号/牌号",
            prop: "specifications",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入型号/牌号",
                trigger: "click",
              },
            ],
          },
          {
            label: "批次号",
            prop: "piNo",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 6,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入批号",
                trigger: "click",
              },
            ],
          },
          {
            label: "借出数量",
            prop: "quantity",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 10,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入借出数量",
                trigger: "click",
              },
            ],
          },
          {
            label: "计量单位",
            prop: "unitName",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 2,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入单位",
                trigger: "click",
              },
            ],
          },
          {
            label: "借用部门",
            prop: "deptName",
            type: "select",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 14,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入借用部门",
                trigger: "click",
              },
            ],
            prop: {
              label: "deptName",
              value: "deptCode",
            },
            dicData: [
              {
                appLink: null,
                createTime: "2022-08-31",
                deleted: false,
                deptCode: "001",
                deptId: 1,
                deptName: "MES开发部",
                deptType: 1,
                deptTypeTitle: "厂",
                keyValue: 1,
                memo: null,
                orders: "00",
                parentDeptId: null,
                parentPath: null,
                ucDeptId: null,
                updateTime: "2022-08-31 16:32:46",
              },
              {
                appLink: null,
                createTime: "2023-02-06",
                deleted: false,
                deptCode: "3400",
                deptId: 41,
                deptName: "热表分厂",
                deptType: 1,
                deptTypeTitle: "厂",
                keyValue: 41,
                memo: null,
                orders: "1",
                parentDeptId: null,
                parentPath: null,
                ucDeptId: null,
                updateTime: "2023-02-06 10:25:08",
              },
              {
                appLink: null,
                createTime: "2023-02-06",
                deleted: false,
                deptCode: "01",
                deptId: 42,
                deptName: "化学镀镍",
                deptType: 1,
                deptTypeTitle: "厂",
                keyValue: 42,
                memo: null,
                orders: "1",
                parentDeptId: 41,
                parentPath: null,
                ucDeptId: null,
                updateTime: "2023-02-06 10:26:13",
              },
            ],
          },
            {
            label: "借用人",
            prop: "leReturnUser",
            type: "select",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 13,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入借用人",
                trigger: "click",
              },
            ],
            dicData: [
              { userId: 1, userName: "admin" },
              { userId: 61, userName: "09391" },
              { userId: 62, userName: "03764" },
            ],
          },
           {
            label: "借出时间",
            prop: "leDate",
            addDisplay: true,
            editDisplay: false,
            type: "date",
            searchRange: true,
            startPlaceholder: "开始日期",
            endPlaceholder: "结束日期",

            span: 6,
            width: 200,
            order: 16,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入借出时间",
                trigger: "click",
              },
            ],
          },
          {
            label: "计划归还时间",
            prop: "leReturnDate",
            order: 9,
            type: "date",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入计划归还",
                trigger: "click",
              },
            ],
          },
          
        
          {
            label: "归还合格数量",
            prop: "passQty",
            addDisplay: false,
            editDisplay: false,
            span: 6,
            width: 200,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入本次归还合格数量",
                trigger: "click",
              },
            ],
          },
          {
            label: "归还丢失数量",
            prop: "loseQty",
            addDisplay: false,
            editDisplay: false,
            span: 6,
            width: 200,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入本次归还丢失数",
                trigger: "click",
              },
            ],
          },
          {
            label: "归还报废数量",
            prop: "bfQty",
            addDisplay: false,
            editDisplay: false,
            span: 6,
            width: 200,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入本次归还报废数",
                trigger: "click",
              },
            ],
          },
          
          // {
          //   label: "库存量",
          //   prop: "stockNum",
          //   addDisplay: true,
          //   addDisabled: true,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   search: false,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入库存量",
          //       trigger: "click",
          //     },
          //   ],
          // },
          // {
          //   label: "可用库存",
          //   prop: "useQuantity",
          //   addDisplay: true,
          //   addDisabled: true,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   search: false,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入可用库存",
          //       trigger: "click",
          //     },
          //   ],
          // },
         
          // {
          //   label: "退库数量",
          //   prop: "returnQty",
          //   addDisplay: false,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   search: false,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入退库数量",
          //       trigger: "click",
          //     },
          //   ],
          // },
         
         
          // {
          //   label: "借出仓库",
          //   prop: "shId",
          //   type: "select",
          //   addDisplay: true,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   order: 15,
          //   search: false,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入借出仓库",
          //       trigger: "click",
          //     },
          //   ],
          //   dicData: [
          //     { label: "仓库一", value: "001" },
          //     { label: "仓库二", value: "002" },
          //   ],
          // },
          
          // {
          //     label: '本次归还续借数',
          //     prop: 'renewQty',
          //     addDisplay: false,
          //     editDisplay: false,
          //     span: 6,
          //     width: 200,
          //     search: false,
          //     rules: [
          //         {
          //             required: true,
          //             message: '请输入本次归还续借数',
          //             trigger: 'click',
          //         },
          //     ],
          // },
          // {
          //   label: "本次归还人",
          //   prop: "createMan",
          //   addDisplay: false,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   search: true,
          //   searchLabelWidth: 90,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入本次归还人",
          //       trigger: "click",
          //     },
          //   ],
          // },
          // {
          //   label: "本次使用次数",
          //   prop: "useNumber",
          //   addDisplay: false,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   search: false,

          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入本次使用次数",
          //       trigger: "click",
          //     },
          //   ],
          // },
          // {
          //   label: "本次归还时间",
          //   prop: "createTime",
          //   addDisplay: false,
          //   editDisplay: false,
          //   span: 6,
          //   width: 200,
          //   type: "date",
          //   searchRange: true,
          //   startPlaceholder: "开始日期",
          //   endPlaceholder: "结束日期",
          //   search: true,
          //   searchLabelWidth: 100,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入本次归还时间",
          //       trigger: "click",
          //     },
          //   ],
          // },
          {
            label: "是否报废",
            prop: "isScrap",
            addDisplay: false,
            editDisplay: false,
            span: 6,
            width: 200,
            search: false,
            type: "select",
            searchOrder: 17,
            dicData: [
              {
                label: "是",
                value: 1,
              },
              {
                label: "否",
                value: 0,
              },
            ],
            rules: [
              {
                required: true,
                message: "请输入状态",
                trigger: "click",
              },
            ],
          },
          {
            label: "状态",
            prop: "curStatus",
            addDisplay: false,
            editDisplay: false,
            span: 6,
            width: 200,
            search: true,
            type: "select",
            searchOrder: 18,
            dicData: [
              {
                label: "待借出",
                value: 1,
              },
              {
                label: "待归还",
                value: 2,
              },
              {
                label: "部分归还",
                value: 4,
              },
              {
                label: "已归还",
                value: 3,
              },
            ],
            rules: [
              {
                required: true,
                message: "请输入状态",
                trigger: "click",
              },
            ],
          },
          {
            label: "备注",
            prop: "curStatus",
            type: "textarea",
            addDisplay: true,
            editDisplay: false,
            span: 6,
            width: 200,
            order: 1,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入备注",
                trigger: "click",
              },
            ],
          },

        ],
      },
      isOpen: false,
      moldAddMore: false,
    };
  },
  mounted() {},
  methods: {
    jichu() {
      this.$confirm("确定将选择数据批量借出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        callback();
      });
    },
    handleEdit() {
      this.isOpen = true;
      this.moldAddMore = false;
    },
    // 借用
    handleAdd() {
      this.isOpen = true;
      this.moldAddMore = true;
    },
    closeDialog() {
      this.isOpen = false;
    },
    handleReturn() {
      this.returnDialog = true;
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // deleteLeveraging(row.id).then(() => {
        //   this.$message.success('删除成功');
        //   this.onLoad();
        // }).catch(() => {
        //   this.$message.error('删除失败');

      }).catch(() => {});
    },
    handleEnter() {
      this.$confirm("确定借出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        callback();
      });
    },
    onLoad() {
      this.data = [
        {
          leCode: "OT202407147982350",
          goodsCode: "89878809",
          goodsName: "物料一",
          shName: "989899",
          location: "库位1",
          returnQty: 8,
          unitName: "單位",
          leDate: "2025-09-11",
          shId: "45",
          leReturnDate: "2025-10-01",
          deptName: "34005",
          leReturnUser: "借用人",
          passQty: 89,
          loseQty: 4,
          bfQty: 7,
          renewQty: 5,
          createMan: "归还人",
          useNumber: 7,
          createTime: "2025-10-9",
          specifications: "344",
          stockNum: 90,
          useQuantity: 8,

          buyCode: "OT202407147982350",
          cccList: null,
          curStatus: 1,
          enrtydate: null,
          invadjCode: "C20240725148120387",
          invadjMoney: 0.0,
          inviefdat: "2026-07-01",
          invysqty: "4.0",
          keyValue: 1167,
          piNo: "090988",
          planBuyMan: null,
          planDeclareMan: null,
          plnarea: "洛阳新区",
          prtdesc: "氧化银钾",
          prtinfo: "1000g / 袋",
          prtlotno: null,
          prtno: "04-05-025",
          prtrepno: null,
          prtum: "千克",
          pushHouse: null,
          pushQuantity: 9,
          qutno: "JF-2407-XC-5344",
          remark: "热表 mes 额外需求",
          rouclp: "-",
          splyName: "热表分厂",
          srId: 1167,
          storarea: "洛阳新区",
          stovePiNo: null,
          validdat: "2024-07-31",
          warctlr: "吕阳",
          warlocno: "G010203",
          warno: "020060JY",
        },
        {
          leCode: "OT2024989879",
          goodsCode: "89878809",
          goodsName: "物料2",
          shName: "989899",
          location: "库位2",
          returnQty: 8,
          unitName: "單位",
          leDate: "2025-09-11",
          shId: "45",
          leReturnDate: "2025-10-01",
          deptName: "34005",
          leReturnUser: "借用人",
          passQty: 89,
          loseQty: 4,
          bfQty: 7,
          renewQty: 5,
          createMan: "归还人",
          useNumber: 7,
          createTime: "2025-10-9",
          specifications: "344",
          stockNum: 90,
          useQuantity: 8,

          buyCode: "OT202407147982350",
          cccList: null,
          curStatus: 1,
          enrtydate: null,
          invadjCode: "C20240725148120387",
          invadjMoney: 0.0,
          inviefdat: "2026-07-01",
          invysqty: "4.0",
          keyValue: 1167,
          piNo: "090988",
          planBuyMan: null,
          planDeclareMan: null,
          plnarea: "洛阳新区",
          prtdesc: "氧化银钾",
          prtinfo: "1000g / 袋",
          prtlotno: null,
          prtno: "04-05-025",
          prtrepno: null,
          prtum: "千克",
          pushHouse: null,
          pushQuantity: 9,
          qutno: "JF-2407-XC-5344",
          remark: "热表 mes 额外需求",
          rouclp: "-",
          splyName: "热表分厂",
          srId: 1167,
          storarea: "洛阳新区",
          stovePiNo: null,
          validdat: "2024-07-31",
          warctlr: "吕阳",
          warlocno: "G010203",
          warno: "020060JY",
        },
      ];
      this.page.total = this.data.length;
    },
  },
};
</script>

<style></style>
