Files
FT546MWS/ruoyi-ui/src/views/bas/traycode/index.vue
2026-02-24 10:17:20 +08:00

484 lines
14 KiB
Vue

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
<!-- <el-form-item label="格式ID" prop="formatId">-->
<!--&lt;!&ndash; <el-input-->
<!-- v-model="queryParams.formatId"-->
<!-- placeholder="请输入格式ID"-->
<!-- clearable-->
<!-- @keyup.enter.native="handleQuery"-->
<!-- />&ndash;&gt;-->
<!-- <el-select v-model="queryParams.formatId" placeholder="请选择格式ID">-->
<!-- <el-option-->
<!-- v-for="item in traycodeFormatList"-->
<!-- :key="item.id"-->
<!-- :label="item.remarks"-->
<!-- :value="item.id"-->
<!-- />-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="条码" prop="trayCode">
<el-input
v-model="queryParams.trayCode"
placeholder="请输入条码"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="是否可用" prop="spare2">
<el-select v-model="queryParams.spare2" placeholder="请选择">
<el-option
v-for="dict in dict.type.sys_yes_no"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['bas:traycode:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['bas:traycode:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['bas:traycode:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['bas:traycode:export']"
>导出</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="info"
plain
icon="el-icon-printer"
size="mini"
:disabled="multiple"
@click="handleBatchPrint"
v-hasPermi="['bas:traycode:print']"
>批量打印</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table ref="table" v-loading="loading" :data="traycodeList" @selection-change="handleSelectionChange" max-height="700">
<el-table-column type="selection" width="55" align="center" />
<!-- <el-table-column label="序号" align="center" prop="id" />-->
<!-- <el-table-column label="格式ID" align="left" prop="formatName" />-->
<el-table-column label="条码" align="center" prop="trayCode" />
<!-- <el-table-column label="Spare Field 1" align="center" prop="spare1" />-->
<el-table-column label="是否可用" align="center" prop="spare2" >
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_yes_no" :value="scope.row.spare2"/>
</template>
</el-table-column>
<!-- <el-table-column label="Spare Field 3" align="center" prop="spare3" />-->
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" >
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['bas:traycode:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['bas:traycode:remove']"
>删除</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-printer"
@click="printBarcode(scope.row)"
v-hasPermi="['bas:traycode:print']"
>打印</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改条码信息对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item label="格式ID" prop="formatId">
<el-select v-model="form.formatId" placeholder="请选择格式ID">
<el-option
v-for="item in traycodeFormatList"
:key="item.id"
:label="item.remarks"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="数量" prop="spare1" v-if="form.id == null">
<el-input v-model="form.spare1" placeholder="请输入数量" />
</el-form-item>
<el-form-item label="托盘编码" prop="trayCode" v-if="form.id != null" >
<el-input v-model="form.trayCode" placeholder="请输入托盘编码" disabled/>
</el-form-item>
<el-form-item label="是否可用" prop="spare2" v-if="form.id != null">
<el-select v-model="form.spare2" placeholder="请选择" >
<el-option
v-for="dict in dict.type.sys_yes_no"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确定</el-button>
<el-button @click="cancel">取消</el-button>
</div>
</el-dialog>
<!-- 打印模板 -->
<vue-easy-print v-show="true" ref="easyPrint2">
<div v-for="item in printData" :key="item.id" style="page-break-after:always" class="vue-easy-print">
<vue-barcode
:value=item.trayCode
format="CODE39"
width="2"
height="100"
display-value
/>
</div>
</vue-easy-print>
</div>
</template>
<script>
import { listTraycode, getTraycode, delTraycode, addTraycode, updateTraycode } from "@/api/bas/traycode"
import { listTraycodeFormat } from "@/api/bas/traycodeFormat"
import vueEasyPrint from 'vue-easy-print'
import VueQr from 'vue-qr'
import VueBarcode from 'vue-barcode'
export default {
name: "Traycode",
dicts:['sys_yes_no'],
components: {
vueEasyPrint,
VueQr,
VueBarcode
},
data() {
return {
// 设置标题
title: this.$t('traycode.title'),
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 条码信息表格数据
traycodeList: [],
traycodeFormatList: [],
printData:[],
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
formatId: null,
trayCode: null,
spare1: null,
spare2: null,
spare3: null
},
queryTrayCodeFormatParams: {
pageNum: 1,
pageSize: 99,
},
// Form parameters
form: {},
// Form validation
rules: {
formatId: [
{ required: true, message: "请输入格式ID", trigger: "blur" }
],
trayCode: [
{ required: true, message: "请输入托盘编码", trigger: "blur" }
]
}
}
},
created() {
this.getTrayCodeFormatList()
this.getList()
},
methods: {
/** 查询条码信息列表 */
getTrayCodeFormatList() {
this.loading = true
listTraycodeFormat(this.queryTrayCodeFormatParams).then(response => {
this.traycodeFormatList = response.rows
this.total = response.total
this.loading = false
})
},
/** 查询条码信息列表 */
getList() {
this.loading = true
listTraycode(this.queryParams).then(response => {
this.traycodeList = response.rows
this.total = response.total
this.loading = false
})
},
// 取消按钮
cancel() {
this.open = false
this.reset()
},
// 表单重置
reset() {
this.form = {
id: null,
formatId: null,
trayCode: null,
createTime: null,
updateTime: null,
spare1: null,
spare2: null,
spare3: null
}
this.resetForm("form")
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm")
this.handleQuery()
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = "新增托盘编码"
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const id = row.id || this.ids
getTraycode(id).then(response => {
this.form = response.data
this.open = true
this.title = "修改托盘编码"
})
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateTraycode(this.form).then(response => {
this.$modal.msgSuccess("修改成功")
this.open = false
this.getList()
})
} else {
addTraycode(this.form).then(response => {
this.$modal.msgSuccess("添加成功")
this.open = false
this.getList()
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids
this.$modal.confirm('是否确认删除选中的数据项?').then(function() {
return delTraycode(ids)
}).then(() => {
this.getList()
this.$modal.msgSuccess("删除成功")
}).catch(() => {})
},
/** 导出按钮操作 */
handleExport() {
this.download('bas/traycode/export', {
...this.queryParams
}, `traycode_${new Date().getTime()}.xlsx`)
},
/** 打印条码 */
printBarcode: function (row) {
const yesValItem = (this.dict && this.dict.type && this.dict.type.sys_yes_no) ? (this.dict.type.sys_yes_no.find(i => i.label === '是') || this.dict.type.sys_yes_no.find(i => i.value === 'Y' || i.value === '1')) : null
const yesVal = yesValItem ? yesValItem.value : 'Y'
if (row.spare2 !== yesVal) {
this.$modal.msgError("该托盘不可打印:仅“是”可用")
return;
}
this.printData = [row]
this.$nextTick(() => {
setTimeout(() => {
this.$refs.easyPrint2.print()
const noValItem = (this.dict && this.dict.type && this.dict.type.sys_yes_no) ? (this.dict.type.sys_yes_no.find(i => i.label === '否') || this.dict.type.sys_yes_no.find(i => i.value === 'N' || i.value === '0')) : null
const noVal = noValItem ? noValItem.value : 'N'
const data = Object.assign({}, row, { spare2: noVal })
updateTraycode(data).then(() => {
this.$modal.msgSuccess("打印完成,已标记为不可用")
this.getList()
}).catch(() => {})
}, 100)
})
},
/** 批量打印按钮操作 */
handleBatchPrint() {
const selection = this.$refs.table.selection;
if (selection.length === 0) {
this.$modal.msgError("请选择要打印的数据项");
return;
}
const yesValItem = (this.dict && this.dict.type && this.dict.type.sys_yes_no) ? (this.dict.type.sys_yes_no.find(i => i.label === '是') || this.dict.type.sys_yes_no.find(i => i.value === 'Y' || i.value === '1')) : null
const yesVal = yesValItem ? yesValItem.value : 'Y'
const invalid = selection.filter(item => item.spare2 !== yesVal)
if (invalid.length > 0) {
this.$modal.msgError("存在不可打印项(非“是”),请重新选择")
return;
}
this.printData = selection;
this.$nextTick(() => {
setTimeout(() => {
this.$refs.easyPrint2.print()
const noValItem = (this.dict && this.dict.type && this.dict.type.sys_yes_no) ? (this.dict.type.sys_yes_no.find(i => i.label === '否') || this.dict.type.sys_yes_no.find(i => i.value === 'N' || i.value === '0')) : null
const noVal = noValItem ? noValItem.value : 'N'
const updates = selection.map(item => {
const data = Object.assign({}, item, { spare2: noVal })
return updateTraycode(data)
})
Promise.all(updates).then(() => {
this.$modal.msgSuccess("批量打印完成,已标记为不可用")
this.getList()
}).catch(() => {})
}, 100)
});
},
}
}
</script>
<style scoped>
/* 统一表单控件宽度 */
.el-select,
.el-input {
width: 100%;
}
/* 打印样式 */
.vue-easy-print {
text-align: center;
}
.num {
display: block;
text-align: center;
font-size: 16px;
margin-top: 15px;
font-family: Arial, sans-serif;
}
.vue-qr {
display: block;
margin: 20px auto;
max-width: 100%;
}
@media print {
@page {
size: 80mm 50mm;
margin: 0;
}
body {
margin: 0;
}
.vue-easy-print {
padding: 20px;
}
.num {
font-size: 14px;
margin-top: 10px;
}
.vue-qr {
margin: 10px auto;
}
}
</style>