From 0523f4b385a9f524b8050f48adda464973828f97 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 13 八月 2025 13:55:33 +0800
Subject: [PATCH] 代码合并

---
 src/views/equipmentManagement/ledger/index.vue |  355 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 279 insertions(+), 76 deletions(-)

diff --git a/src/views/equipmentManagement/ledger/index.vue b/src/views/equipmentManagement/ledger/index.vue
index 4327e98..16fbbc6 100644
--- a/src/views/equipmentManagement/ledger/index.vue
+++ b/src/views/equipmentManagement/ledger/index.vue
@@ -1,104 +1,307 @@
 <template>
   <div class="app-container">
     <el-form :model="filters" :inline="true">
-      <el-form-item label="鎼滅储">
+      <el-form-item label="璁惧鍚嶇О">
         <el-input
-          v-model="filters.searchText"
+          v-model="filters.deviceName"
           style="width: 240px"
-          placeholder="璇疯緭鍏�"
+          placeholder="璇疯緭鍏ヨ澶囧悕绉�"
           clearable
           :prefix-icon="Search"
           @change="getTableData"
         />
+      </el-form-item>
+      <el-form-item label="瑙勬牸鍨嬪彿">
+        <el-input
+            v-model="filters.deviceModel"
+            style="width: 240px"
+            placeholder="璇疯緭鍏ヨ鏍煎瀷鍙�"
+            clearable
+            :prefix-icon="Search"
+            @change="getTableData"
+        />
+      </el-form-item>
+      <el-form-item label="渚涘簲鍟�">
+        <el-input
+            v-model="filters.supplierName"
+            style="width: 240px"
+            placeholder="璇疯緭鍏ヤ緵搴斿晢"
+            clearable
+            :prefix-icon="Search"
+            @change="getTableData"
+        />
+      </el-form-item>
+      <el-form-item label="鍗曚綅">
+        <el-input
+            v-model="filters.unit"
+            style="width: 240px"
+            placeholder="璇疯緭鍏ュ崟浣�"
+            clearable
+            :prefix-icon="Search"
+            @change="getTableData"
+        />
+      </el-form-item>
+      <el-form-item label="褰曞叆鏃ユ湡:">
+        <el-date-picker v-model="filters.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange"
+                        placeholder="璇烽�夋嫨" clearable @change="changeDaterange" />
       </el-form-item>
       <el-form-item>
         <el-button type="primary" @click="getTableData">鎼滅储</el-button>
         <el-button @click="resetFilters">閲嶇疆</el-button>
       </el-form-item>
     </el-form>
-    <PIMTable
-      :column="columns"
-      :tableData="dataList"
-      :page="{
-        current: pagination.currentPage,
-        size: pagination.pageSize,
-        total: pagination.total,
-      }"
-    >
-      <template #operation>
-        <el-button type="primary" text>缂栬緫</el-button>
-        <el-button type="danger" text>鍒犻櫎</el-button>
-      </template>
-    </PIMTable>
+    <div class="table_list">
+      <div class="actions">
+        <div></div>
+        <div>
+          <el-button type="primary" @click="add" icon="Plus"> 鏂板 </el-button>
+          <el-button @click="handleOut" icon="download">瀵煎嚭</el-button>
+          <el-button
+            type="danger"
+            icon="Delete"
+            :disabled="multipleList.length <= 0"
+            @click="deleteRow(multipleList.map((item) => item.id))"
+          >
+            鎵归噺鍒犻櫎
+          </el-button>
+        </div>
+      </div>
+      <PIMTable
+        rowKey="id"
+        isSelection
+        :column="columns"
+        :tableData="dataList"
+        :page="{
+          current: pagination.currentPage,
+          size: pagination.pageSize,
+          total: pagination.total,
+        }"
+        @selection-change="handleSelectionChange"
+        @pagination="changePage"
+      >
+      </PIMTable>
+    </div>
+    <Modal ref="modalRef" @success="getTableData"></Modal>
+    <el-dialog v-model="qrDialogVisible" title="浜岀淮鐮�" width="300px">
+      <div style="text-align:center;">
+        <img :src="qrCodeUrl" alt="浜岀淮鐮�" style="width:200px;height:200px;" />
+        <div style="margin:10px 0;">
+          <el-button type="primary" @click="downloadQRCode">涓嬭浇浜岀淮鐮佸浘鐗�</el-button>
+        </div>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script setup>
 import { usePaginationApi } from "@/hooks/usePaginationApi";
