Przeglądaj źródła

修改分页和上传的功能

695593266@qq.com 1 rok temu
rodzic
commit
b40d9ae7d6

BIN
public/importTemplate/质检项导入模板.xlsx


+ 0 - 0
public/static/model.xlsx → public/static/质检项导入模板.xlsx


+ 13 - 8
src/components/upload/import-dialog.vue

@@ -44,11 +44,15 @@
 <script>
   import { importBatch } from '@/api/system/file/index.js';
   import { importFile, importTemplate } from '@/api/inspectionProject';
+  import { download1 } from '@/utils/file';
 
   export default {
     props: {
       // eslint-disable-next-line vue/require-prop-type-constructor
-      defModule: ''
+      defModule: '',
+      fileUrl: '',
+      fileName: '',
+      apiUrl: ''
     },
     //注册组件
     data() {
@@ -114,13 +118,14 @@
           });
       },
       downLoadTemplate() {
-        var a = document.createElement('a'); //创建一个<a></a>标签
-        a.href = 'static/model.xlsx'; // 给a标签的href属性值加上地址,注意,这里是绝对路径,不用加 点.
-        a.download = '质检项导入模板.xlsx'; //设置下载文件文件名,这里加上.xlsx指定文件类型,pdf文件就指定.fpd即可
-        a.style.display = 'none'; // 障眼法藏起来a标签
-        document.body.appendChild(a); // 将a标签追加到文档对象中
-        a.click(); // 模拟点击了a标签,会触发a标签的href的读取,浏览器就会自动下载了
-        a.remove();
+        download1(window.location.origin + this.fileUrl, this.fileName);
+        // var a = document.createElement('a'); //创建一个<a></a>标签
+        // a.href = 'static/model.xlsx'; // 给a标签的href属性值加上地址,注意,这里是绝对路径,不用加 点.
+        // a.download = '质检项导入模板.xlsx'; //设置下载文件文件名,这里加上.xlsx指定文件类型,pdf文件就指定.fpd即可
+        // a.style.display = 'none'; // 障眼法藏起来a标签
+        // document.body.appendChild(a); // 将a标签追加到文档对象中
+        // a.click(); // 模拟点击了a标签,会触发a标签的href的读取,浏览器就会自动下载了
+        // a.remove();
       }
     }
   };

+ 8 - 0
src/utils/file.js

@@ -43,3 +43,11 @@ export function download(data, name) {
   a.click();
   window.URL.revokeObjectURL(url);
 }
+
+export function download1(url, name) {
+  const a = document.createElement('a');
+  const filename = name;
+  a.href = url;
+  a.download = filename;
+  a.click();
+}

+ 102 - 15
src/views/inspectionPlan/components/edit.vue

@@ -29,7 +29,7 @@
     ></base-info>
     <el-row>
       <header-title title="质检内容"></header-title>
-
+      <!-- :needPage="btnType == 'add' ? false : true" -->
       <el-tabs v-model="activeName" @tab-click="handleClick">
         <el-tab-pane label="来源清单" name="1">
           <!-- 来料列表表格 -->
@@ -37,8 +37,10 @@
             ref="table12"
             :columns="tableColumns"
             :datasource="datasource"
-            :needPage="btnType == 'add' ? false : true"
+            :needPage="btnType != 'detail' ? false : true"
             @selection-change="handleSelectionChange"
+            :page-size="50000"
+            :page-sizes="[5000]"
           >
             <template
               v-slot:toolbar
@@ -466,9 +468,12 @@
             }
           ]
         },
+        isScheme: true,
+        isOrder: true,
         isConsumable: '', //0 单件 1批量
         netWeight: '', // 净重
         conditionType: null,
+        isFormNumber: true,
 
         sampleListCode: '',
         productItem: {} //产品信息
