Преглед изворни кода

修改预览,增加打印全部

liuyanpeng пре 3 година
родитељ
комит
df7578afb4
2 измењених фајлова са 113 додато и 77 уклоњено
  1. 3 1
      src/customer/printTemp/index.vue
  2. 110 76
      src/print/PrintCard.vue

+ 3 - 1
src/customer/printTemp/index.vue

@@ -25,7 +25,9 @@ import CreateJPEG from '../../common/X6.js';
 const router =  useRouter();
 const store = useStore();
 const step = computed(()=>store.state.downloadStore.step);
-
+onMounted(() => {
+  store.commit('changeStep',0);
+});
 
 </script>
 <style scoped></style>

+ 110 - 76
src/print/PrintCard.vue

@@ -81,7 +81,7 @@
             style="margin-right: 16px"
             @click="printPreview"
           >
-            打印预览
+            效果预览
           </a-button>
           <a-button
             type="dashed"
@@ -90,6 +90,9 @@
           >
             打印
           </a-button>
+          <a-button type="dashed" style="margin-right: 16px" @click="printAll">
+            打印全部
+          </a-button>
           <a-button type="dashed" @click="downloadImageZip">
             下载全部
           </a-button>
@@ -120,7 +123,11 @@
           title="包装信息"
           ok-text="确认"
           cancel-text="取消"
-          @ok="printCard"
+          @ok="
+            all === false
+              ? printCard(select.selectedRows)
+              : printCard(select.allData)
+          "
         >
           <label>包装批号:</label>
           <a-input
@@ -164,46 +171,41 @@
           title="打印预览"
           ok-text="确认"
           cancel-text="取消"
+          mask-closable="false"
+          keyboard="false"
+          closable="false"
           :body-style="bodyStyle"
           @ok="imageVisible = false"
         >
-          <a-image
-            :preview="{ visible: false }"
-            :width="200"
-            class="image"
-            :src="imageUrls[0]"
-            @click="visible = true"
-          />
-          <div style="display: none">
-            <a-image-preview-group
-              :preview="{ visible, onVisibleChange: (vis) => (visible = vis) }"
-            >
-              <a-image v-for="item in imageUrls" :key="item" :src="item" />
-            </a-image-preview-group>
-          </div>
+          <a-image :src="imageUrls[0]" />
           <template #footer />
         </a-modal>
         <Loading v-if="globalLoading" />
+        <a-modal
+          v-model:visible="modelVisible"
+          title="正在打印中"
+          mask-closable="false"
+          keyboard="false"
+          closable="false"
+        >
+          <p>正在打印中,请稍等....</p>
+          <template #footer />
+        </a-modal>
       </div>
     </div>
     <div ref="hua" style="float: left; z-index: -999" />
-    <a-modal v-model:visible="modelVisible" title="正在打印中">
-      <p>正在打印中,请稍等....</p>
-      <template #footer />
-    </a-modal>
   </div>
 </template>
 
 <script setup>
-import AuthImage from '../widget/AuthImage.vue';
-import CommonTable from './CommonTable.vue';
 import Common from '../common/Common';
-import { message } from 'ant-design-vue';
-import { ref, reactive, onMounted, watch } from 'vue';
 import CreateJPEG from '../common/X6';
+import { message } from 'ant-design-vue';
 import { base64toFile } from '../common/X6';
+import CommonTable from './CommonTable.vue';
 import { SqlApi, Notify } from 'pc-component-v3';
 import { getImageSrc } from '../common/image-src';