-import { Search } from "@element-plus/icons-vue";
+// import { Search } from "@element-plus/icons-vue";
+import { getLedgerPage, delLedger } from "@/api/equipmentManagement/ledger";
+import { onMounted, getCurrentInstance } from "vue";
+import Modal from "./Modal.vue";
+import { ElMessageBox, ElMessage } from "element-plus";
+import dayjs from "dayjs";
+import QRCode from "qrcode";
+import { ref } from "vue";
 
 defineOptions({
   name: "璁惧鍙拌处",
 });
 
-const { filters, columns, dataList, pagination, getTableData, resetFilters } =
-  usePaginationApi(
-    () => {},
+// 琛ㄦ牸澶氶�夋閫変腑椤�
+const multipleList = ref([]);
+const { proxy } = getCurrentInstance();
+const modalRef = ref();
+const qrDialogVisible = ref(false);
+const qrCodeUrl = ref("");
+const qrRowData = ref(null);
+
+const {
+  filters,
+  columns,
+  dataList,
+  pagination,
+  getTableData,
+  resetFilters,
+  onCurrentChange,
+} = usePaginationApi(
+  getLedgerPage,
+  {
+    searchText: undefined,
+  },
+  [
     {
-      searchText: undefined,
+      label: "璁惧鍚嶇О",
+      align: "center",
+      prop: "deviceName",
     },
-    [
-      {
-        label: "璁惧鍚嶇О",
-        align: "center",
-      },
-      {
-        label: "瑙勬牸鍨嬪彿",
-        align: "center",
-      },
-      {
-        label: "渚涘簲鍟�",
-        align: "center",
-      },
-      {
-        label: "鍗曚綅",
-        align: "center",
-      },
-      {
-        label: "鏁伴噺",
-        align: "center",
-      },
-      {
-        label: "鍚◣鍗曚环",
-        align: "center",
-      },
-      {
-        label: "鍚◣鎬讳环",
-        align: "center",
-      },
-      {
-        label: "绋庣巼",
-        align: "center",
-      },
-      {
-        label: "涓嶅惈绋庢�讳环",
-        align: "center",
-      },
-      {
-        label: "褰曞叆浜�",
-        align: "center",
-      },
-      {
-        label: "褰曞叆鏃ユ湡",
-        align: "center",
-      },
-      {
-        label: "鎿嶄綔",
-        dataType: "slot",
-        slot: "operation",
-        align: "center",
-        width: "150px",
-      },
-    ]
-  );
+    {
+      label: "瑙勬牸鍨嬪彿",
+      align: "center",
+      prop: "deviceModel",
+    },
+    {
+      label: "渚涘簲鍟�",
+      align: "center",
+      prop: "supplierName",
+    },
+    {
+      label: "鍗曚綅",
+      align: "center",
+      prop: "unit",
+    },
+    {
+      label: "鏁伴噺",
+      align: "center",
+      prop: "number",
+    },
+    {
+      label: "鍚◣鍗曚环",
+      align: "center",
+      prop: "taxIncludingPriceUnit",
+    },
+    {
+      label: "鍚◣鎬讳环",
+      align: "center",
+      prop: "taxIncludingPriceTotal",
+    },
+    {
+      label: "绋庣巼",
+      align: "center",
+      prop: "taxRate",
+    },
+    {
+      label: "涓嶅惈绋庢�讳环",
+      align: "center",
+      prop: "unTaxIncludingPriceTotal",
+    },
+    {
+      label: "褰曞叆浜�",
+      align: "center",
+      prop: "createUser",
+    },
+    {
+      label: "褰曞叆鏃ユ湡",
+      align: "center",
+      prop: "createTime",
+    },
+		{
+			dataType: "action",
+			label: "鎿嶄綔",
+			align: "center",
+			fixed: 'right',
+			width: 140,
+			operation: [
+				{
+					name: "缂栬緫",
+					type: "text",
+					clickFun: (row) => {
+						edit(row.id)
+					},
+				},
+				{
+					name: "鐢熸垚浜岀淮鐮�",
+					type: "text",
+					clickFun: (row) => {
+						showQRCode(row)
+					},
+				},
+			],
+		},
+  ]
+);
+
+// 澶氶�夊悗鍋氫粈涔�
+const handleSelectionChange = (selectionList) => {
+  multipleList.value = selectionList;
+};
+
+const add = () => {
+  modalRef.value.openModal();
+};
+const edit = (id) => {
+  modalRef.value.loadForm(id);
+};
+const changePage = ({ page, limit }) => {
+  pagination.currentPage = page;
+	pagination.pageSize = limit;
+  onCurrentChange(page);
+};
+const deleteRow = (id) => {
+  ElMessageBox.confirm("姝ゆ搷浣滃皢姘镐箙鍒犻櫎璇ユ枃浠�, 鏄惁缁х画?", "鎻愮ず", {
+    confirmButtonText: "纭畾",
+    cancelButtonText: "鍙栨秷",
+    type: "warning",
+  }).then(async () => {
+    const { code } = await delLedger(id);
+    if (code == 200) {
+      ElMessage({
+        type: "success",
+        message: "鍒犻櫎鎴愬姛",
+      });
+      getTableData();
+    }
+  });
+};
+
+const changeDaterange = (value) => {
+  if (value) {
+    filters.entryDateStart = dayjs(value[0]).format("YYYY-MM-DD");
+    filters.entryDateEnd = dayjs(value[1]).format("YYYY-MM-DD");
+  } else {
+    filters.entryDateStart = undefined;
+    filters.entryDateEnd = undefined;
+  }
+  getTableData();
+};
+
+const handleOut = () => {
+  ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�", "瀵煎嚭", {
+    confirmButtonText: "纭",
+    cancelButtonText: "鍙栨秷",
+    type: "warning",
+  })
+    .then(() => {
+      proxy.download(`/device/ledger/export`, {}, "璁惧鍙拌处妗f.xlsx");
+    })
+    .catch(() => {
+      proxy.$modal.msg("宸插彇娑�");
+    });
+};
+
+const showQRCode = async (row) => {
+  // 浣犲彲浠ヨ嚜瀹氫箟浜岀淮鐮佸唴瀹癸紝姣斿 row.id 鎴� row.deviceName
+  const qrContent = JSON.stringify(row); // 鎴� `${row.id}`
+  qrCodeUrl.value = await QRCode.toDataURL(qrContent);
+  qrRowData.value = row;
+  qrDialogVisible.value = true;
+};
+
+const downloadQRCode = () => {
+  const a = document.createElement("a");
+  a.href = qrCodeUrl.value;
+  a.download = `${qrRowData.value.deviceName || "浜岀淮鐮�"}.png`;
+  a.click();
+};
+
+onMounted(() => {
+  filters.entryDate = [
+    dayjs().format("YYYY-MM-DD"),
+    dayjs().add(1, "day").format("YYYY-MM-DD"),
+  ]
+  filters.entryDateStart = dayjs().format("YYYY-MM-DD")
+  filters.entryDateEnd = dayjs().add(1, "day").format("YYYY-MM-DD")
+  getTableData();
+});
 </script>
+
+<style lang="scss" scoped>
+.table_list {
+  margin-top: unset;
+}
+.actions {
+  display: flex;
+  justify-content: space-between;
+  margin-bottom: 10px;
+}
+</style>

--
Gitblit v1.9.3