quwangxin il y a 2 ans
Parent
commit
8a579faabe
3 fichiers modifiés avec 117 ajouts et 40 suppressions
  1. 18 0
      src/utils/math.js
  2. 54 8
      src/views/productionPlan/index.vue
  3. 45 32
      src/views/saleOrder/salesToProduction.vue

+ 18 - 0
src/utils/math.js

@@ -0,0 +1,18 @@
+export function add(a, b) {
+  let aLen = (a + '').split('.')[1]?.length || 0;
+  let bLen = (b + '').split('.')[1]?.length || 0;
+
+  const powN = Math.pow(10, Math.max(aLen, bLen));
+
+  return (a * powN + b * powN) / powN;
+}
+
+export function multiply(a, b) {
+  let aLen = (a + '').split('.')[1]?.length || 0;
+  let bLen = (b + '').split('.')[1]?.length || 0;
+
+  const powA = Math.pow(10, aLen);
+  const powB = Math.pow(10, bLen);
+
+  return (a * powA * (b * powB)) / (powA * powB);
+}

+ 54 - 8
src/views/productionPlan/index.vue

@@ -35,7 +35,7 @@
         </template>
         <!-- 操作列 -->
         <template v-slot:action="{ row }">
-          <!-- <el-link
+          <el-link
             type="primary"
             :underline="false"
             icon="el-icon-truck"
@@ -43,7 +43,7 @@
             @click="handleOrderPublish(1, row)"
           >
             发布工单
-          </el-link> -->
+          </el-link>
           <el-link
             type="primary"
             v-if="row.status == 3"
@@ -78,6 +78,9 @@
 <script>
   import { getList, del } from '@/api/productionPlan/index.js';
   import productionPlanSearch from './components/productionPlan-search.vue';
+  import { release } from '@/api/productionPlan/order.js';
+  import { multiply } from '@/utils/math';
+  import { getCode } from '@/api/codeManagement';
   export default {
     components: {
       productionPlanSearch
@@ -313,13 +316,56 @@
       },
       // 发布工单
       handleOrderPublish(type, row) {
-        this.$router.push({
-          path: '/productionPlan/workOrderPublish',
-          query: {
-            type,
-            id: row.id
+        this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认').then(
+          async () => {
+            const loading = this.$loading({
+              lock: true,
+              fullscreen: true,
+              text: '工单发布中...'
+            });
+            try {
+              let code = row.workOrderCode;
+              if (!code) {
+                code = await getCode('product_order_code');
+              }
+              // 反显对象会报错 status
+              const data = await release([
+                {
+                  productionPlanCode: row.code,
+                  code,
+                  formingNum: row.requiredFormingNum,
+                  formingWeight: multiply(
+                    row.requiredFormingNum * row.productUnitWeight
+                  ),
+                  produceVersionId: row.produceVersionId,
+                  status: 4,
+                  model: row.model,
+                  brandNo: row.brandNo,
+                  categoryId: row.categoryId,
+                  productCode: row.productCode,
+                  productName: row.productName
+                }
+              ]);
+              if (data) {
+                this.$message.success('发布成功!');
+              } else {
+                this.$message.error('发布失败,请重新发布!');
+              }
+              this.back();
+            } catch (error) {
+              console.error(error);
+            }
+            loading.close();
           }
-        });
+        );
+
+        // this.$router.push({
+        //   path: '/productionPlan/workOrderPublish',
+        //   query: {
+        //     type,
+        //     id: row.id
+        //   }
+        // });
       },
       // 修改计划
       planEdit({ id }) {

+ 45 - 32
src/views/saleOrder/salesToProduction.vue

@@ -565,39 +565,52 @@
           delete params.id;
         }
         if (type === 2) {
-          const code = await getCode('product_order_code');
-          const data = {
-            productionPlan: params,
-            workOrder: {
-              productionPlanCode: params.code,
-              code: code,
-              formingNum: params.contractNum,
-              formingWeight: params.sumOrderWeight,
-              produceVersionId: params.produceVersionId,
-              status: 4,
-              model: params.model,
-              brandNo: params.brandNo,
-              categoryId: params.categoryId,
-              productCode: params.productCode,
-              productName: params.productName
-            }
-          };
-          if (this.$route.query.type == 'edit') {
-            data.workOrder.productionPlanId = params.id;
-          }
-
-          const key = getRouteTabKey();
-          releaseSave(data)
-            .then(() => {
-              this.$message.success('发布成功!');
-              this.$router.push({
-                path: '/productionPlan'
+          this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认').then(
+            async () => {
+              const loading = this.$loading({
+                lock: true,
+                fullscreen: true,
+                text: '工单发布中...'
               });
-              removePageTab({ key });
-            })
-            .catch(() => {
-              this.$message.error('发布失败,请重新发布!');
-            });
+              try {
+                const code = await getCode('product_order_code');
+                const data = {
+                  productionPlan: params,
+                  workOrder: {
+                    productionPlanCode: params.code,
+                    code: code,
+                    formingNum: params.contractNum,
+                    formingWeight: params.sumOrderWeight,
+                    produceVersionId: params.produceVersionId,
+                    status: 4,
+                    model: params.model,
+                    brandNo: params.brandNo,
+                    categoryId: params.categoryId,
+                    productCode: params.productCode,
+                    productName: params.productName
+                  }
+                };
+                if (this.$route.query.type == 'edit') {
+                  data.workOrder.productionPlanId = params.id;
+                }
+
+                const key = getRouteTabKey();
+                releaseSave(data)
+                  .then(() => {
+                    this.$message.success('发布成功!');
+                    this.$router.push({
+                      path: '/productionPlan'
+                    });
+                    removePageTab({ key });
+                  })
+                  .catch(() => {
+                    this.$message.error('发布失败,请重新发布!');
+                  });
+              } catch (error) {}
+
+              loading.close();
+            }
+          );
         } else {
           let request =
             this.$route.query.type == 'edit'