1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<template>
  <div class="app-container">
    <div class="search_form">
      <el-form :model="searchForm" :inline="true">
        <el-form-item label="流水号:">
          <el-input v-model="searchForm.serialNo" placeholder="请输入" clearable style="width: 200px" @change="handleQuery" />
        </el-form-item>
        <el-form-item label="车号:">
          <el-input v-model="searchForm.carNo" placeholder="请输入" clearable style="width: 200px" @change="handleQuery" />
        </el-form-item>
        <el-form-item label="货名:">
          <el-input v-model="searchForm.goodsName" placeholder="请输入" clearable style="width: 200px" @change="handleQuery" />
        </el-form-item>
        <el-form-item label="收货单位:">
          <el-input v-model="searchForm.receiveUnit" placeholder="请输入" clearable style="width: 200px" @change="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
 
    <div class="table_list">
      <div class="actions">
        <div />
        <div>
          <el-button type="primary" plain @click="openImportDialog">导入</el-button>
          <el-button type="danger" plain @click="handleDelete">删除</el-button>
        </div>
      </div>
 
      <el-table
        :data="tableData"
        border
        v-loading="tableLoading"
        @selection-change="handleSelectionChange"
        :row-key="(row) => row.id"
        style="width: 100%"
        height="calc(100vh - 21.5em)"
      >
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column label="流水号" prop="serialNo" show-overflow-tooltip min-width="120" />
        <el-table-column label="车号" prop="carNo" show-overflow-tooltip min-width="120" />
        <el-table-column label="发货单位" prop="shipUnit" show-overflow-tooltip min-width="140" />
        <el-table-column label="收货单位" prop="receiveUnit" show-overflow-tooltip min-width="140" />
        <el-table-column label="货名" prop="goodsName" show-overflow-tooltip min-width="120" />
        <el-table-column label="规格" prop="specification" show-overflow-tooltip min-width="120" />
        <el-table-column label="毛重" prop="grossWeight" show-overflow-tooltip min-width="100" />
        <el-table-column label="皮重" prop="tareWeight" show-overflow-tooltip min-width="100" />
        <el-table-column label="净重" prop="netWeight" show-overflow-tooltip min-width="100" />
        <el-table-column label="一次过磅时间" prop="firstWeighTime" show-overflow-tooltip min-width="180" />
        <el-table-column label="二次过磅时间" prop="secondWeighTime" show-overflow-tooltip min-width="180" />
        <el-table-column label="原发" prop="originalSender" show-overflow-tooltip min-width="100" />
        <el-table-column label="更新人" prop="updateBy" show-overflow-tooltip min-width="120" />
      </el-table>
 
      <pagination
        v-show="total > 0"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        :page="page.current"
        :limit="page.size"
        @pagination="paginationChange"
      />
    </div>
 
    <el-dialog v-model="importUpload.open" :title="importUpload.title" width="500px" append-to-body>
      <el-upload
        ref="importUploadRef"
        drag
        :limit="1"
        :action="importUpload.url"
        :headers="importUpload.headers"
        :before-upload="importUpload.beforeUpload"
        :on-success="importUpload.onSuccess"
        :on-error="importUpload.onError"
        :auto-upload="false"
        accept=".xlsx,.xls"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处,或<em>点击上传</em>
        </div>
        <template #tip>
          <div class="el-upload__tip">仅支持 xlsx/xls 文件</div>
        </template>
      </el-upload>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" :loading="importUpload.isUploading" @click="submitImport">确定</el-button>
          <el-button @click="importUpload.open = false">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import pagination from "@/components/PIMTable/Pagination.vue";
import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
import { getToken } from "@/utils/auth";
import { weighbridgeLedgerListPage, delWeighbridgeLedger } from "@/api/salesManagement/deliveryLedger.js";
 
const { proxy } = getCurrentInstance();
 
const tableData = ref([]);
const selectedRows = ref([]);
const tableLoading = ref(false);
const page = reactive({
  current: 1,
  size: 100,
});
const total = ref(0);
 
const data = reactive({
  searchForm: {
    serialNo: "",
    carNo: "",
    goodsName: "",
    receiveUnit: "",
  },
});
const { searchForm } = toRefs(data);
 
const importUploadRef = ref(null);
const importUpload = reactive({
  title: "导入台账",
  open: false,
  isUploading: false,
  url: import.meta.env.VITE_APP_BASE_API + "/sales/weighbridgeLedger/import",
  headers: { Authorization: "Bearer " + getToken() },
  beforeUpload: (file) => {
    const isExcel = file.name.endsWith(".xlsx") || file.name.endsWith(".xls");
    if (!isExcel) {
      proxy.$modal.msgError("上传文件只能是 xlsx/xls 格式");
      return false;
    }
    return true;
  },
  onSuccess: (res) => {
    importUpload.isUploading = false;
    if (res?.code === 200) {
      proxy.$modal.msgSuccess("导入成功");
      importUpload.open = false;
      importUploadRef.value?.clearFiles();
      getList();
      return;
    }
    proxy.$modal.msgError(res?.msg || "导入失败");
  },
  onError: () => {
    importUpload.isUploading = false;
    proxy.$modal.msgError("导入失败,请重试");
  },
});
 
const handleQuery = () => {
  page.current = 1;
  getList();
};
 
const paginationChange = (obj) => {
  page.current = obj.page;
  page.size = obj.limit;
  getList();
};
 
const getList = () => {
  tableLoading.value = true;
  weighbridgeLedgerListPage({ ...searchForm.value, ...page })
    .then((res) => {
      tableData.value = res?.data?.records || res?.records || [];
      total.value = res?.data?.total || res?.total || 0;
    })
    .finally(() => {
      tableLoading.value = false;
    });
};
 
const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};
 
const handleDelete = () => {
  if (!selectedRows.value.length) {
    proxy.$modal.msgWarning("请选择数据");
    return;
  }
  const ids = selectedRows.value.map((item) => item.id);
  proxy.$modal
    .confirm("选中的内容将被删除,是否确认?")
    .then(() => delWeighbridgeLedger(ids))
    .then(() => {
      proxy.$modal.msgSuccess("删除成功");
      getList();
    })
    .catch(() => {});
};
 
const openImportDialog = () => {
  importUpload.open = true;
  importUploadRef.value?.clearFiles();
};
 
const submitImport = () => {
  if (!importUploadRef.value) return;
  importUpload.isUploading = true;
  importUploadRef.value.submit();
};
 
onMounted(() => {
  getList();
});
</script>
 
<style scoped lang="scss">
.table_list {
  margin-top: unset;
}
 
.actions {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}
</style>