@@ -574,7 +579,7 @@
       },
       // 分页后的样品列表
       paginatedSampleList() {
-        if (this.rowIds) {
+        if (this.rowIds && this.isOrder) {
           return this.sampleList;
         }
         const { currentPage, pageSize } = this.samplePagination;
@@ -584,7 +589,7 @@
       },
       // 分页后的质检方案列表
       paginatedSchemeList() {
-        if (this.rowIds) {
+        if (this.rowIds && this.isScheme) {
           return this.schemeList;
         }
         const { currentPage, pageSize } = this.schemePagination;
@@ -598,9 +603,9 @@
       //成品检验类型,计划来源主数据,修改数量生成来源清单
       changeProductNumberModel(num) {
         this.$refs.table12.setData([]);
+        this.isOrder = false;
         let nums = Number(num);
         let p = this.productItem;
-        console.log(p, 'productItem');
         let list = [];
         if (this.isConsumable == 0) {
           for (let i = 0; i < nums; i++) {
@@ -609,7 +614,7 @@
               batchNo: p.batchNo,
               categoryCode: p.code, //编码
               categoryName: p.name, //名称
-              measureQuantity: 1, //计量数量
+              measureQuantity: 1,
               measureUnit: p.measuringUnit, //计量单位
               weightUnit: p.weightUnit, //重量单位
               weight: p.netWeight //重量
@@ -636,6 +641,7 @@
           this.baseForm.qualityMode == 1 &&
           this.baseForm.inspectionStandards
         ) {
+          this.isFormNumber = false;
           this.handleSampleList();
         }
         console.log(this.baseForm, 'form --');
@@ -665,6 +671,7 @@
       getInspectionStandards(data) {
         console.log(data, 'data');
         this.baseForm.inspectionStandards = data;
+        this.isOrder = false;
         this.handleSampleList();
       },
       async datasource({ page, limit, where }) {
@@ -709,7 +716,10 @@
         let data = await getQualityTemplateByIds({
           templateIds: select.map((item) => item.id)
         });
+        console.log('---------------------------');
+        this.isScheme = false;
         this.schemeList.push(...data);
+        this.schemePagination.total = this.schemeList.length;
       },
       async handleEditOrDetail(row) {
         console.log('row====', row);
@@ -744,6 +754,16 @@
         // 如果是编辑或者详情,则查询物料清单、质检方案和样品列表
         if (row.id) {
           this.rowIds = row.id;
+          this.isScheme = true;
+          this.schemePagination.currentPage = 1;
+          this.schemePagination.pageSize = 10;
+          this.schemePagination.total = 0;
+          this.samplePagination.pageSize = 10;
+          this.samplePagination.currentPage = 1;
+          this.samplePagination.total = 0;
+          this.isFormNumber = true;
+          this.isOrder = true;
+
           if (row.isUnpack === 1) {
             this.isCheck = true;
           } else {
@@ -892,6 +912,11 @@
       },
       async handleSampleList() {
         let packingList = this.$refs.table12.getData();
+        // console.log(
+        //   this.baseForm.qualityMode,
+        //   this.baseForm.inspectionStandards,
+        //   this.btnType
+        // );
         //全检时 计量时
         if (
           this.baseForm.qualityMode == 1 &&
@@ -900,7 +925,45 @@
         ) {
           this.sampleList = [];
           console.log(this.baseForm, '---isUnpack---');
-          await this.handleUnpackCase(packingList);
+          if (this.baseForm.productNumber) {
+            this.$refs.table12.setData([]);
+            let nums = Number(this.baseForm.productNumber);
+            let p = this.productItem;
+            let list = [];
+
+            for (let i = 0; i < nums; i++) {
+              let obj = {
+                id: p.id,
+                batchNo: p.batchNo,
+                categoryCode: p.code, //编码
+                categoryName: p.name, //名称
+                measureQuantity: 1,
+                measureUnit: p.measuringUnit, //计量单位
+                weightUnit: p.weightUnit, //重量单位
+                weight: p.netWeight //重量
+              };
+              list.push(obj);
+            }
+            this.$refs.table12.setData(list);
+            let packList = this.$refs.table12.getData();
+            await this.handleUnpackCase(packList);
+
+            return;
+          }
+          // if (this.rowIds) {
+          //   const res = await getInventoryListByPlanId({
+          //     planId: this.rowIds,
+          //     pageNum: 1,
+          //     size: 5000
+          //   });
+          //   // console.log(res.list);
+          //   if (res.list.length > 0) {
+          //     await this.handleUnpackCase(res.list);
+          //   }
+          // } else {
+          // await this.handleUnpackCase(packingList);
+          // }
+
           // if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
           //   //拆包
           //   if (this.baseForm.isUnpack == 1) {
@@ -923,7 +986,25 @@
           this.btnType != 'detail'
         ) {
           this.sampleList = [];
-          this.getFullInspectionWeight(packingList);
+          let list = [];
+          if (this.baseForm.productNumber) {
+            let p = this.productItem;
+            let obj = {
+              id: p.id,
+              batchNo: p.batchNo,
+              categoryCode: p.code, //编码
+              categoryName: p.name, //名称
+              measureQuantity: this.baseForm.productNumber, //计量数量
+              measureUnit: p.measuringUnit, //计量单位
+              weightUnit: p.weightUnit, //重量单位
+              weight: p.netWeight * this.baseForm.productNumber //重量
+            };
+            list.push(obj);
+          }
+          this.$refs.table12.setData(list);
+          let packList = this.$refs.table12.getData();
+          // console.log(list);
+          this.getFullInspectionWeight(packList);
         } else {
           this.sampleList = [];
         }
@@ -937,6 +1018,7 @@
       //拆包处理样品清单数据
       async handleUnpackCase(packingList) {
         const num = Number(this.baseForm.productNumber || 0);
+        console.log('num:' + num);
         if (num) {
           await this.getUnpackSamList(packingList, num);
         }
@@ -948,6 +1030,7 @@
 
       //更新样品清单数据
       async updatePackingList(list) {
+        console.log(list);
         for (let i = 0; i < list.length; i++) {
           list[i].sampleCode = await this.getSampleCode();
         }
@@ -955,11 +1038,13 @@
         this.baseForm.sampleNumber = list.length;
         this.samplePagination.currentPage = 1;
         this.samplePagination.total = list.length;
+        // this.samplePagination.total = this.sampleList.length;
       },
 
       async getUnpackSamList(list, num) {
+        console.log(list, num);
         let data = [];
-        list.forEach((oldItem) => {
+        list.forEach((oldItem, index) => {
           const newMeasureQuantity =
             oldItem.measureQuantity / this.baseForm.productNumber;
           const newWeight = parseFloat(
@@ -985,6 +1070,10 @@
               ...oldItem,
               measureQuantity: 1,
               weight: this.netWeight || 0
+              // weight:
+              //   num - index >= 1
+              //     ? this.netWeight
+              //     : ((num * 100000 - index * 100000) / 100000) * this.netWeight
             });
           }
         });
@@ -1541,16 +1630,14 @@
       async handleSampleSizeChange(val) {
         this.samplePagination.pageSize = val;
         this.samplePagination.currentPage = 1;
-        console.log(1111);
-        if (this.rowIds) {
-          console.log(2222);
+        if (this.rowIds && this.isOrder) {
           await this.getSampleList(this.rowIds);
         }
         //操作行点击时查询样品
       },
       async handleSampleCurrentChange(val) {
         this.samplePagination.currentPage = val;
-        if (this.rowIds) {
+        if (this.rowIds && this.isOrder) {
           await this.getSampleList(this.rowIds);
         }
       },
@@ -1559,14 +1646,14 @@
         this.schemePagination.pageSize = val;
         this.schemePagination.currentPage = 1;
         //操作行点击时查询质检
-        if (this.rowIds) {
+        if (this.rowIds && this.isScheme) {
           await this.getTemplateList(this.rowIds);
         }
       },
       async handleSchemeCurrentChange(val) {
         this.schemePagination.currentPage = val;
         //操作行点击时查询质检
-        if (this.rowIds) {
+        if (this.rowIds && this.isScheme) {
           await this.getTemplateList(this.rowIds);
         }
       },

+ 244 - 200
src/views/inspectionProject/index.vue

@@ -4,14 +4,33 @@
       <!-- 搜索表单 -->
       <user-search @search="reload" />
       <!-- 数据表格 -->
-      <ele-pro-table ref="table" :columns="columns" :datasource="datasource" :selection.sync="selection" row-key="code">
+      <ele-pro-table
+        ref="table"
+        :columns="columns"
+        :datasource="datasource"
+        :selection.sync="selection"
+        row-key="code"
+      >
         <!-- 表头工具栏 -->
         <template v-slot:toolbar>
-          <el-button size="small" type="primary" icon="el-icon-plus" class="ele-btn-icon" @click="openEdit()">
+          <el-button
+            size="small"
+            type="primary"
+            icon="el-icon-plus"
+            class="ele-btn-icon"
+            @click="openEdit()"
+          >
             新建
           </el-button>
 
-          <el-button type="primary" size="mini" icon="el-icon-upload2" plain @click="uploadFile">导入</el-button>
+          <el-button
+            type="primary"
+            size="mini"
+            icon="el-icon-upload2"
+            plain
+            @click="uploadFile"
+            >导入</el-button
+          >
         </template>
 
         <template v-slot:maxValue="{ row }">
@@ -32,18 +51,18 @@
             row.textType == 1
               ? '数值'
               : row.textType == 2
-                ? '选择'
-                : row.textType == 3
-                  ? '上下限'
-                  : row.textType == 4
-                    ? '规格'
-                    : row.textType == 5
-                      ? '时间'
-                      : row.textType == 6
-                        ? '范围'
-                        : row.textType == 7
-                          ? '文本'
-                          : ''
+              ? '选择'
+              : row.textType == 3
+              ? '上下限'
+              : row.textType == 4
+              ? '规格'
+              : row.textType == 5
+              ? '时间'
+              : row.textType == 6
+              ? '范围'
+              : row.textType == 7
+              ? '文本'
+              : ''
           }}
         </template>
 
@@ -52,19 +71,33 @@
         </template>
 
         <template v-slot:toolList="{ row }">
-          <div style="display: inline-block" v-for="(item, idx) in row.toolList" :key="idx">{{ item.name }}
-            <span v-if="row.toolList && idx != row.toolList.length - 1">,
+          <div
+            style="display: inline-block"
+            v-for="(item, idx) in row.toolList"
+            :key="idx"
+            >{{ item.name }}
+            <span v-if="row.toolList && idx != row.toolList.length - 1"
+              >,
             </span>
           </div>
         </template>
 
         <!-- 操作列 -->
         <template v-slot:action="{ row }">
-          <el-link type="primary" :underline="false" icon="el-icon-edit" @click="openEdit(row)">
+          <el-link
+            type="primary"
+            :underline="false"
+            icon="el-icon-edit"
+            @click="openEdit(row)"
+          >
             修改
           </el-link>
 
-          <el-popconfirm class="ele-action" title="确定要删除当前质检吗?" @confirm="remove(row)">
+          <el-popconfirm
+            class="ele-action"
+            title="确定要删除当前质检吗?"
+            @confirm="remove(row)"
+          >
             <template v-slot:reference>
               <el-link type="danger" :underline="false" icon="el-icon-delete">
                 删除
@@ -75,211 +108,222 @@
       </ele-pro-table>
     </el-card>
     <!-- 编辑弹窗 -->
-    <user-edit :visible.sync="showEdit" :data="current" @done="reload" ref="userEdit" />
+    <user-edit
+      :visible.sync="showEdit"
+      :data="current"
+      @done="reload"
+      ref="userEdit"
+    />
     <!-- 导入弹窗 -->
 
-    <importDialog :defModule="moudleName" ref="importDialogRef" @success="reload"></importDialog>
+    <importDialog
+      ref="importDialogRef"
+      @success="reload"
+      :fileUrl="'/qms/static/质检项导入模板.xlsx'"
+      fileName="质检项导入模板"
+      apiUrl="/qms/inspectionProject/importFile"
+    ></importDialog>
   </div>
 </template>
 
 <script>
-import UserSearch from './components/user-search.vue';
-import UserEdit from './components/user-edit.vue';
-import importDialog from '@/components/upload/import-dialog.vue';
+  import UserSearch from './components/user-search.vue';
+  import UserEdit from './components/user-edit.vue';
+  import importDialog from '@/components/upload/import-dialog.vue';
 
-import { getList, removeItem } from '@/api/inspectionProject';
-import dictMixins from '@/mixins/dictMixins';
-export default {
-  name: 'inspectionProject',
-  components: {
-    UserSearch,
-    UserEdit,
-    importDialog
-  },
-  mixins: [dictMixins],
-  data() {
-    return {
-      // 表格列配置
-      columns: [
-        {
-          prop: 'inspectionCode',
-          label: '参数编码',
-          align: 'center',
-          minWidth: 130
-        },
-        {
-          prop: 'inspectionName',
-          label: '参数名称',
-
-          align: 'center',
-          minWidth: 110
-        },
+  import { getList, removeItem } from '@/api/inspectionProject';
+  import dictMixins from '@/mixins/dictMixins';
+  export default {
+    name: 'inspectionProject',
+    components: {
+      UserSearch,
+      UserEdit,
+      importDialog
+    },
+    mixins: [dictMixins],
+    data() {
+      return {
+        // 表格列配置
+        columns: [
+          {
+            prop: 'inspectionCode',
+            label: '参数编码',
+            align: 'center',
+            minWidth: 130
+          },
+          {
+            prop: 'inspectionName',
+            label: '参数名称',
 
-        {
-          prop: 'textType',
-          label: '参数类型',
+            align: 'center',
+            minWidth: 110
+          },
 
-          align: 'center',
-          slot: 'textType',
-          minWidth: 110
-        },
+          {
+            prop: 'textType',
+            label: '参数类型',
 
-        {
-          prop: 'defaultValue',
-          slot: 'defaultValue',
-          label: '默认值',
-          align: 'center',
-          showOverflowTooltip: true
-        },
+            align: 'center',
+            slot: 'textType',
+            minWidth: 110
+          },
 
-        {
-          prop: 'maxValue',
-          slot: 'maxValue',
-          label: '参数上限',
-          align: 'center',
-          showOverflowTooltip: true
-        },
-        {
-          prop: 'minValue',
-          slot: 'minValue',
-          label: '参数下限',
-          align: 'center',
-          showOverflowTooltip: true
-        },
-        // {
-        //   label: '工艺要求',
-        //   prop: 'inspectionStandard',
-        //   formatter: (row, column, cellValue) => {
-        //     return row.symbol + ' ' + cellValue + ' ' + row.unit;
-        //   },
-        //   minWidth: 150
-        // },
+          {
+            prop: 'defaultValue',
+            slot: 'defaultValue',
+            label: '默认值',
+            align: 'center',
+            showOverflowTooltip: true
+          },
 
-        {
-          label: '标准类型',
-          prop: 'type',
-          slot: 'type'
-        },
-        {
-          prop: 'unitName',
-          label: '参数单位',
-          align: 'center',
-        },
-        {
-          prop: 'qualityStandardName',
-          label: '标准名称',
-          align: 'center',
-          minWidth: 110
-        },
+          {
+            prop: 'maxValue',
+            slot: 'maxValue',
+            label: '参数上限',
+            align: 'center',
+            showOverflowTooltip: true
+          },
+          {
+            prop: 'minValue',
+            slot: 'minValue',
+            label: '参数下限',
+            align: 'center',
+            showOverflowTooltip: true
+          },
+          // {
+          //   label: '工艺要求',
+          //   prop: 'inspectionStandard',
+          //   formatter: (row, column, cellValue) => {
+          //     return row.symbol + ' ' + cellValue + ' ' + row.unit;
+          //   },
+          //   minWidth: 150
+          // },
 
-        {
-          prop: 'toolList',
-          slot: 'toolList',
-          label: '工具名称',
-          align: 'center',
-          minWidth: 150
-        },
+          {
+            label: '标准类型',
+            prop: 'type',
+            slot: 'type'
+          },
+          {
+            prop: 'unitName',
+            label: '参数单位',
+            align: 'center'
+          },
+          {
+            prop: 'qualityStandardName',
+            label: '标准名称',
+            align: 'center',
+            minWidth: 110
+          },
 
-        {
-          label: '状态',
-          prop: 'status',
-          formatter: (row, column, cellValue) => {
-            return cellValue == 1 ? '启用' : cellValue === 0 ? '停用' : '';
-          }
-        },
+          {
+            prop: 'toolList',
+            slot: 'toolList',
+            label: '工具名称',
+            align: 'center',
+            minWidth: 150
+          },
 
-        {
-          label: '备注',
-          prop: 'inspectionRemark'
-        },
+          {
+            label: '状态',
+            prop: 'status',
+            formatter: (row, column, cellValue) => {
+              return cellValue == 1 ? '启用' : cellValue === 0 ? '停用' : '';
+            }
+          },
 
-        {
-          columnKey: 'action',
-          label: '操作',
-          width: 220,
-          align: 'center',
-          resizable: false,
-          slot: 'action',
-          showOverflowTooltip: true
-        }
-      ],
+          {
+            label: '备注',
+            prop: 'inspectionRemark'
+          },
 
-      // 表格选中数据
-      selection: [],
-      // 当前编辑数据
-      current: null,
-      // 是否显示编辑弹窗
-      showEdit: false,
-      // 是否显示导入弹窗
-      showImport: false,
-      moudleName: ''
-    };
-  },
-  methods: {
-    /*回显类型 */
+          {
+            columnKey: 'action',
+            label: '操作',
+            width: 220,
+            align: 'center',
+            resizable: false,
+            slot: 'action',
+            showOverflowTooltip: true
+          }
+        ],
 
-    /* 表格数据源 */
-    datasource({ page, where, limit }) {
-      return getList({
-        ...where,
-        pageNum: page,
-        size: limit
-      });
-    },
-    /* 刷新表格 */
-    reload(where) {
-      this.$refs.table.reload({ page: 1, where: where });
+        // 表格选中数据
+        selection: [],
+        // 当前编辑数据
+        current: null,
+        // 是否显示编辑弹窗
+        showEdit: false,
+        // 是否显示导入弹窗
+        showImport: false,
+        moudleName: ''
+      };
     },
+    methods: {
+      /*回显类型 */
 
-    uploadFile() {
-      this.$refs.importDialogRef.open();
-    },
+      /* 表格数据源 */
+      datasource({ page, where, limit }) {
+        return getList({
+          ...where,
+          pageNum: page,
+          size: limit
+        });
+      },
+      /* 刷新表格 */
+      reload(where) {
+        this.$refs.table.reload({ page: 1, where: where });
+      },
 
-    /* 打开编辑弹窗 */
-    openEdit(row) {
-      this.current = row;
-      this.showEdit = true;
-      this.$refs.userEdit.$refs.form &&
-        this.$refs.userEdit.$refs.form.clearValidate();
-    },
+      uploadFile() {
+        this.$refs.importDialogRef.open();
+      },
 
-    /* 删除 */
-    remove(row) {
-      const loading = this.$loading({ lock: true });
+      /* 打开编辑弹窗 */
+      openEdit(row) {
+        this.current = row;
+        this.showEdit = true;
+        this.$refs.userEdit.$refs.form &&
+          this.$refs.userEdit.$refs.form.clearValidate();
+      },
 
-      removeItem([row.id])
-        .then((msg) => {
-          loading.close();
-          this.$message.success('删除' + msg);
-          this.reload();
+      /* 删除 */
+      remove(row) {
+        const loading = this.$loading({ lock: true });
+
+        removeItem([row.id])
+          .then((msg) => {
+            loading.close();
+            this.$message.success('删除' + msg);
+            this.reload();
+          })
+          .catch((e) => {
+            loading.close();
+          });
+      },
+      /* 批量删除 */
+      removeBatch() {
+        if (!this.selection.length) {
+          this.$message.error('请至少选择一条数据');
+          return;
+        }
+        this.$confirm('确定要删除选中的质检吗?', '提示', {
+          type: 'warning'
         })
-        .catch((e) => {
-          loading.close();
-        });
-    },
-    /* 批量删除 */
-    removeBatch() {
-      if (!this.selection.length) {
-        this.$message.error('请至少选择一条数据');
-        return;
+          .then(() => {
+            const loading = this.$loading({ lock: true });
+            removeItem(this.selection.map((d) => d.id))
+              .then((msg) => {
+                loading.close();
+                this.$message.success('删除' + msg);
+                this.reload();
+              })
+              .catch((e) => {
+                loading.close();
+              });
+          })
+          .catch(() => {});
       }
-      this.$confirm('确定要删除选中的质检吗?', '提示', {
-        type: 'warning'
-      })
-        .then(() => {
-          const loading = this.$loading({ lock: true });
-          removeItem(this.selection.map((d) => d.id))
-            .then((msg) => {
-              loading.close();
-              this.$message.success('删除' + msg);
-              this.reload();
-            })
-            .catch((e) => {
-              loading.close();
-            });
-        })
-        .catch(() => { });
     }
-  }
-};
+  };
 </script>