|
@@ -0,0 +1,267 @@
|
|
|
+import { disAutoConnect, hiprint, defaultElementTypeProvider } from 'vue-plugin-hiprint'
|
|
|
+disAutoConnect();
|
|
|
+import panel from '@/utils/panel'
|
|
|
+import { getDeliverDetail } from "@/api/supply/deliver";
|
|
|
+import { addPrints } from "@/api/supply/pickup";
|
|
|
+import { getCompanyList } from "@/api/user";
|
|
|
+
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ company: '', // 公司名称
|
|
|
+ clonelData: [], // 克隆数据
|
|
|
+ outputData: [], // 打印数据
|
|
|
+ curPaper: {
|
|
|
+ type: 'A5',
|
|
|
+ width: 500,
|
|
|
+ height: 147.6
|
|
|
+ },
|
|
|
+ paperTypes: {
|
|
|
+ 'A3': {
|
|
|
+ width: 420,
|
|
|
+ height: 296.6
|
|
|
+ },
|
|
|
+ 'A4': {
|
|
|
+ width: 210,
|
|
|
+ height: 296.6
|
|
|
+ },
|
|
|
+ 'A5': {
|
|
|
+ width: 210,
|
|
|
+ height: 147.6
|
|
|
+ },
|
|
|
+ 'B3': {
|
|
|
+ width: 500,
|
|
|
+ height: 352.6
|
|
|
+ },
|
|
|
+ 'B4': {
|
|
|
+ width: 250,
|
|
|
+ height: 352.6
|
|
|
+ },
|
|
|
+ 'B5': {
|
|
|
+ width: 250,
|
|
|
+ height: 175.6
|
|
|
+ }
|
|
|
+ },
|
|
|
+ scaleValue: 1,
|
|
|
+ scaleMax: 5,
|
|
|
+ scaleMin: 0.5,
|
|
|
+ loading: false,
|
|
|
+ hiprintTemplate: '',
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ curPaperType() {
|
|
|
+ let type = 'other'
|
|
|
+ let types = this.paperTypes
|
|
|
+ for (const key in types) {
|
|
|
+ let item = types[key]
|
|
|
+ let { width, height } = this.curPaper
|
|
|
+ if (item.width === width && item.height === height) {
|
|
|
+ type = key
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return type
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getCompanyLists()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 初始化打印模板
|
|
|
+ initPrint() {
|
|
|
+ hiprint.init({
|
|
|
+ providers: [new defaultElementTypeProvider()]
|
|
|
+ });
|
|
|
+ // 替换配置
|
|
|
+ hiprint.setConfig({
|
|
|
+ movingDistance: 2.5,
|
|
|
+ text: {
|
|
|
+ supportOptions: [
|
|
|
+ {
|
|
|
+ name: 'styler',
|
|
|
+ hidden: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'formatter',
|
|
|
+ hidden: true
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // eslint-disable-next-line no-undef
|
|
|
+ hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
|
|
|
+ this.hiprintTemplate = new hiprint.PrintTemplate({
|
|
|
+ template: panel,
|
|
|
+ settingContainer: '#PrintElementOptionSetting',
|
|
|
+ paginationContainer: '.hiprint-printPagination'
|
|
|
+ });
|
|
|
+ this.hiprintTemplate.design('#hiprint-printTemplate');
|
|
|
+ // 获取当前放大比例, 当zoom时传true 才会有
|
|
|
+ // this.scaleValue = hiprintTemplate.editingPanel.scale || 1;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 获取需要打印数据详情
|
|
|
+ * @param {Array} ids
|
|
|
+ */
|
|
|
+ getDateil(ids) {
|
|
|
+ console.log(ids);
|
|
|
+ // 清空之前打印的数据
|
|
|
+ this.outputData = [];
|
|
|
+ // 筛选id
|
|
|
+ let formatting = [];
|
|
|
+ // 获取数据id
|
|
|
+ for (let i = ids.length; i > 0; i--) {
|
|
|
+ formatting.push(ids[i - 1].id);
|
|
|
+ }
|
|
|
+ // id 去重
|
|
|
+ formatting = [...new Set(formatting)];
|
|
|
+
|
|
|
+ for (let i = formatting.length; i > 0; i--) {
|
|
|
+ // 延迟请求
|
|
|
+ setTimeout(async () => {
|
|
|
+ try {
|
|
|
+ const { data } = await getDeliverDetail({
|
|
|
+ id: formatting[i - 1],
|
|
|
+ });
|
|
|
+ //避免数据发生改变
|
|
|
+ this.clonelData.push(JSON.parse(JSON.stringify(data)))
|
|
|
+ // 需要计算长度和数据裁切
|
|
|
+ let invoicePickBeans = data.invoicePickBeans;
|
|
|
+ // 获取length向上取整
|
|
|
+ let len = Math.ceil(invoicePickBeans.length / 5);
|
|
|
+ for (let index = 0; index < len; index++) {
|
|
|
+ const table = [];
|
|
|
+ // length <= 0 则不执行打印
|
|
|
+ if (invoicePickBeans.length) {
|
|
|
+ const newInvoicePickBeans = invoicePickBeans.splice(0, 5);
|
|
|
+ for (let e = newInvoicePickBeans.length; e > 0; e--) {
|
|
|
+ const tempData = newInvoicePickBeans[e - 1];
|
|
|
+ //添加表格数据
|
|
|
+ table.push({
|
|
|
+ salesId: tempData.salesOrderId,
|
|
|
+ invoiceId: tempData.invoiceId,
|
|
|
+ id: tempData.id,
|
|
|
+ createTime: tempData.id
|
|
|
+ ? this.dateToDayFilter(tempData.createTime)
|
|
|
+ : '',
|
|
|
+ enginOrderType:
|
|
|
+ tempData.orderType == "HOME" || tempData.orderType == "TRADE"
|
|
|
+ ? tempData.enginOrderNo
|
|
|
+ : tempData.mainOrderId,
|
|
|
+ materialName: tempData.materialName,
|
|
|
+ specification: tempData.specification,
|
|
|
+ refundableQty: tempData.refundableQty,
|
|
|
+ pjxh1Text: tempData.pjxh1Text,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加print输出数据
|
|
|
+ this.outputData.push({
|
|
|
+ pageNumber: `${len}-${index + 1}`,
|
|
|
+ type: data.type,
|
|
|
+ tiTui: data.type === 2 ? `退货人` : `提货人`,
|
|
|
+ takerPhone: data.takerPhone || '',
|
|
|
+ headerRemark: data.remark,
|
|
|
+ total_num: data.total_num,
|
|
|
+ company:
|
|
|
+ data.type === 2 ? `${this.company}销售退货单` : `${this.company}销售发货单`,
|
|
|
+ pickOrderWater: data.pickOrderWater,
|
|
|
+ customerNumber: data.customerNumber,
|
|
|
+ takerDa: '',
|
|
|
+ nowDate: this.nowDate(),
|
|
|
+ takerName:
|
|
|
+ data.type === 2
|
|
|
+ ? `退货人:${data.takerName || ''}`
|
|
|
+ : `提货人:${data.takerName || ''}`,
|
|
|
+ customerName: data.customerName || '',
|
|
|
+ correspondName: data.correspondName,
|
|
|
+ correspondNames: '',
|
|
|
+ pickCar: data.pickCar || '',
|
|
|
+ createBy: JSON.parse(localStorage.getItem("supply_user")).nickName,
|
|
|
+ table,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取打印数据失败')
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取公司名称
|
|
|
+ async getCompanyLists() {
|
|
|
+ try {
|
|
|
+ const { data } = await getCompanyList();
|
|
|
+ this.company = data ? data[0].companyName : '';
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取公司名称失败')
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 获取当前时间
|
|
|
+ nowDate() {
|
|
|
+ var date = new Date();
|
|
|
+ var seperator1 = "-";
|
|
|
+ var year = date.getFullYear();
|
|
|
+ var month = date.getMonth() + 1;
|
|
|
+ var strDate = date.getDate();
|
|
|
+ if (month >= 1 && month <= 9) {
|
|
|
+ month = "0" + month;
|
|
|
+ }
|
|
|
+ if (strDate >= 0 && strDate <= 9) {
|
|
|
+ strDate = "0" + strDate;
|
|
|
+ }
|
|
|
+ var currentdate = year + seperator1 + month + seperator1 + strDate;
|
|
|
+ console.log(currentdate);
|
|
|
+ return currentdate;
|
|
|
+ },
|
|
|
+ // 格式化时间
|
|
|
+ dateToDayFilter(date) {
|
|
|
+ if (!date) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ return date.slice(0, 10);
|
|
|
+ },
|
|
|
+ // 添加次数
|
|
|
+ async addPrint() {
|
|
|
+
|
|
|
+ let ids = []
|
|
|
+ for (let i = this.clonelData.length; i > 0; i--) {
|
|
|
+ const tempData = this.clonelData[i - 1].invoicePickBeans;
|
|
|
+ if (tempData.length) {
|
|
|
+ for (let e = tempData.length; e > 0; e--) {
|
|
|
+ const newTempData = tempData[e - 1];
|
|
|
+ ids.push(newTempData.id)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return this.clonelData[i - 1].invoiceOrderId || this.clonelData[i - 1].id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await addPrints({ ids: ids.join(',') })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('添加打印次数失败');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 设置纸张大小
|
|
|
+ * @param type [A3, A4, A5, B3, B4, B5, other]
|
|
|
+ * @param value {width,height} mm
|
|
|
+ */
|
|
|
+ setPaper(type, value) {
|
|
|
+ try {
|
|
|
+ if (Object.keys(this.paperTypes).includes(type)) {
|
|
|
+ this.curPaper = { type: type, width: value.width, height: value.height }
|
|
|
+ this.hiprintTemplate.setPaper(value.width, value.height)
|
|
|
+ } else {
|
|
|
+ this.curPaper = { type: 'other', width: value.width, height: value.height }
|
|
|
+ this.hiprintTemplate.setPaper(value.width, value.height)
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(`操作失败: ${error}`)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|