+import { ref, reactive, onMounted, watch } from 'vue';
 import {
   columns,
   dateConvert,
@@ -220,12 +222,13 @@ const printing = ref(true);
 const total = ref(0);
 const isSelect = ref(true);
 const isLoading = ref(false);
-const select = reactive({ selectedRows: [] });
+const select = reactive({ selectedRows: [], allData: [] });
 const dataSource = ref([]);
 const printVisible = ref(false);
 const imageVisible = ref(false);
 const visible = ref(false);
 const globalLoading = ref(false);
+const all = ref(false);
 const bodyStyle = {
   display: 'flex',
   justifyContent: 'center',
@@ -278,6 +281,7 @@ const packageName = ref('');
 const lastPackageName = ref('');
 const newPackageName = ref('');
 const hua = ref(null);
+const clientId = ref('');
 let getBase64;
 // 获取分页
 const getPageParams = (start, length) => {
@@ -294,7 +298,8 @@ const searchPrintInfo = () => {
       status.value.indexOf('-'),
     );
   }
-  let params = { ...queryParams, ...pager };
+  clientId.value = JSON.parse(localStorage.getItem('#LoginInfo')).loginClientId;
+  let params = { ...queryParams, ...pager, clientId: clientId.value };
   if (queryParams.batchNo !== '') {
     SqlApi.execute('20230613_140456', params).then(
       successData => {
@@ -302,6 +307,7 @@ const searchPrintInfo = () => {
         if (errorCode == 0) {
           total.value = successData.total;
           dataSource.value = lines;
+          select.allData = lines;
           isLoading.value = false;
         } else {
           Notify.error('查询异常', errorMessage, true);
@@ -314,7 +320,7 @@ const searchPrintInfo = () => {
       },
     );
   } else {
-    message.error('请选择导入批次');
+    message.warning('请选择导入批次');
     status.value = '';
     dataSource.value = [];
     queryParams.clientName = '';
@@ -331,7 +337,7 @@ const selectColumn = rows => {
 };
 // 展开打印框
 const showPrintInfo = () => {
-  if (printTemplate.value !== '') {
+  if (printTemplate.value !== '' && queryParams.batchNo !== '') {
     printVisible.value = true;
     const nameArr = [];
     const obj = JSON.parse(JSON.stringify(queryParams));
@@ -343,7 +349,7 @@ const showPrintInfo = () => {
     newPackageName.value = nameArr.join('-');
     packageBatchNo.value = dateConvert(new Date());
   } else {
-    message.error('请选择打印模板');
+    message.warning('请检查是否已选择导入批次和模板!');
   }
 };
 // 同上一次包装信息
@@ -377,57 +383,80 @@ const getTemplateInfo = async () => {
 
 // 打印预览
 const printPreview = async () => {
-  imageVisible.value = true;
-  printing.value = false;
-  imageUrls.length = 0;
-  let tempStr = JSON.stringify(templateData.value);
-  const rows = JSON.parse(JSON.stringify(select.selectedRows));
-  for (let key in rows) {
-    let base64 = await getBase64(rows[key], tempStr);
+  if (printTemplate.value !== '' && queryParams.batchNo !== '') {
+    imageVisible.value = true;
+    printing.value = false;
+    imageUrls.length = 0;
+    let tempStr = JSON.stringify(templateData.value);
+    const rows = JSON.parse(JSON.stringify(dataSource.value[0]));
+    let base64 = await getBase64(rows, tempStr);
     imageUrls.push(base64);
+    printing.value = true;
+  } else {
+    message.warning('请检查是否已选择导入批次和模板!');
   }
-  printing.value = true;
 };
 
 // 确认打印
-const printCard = async () => {
-  printVisible.value = false;
-  modelVisible.value = true;
-  printing.value = false;
-  const formData = new FormData();
-  formData.append('customerPrintTemplateId', templateId.value);
-  formData.append('packageBatchNo', packageBatchNo.value);
-  formData.append('packageName', packageName.value);
+const printCard = async data => {
+  if (data.length !== 0) {
+    printVisible.value = false;
+    modelVisible.value = true;
+    globalLoading.value = true;
+    printing.value = false;
+    const formData = new FormData();
+    formData.append('customerPrintTemplateId', templateId.value);
+    formData.append('packageBatchNo', packageBatchNo.value);
+    formData.append('packageName', packageName.value);
 
-  let tempStr = JSON.stringify(templateData.value);
-  const rows = JSON.parse(JSON.stringify(select.selectedRows));
-  for (let key in rows) {
-    let base64 = await getBase64(rows[key], tempStr, rows[key].assetNo);
-    let file = base64toFile(base64, rows[key].id);
-    formData.append('file', file);
-  }
+    let tempStr = JSON.stringify(templateData.value);
+    const rows = JSON.parse(JSON.stringify(data));
+    for (let key in rows) {
+      let base64 = await getBase64(rows[key], tempStr, rows[key].assetNo);
+      let file = base64toFile(base64, rows[key].id);
+      formData.append('file', file);
+    }
 
-  multipleImageUpload(formData).then(
-    successData => {
-      if (successData.success === true) {
-        message.success('资产生产图片成功');
-      } else {
-        message.error('资产生产图片失败');
-      }
-      modelVisible.value = false;
-      printing.value = true;
-      searchPrintInfo();
-      clearSelect();
-    },
-    errorData => {
-      Common.processException(errorData);
-      modelVisible.value = false;
-      printing.value = true;
-      clearSelect();
-    },
-  );
+    multipleImageUpload(formData).then(
+      successData => {
+        if (successData.success === true) {
+          message.success('资产生产图片成功');
+        } else {
+          message.error('资产生产图片失败');
+        }
+        modelVisible.value = false;
+        globalLoading.value = false;
+        printing.value = true;
+        all.value = false;
+        searchPrintInfo();
+        clearSelect();
+      },
+      errorData => {
+        Common.processException(errorData);
+        modelVisible.value = false;
+        globalLoading.value = false;
+
+        printing.value = true;
+        all.value = false;
+        clearSelect();
+      },
+    );
+  } else {
+    all.value = false;
+    printVisible.value = false;
+    message.warning('请选择打印数据');
+  }
+};
+// 全部生成图片
+const printAll = () => {
+  all.value = true;
+  pager.start = 0;
+  pager.length = 10000;
+  searchPrintInfo();
+  showPrintInfo();
 };
 
+//下载全部图片(zip)
 const downloadImageZip = () => {
   if (queryParams.batchNo === '') {
     message.warning('请选择导入批次');
@@ -460,11 +489,14 @@ watch(
 onMounted(() => {
   init();
   getBase64 = CreateJPEG(hua.value);
+  clientId.value = JSON.parse(localStorage.getItem('#LoginInfo')).loginClientId;
 });
 
 // 封装通用sqlApi请求函数
 const commonSqlApi = (url, data) => {
-  SqlApi.execute(url).then(
+  clientId.value = JSON.parse(localStorage.getItem('#LoginInfo')).loginClientId;
+  let params = { clientId: clientId.value };
+  SqlApi.execute(url, params).then(
     successData => {
       if (successData.errorCode == 0) {
         if (successData.lines !== null) {
@@ -485,6 +517,8 @@ const commonSqlApi = (url, data) => {
 
 // 初始化数据
 const init = () => {
+  clientId.value = JSON.parse(localStorage.getItem('#LoginInfo')).loginClientId;
+  let params = { clientId: clientId.value };
   getTemplate().then(res => {
     allTemplate.value = res.datas;
   });
@@ -493,7 +527,7 @@ const init = () => {
   commonSqlApi('20230613_194108', organizationNames); // 查询部门
   commonSqlApi('20230613_194557', costCenterNames); // 查询成本中心
   // 查询批次号
-  SqlApi.execute('20230613_134214').then(
+  SqlApi.execute('20230613_134214', params).then(
     successData => {
       if (successData.errorCode == 0) {
         if (successData.lines !== null) {
@@ -510,14 +544,14 @@ const init = () => {
     },
   );
   // 查询模板
-  SqlApi.execute('20230613_135541').then(
+  SqlApi.execute('20230613_135541', params).then(
     successData => {
       if (successData.errorCode == 0) {
         if (successData.label !== null) {
           templateNames.value = successData.lines;
         }
       } else {
-        Notify.error('获取包装信息异常', successData.errorMessage, true);
+        Notify.error('查询模板信息异常', successData.errorMessage, true);
       }
     },
     errorData => {
@@ -525,7 +559,7 @@ const init = () => {
     },
   );
   // 获取上一次的包装信息
-  SqlApi.execute('20230613_194855').then(
+  SqlApi.execute('20230613_194855', params).then(
     successData => {
       if (successData.errorCode == 0) {
         const { packageName, packageBatchNo } = successData.lines;