文件

453 行
20 KiB
HTML
可执行文件

<!--[1.6.48]-->
<style>
th > .cell, td > .cell {
text-align: center;
white-space: nowrap;
}
#expressOrder .cell {
font-size: 12px;
}
.el-table__row > td:last-child > .cell {
white-space: nowrap;
}
.el-radio {
margin-bottom: 10px;
}
</style>
<div id="expressOrder" v-cloak style="padding-top: 20px">
<div>
<el-date-picker
width="400"
size="small"
v-model="time"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss"
range-separator="至"
start-placeholder="下单开始时间"
end-placeholder="结束时间">
</el-date-picker>
<el-input placeholder="电子面单号"
type="text"
size="small"
v-model="waybill_code"
clearable
@keydown.enter.exact.native.prevent="search" style="width:200px">
</el-input>
<el-select size="small"
v-model="express_type"
clearable
placeholder="面单状态"
style="padding-left:20px;width:200px">
<el-option label="正常" value="1"></el-option>
<el-option label="取消" value="2"></el-option>
</el-select>
<el-button type="primary" @click="search" size="small" style="margin-left:20px;">搜索</el-button>
<el-button size="small" @click="adjustPrinter">
调整打印机
<el-tooltip class="item" effect="dark" content="打印位置偏差可点击此处打开设置" placement="top-start">
<i class="el-icon-question"></i>
</el-tooltip>
</el-button>
</div>
<el-form>
<el-form-item label="打印设置">
<el-radio-group v-model="printer_type" @change="selectPinterType">
<el-radio :label="1">使用默认打印机打印</el-radio>
<el-radio :label="2">弹出打印机选择打印</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div style="border: 1px solid #e6e6e6;max-width: calc(100vw - 208px);margin-top: 20px;">
<el-table border :data="orderList" style="width: calc(100vw - 208px);border: none;box-sizing: border-box;">
<el-table-column type="index" label="序号" width="60"></el-table-column>
<el-table-column prop="waybill_code" label="电子面单号" min-width="140" show-overflow-tooltip></el-table-column>
<el-table-column prop="status" label="状态" min-width="60" show-overflow-tooltip>
<template slot-scope="scope">
<span v-if="scope.row.status==1" style="color: #0BB20C">正常</span>
<span v-else style="color: red">已取消</span>
</template>
</el-table-column>
<el-table-column prop="add_time" label="下单时间" min-width="140" show-overflow-tooltip></el-table-column>
<el-table-column prop="cp_code" label="公司编码" min-width="70" show-overflow-tooltip></el-table-column>
<el-table-column prop="branch_code" label="网点code" min-width="80" show-overflow-tooltip></el-table-column>
<el-table-column prop="branch_name" label="网点名称" min-width="80" show-overflow-tooltip></el-table-column>
<el-table-column label="发货人信息">
<el-table-column prop="sender_name" label="姓名" min-width="60" show-overflow-tooltip></el-table-column>
<el-table-column prop="sender_mobile" label="手机" min-width="100"
show-overflow-tooltip></el-table-column>
<el-table-column prop="sender_phone" label="电话" min-width="100" show-overflow-tooltip></el-table-column>
<el-table-column prop="sender_address" label="地址" min-width="100"
show-overflow-tooltip></el-table-column>
</el-table-column>
<el-table-column label="商品">
<el-table-column prop="goods_name" label="名称" min-width="60" show-overflow-tooltip></el-table-column>
<el-table-column prop="goods_count" label="数量" min-width="50" show-overflow-tooltip></el-table-column>
<el-table-column prop="goods_weight" label="重量/g" min-width="60"
show-overflow-tooltip></el-table-column>
<el-table-column prop="goods_volume" label="体积/ml" min-width="70"
show-overflow-tooltip></el-table-column>
</el-table-column>
<el-table-column label="收件人信息">
<el-table-column prop="recipient_name" label="姓名" min-width="60"
show-overflow-tooltip></el-table-column>
<el-table-column prop="recipient_mobile" label="手机" min-width="100"
show-overflow-tooltip></el-table-column>
<el-table-column prop="recipient_phone" label="电话" min-width="100"
show-overflow-tooltip></el-table-column>
<el-table-column prop="recipient_address" label="地址" min-width="100"
show-overflow-tooltip></el-table-column>
</el-table-column>
<el-table-column fixed="right" label="操作" width="140px" style="border-right: none;">
<template slot-scope="scope">
<template v-if="scope.row.status==1">
<if condition="$authArr['printFaceSheet']">
<el-button @click="printFaceSheet(scope.row.id)" type="text"
size="small">打印面单
</el-button>
</if>
<if condition="$authArr['cancelExpress']">
<el-button @click="cancelExpress(scope.row.id)" type="text"
size="small">取消面单
</el-button>
</if>
</template>
<template v-else>
<el-button @click="delExpress(scope.row.id)" type="text"
size="small">删除记录
</el-button>
</template>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 15, 20, 25, 30, 35, 40, 45, 50]"
:page-size="100"
layout="total, sizes, prev, pager, next, jumper"
:total="currentLen">
</el-pagination>
</div>
<el-dialog title="选择打印机" :modal-append-to-body="false" :visible.sync="showSelectPrinter" :width="'600px'" :close-on-click-modal="false">
<div class="menu-index-code-big-box">
<el-radio-group v-model="choosePrinter" size="small">
<el-radio v-for="item in printerList" :key="item.name" :label="item.name" border>{{item.name}}
</el-radio>
</el-radio-group>
</div>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="showSelectPrinter = false">取消打印</el-button>
<el-button size="small" type="primary" @click="surePrinter">确认打印</el-button>
</span>
</el-dialog>
</div>
<script type="text/javascript">
var expressOrder = new Vue({
el: '#expressOrder',
data: {
orderList: [],
currentPage: 1,
currentLimit: 10,
currentLen: 0,
waybill_code: '',
express_type: '',
time: '',
websocketConnect: false,
ws: null,
printerList: [],//打印机列表
defaultPrinter: '',//默认打印机
printer_type: 2,//1使用默认打印机打印 2弹出打印机选择打印
printerData: {},//打印数据
showSelectPrinter: false,//是否显示选择打印机弹窗
choosePrinter: '',//选择的打印机
},
methods: {
//切换打印机方式
selectPinterType: function () {
localStorage.pinterType = this.printer_type;
},
//取消电子面单
cancelExpress: function (id) {
var that = this;
this.$confirm('您确认要取消该电子面单吗,取消后将不能撤回,请谨慎操作!', '提示', {
confirmButtonText: '确人取消',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
that.$loading({
lock: true,
text: '电子面单取消中,请等待',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.7)'
});
sendRequest({
url: "{:U('cancelExpress')}",
data: {
id: id,
},
success: function (res) {
that.$loading().close();
if (res.status == 1) {
that.$message({message: res.msg, type: 'success'});
that.getData();
} else {
that.$message({message: res.msg, type: 'error'});
}
}
})
});
},
//删除电子面单记录
delExpress: function (id) {
var that = this;
this.$confirm('您确认要删除该电子面单记录吗,删除后将不能找回,请谨慎操作!', '提示', {
confirmButtonText: '确人删除',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
that.$loading({
lock: true,
text: '记录删除中,请等待',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.7)'
});
sendRequest({
url: "{:U('delExpress')}",
data: {
id: id,
},
success: function (res) {
that.$loading().close();
if (res.status == 1) {
that.$message({message: res.msg, type: 'success'});
that.getData();
} else {
that.$message({message: res.msg, type: 'error'});
}
}
})
});
},
//获取打印电子面单数据
printFaceSheet: function (id) {
console.log(id);
if (!this.printerList.length) {
this.$message({message: '本机暂未配置打印机,请先配置打印机后刷新页面重试'});
return;
}
var that = this;
sendRequest({
url: "{:U('printFaceSheet')}",
data: {
id: id,
},
success: function (res) {
if (res.status == 1) {
if (that.websocketConnect) {
that.printerData = res.data;
if (that.printer_type == 1) {
that.$message({message: '面单获取成功,将开始使用默认打印机打印', type: 'success'});
//使用默认打印机
that.print(that.defaultPrinter);
} else {
that.$message({message: '面单获取成功,请选择打印机进行打印', type: 'success'});
that.showSelectPrinter = true;
}
}
} else {
that.$message({message: res.msg, type: 'error'});
}
}
})
},
//选择打印机打印
surePrinter: function () {
if (!this.choosePrinter) {
this.$message({message: '请选择打印机'});
return;
}
this.showSelectPrinter = false;
this.print(this.choosePrinter);
},
//切换每页数量
handleSizeChange(val) {
this.currentLimit = val;
this.currentPage = 1;
this.getData();
},
//切换页数
handleCurrentChange(val) {
this.currentPage = val;
this.getData();
},
//搜索
search: function () {
this.currentPage = 1;
this.getData();
},
//获取数据
getData: function () {
var that = this;
sendRequest({
url: "{:U('getExpressList')}",
data: {
time: this.time,
page: this.currentPage,
limit: this.currentLimit,
waybill_code: this.waybill_code,
express_type: this.express_type,
},
success: function (res) {
if (res.status == 1) {
that.orderList = [];
that.orderList = res.data;
that.currentLen = res.count;
} else {
that.$message({message: res.msg, type: 'error'});
}
}
})
},
//连接websocket
connectWebsocket: function () {
var that = this;
that.ws = new WebSocket('ws://localhost:13528');
//如果是https的话,端口是13529
//socket = new WebSocket('wss://localhost:13529');
// 打开Socket
that.ws.onopen = function (event) {
// 监听消息
that.websocketConnect = true;
that.ws.onmessage = function (event) {
console.log('Client received a message', event);
var response = JSON.parse(event.data);
if (response.cmd == 'getPrinters') {
that.getPrintersHandler(response);//处理打印机列表
} else if (response.cmd == 'printerConfig') {
that.printConfigHandler(response);//配置打印机
}
};
// 监听Socket的关闭
that.ws.onclose = function (event) {
console.log('Client notified socket has closed', event);
};
/**
* 请求打印机列表demo
* */
var request = that.getRequestObject("getPrinters");
that.ws.send(JSON.stringify(request));
};
that.ws.onerror = function () {
console.log('Client connected error');
};
},
//处理打印机列表
getPrintersHandler: function (data) {
console.log('打印机列表:', data);
if (!data.printers || !data.printers.length) {
this.$message({message: '本机没有配置打印机,请先配置打印机', type: 'warning'});
} else {
this.printerList = data.printers;
}
if (data.defaultPrinter) {
//默认打印机
this.defaultPrinter = data.defaultPrinter;
}
},
//发起配置打印机请求 弹窗模式配置打印机
adjustPrinter: function () {
var request = this.getRequestObject("printerConfig");
this.ws.send(JSON.stringify(request));
},
//配置打印机
printConfigHandler: function (data) {
console.log('打印机配置:', data);
},
//构造request对象
getRequestObject: function (cmd) {
var request = new Object();
request.requestID = getUUID(8, 16);
request.version = "1.0";
request.cmd = cmd;
return request;
},
//打印电子面单 printer 指定要使用那台打印机
print: function (printer) {
var request = this.getRequestObject("print");
request.task = {
taskID: getUUID(8, 10),
preview: false,
previewType: 'pdf',
printer: printer,
documents: [{
documentID: this.printerData.waybill_code,
contents: [JSON.parse(this.printerData.print_data)],
}],
};
request = JSON.stringify(request);
this.ws.send(request);
},
},
created: function () {
this.getData();
this.connectWebsocket();
if (localStorage.pinterType) {
this.printer_type = parseInt(localStorage.pinterType);
}
}
});
/**
* ajax post发送请求
*/
function sendRequest(options) {
$.ajax({
url: options.url,
data: options.data,
type: 'post',
success: function (res) {
options.success(res);
},
error: function () {
var res = {
status: 0,
msg: '请求发生错误',
};
options.success(res);
}
})
}
/***
*
* 获取请求的UUID,指定长度和进制,如
* getUUID(8, 2) //"01001010" 8 character (base=2)
* getUUID(8, 10) // "47473046" 8 character ID (base=10)
* getUUID(8, 16) // "098F4D35"。 8 character ID (base=16)
*
*/
function getUUID(len, radix) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = [], i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
</script>