Просмотр исходного кода

生产订单 批量派单 + 派单时间选择限制功能完成

jingshuyong 1 год назад
Родитель
Сommit
020ff0026c

+ 10 - 1
src/api/mainData/index.js

@@ -197,4 +197,13 @@ export async function parameterGetByCode(data) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
-}
+}
+
+// 批量派单提交
+export async function batchReleaseWorkOrder(data) {
+  const res = await request.post('/aps/workorder/batchReleaseWorkOrder', data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 44 - 29
src/api/productionPlan/index.js

@@ -3,7 +3,7 @@ import request from '@/utils/request';
 /**
  * 列表
  */
-export async function getList (data) {
+export async function getList(data) {
   const res = await request.post('/aps/productionplan/page', data);
   if (res.data.code == 0) {
     return res.data.data;
@@ -13,7 +13,7 @@ export async function getList (data) {
 /**
  * 保存
  */
-export async function save (data) {
+export async function save(data) {
   const res = await request.post('/aps/productionplan/save', data);
   if (res.data.code == 0) {
     return res.data.data;
@@ -23,9 +23,9 @@ export async function save (data) {
 /**
  * 基本信息
  */
-export async function getById (id) {
+export async function getById(id) {
   console.log(id);
-  const res = await request.get(`/aps/productionplan/getById/`+id);
+  const res = await request.get(`/aps/productionplan/getById/` + id);
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -34,7 +34,7 @@ export async function getById (id) {
 /**
  * 发布信息返显
  */
-export async function getReleaseInfoById (id) {
+export async function getReleaseInfoById(id) {
   const res = await request.get(`/aps/productionplan/getReleaseInfoById/${id}`);
   if (res.data.code == 0) {
     return res.data.data;
@@ -44,7 +44,7 @@ export async function getReleaseInfoById (id) {
 /**
  * 详情
  */
-export async function getProductPlanDetail (id) {
+export async function getProductPlanDetail(id) {
   const res = await request.get(
     `/aps/productionplan/getProductPlanDetail/${id}`
   );
@@ -56,8 +56,10 @@ export async function getProductPlanDetail (id) {
 /**
  * 根据计划id获取物料信息
  */
-export async function getMaterialinfo (planId) {
-  const res = await request.get(`/aps/materialinfo/getByPlanId/${planId}`);
+export async function getMaterialinfo(planId) {
+  const res = await request.get(`/aps/materialinfo/listByPlanId`, {
+    params: { planId }
+  });
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -66,7 +68,7 @@ export async function getMaterialinfo (planId) {
 /**
  * 删除
  */
-export async function del (id) {
+export async function del(id) {
   const res = await request.delete(`/aps/productionplan/delete/${id}`);
   if (res.data.code == 0) {
     return res.data.data;
@@ -75,7 +77,7 @@ export async function del (id) {
 }
 
 // 拆分
-export async function splitWork (params) {
+export async function splitWork(params) {
   const res = await request.post(`/aps/productionplan/splitBatch`, params);
   if (res.data.code == 0) {
     return res.data.data;
@@ -83,9 +85,8 @@ export async function splitWork (params) {
   return Promise.reject(new Error(res.data.message));
 }
 
-
 // 计划合批
-export async function mergeBatch (params) {
+export async function mergeBatch(params) {
   const res = await request.post(`/aps/productionplan/mergeBatch`, params);
   if (res.data.code == 0) {
     return res.data.data;
@@ -95,7 +96,7 @@ export async function mergeBatch (params) {
 
 // 修改优先级
 export async function updatePriority(data) {
-  const res = await request.post(`/aps/productionplan/updatePriority`,  data);
+  const res = await request.post(`/aps/productionplan/updatePriority`, data);
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -104,15 +105,16 @@ export async function updatePriority(data) {
 /**
  * 生产详情列表
  */
- export async function queryTaskDetail (data) {
-  const res = await request.get('/aps/quality_details_work_order/queryPlanId/'+data);
+export async function queryTaskDetail(data) {
+  const res = await request.get(
+    '/aps/quality_details_work_order/queryPlanId/' + data
+  );
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
 }
 
-
 // 计划分解(获取产品BOM)
 
 export async function getBom(params) {
@@ -123,11 +125,10 @@ export async function getBom(params) {
   return Promise.reject(new Error(res.data.message));
 }
 
-
 // 计划分解 (保存)
 
 export async function batchSave(data) {
-  const res = await request.post(`/aps/productionplan/batchSave`,  data);
+  const res = await request.post(`/aps/productionplan/batchSave`, data);
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -135,20 +136,23 @@ export async function batchSave(data) {
 }
 // 齐套性检查
 export async function homogeneityInspect(data) {
-  const res = await request.post(`/aps/productionplan/homogeneityInspect`,  data);
+  const res = await request.post(
+    `/aps/productionplan/homogeneityInspect`,
+    data
+  );
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
 }
-export async function getStockList (params) {
-  const res = await request.get('/wms/outindetailtwo/page', {params});
+export async function getStockList(params) {
+  const res = await request.get('/wms/outindetailtwo/page', { params });
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
 }
-export async function getCurrentList (data) {
+export async function getCurrentList(data) {
   const res = await request.post('/eom/purchaseorder/getZtDetail', data);
   if (res.data.code == 0) {
     return res.data.data;
@@ -158,7 +162,10 @@ export async function getCurrentList (data) {
 
 // 齐套性检查
 export async function homogeneityInspectMerge(data) {
-  const res = await request.post(`/aps/productionplan/homogeneityInspectMerge`,  data);
+  const res = await request.post(
+    `/aps/productionplan/homogeneityInspectMerge`,
+    data
+  );
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -167,7 +174,7 @@ export async function homogeneityInspectMerge(data) {
 
 // PBOM树
 export async function getBomRoot(data) {
-  const res = await request.post(`/aps/productionplan/getBomRoot`,  data);
+  const res = await request.post(`/aps/productionplan/getBomRoot`, data);
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -176,7 +183,10 @@ export async function getBomRoot(data) {
 
 // PBOM 齐套性检查
 export async function pbomHomogeneityInspect(data) {
-  const res = await request.post(`/aps/productionplan/pbomHomogeneityInspect`,  data);
+  const res = await request.post(
+    `/aps/productionplan/pbomHomogeneityInspect`,
+    data
+  );
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -184,22 +194,27 @@ export async function pbomHomogeneityInspect(data) {
 }
 
 export async function orderPbomHomogeneityInspect(data) {
-  const res = await request.post(`/aps/productionplan/orderPbomHomogeneityInspect`,  data);
+  const res = await request.post(
+    `/aps/productionplan/orderPbomHomogeneityInspect`,
+    data
+  );
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
 }
 
-export async function getPlanStatistics(params){
-  const res = await request.get('/aps/productionplan/getPlanStatistics', {params});
+export async function getPlanStatistics(params) {
+  const res = await request.get('/aps/productionplan/getPlanStatistics', {
+    params
+  });
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
 }
 export async function getOrderBomRoot(data) {
-  const res = await request.post(`/aps/productionplan/getOrderBomRoot`,  data);
+  const res = await request.post(`/aps/productionplan/getOrderBomRoot`, data);
   if (res.data.code == 0) {
     return res.data.data;
   }

+ 3 - 2
src/store/modules/user.js

@@ -18,7 +18,7 @@ const formatRouter = (list) => {
     for (const p of list) {
       if (p.menuType === 2) {
         // p.children = [];
-        // authorities.push(p);
+        authorities.push(p);
         p.hide = true;
       }
       //报表菜单 source = 2 为报表时 extend 为报表id
@@ -70,7 +70,8 @@ export default {
     },
     // 设置登录用户的权限
     setAuthorities (state, authorities) {
-      state.authorities = authorities;
+      // state.authorities = authorities
+       state.authorities = authorities.map((item) => item.permissionCode);
     },
     // 设置登录用户的权限路由
     setAuthoritiesRouter (state, authoritiesRouter) {

+ 2 - 2
src/views/productionPlan/detail.vue

@@ -9,11 +9,11 @@
         <el-tab-pane label="计划信息" name="plan">
           <plan :infoData="infoData" />
         </el-tab-pane>
-        <el-tab-pane label="物料信息表" name="material">
+        <!-- <el-tab-pane label="物料信息表" name="material">
           <material
             :planId="infoData.productionPlan && infoData.productionPlan.id"
           />
-        </el-tab-pane>
+        </el-tab-pane> -->
         <el-tab-pane
           label="生产详情表"
           name="productionDetail"

+ 1 - 0
src/views/productionPlan/index.vue

@@ -968,6 +968,7 @@
       },
 
       goDetail({ id }) {
+        console.log('尽然详情')
         this.$router.push({
           path: '/productionPlan/detail',
           query: { id }

+ 386 - 0
src/views/workOrder/components/batchDialog.vue

@@ -0,0 +1,386 @@
+<template>
+  <ele-modal
+    :before-close="cancel"
+    :close-on-click-modal="false"
+    :maxable="true"
+    :title="'批量派单'"
+    :visible.sync="batchDialog"
+    append-to-body
+    custom-class="ele-dialog-form"
+    width="1000px"
+  >
+    <el-form
+      ref="form"
+      :model="form"
+      label-position="right"
+      label-width="110px"
+    >
+      <el-row>
+        <el-col :span="12">
+          <el-form-item label="所属工作中心:" required>
+            <el-select
+              v-model="form.workCenterId"
+              placeholder="请选择"
+              style="width: 100%"
+              @change="changeWork"
+            >
+              <el-option
+                v-for="item in workCenterList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+        <el-col :span="12">
+          <el-form-item label="所属班组:" required>
+            <el-select
+              v-model="form.teamId"
+              placeholder="请选择"
+              style="width: 100%"
+              @change="changeGroups"
+            >
+              <el-option
+                v-for="item in teamList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+      </el-row>
+
+      <el-row>
+        <el-form-item label="报工类型:" required>
+          <el-radio-group v-model="form.singleReport">
+            <el-radio :label="1">单件报工</el-radio>
+            <el-radio :label="0">批量报工</el-radio>
+          </el-radio-group>
+        </el-form-item>
+      </el-row>
+      <el-row>
+        <el-form-item label="派单方式:" required>
+          <el-radio-group v-model="form.taskAss">
+            <el-radio :label="1">生产订单派单</el-radio>
+          </el-radio-group>
+        </el-form-item>
+      </el-row>
+      <el-row>
+        <el-col :span="24">
+          <el-form-item label="指派:" prop="assignType" required>
+            <el-radio-group v-model="form.assignType" size="mini">
+              <el-radio-button :label="1">工位</el-radio-button>
+              <el-radio-button :label="2">人员</el-radio-button>
+              <el-radio-button :label="3">产线</el-radio-button>
+            </el-radio-group>
+          </el-form-item>
+        </el-col>
+        <el-col :span="8">
+          <el-form-item v-if="form.assignType == 1" label="工位:" required>
+            <el-select
+              v-model="form.workstationIds"
+              class="ele-block"
+              filterable
+              multiple
+              placeholder="请选择工位"
+              size="mini"
+            >
+              <el-option
+                v-for="item in stationList"
+                :key="item.id"
+                :label="item.name + '(' + item.code + ')'"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+        <el-col :span="8">
+          <el-form-item v-if="form.assignType == 2" label="人员:">
+            <el-select
+              v-model="form.crewIds"
+              class="ele-block"
+              filterable
+              multiple
+              placeholder="请选择人员"
+              size="mini"
+            >
+              <el-option
+                v-for="item in crewList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+        <el-col :span="8">
+          <el-form-item v-if="form.assignType == 3" label="产线:" required>
+            <el-select
+              v-model="form.factoryLineIds"
+              class="ele-block"
+              filterable
+              multiple
+              placeholder="请选择产线"
+              size="mini"
+            >
+              <el-option
+                v-for="item in productionList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+      </el-row>
+    </el-form>
+    <ele-pro-table
+      ref="table"
+      :columns="columns"
+      :datasource="datasource"
+      :needPage="false"
+      row-key="userId"
+    >
+    </ele-pro-table>
+    <div slot="footer">
+      <el-button :loading="loading" plain @click="cancel">取消</el-button>
+      <el-button :loading="loading" type="primary" @click="save"
+        >确定
+      </el-button>
+    </div>
+  </ele-modal>
+</template>
+<script>
+  import {
+    batchReleaseWorkOrder,
+    lineByCurrentUser,
+    listByFirstTaskId,
+    listUserByIds,
+    listWorkCenter
+  } from '@/api/mainData/index.js';
+
+  export default {
+    data() {
+      return {
+        batchDialog: false,
+        datasource: [],
+        columns: [
+          {
+            width: 45,
+            type: 'index',
+            columnKey: 'index',
+            align: 'center'
+          },
+          {
+            label: '名称',
+            prop: 'productName',
+            minWidth: 170
+          },
+          {
+            label: '编码',
+            prop: 'productCode',
+            minWidth: 120
+          },
+          {
+            prop: 'code',
+            label: '生产订单号',
+            minWidth: 210
+          },
+          {
+            label: '计划编号',
+            prop: 'productionPlanCode',
+            minWidth: 150
+          },
+          {
+            label: '批次号',
+            prop: 'batchNo',
+            minWidth: 100
+          },
+          {
+            label: '要求生产数量',
+            prop: 'formingNum',
+            minWidth: 110
+          }
+        ],
+        form: {
+          assignType: 1,
+          crewIds: '',
+          workstationIds: '',
+          teamId: '',
+          singleReport: 0,
+          workCenterId: '',
+          taskAss: 1,
+          factoryName: '',
+          factoryLineIds: ''
+        },
+        workCenterList: [],
+        teamList: [],
+        crewList: [],
+        stationList: [],
+        productionList: [],
+        firstTaskId: '',
+        loading: false
+      };
+    },
+    computed: {
+      clientEnvironmentId() {
+        return this.$store.state.user.info.clientEnvironmentId;
+      }
+    },
+    methods: {
+      cancel() {
+        this.batchDialog = false;
+        this.form = {
+          assignType: 1,
+          crewIds: '',
+          workstationIds: '',
+          teamId: '',
+          singleReport: 0,
+          workCenterId: '',
+          taskAss: 1,
+          factoryName: '',
+          factoryLineIds: ''
+        };
+        this.workCenterList =  [];
+        this.teamList = [];
+        this.crewList = [];
+        this.stationList = [];
+        this.productionList = [];
+        this.firstTaskId = '';
+        this.datasource = [];
+      },
+      open(list) {
+        this.batchDialog = true;
+        this.firstTaskId = list[0].firstTaskId;
+        this.datasource = list;
+        this.workCenterData();
+        this.form.singleReport = this.clientEnvironmentId === 2 ? 0 : 1;
+      },
+      async workCenterData() {
+        const res = await listWorkCenter(this.firstTaskId);
+        this.workCenterList = res;
+        if (res.length > 0) {
+          this.form.factoryName = res[0].factoryName;
+          this.form.workCenterId = res[0].id;
+          // 查首工序
+          await this.changeWork(res[0].id); // 选择工作中心
+          this.getProductionData(res[0].id); // 查询产线
+          this.FirstTaskIdFn(); // 查询工位数据
+        } else {
+          this.$message.warning(
+            `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
+          );
+        }
+      },
+      // 获取产线数据
+      async getProductionData() {
+        const res = await lineByCurrentUser(this.form.workCenterId);
+        this.productionList = res;
+      },
+      // 查询工位数据
+      FirstTaskIdFn() {
+        listByFirstTaskId(this.firstTaskId)
+          .then((res) => {
+            this.stationList = res;
+          })
+          .catch((err) => {
+            this.stationList = [];
+            this.$message.error(err.message);
+          });
+      },
+      // 选择工作中心
+      async changeWork(e) {
+        this.form.workCenterId = e;
+        // this.changeDispatch(); // 查询工序列表
+        let data = this.workCenterList.find((item) => item.id == e);
+        this.form.workCenterName = data.name;
+        this.teamList = data.teamList || []; // 重新获取 班组数据
+        if (this.teamList.length > 0) {
+          this.form.teamId = this.teamList[0].id;
+          await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
+        } else {
+          // 如果没有 班组数据 将人员数据清空 并且判断
+          this.crewList = [];
+          this.form.teamId = '';
+        }
+      },
+      // 选择班组 查询人员的数据
+      async changeGroups(e) {
+        let data = this.teamList.find((item) => item.id == e);
+        this.form.teamName = data.name;
+        try {
+          const res = await listUserByIds([e]);
+          this.crewList = res;
+        } catch {
+          this.crewList = [];
+        }
+      },
+      save() {
+        if (!this.form.teamId) {
+          this.$message.warning('请先选择班组');
+          return;
+        }
+        if (this.form.assignType === 1) {
+          if (
+            !this.form.workstationIds ||
+            this.form.workstationIds.length === 0
+          ) {
+            this.$message.warning('请选择工位数据');
+            return;
+          }
+        }
+        if (this.form.assignType === 3) {
+          if (
+            !this.form.factoryLineIds ||
+            this.form.factoryLineIds.length === 0
+          ) {
+            this.$message.warning('请选择产线数据');
+            return;
+          }
+        }
+        let data = {
+          assignType: this.form.assignType,
+          singleReport: this.form.singleReport,
+          teamId: this.form.teamId,
+          crewIds: [],
+          workstationIds: [],
+          factoryLineIds: []
+        };
+        if (this.form.assignType === 1) {
+          data.workstationIds = this.form.workstationIds || [];
+        } else if (this.form.assignType === 2) {
+          data.crewIds = this.form.crewIds || [];
+        } else {
+          data.factoryLineIds = this.form.factoryLineIds || [];
+        }
+        let dataArr = this.datasource.map((item) => {
+          return {
+            id: item.id,
+            ...data
+          };
+        });
+        this.loading = true;
+        batchReleaseWorkOrder(dataArr)
+          .then((res) => {
+            if ( res){
+              this.loading = false;
+              this.$message.success('操作成功');
+              this.cancel();
+              this.$emit('createSuccess');
+            }
+          })
+          .catch((err) => {
+            this.loading = false;
+            this.$message.error(err.message);
+          });
+      }
+    }
+  };
+</script>

+ 5 - 851
src/views/workOrder/components/releaseDialog.vue

@@ -409,23 +409,8 @@
 </template>
 
 <script>
-  import {
-    listByFirstTaskId,
-    listUserByIds,
-    listWorkCenter,
-    listByWorkCenter,
-    lineByCurrentUser,
-    taskSave,
-    taskRevoked,
-    taskAssignment,
-    listAssign,
-    checkAssignConfirm,
-    resetAssignee,
-    listByRoutingIds,
-    listByFactoryId,
-    checkExists
-  } from '@/api/mainData/index.js';
-  import { releaseWorkOrder } from '@/api/workOrder/index.js';
+import releaseMixin from '../mixins/release'; 
+
   export default {
     components: {},
     props: {
@@ -438,6 +423,7 @@
         default: false
       }
     },
+    mixins:[releaseMixin],
     data() {
       return {
         processId: '',
@@ -448,7 +434,7 @@
           crewIds: '',
           workstationIds: '',
           teamId: '',
-          singleReport: '',
+          singleReport: 0,
           workCenterId: '',
           taskAss: 1,
           factoryName: '',
@@ -631,839 +617,7 @@
       this.form.singleReport = this.clientEnvironmentId == 2 ? 0 : 1;
       this.dateValue = this.getFormattedDate();
     },
-    methods: {
-      // 查询班次
-      getClassesData() {
-        if (!this.current.factoriesId) return;
-        listByFactoryId(this.current.factoriesId).then((res) => {
-          if (!res) return;
-          this.shiftList = res;
-        });
-      },
-      // 查询是否派单
-      queryCheckExists() {
-        let params = {
-          workOrderId: this.current.id,
-          workCenterId: 123,
-          teamId: 345
-        };
-        checkExists(params)
-          .then((res) => {
-            if (!res) return;
-            this.isDispatchRow = res;
-            if (res.hasExists) {
-              this.form.taskAss = 0;
-              this.orderDis = true;
-              this.procTaskDis = false;
-              // 报工类型 判断
-              this.form.singleReport = res.dispatchType;
-              if (res.dispatchType == 1) {
-                this.batchDis = true;
-                this.singleDis = false;
-              } else {
-                this.singleDis = true;
-                this.batchDis = false;
-              }
-            } else {
-              this.batchDis = false;
-              this.singleDis = false;
-              this.orderDis = false;
-              this.procTaskDis = false;
-            }
-          })
-          .catch((err) => {
-            this.$message.error(err.message);
-          });
-      },
-      // 获取当前年月日
-      getFormattedDate() {
-        const now = new Date();
-        const year = now.getFullYear();
-        const month = String(now.getMonth() + 1).padStart(2, '0');
-        const date = String(now.getDate()).padStart(2, '0');
-        return `${year}-${month}-${date}`;
-      },
-      // 查询工作中心
-      async workCenterData() {
-        // const res = await listWorkCenter(this.current.firstTaskId);
-        const res = await listWorkCenter(this.current.firstTaskId);
-        this.workCenterList = res;
-        if (res.length > 0) {
-          this.form.factoryName = res[0].factoryName;
-          this.form.workCenterId = res[0].id;
-          // 查首工序
-          await this.changeWork(res[0].id); // 选择工作中心
-          this.getProductionData(res[0].id); // 查询产线
-          this.FirstTaskIdFn(); // 查询工位数据
-        } else {
-          this.$message.warning(
-            `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
-          );
-        }
-      },
-      // 查询工序列表数据
-      changeDispatch(e) {
-        this.tabsLoading = true;
-        // listByWorkCenter(this.form.workCenterId)
-        listByRoutingIds([this.current.produceRoutingId])
-          .then((res) => {
-            this.tabsLoading = false;
-            // 如果没有首工序的数据 就不能选择工序任务派单
-            if (!res || res.length == 0) {
-              this.processList = [];
-              this.form.taskAss = 1;
-              this.procTaskDis = true;
-              return;
-            }
-            this.procTaskDis = false;
-            let list = [];
-            let isExist = false;
-            let firstTaskindex = '';
-            res.forEach((item, index) => {
-              isExist = isExist
-                ? isExist
-                : item.sourceTaskId === this.current.firstTaskId;
-              // 如果有首工序id 存储它的下标
-              if (isExist) {
-                if (!firstTaskindex && firstTaskindex !== 0) {
-                  firstTaskindex = index;
-                }
-              }
-              let obj = {
-                id: item.sourceTaskId, //工序 id
-                name: item.name, //工序 名称
-                assignType: 1, // 默认的指派数据
-                assignName: '工位', // 默认指派数据名称
-                list: [], // 当前工序下面的指派 绑定的表格
-                selection: [], // 当前工序下面的指派 选中的数据
-                code: item.code, // 工序 编码
-                index: index, // 当前工序数据的下标
-                radioBun: {
-                  // 指派按钮的操作状态 绑定 默认false(可操作)
-                  stationDis: false, // 工位按钮
-                  staffDis: false, // 人员按钮
-                  lineDis: false // 产线按钮
-                },
-                startDate: '', // 开始日期 (当前工序中最早的计划开始时间)
-                endDate: '' // 结束日期 (当前工序中最晚的计划结束时间)
-              };
-              list.push(obj);
-            });
-            this.firstTaskindex = firstTaskindex;
-            // 存在首工序报工
-            if (isExist) {
-              this.processList = list;
-              this.handleClick({ name: res[0].sourceTaskId });
-            } else {
-              this.processList = [];
-              this.form.taskAss = 1;
-              this.procTaskDis = true;
-              this.$message.warning('当前任务没有首工序报工');
-            }
-            console.log(this.processList, '工序的数据 1234');
-          })
-          .catch((err) => {
-            this.processList = [];
-            this.tabsLoading = false;
-            this.$message.error(err.message);
-          });
-      },
-      // 选择工作中心
-      async changeWork(e) {
-        this.form.workCenterId = e;
-        // this.changeDispatch(); // 查询工序列表
-        let data = this.workCenterList.find((item) => item.id == e);
-        this.form.workCenterName = data.name;
-        this.teamList = data.teamList || []; // 重新获取 班组数据
-        if (this.teamList.length > 0) {
-          this.form.teamId = this.teamList[0].id;
-          await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
-        } else {
-          // 如果没有 班组数据 将人员数据清空 并且判断
-          this.crewList = [];
-          this.form.teamId = '';
-          let data = this.processList.find((item) => item.id == this.processId);
-          if (data.assignType == 2) {
-            this.$set(data, 'list', []);
-          }
-        }
-      },
-      // 选择班组 查询人员的数据
-      async changeGroups(e) {
-        let data = this.teamList.find((item) => item.id == e);
-        this.form.teamName = data.name;
-        try {
-          const res = await listUserByIds([e]);
-          this.crewList =
-            res &&
-            res.map((el) => {
-              return {
-                code: el.code,
-                name: el.name,
-                id: el.id
-              };
-            });
-          // 查看当前的工序数据是不是 选择的人员 是的话同步更改
-          if (!this.processId || this.processId == 0) {
-            return;
-          }
-          let data = this.processList.find((item) => item.id == this.processId);
-          if (data.assignType == 2) {
-            this.handleClick({ name: this.processId });
-            // this.$set(data, 'list', res);
-          }
-        } catch {
-          this.crewList = [];
-        }
-      },
-      // 获取产线数据
-      async getProductionData() {
-        const res = await lineByCurrentUser(this.form.workCenterId);
-        this.productionList =
-          res &&
-          res.map((el) => {
-            return {
-              name: el.name,
-              code: el.code,
-              id: el.id
-            };
-          });
-      },
-      // 查询工位数据
-      FirstTaskIdFn() {
-        // listByFirstTaskId(this.current.firstTaskId)
-        listByFirstTaskId(this.current.firstTaskId)
-          .then((res) => {
-            console.log(res, 'res -----');
-            this.stationList = res;
-            // res &&
-            // res.map((el) => {
-            //   return {
-            //     name: el.name,
-            //     code: el.code,
-            //     id: el.id
-            //   };
-            // });
-            this.changeDispatch();
-          })
-          .catch((err) => {
-            this.stationList = [];
-            this.$message.error(err.message);
-          });
-      },
-      // 重置(单个)
-      resetData(row, item) {
-        if (!row.changeId) {
-          return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
-        }
-        this.toolbarLoading = true;
-        resetAssignee(row.changeId)
-          .then((res) => {
-            this.toolbarLoading = false;
-            if (res) {
-              this.$message.success('操作成功');
-              // 更改当前表格数据
-              this.setCurrentTab(item);
-            }
-          })
-          .catch((err) => {
-            this.toolbarLoading = false;
-            this.$message.error(err.message);
-          });
-      },
-      // 撤回的逻辑
-      getWithdrawT(row, type) {
-        if (type != 2) {
-          return true;
-        }
-        let isFlag = true;
-        row.selection.forEach((item) => {
-          if (!item.status) {
-            isFlag = false;
-            return;
-          }
-          if (!item.status.code) {
-            isFlag = false;
-            return;
-          }
-        });
-        return isFlag;
-      },
-      // 派单
-      dispatch(row, type) {
-        if (row.selection.length == 0) {
-          return this.$message.warning('请最少选择一条数据');
-        }
-        let isWithdraw = this.getWithdrawT(row, type);
-        if (!isWithdraw) {
-          this.$message.warning('只有状态为派单的数据才能进行撤回');
-          return;
-        }
-        let assignees = [];
-        let changeIds = [];
-        let flag = true; // 是否填写 校验
-        row.selection.forEach((item) => {
-          if (!item.quantity || !item.startTime || !item.endTime) {
-            flag = false;
-            return;
-          }
-
-          let Aobj = {
-            assigneeId: item.id,
-            quantity: item.quantity,
-            weight: item.weight,
-            startTime: item.startTime,
-            endTime: item.endTime,
-            assigneeType: row.assignType,
-            assigneeName: item.name
-          };
-          if (item.teamTimeDetailId) {
-            Aobj.teamTimeDetailId = item.teamTimeDetailId;
-          }
-          assignees.push(Aobj);
-          changeIds.push(item.changeId);
-        });
-        // 校验没过 就不往下进行
-        if (!flag) {
-          this.$message.warning(
-            '请将所选数据的 数量,开始时间,完成时间 填写完毕'
-          );
-          return;
-        }
-        let data = null;
-        this.toolbarLoading = true;
-        if (type == 2) {
-          data = changeIds;
-        } else {
-          data = {
-            taskId: this.processId,
-            taskName: row.name,
-            taskCode: row.code,
-            teamName: this.form.teamName,
-            teamId: this.form.teamId,
-            workCenterId: this.form.workCenterId,
-            workCenterName: this.form.workCenterName,
-            workOrderId: this.current.id,
-            dispatchMethod: 0,
-            assignees
-          };
-          // 先判断是否派单过 有的话直接用前面派单的 类型数据 否则就是自己选择的数据
-          if (this.isDispatchRow.hasExists) {
-            data.dispatchType = this.isDispatchRow.dispatchType;
-          } else {
-            data.dispatchType = this.form.singleReport;
-          }
-        }
-        const api =
-          type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
-        api(data)
-          .then((res) => {
-            this.toolbarLoading = false;
-            if (res) {
-              this.$message.success('操作成功');
-              // 更改当前表格数据
-              this.setCurrentTab(row);
-              // 查询是否派单
-              this.queryCheckExists();
-            }
-          })
-          .catch((err) => {
-            this.toolbarLoading = false;
-            this.$message.error(err.message);
-          });
-      },
-      cancel() {
-        this.$emit('update:dispatchVisible', false);
-      },
-      // 按钮操作成功后 更改当前的表格数据
-      setCurrentTab(row) {
-        let arr = [];
-        if (row.assignType == 1) {
-          arr = this.stationList;
-        } else if (row.assignType == 2) {
-          arr = this.crewList;
-        } else {
-          arr = this.productionList;
-        }
-        this.getAssignData(row.index, arr);
-      },
-      // 最后提交
-      async confirm() {
-        if (this.form.singleReport != 1 && this.form.singleReport != 0) {
-          this.$message.warning('请先选择报工类型');
-          return;
-        }
-        // if (!this.form.singleReport) {
-
-        // }
-        if (!this.form.teamId) {
-          this.$message.warning('请先选择班组');
-          return;
-        }
-        if (this.form.taskAss == 1) {
-          this.issue();
-          // 按原来的逻辑
-          return;
-        }
-        // 获取到首工序id 的 绑定表格数据
-        let data = this.processList[this.firstTaskindex];
-        // 是否进行首工序派单
-        let isFirstDispatch = false;
-        let dispatchArr = []; // 已派单数据
-        data.list.map((item) => {
-          if (!item.status) {
-            return;
-          }
-          if (item.status.code == 1) {
-            isFirstDispatch = true;
-            dispatchArr.push(item.id);
-          }
-        });
-        // 判断是否进行首工序派单
-        if (!isFirstDispatch) {
-          this.$message.warning(`请您先进行首工序任务(${data.name}工序)派单`);
-          this.handleClick({ name: data.id });
-          return;
-        }
-        let totalSum = 0;
-        // 判断派单的数据 数量相加是否为 要求生产数量
-        data.list.map((item) => {
-          if (item.status && item.status.code == 1) {
-            totalSum += item.quantity - 0;
-          }
-        });
-        if (totalSum != this.current.formingNum - 0) {
-          this.$message.warning(
-            `已派单的数据数量相加需要等于要求生产数量${this.current.formingNum}`
-          );
-          return;
-        }
-        let params = {
-          teamId: this.form.teamId,
-          workCenterId: this.form.workCenterId,
-          workOrderId: this.current.id
-        };
-        this.toolbarLoading = true;
-        try {
-          const res = await checkAssignConfirm(params);
-          if (!res) {
-            this.toolbarLoading = false;
-            return;
-          }
-          let paramsD = {
-            assignType: data.assignType,
-            singleReport: this.form.singleReport,
-            teamId: this.form.teamId,
-            crewIds: data.assignType == 2 ? dispatchArr : [], // 人员 2
-            workstationIds: data.assignType == 1 ? dispatchArr : [], // 工位 1
-            id: this.current.id
-          };
-          const response = await releaseWorkOrder(paramsD);
-          this.toolbarLoading = false;
-          if (response) {
-            this.$message.success('操作成功');
-            this.cancel();
-            this.$emit('createSuccess');
-          }
-        } catch (err) {
-          this.toolbarLoading = false;
-          // this.$message.warning(err.message);
-        }
-      },
-      // 下达
-      issue() {
-        if (this.form.assignType == 1) {
-          if (
-            !this.form.workstationIds ||
-            this.form.workstationIds.length == 0
-          ) {
-            this.$message.warning('请选择工位数据');
-            return;
-          }
-        }
-        if (this.form.assignType == 3) {
-          if (
-            !this.form.factoryLineIds ||
-            this.form.factoryLineIds.length == 0
-          ) {
-            this.$message.warning('请选择产线数据');
-            return;
-          }
-        }
-        let data = {
-          assignType: this.form.assignType,
-          singleReport: this.form.singleReport,
-          teamId: this.form.teamId,
-          crewIds: [],
-          workstationIds: [],
-          id: this.current.id,
-          factoryLineIds: []
-        };
-        if (this.form.assignType == 1) {
-          data.workstationIds = this.form.workstationIds || [];
-        } else if (this.form.assignType == 2) {
-          data.crewIds = this.form.crewIds || [];
-        } else {
-          data.factoryLineIds = this.form.factoryLineIds || [];
-        }
-        this.toolbarLoading = true;
-        releaseWorkOrder(data)
-          .then((res) => {
-            this.toolbarLoading = false;
-            if (res) {
-              this.$message.success('操作成功');
-              this.cancel();
-              this.$emit('createSuccess');
-            }
-          })
-          .catch((err) => {
-            this.toolbarLoading = false;
-            this.$message.error(err.message);
-          });
-      },
-      // 工序选择
-      handleClick(tab) {
-        let id = tab.name;
-        this.processId = id;
-        let data = this.processList.find((item) => item.id == this.processId);
-        // 传指定的指派类型
-        // if (data.list.length == 0) {
-        this.changeRadio(data.assignType, data.index);
-        // }
-      },
-      // 指派选择
-      changeRadio(e, index) {
-        let data = this.processList[index];
-        if (e == 1) {
-          this.dynamicName = '工位名称';
-          data.assignName = '工位';
-          this.getAssignData(index, this.stationList);
-        } else if (e == 2) {
-          this.dynamicName = '人员名称';
-          data.assignName = '人员';
-          this.getAssignData(index, this.crewList);
-        } else {
-          this.dynamicName = '产线名称';
-          data.assignName = '产线';
-          this.getAssignData(index, this.productionList);
-        }
-      },
-      // 指派数据处理
-      async getAssignData(index, arr) {
-        let list = JSON.parse(JSON.stringify(arr));
-        let dataRow = this.processList[index];
-        // 不存在 班组数据的话 就不调用这个方法
-        if (!this.form.teamId) {
-          return;
-        }
-        let params = {
-          workOrderId: this.current.id,
-          workCenterId: this.form.workCenterId,
-          teamId: this.form.teamId,
-          taskId: this.processId
-        };
-        this.tabLoading = true;
-        try {
-          const res = await listAssign(params);
-          this.tabLoading = false;
-          // 如果 res 没有数据 说明未对数据进行操作 直接赋值
-          if (res.length == 0) {
-            this.$set(dataRow, 'list', list);
-            return;
-          }
-          // 对有操作过的数据进行赋值
-          this.operationalData(index, res, list);
-        } catch (err) {
-          console.log(err, 'errerrerrerrerr');
-          this.tabLoading = false;
-          this.$message.warning(err.message);
-        }
-      },
-      // 操作过的数据 赋值
-      operationalData(index, res, list) {
-        const dataRow = this.processList[index];
-        // 键值对存储 当前工序 操作的数据  指派的code(键) 数据(list:值)
-        let arrMap = {};
-        // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
-        let codeT = null; // 表示有已操作的数据(对应的 code)
-        res[0].assignees.map((el) => {
-          let code = el.assigneeType.code;
-          if (arrMap[code]) {
-            arrMap[code].arr.push(el);
-            arrMap[code].bunDis = arrMap[code].bunDis
-              ? arrMap[code].bunDis
-              : el.status.desc
-              ? true
-              : false;
-          } else {
-            arrMap[code] = {
-              arr: [el],
-              bunDis: el.status.desc ? true : false
-            };
-          }
-          codeT = codeT ? codeT : el.status.desc ? code : '';
-        });
-        let radioBun = {
-          lineDis: false, // 产线 3
-          staffDis: false, // 人员 2
-          stationDis: false // 工位 1
-        };
-        // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
-        // 需要自动切换过去
-        let listArr = list;
-        if (codeT) {
-          if (codeT == 1) {
-            radioBun.staffDis = true;
-            radioBun.lineDis = true;
-            radioBun.stationDis = false;
-            listArr = JSON.parse(JSON.stringify(this.stationList));
-            dataRow.assignType = 1;
-            dataRow.assignName = '工位';
-          } else if (codeT == 2) {
-            radioBun.stationDis = true;
-            radioBun.lineDis = true;
-            radioBun.staffDis = false;
-            listArr = JSON.parse(JSON.stringify(this.crewList));
-            dataRow.assignType = 2;
-            dataRow.assignName = '人员';
-          } else {
-            radioBun.stationDis = true;
-            radioBun.staffDis = true;
-            radioBun.lineDis = false;
-            listArr = JSON.parse(JSON.stringify(this.productionList));
-            dataRow.assignType = 3;
-            dataRow.assignName = '产线';
-          }
-        }
-        // 切换完后 对 指派的数组数据进行赋值
-        let listMap = {};
-        listArr.map((el, index) => (listMap[el.id] = index));
-        let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
-        dataRow.startDate = ''; // 每次计算的时候清空之前的
-        dataRow.endDate = '';
-        arrList.map((item) => {
-          if (item.assigneeType.code == dataRow.assignType) {
-            console.log(item, 'itemitemitemitemitemitemitemitemitemitem');
-            let idx = listMap[item.assigneeId];
-            if (!idx && idx !== 0) {
-              return;
-            }
-            listArr[idx].status = item.status;
-            listArr[idx].startTime = item.startTime;
-            listArr[idx].endTime = item.endTime;
-            listArr[idx].quantity = item.quantity;
-            listArr[idx].weight = item.weight;
-            listArr[idx].changeId = item.id;
-            listArr[idx].teamTimeDetailId = item.teamTimeDetailId;
-            // this.compareAndSetTime(listArr[idx], dataRow);
-            // this.compareEndSetTime(listArr[idx], dataRow);
-          }
-        });
-        console.log(arrList, 'arrList arrList');
-        // 这里重新调用一个方法 计算出 startDate endDate
-        console.log(dataRow, 'dataRow +++++');
-        this.$set(dataRow, 'list', listArr);
-        this.$set(dataRow, 'radioBun', radioBun);
-      },
-
-      // 时间比较与赋值方法 开始时间
-      compareAndSetTime(data, dataRow) {
-        // 如果startDate为空,直接赋值为startTime
-        if (!dataRow.startDate) {
-          dataRow.startDate = data['startTime'];
-          return;
-        }
-
-        // 转换为Date对象进行比较
-        const startTimeDate = new Date(data['startTime']);
-        const startDateDate = new Date(dataRow.startDate);
-
-        // 比较时间(getTime()获取时间戳)
-        if (startTimeDate.getTime() < startDateDate.getTime()) {
-          dataRow.startDate = data['startTime'];
-        }
-      },
-
-      // 时间比较与赋值方法 结束时间时间
-      compareEndSetTime(data, dataRow) {
-        // 如果startDate为空,直接赋值为endTime
-        if (!dataRow.endDate) {
-          dataRow.endDate = data['endTime'];
-          return;
-        }
-
-        // 转换为Date对象进行比较
-        const endTimeDate = new Date(data['endTime']);
-        const endDateDate = new Date(dataRow.endDate);
-
-        // 比较时间(getTime()获取时间戳)
-        if (endTimeDate.getTime() > endDateDate.getTime()) {
-          dataRow.endDate = data['endTime'];
-        }
-      },
-
-      assignRadio(e) {},
-      // 数量正则 quantity
-      handleQuantityInput(e, row, item) {
-        // 过滤非数字字符(包括负号)
-        let value = e.replace(/[^\d]/g, '');
-        // 限制不能以 0 开头(除非是 0 本身)
-        if (value.startsWith('0') && value.length > 1) {
-          value = value.slice(1);
-        }
-        // 更新绑定值
-        row.quantity = value;
-        this.calculateQuantity(row, item);
-        this.bringWeight(row.quantity, row);
-      },
-      // 自动算重量
-      bringWeight(value, row) {
-        if (!this.current.formingWeight) {
-          this.$set(row, 'weight', 0);
-          return;
-        }
-        let weight =
-          (this.current.formingWeight / this.current.formingNum) * value;
-        if (weight > 0) {
-          weight = weight.toFixed(4) - 0;
-        }
-        this.$set(row, 'weight', weight);
-      },
-      calculateQuantity(row, item) {
-        // 如果没有该字段 就不做判断
-        if (!this.current.formingNum) {
-          return;
-        }
-        let total = 0;
-        item.list.forEach((el) => {
-          if (el.quantity) {
-            total = total + (el.quantity - 0);
-          }
-        });
-        if (total > this.current.formingNum - 0) {
-          this.$message.warning('列表数量相加不能大于目标要求生产数量');
-          row.quantity = 0;
-        }
-      },
-      // 计算重量
-      calculateWeight(row, item) {
-        // 如果没有该字段 就不做判断
-        if (!this.current.formingWeight) {
-          return;
-        }
-        let total = 0;
-        item.list.forEach((el) => {
-          if (el.weight) {
-            total = total + (el.weight - 0);
-          }
-        });
-        if (total > this.current.formingWeight - 0) {
-          this.$message.warning('列表数量相加不能大于目标要求生产数量');
-          row.weight = 0;
-        }
-      },
-      // 重量正则 weight
-      handleWeightInput(e, row, item) {
-        // 过滤非数字和非小数点字符(包括负号)
-        let value = e.replace(/[^\d.]/g, '');
-        // 限制只能有一个小数点
-        const dotCount = (value.match(/\./g) || []).length;
-        if (dotCount > 1) {
-          value = value.slice(0, value.lastIndexOf('.'));
-        }
-
-        // 限制不能以小数点开头
-        if (value.startsWith('.')) {
-          value = '0' + value;
-        }
-        // 更新绑定值
-        row.weight = value;
-        this.calculateWeight(row, item);
-      },
-      // 选中班次
-      shiftSelection(e, row, item) {
-        let data = this.shiftList.find((item) => item.id == e);
-        let startTime = `${this.dateValue} ${data.startTime}`;
-        let endTime = `${this.dateValue} ${data.endTime}`;
-        this.$set(row, 'startTime', startTime);
-        this.$set(row, 'endTime', endTime);
-        this.handleStartTimeChange(row, item);
-        this.handleEndTimeChange(row, item);
-      },
-      // 【开始时间变化时】触发
-      handleStartTimeChange(row, item) {
-        // 后一道工序的开始时间 不能小于前一道工序的结束时间
-        // if (item.index !== 0) {
-        //   let frontIdx = item.index - 1;
-        //   let frontName = this.processList[frontIdx].name;
-        //   let time = this.processList[frontIdx].endDate;
-        //   const frontTime = new Date(time); // 上一道工序的结束时间
-        //   const startTime = new Date(row.startTime); // 开始时间
-        //   const endTime = item.endTime ? new Date(item.endTime) : null; // 结束时间
-        //   console.log(startTime,'startTime 开始的')
-        //   if (endTime && endTime < frontTime) {
-        //     row.endTime = '';
-        //   }
-        //   if (startTime < frontTime) {
-        //     this.$message.info(
-        //       `开始时间不能小于上一道工序${frontName}的结束时间${time}`
-        //     );
-        //     row.startTime = time;
-        //     return;
-        //   }
-        // }
-        // 校验 是否 大于结束时间  wda
-        this.checkEndTimeValid(row);
-        // 更新当前结束时间段  每次计算的时候清空之前的
-        // item.startDate = '';
-        // item.list.forEach((el) => {
-        //   this.compareAndSetTime(el, item);
-        // });
-      },
-
-      // 【结束时间变化时】触发
-      handleEndTimeChange(row, item) {
-        // 当前工序的结束时间 不能大于后一道工序的开始时间
-        // if (item.index !== this.processList.length - 1) {
-        //   let latterIdx = item.index + 1;
-        //   let latterName = this.processList[latterIdx].name;
-        //   let time = this.processList[latterIdx].startDate;
-        //   const latterTime = new Date(time); // 下一道工序的开始时间
-        //   const endTime = new Date(row.endTime); // 结束时间
-        //   const startTime = item.startTime ? new Date(item.startTime) : null; // 开始时间
-        //   console.log(startTime,'startTime')
-        //   console.log(latterTime,'latterTime')
-        //   if (startTime && startTime > latterTime) {
-        //     row.startTime = '';
-        //   }
-        //   if (endTime > latterTime) {
-        //     this.$message.info(
-        //       `结束时间不能大于下一道工序${latterName}的开始时间${time}`
-        //     );
-        //     row.endTime = time;
-        //     return;
-        //   }
-        // }
-        this.checkEndTimeValid(row, item);
-        // 更新当前结束时间段 每次计算的时候清空之前的
-        // item.endDate = '';
-        // item.list.forEach((el) => {
-        //   this.compareEndSetTime(el, item);
-        // });
-        console.log(item, 'item,结束');
-      },
-      // 时间校验
-      checkEndTimeValid(row) {
-        const { startTime: start, endTime: end } = row;
-        // if (!start || !end) return; // 开始/结束时间未填,跳过
-        const startTime = new Date(start); // 开始时间
-        const endTime = new Date(end); // 结束时间
-        if (endTime < startTime) {
-          row.endTime = new Date(startTime); // 修正为开始时间
-          this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
-        }
-      }
-    }
+    methods: {}
   };
 </script>
 

+ 632 - 614
src/views/workOrder/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="ele-body">
-    <el-card shadow="never" v-loading="loading">
-      <order-search @search="reload" ref="searchRef"> </order-search>
+    <el-card v-loading="loading" shadow="never">
+      <order-search ref="searchRef" @search="reload"></order-search>
       <!--      <el-tabs v-model="activeName" type="card">
         <el-tab-pane label="未完成工单" name="first"></el-tab-pane>
         <el-tab-pane label="已完成工单" name="second"></el-tab-pane>
@@ -23,59 +23,63 @@
       > -->
       <ele-pro-table
         ref="table"
+        :cache-key="cacheKeyUrl"
         :columns="newColumns"
         :datasource="datasource"
+        :parse-data="parseData"
+        autoAmendPage
         cache-key="workOrderTable"
         row-key="id"
         @sort-change="onSortChange"
-        autoAmendPage
-        :parse-data="parseData"
-        :cache-key="cacheKeyUrl"
         @columns-change="handleColumnChange"
-        :selection.sync="selection"
       >
         <!-- :key="activeName" -->
         <!-- :selection.sync="selection" -->
         <!-- @update:selection="handleSelectionChange" -->
-        <!-- <template v-slot:toolbar>
+        <template v-slot:toolbar>
           <el-button
+            class="ele-btn-icon"
+            icon="el-icon-truck"
             size="small"
             type="primary"
-            icon="el-icon-truck"
-            class="ele-btn-icon"
+            v-if="$hasPermission('aps:batchReleaseWorkOrder:release')"
             @click="batchDispatch"
-            >批量派单</el-button
-          >
-        </template> -->
+          >批量派单
+        <!--  -->
+          </el-button>
+        </template>
         <template v-slot:selection="{ row }">
-          <el-checkbox v-model="row.checked"></el-checkbox>
+          <el-checkbox
+            :disabled="!dispatchPermission(row)"
+            :value="checkRowData(row)"
+            class="batch_checked"
+            @change="(e) => selectRow(e, row)"
+          ></el-checkbox>
         </template>
         <template v-slot:code="{ row }">
           {{ row.code }}
         </template>
-
         <template v-slot:formingWeight="{ row }">
           {{ row.formingWeight }} {{ row.newWeightUnit }}
         </template>
-
         <template v-slot:priority="{ row }">
           <div style="display: flex">
             <el-input
               v-model="row.priority"
-              type="number"
-              size="mini"
-              :min="0"
               :max="10"
-              @change="priorityChange(row)"
+              :min="0"
+              size="mini"
               style="width: 80px"
+              type="number"
+              @change="priorityChange(row)"
             ></el-input>
             <el-popover
+              content="数值越大优先级越高(0-3普通, 4-6优先, 7-10紧急)"
               placement="right"
-              width="200"
               trigger="hover"
-              content="数值越大优先级越高(0-3普通, 4-6优先, 7-10紧急)"
+              width="200"
             >
-              <div class="sort-wrap" slot="reference">
+              <div slot="reference" class="sort-wrap">
                 <i class="el-icon-caret-top" @click="sortTop(row)"></i>
                 <i class="el-icon-caret-bottom" @click="sortBottom(row)"></i>
               </div>
@@ -91,15 +95,15 @@
         <!-- 操作列 -->
         <template v-slot:action="{ row }">
           <el-link
-            type="primary"
-            :underline="false"
-            @click="toUnpack(row)"
             v-if="
               (clientEnvironmentId != '4' && row.status == 8) ||
               (clientEnvironmentId == '4' &&
                 !row.productName.includes('板材') &&
                 row.status == 8)
             "
+            :underline="false"
+            type="primary"
+            @click="toUnpack(row)"
           >
             拆单
           </el-link>
@@ -138,655 +142,669 @@
           </el-link> -->
 
           <el-link
-            type="primary"
+            v-if="dispatchPermission(row)"
             :underline="false"
             icon="el-icon-truck"
+            type="primary"
             @click="toReleaseOpen(row)"
-            v-if="dispatchPermission(row)"
           >
             派单
           </el-link>
         </template>
       </ele-pro-table>
     </el-card>
-
-    <el-dialog :visible.sync="visible" title="派单" width="500px">
-      <el-form
-        ref="form"
-        :model="form"
-        :rules="rules"
-        label-position="left"
-        label-width="100px"
-      >
-        <el-form-item label="报工类型:" prop="singleReport">
-          <el-radio-group v-model="form.singleReport">
-            <el-radio :label="1" v-if="clientEnvironmentId != 2"
-              >单件报工</el-radio
-            >
-            <el-radio :label="0">批量报工</el-radio>
-          </el-radio-group>
-        </el-form-item>
-
-        <el-form-item label="指定:" prop="assignType">
-          <el-radio-group
-            v-model="form.assignType"
-            size="mini"
-            @change="assignTypeFn"
-          >
-            <el-radio-button :label="1">工位</el-radio-button>
-            <el-radio-button :label="2">人员</el-radio-button>
-          </el-radio-group>
-        </el-form-item>
-
-        <el-form-item label="班组:" prop="teamId">
-          <el-select
-            class="ele-block"
-            v-model="form.teamId"
-            placeholder="请选择班组"
-            size="mini"
-            filterable
-            @change="stationChange"
-          >
-            <el-option
-              v-for="item in teamsList"
-              :key="item.id"
-              :label="item.name + '(' + item.code + ')'"
-              :value="item.id"
-            >
-            </el-option>
-          </el-select>
-        </el-form-item>
-
-        <el-form-item
-          label="工位:"
-          prop="workstationIds"
-          v-if="form.assignType == 1"
-        >
-          <el-select
-            class="ele-block"
-            v-model="form.workstationIds"
-            placeholder="请选择工位"
-            size="mini"
-            multiple
-            filterable
-          >
-            <el-option
-              v-for="item in stationList"
-              :key="item.id"
-              :label="item.name + '(' + item.code + ')'"
-              :value="item.id"
-            >
-            </el-option>
-          </el-select>
-        </el-form-item>
-
-        <el-form-item label="人员:" prop="crewIds" v-if="form.assignType == 2">
-          <el-select
-            class="ele-block"
-            v-model="form.crewIds"
-            placeholder="请选择人员"
-            size="mini"
-            filterable
-            multiple
-          >
-            <el-option
-              v-for="item in crewList"
-              :key="item.id"
-              :label="item.name"
-              :value="item.id"
-            >
-            </el-option>
-          </el-select>
-        </el-form-item>
-      </el-form>
-
-      <div class="footer" slot="footer">
-        <el-button @click="close">取消</el-button>
-        <el-button type="primary" v-click-once @click="confirm">确定</el-button>
-      </div>
-    </el-dialog>
+<!--    <el-dialog :visible.sync="visible" title="派单" width="500px">-->
+<!--      <el-form-->
+<!--        ref="form"-->
+<!--        :model="form"-->
+<!--        :rules="rules"-->
+<!--        label-position="left"-->
+<!--        label-width="100px"-->
+<!--      >-->
+<!--        <el-form-item label="报工类型:" prop="singleReport">-->
+<!--          <el-radio-group v-model="form.singleReport">-->
+<!--            <el-radio v-if="clientEnvironmentId != 2" :label="1"-->
+<!--            >单件报工-->
+<!--            </el-radio>-->
+<!--            <el-radio :label="0">批量报工</el-radio>-->
+<!--          </el-radio-group>-->
+<!--        </el-form-item>-->
+
+<!--        <el-form-item label="指定:" prop="assignType">-->
+<!--          <el-radio-group-->
+<!--            v-model="form.assignType"-->
+<!--            size="mini"-->
+<!--            @change="assignTypeFn"-->
+<!--          >-->
+<!--            <el-radio-button :label="1">工位</el-radio-button>-->
+<!--            <el-radio-button :label="2">人员</el-radio-button>-->
+<!--          </el-radio-group>-->
+<!--        </el-form-item>-->
+
+<!--        <el-form-item label="班组:" prop="teamId">-->
+<!--          <el-select-->
+<!--            v-model="form.teamId"-->
+<!--            class="ele-block"-->
+<!--            filterable-->
+<!--            placeholder="请选择班组"-->
+<!--            size="mini"-->
+<!--            @change="stationChange"-->
+<!--          >-->
+<!--            <el-option-->
+<!--              v-for="item in teamsList"-->
+<!--              :key="item.id"-->
+<!--              :label="item.name + '(' + item.code + ')'"-->
+<!--              :value="item.id"-->
+<!--            >-->
+<!--            </el-option>-->
+<!--          </el-select>-->
+<!--        </el-form-item>-->
+
+<!--        <el-form-item-->
+<!--          v-if="form.assignType == 1"-->
+<!--          label="工位:"-->
+<!--          prop="workstationIds"-->
+<!--        >-->
+<!--          <el-select-->
+<!--            v-model="form.workstationIds"-->
+<!--            class="ele-block"-->
+<!--            filterable-->
+<!--            multiple-->
+<!--            placeholder="请选择工位"-->
+<!--            size="mini"-->
+<!--          >-->
+<!--            <el-option-->
+<!--              v-for="item in stationList"-->
+<!--              :key="item.id"-->
+<!--              :label="item.name + '(' + item.code + ')'"-->
+<!--              :value="item.id"-->
+<!--            >-->
+<!--            </el-option>-->
+<!--          </el-select>-->
+<!--        </el-form-item>-->
+
+<!--        <el-form-item v-if="form.assignType == 2" label="人员:" prop="crewIds">-->
+<!--          <el-select-->
+<!--            v-model="form.crewIds"-->
+<!--            class="ele-block"-->
+<!--            filterable-->
+<!--            multiple-->
+<!--            placeholder="请选择人员"-->
+<!--            size="mini"-->
+<!--          >-->
+<!--            <el-option-->
+<!--              v-for="item in crewList"-->
+<!--              :key="item.id"-->
+<!--              :label="item.name"-->
+<!--              :value="item.id"-->
+<!--            >-->
+<!--            </el-option>-->
+<!--          </el-select>-->
+<!--        </el-form-item>-->
+<!--      </el-form>-->
+
+<!--      <div slot="footer" class="footer">-->
+<!--        <el-button @click="close">取消</el-button>-->
+<!--        <el-button v-click-once type="primary" @click="confirm">确定</el-button>-->
+<!--      </div>-->
+<!--    </el-dialog>-->
 
     <unpackDialog ref="unpackRef" @success="createSuccess" />
     <releaseDialog
+      v-if="dispatchVisible"
       ref="releaseRef"
       :current="dispatchRow"
       :dispatchVisible.sync="dispatchVisible"
       @createSuccess="createSuccess"
-      v-if="dispatchVisible"
     />
+    <BatchDialog ref="batchRef" @createSuccess="createSuccess" />
   </div>
 </template>
 
 <script>
-  import {
-    getList,
-    releaseWorkOrder,
-    updatePriority
-  } from '@/api/workOrder/index.js';
-  import {
-    teamPage,
-    listByFirstTaskId,
-    listByWorkCenterId,
-    listUserByIds,
-    getTaskIdByInstanceId
-  } from '@/api/mainData/index.js';
-  import OrderSearch from './components/order-search.vue';
-  import unpackDialog from './components/unpackDialog.vue';
-  import releaseDialog from './components/releaseDialog.vue';
-
-  import { fieldModel } from '@/api/saleOrder';
-
-  import { debounce } from 'lodash';
-  import PlanStatistics from '@/components/statistics/PlanStatistics.vue';
-  import tabMixins from '@/mixins/tableColumnsMixin';
-
-  export default {
-    mixins: [tabMixins],
-    components: {
-      PlanStatistics,
-      OrderSearch,
-      unpackDialog,
-      releaseDialog
-    },
-    data() {
-      return {
-        visible: false,
-        loading: false,
-        form: {
-          assignType: 1,
-          crewIds: '',
-          workstationIds: '',
-          teamId: '',
-          singleReport: ''
-        },
-        rules: {
-          singleReport: [
-            {
-              required: true,
-              message: '请选择报工类型',
-              trigger: ['blur', 'change']
-            }
-          ],
-          workstationIds: [
-            {
-              required: true,
-              message: '请选择工位',
-              trigger: ['blur']
-            }
-          ],
-          teamId: [
-            {
-              required: true,
-              message: '请选择班组',
-              trigger: ['blur']
-            }
-          ]
-        },
-        teamList: [],
-        statusOpt: [
-          { label: '待生产', value: 4 },
-          { label: '生产中', value: 5 },
-          { label: '待下达', value: 8 }
-        ],
-        newColumns: [],
-        stationList: [],
-        teamsList: [],
-        crewList: [],
-        current: null,
-        cacheKeyUrl: '3cbbdff9-aps-workOrder',
-        columnsVersion: 1,
-        dispatchRow: {},
-        dispatchVisible: false,
-        selection: []
-      };
-    },
-    computed: {
-      dispatchPermission() {
-        return (row) => {
-          if (!row.firstTaskId) {
-            return false;
-          }
-          return (
-            (row.isSplit != 1 &&
-              this.clientEnvironmentId != '4' &&
-              row.status == 8) ||
-            (this.clientEnvironmentId == '4' &&
-              !row.productName.includes('板材') &&
-              row.status == 8)
-          );
-        };
-      },
-      teamId() {
-        return this.$store.state.user.info.teamId;
-      },
-      clientEnvironmentId() {
-        return this.$store.state.user.info.clientEnvironmentId;
+import { getList, releaseWorkOrder, updatePriority } from "@/api/workOrder/index.js";
+import { listByFirstTaskId, listByWorkCenterId, listUserByIds } from "@/api/mainData/index.js";
+import OrderSearch from "./components/order-search.vue";
+import unpackDialog from "./components/unpackDialog.vue";
+import releaseDialog from "./components/releaseDialog.vue";
+import { fieldModel } from "@/api/saleOrder";
+import { debounce } from "lodash";
+import PlanStatistics from "@/components/statistics/PlanStatistics.vue";
+import tabMixins from "@/mixins/tableColumnsMixin";
+import BatchDialog  from "@/views/workOrder/components/batchDialog.vue";
+export default {
+  mixins: [tabMixins],
+  components: {
+    PlanStatistics,
+    OrderSearch,
+    unpackDialog,
+    releaseDialog,
+    BatchDialog
+  },
+  data() {
+    return {
+      visible: false,
+      loading: false,
+      form: {
+        assignType: 1,
+        crewIds: '',
+        workstationIds: '',
+        teamId: '',
+        singleReport: ''
       },
-      // 表格列配置
-      columns() {
-        // const num = this.columnsVersion;
-        return [
-          // {
-          //   width: 45,
-          //   type: 'selection',
-          //   columnKey: 'selection',
-          //   align: 'center',
-          //   slot: 'selection',
-          //   fixed: 'left',
-          //   selectable: (row, index) => {
-          //     if (row.children) {
-          //     }
-          //     return this.dispatchPermission(row);
-          //   }
-          // },
-          {
-            columnKey: 'index',
-            slot: 'index',
-            label: '序号',
-            type: 'index',
-            width: 55,
-            align: 'center',
-            showOverflowTooltip: true,
-            fixed: 'left'
-          },
-          {
-            slot: 'code',
-            label: '生产订单号',
-            align: 'center',
-            minWidth: 210,
-            sortable: true
-          },
-          {
-            prop: 'productionPlanCode',
-            label: '计划编号',
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'produceRoutingName',
-            label: '工艺路线',
-            align: 'center',
-            minWidth: 170
-          },
-          {
-            prop: 'productCode',
-            label: '编码',
-            align: 'center',
-            minWidth: 110
-          },
-          {
-            prop: 'productName',
-            label: '名称',
-            align: 'center',
-            minWidth: 170
-          },
-          {
-            prop: 'productionCodes',
-            label: '生产编号',
-            align: 'center',
-            minWidth: 150,
-            showOverflowTooltip: true
-          },
+      rules: {
+        singleReport: [
           {
-            prop: 'brandNo',
-            label: '牌号',
-            align: 'center'
-          },
-
+            required: true,
+            message: '请选择报工类型',
+            trigger: ['blur', 'change']
+          }
+        ],
+        workstationIds: [
           {
-            prop: 'batchNo',
-            label: '批次号',
-            align: 'center',
-            minWidth: 100,
-            showOverflowTooltip: true
-          },
+            required: true,
+            message: '请选择工位',
+            trigger: ['blur']
+          }
+        ],
+        teamId: [
           {
-            prop: 'model',
-            label: '型号',
-            align: 'center',
-            showOverflowTooltip: true
-          },
+            required: true,
+            message: '请选择班组',
+            trigger: ['blur']
+          }
+        ]
+      },
+      teamList: [],
+      statusOpt: [
+        { label: '待生产', value: 4 },
+        { label: '生产中', value: 5 },
+        { label: '待下达', value: 8 }
+      ],
+      newColumns: [],
+      stationList: [],
+      teamsList: [],
+      crewList: [],
+      current: null,
+      cacheKeyUrl: '3cbbdff9-aps-workOrder',
+      columnsVersion: 1,
+      dispatchRow: {},
+      dispatchVisible: false,
+      selectionMap: {},
+    };
+  },
+  computed: {
+    dispatchPermission() {
+      return (row) => {
+        if (!row.firstTaskId) {
+          return false;
+        }
+        return (
+          (row.isSplit != 1 &&
+            this.clientEnvironmentId != '4' &&
+            row.status == 8) ||
+          (this.clientEnvironmentId == '4' &&
+            !row.productName.includes('板材') &&
+            row.status == 8)
+        );
+      };
+    },
+    teamId() {
+      return this.$store.state.user.info.teamId;
+    },
+    clientEnvironmentId() {
+      return this.$store.state.user.info.clientEnvironmentId;
+    },
+    // 表格列配置
+    columns() {
+      // const num = this.columnsVersion;
+      return [
+        {
+          width: 45,
+          type: 'selection',
+          columnKey: 'selection',
+          align: 'center',
+          slot: 'selection',
+          fixed: 'left'
+          // selectable: (row, index) => {
+          //   if (row.children) {
+          //   }
+          //   return this.dispatchPermission(row);
+          // }
+        },
+        {
+          columnKey: 'index',
+          slot: 'index',
+          label: '序号',
+          type: 'index',
+          width: 55,
+          align: 'center',
+          showOverflowTooltip: true,
+          fixed: 'left'
+        },
+        {
+          slot: 'code',
+          label: '生产订单号',
+          align: 'center',
+          minWidth: 210,
+          sortable: true
+        },
+        {
+          prop: 'productionPlanCode',
+          label: '计划编号',
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'produceRoutingName',
+          label: '工艺路线',
+          align: 'center',
+          minWidth: 170
+        },
+        {
+          prop: 'productCode',
+          label: '编码',
+          align: 'center',
+          minWidth: 120
+        },
+        {
+          prop: 'productName',
+          label: '名称',
+          align: 'center',
+          minWidth: 170
+        },
+        {
+          prop: 'productionCodes',
+          label: '生产编号',
+          align: 'center',
+          minWidth: 150,
+          showOverflowTooltip: true
+        },
+        {
+          prop: 'brandNo',
+          label: '牌号',
+          align: 'center'
+        },
 
-          {
-            prop: 'priority',
-            label: '优先级',
-            align: 'center',
-            minWidth: 120,
-            slot: 'priority',
-            sortable: 'custom'
-          },
+        {
+          prop: 'batchNo',
+          label: '批次号',
+          align: 'center',
+          minWidth: 100,
+          showOverflowTooltip: true
+        },
+        {
+          prop: 'model',
+          label: '型号',
+          align: 'center',
+          showOverflowTooltip: true
+        },
 
-          {
-            prop: 'formingNum',
-            label: '要求生产数量',
-            align: 'center',
-            showOverflowTooltip: true,
-            minWidth: 110
-          },
-          {
-            prop: 'formingWeight',
-            label: '要求生产重量',
-            align: 'center',
-            showOverflowTooltip: true,
-            minWidth: 110,
-            slot: 'formingWeight'
-          },
-          {
-            prop: 'planStartTime',
-            label: '计划开始时间',
-            align: 'center',
-            showOverflowTooltip: true,
-            minWidth: 110
-          },
+        {
+          prop: 'priority',
+          label: '优先级',
+          align: 'center',
+          minWidth: 120,
+          slot: 'priority',
+          sortable: 'custom'
+        },
 
-          {
-            prop: 'planCompleteTime',
-            label: '计划结束时间',
-            align: 'center',
-            showOverflowTooltip: true,
-            minWidth: 110
-          },
+        {
+          prop: 'formingNum',
+          label: '要求生产数量',
+          align: 'center',
+          showOverflowTooltip: true,
+          minWidth: 110
+        },
+        {
+          prop: 'formingWeight',
+          label: '要求生产重量',
+          align: 'center',
+          showOverflowTooltip: true,
+          minWidth: 110,
+          slot: 'formingWeight'
+        },
+        {
+          prop: 'planStartTime',
+          label: '计划开始时间',
+          align: 'center',
+          showOverflowTooltip: true,
+          minWidth: 110
+        },
 
-          {
-            prop: 'workCenterName',
-            label: '工作中心',
-            align: 'center',
-            minWidth: 110,
-            showOverflowTooltip: true
-          },
+        {
+          prop: 'planCompleteTime',
+          label: '计划结束时间',
+          align: 'center',
+          showOverflowTooltip: true,
+          minWidth: 110
+        },
 
-          {
-            prop: 'firstTaskName',
-            label: '首工序',
-            align: 'center',
-            minWidth: 110,
-            showOverflowTooltip: true
-          },
+        {
+          prop: 'workCenterName',
+          label: '工作中心',
+          align: 'center',
+          minWidth: 110,
+          showOverflowTooltip: true
+        },
 
-          {
-            prop: 'createTime',
-            label: '创建时间',
-            align: 'center',
-            showOverflowTooltip: true,
-            minWidth: 110,
-            sortable: 'custom'
-          },
-          {
-            slot: 'status',
-            label: '状态',
-            align: 'center',
-            formatter: (row) => {
-              const obj = this.statusOpt.find((i) => i.value == row.status);
-              return obj && obj.label;
-            }
-          },
-          {
-            prop: 'customerName',
-            label: '客户名称',
-            align: 'center',
-            showOverflowTooltip: true
-          },
-          {
-            prop: 'serialNo',
-            label: '客户代号',
-            align: 'center',
-            showOverflowTooltip: true
-          },
+        {
+          prop: 'firstTaskName',
+          label: '首工序',
+          align: 'center',
+          minWidth: 110,
+          showOverflowTooltip: true
+        },
 
-          {
-            prop: 'simpleName',
-            label: '客户简称',
-            align: 'center',
-            showOverflowTooltip: true
+        {
+          prop: 'createTime',
+          label: '创建时间',
+          align: 'center',
+          showOverflowTooltip: true,
+          minWidth: 110,
+          sortable: 'custom'
+        },
+        {
+          slot: 'status',
+          label: '状态',
+          align: 'center',
+          formatter: (row) => {
+            const obj = this.statusOpt.find((i) => i.value == row.status);
+            return obj && obj.label;
           }
-        ];
+        },
+        {
+          prop: 'customerName',
+          label: '客户名称',
+          align: 'center',
+          showOverflowTooltip: true
+        },
+        {
+          prop: 'serialNo',
+          label: '客户代号',
+          align: 'center',
+          showOverflowTooltip: true
+        },
+
+        {
+          prop: 'simpleName',
+          label: '客户简称',
+          align: 'center',
+          showOverflowTooltip: true
+        }
+      ];
+    },
+
+    checkRowData() {
+      return (row) => {
+        return row.checkedata ? true : false;
+      };
+    }
+  },
+  created() {
+    this.getFieldModel();
+  },
+
+  methods: {
+    // 单选数据
+    selectRow(e, row) {
+      if (e) {
+        this.selectionMap[row.id] = {
+          id: row.id,
+          firstTaskId: row.firstTaskId,
+          productName: row.productName,
+          productCode: row.productCode,
+          code: row.code,
+          productionPlanCode: row.productionPlanCode,
+          batchNo: row.batchNo,
+          formingNum: row.formingNum
+        };
+      } else {
+        delete this.selectionMap[row.id];
+      }
+    },
+
+    // 批量派单
+    batchDispatch() {
+      let list = Object.values(this.selectionMap);
+      if (list.length === 0) {
+        this.$message.warning('请至少选择一条派单的数据');
       }
+      this.$refs.batchRef.open(list);
     },
-    created() {
-      this.getFieldModel();
+    assignTypeFn(e) {
+    },
+    statusFormatter(status) {
+      const obj = this.statusOpt.find((i) => i.value == status);
+      return obj && obj.label;
+    },
+    /* 表格数据源 */
+    datasource({ page, limit, where }) {
+      this.selectionMap = {};
+      if (where.status) {
+        where.statusList = [];
+        where.statusList.push(where.status);
+      }
+      return getList({
+        pageNum: page,
+        size: limit,
+        ...where,
+        ...this.sort
+      });
     },
 
-    methods: {
-      // 批量派单
-      batchDispatch() {
-        if (this.selection.length === 0) {
-          return this.$message.warning('请至少选择一条数据');
-        }
-        let firstTaskId = this.selection[0].firstTaskId;
-        for (let i = 0; i < this.selection.length; i++) {
-          let item = this.selection[i];
-          // if(this.dispatchPermission(item) == false){
-          //   return this.$message.warning('请选择有派单按钮的进行批量派单');
-          // }
-          if (item.firstTaskId != firstTaskId) {
-            return this.$message.warning('请选择首工序一致的数据进行批量派单');
+    /* 数据转为树形结构 */
+    parseData(data) {
+      const obj = {
+        ...data,
+        list: this.$util.toTreeData({
+          data: data.list,
+          count: data.total,
+
+          idField: 'code',
+          parentIdField: 'originalCode'
+        })
+      };
+      return obj;
+    },
+
+    getFieldModel() {
+      fieldModel({ fieldModel: 't_main_category' }).then((res) => {
+        const privateColumn = [
+          {
+            columnKey: 'action',
+            label: '操作',
+            width: 120,
+            align: 'center',
+            resizable: false,
+            fixed: 'right',
+            slot: 'action'
           }
-        }
-        console.log(this.selection, '选择');
-      },
-      assignTypeFn(e) {},
-      statusFormatter(status) {
-        const obj = this.statusOpt.find((i) => i.value == status);
-        return obj && obj.label;
-      },
-      /* 表格数据源 */
-      datasource({ page, limit, where }) {
-        if (where.status) {
-          where.statusList = [];
-          where.statusList.push(where.status);
-        }
-        return getList({
-          pageNum: page,
-          size: limit,
-          ...where,
-          ...this.sort
+        ];
+
+        let newRes = res.map((m) => {
+          return {
+            prop: 'extField.' + m.prop,
+            label: m.label,
+            align: 'center',
+            showOverflowTooltip: true
+          };
         });
-      },
 
-      /* 数据转为树形结构 */
-      parseData(data) {
-        const obj = {
-          ...data,
-          list: this.$util.toTreeData({
-            data: data.list,
-            count: data.total,
+        this.newColumns = [...this.columns, ...newRes, ...privateColumn];
 
-            idField: 'code',
-            parentIdField: 'originalCode'
-          })
-        };
-        console.log(obj, 'obj ------');
-        return obj;
-      },
+        this.$forceUpdate();
+      });
+    },
 
-      getFieldModel() {
-        fieldModel({ fieldModel: 't_main_category' }).then((res) => {
-          const privateColumn = [
-            {
-              columnKey: 'action',
-              label: '操作',
-              width: 120,
-              align: 'center',
-              resizable: false,
-              fixed: 'right',
-              slot: 'action'
-            }
-          ];
-
-          let newRes = res.map((m) => {
-            return {
-              prop: 'extField.' + m.prop,
-              label: m.label,
-              align: 'center',
-              showOverflowTooltip: true
-            };
-          });
-
-          this.newColumns = [...this.columns, ...newRes, ...privateColumn];
-
-          this.$forceUpdate();
-        });
-      },
+    // 下达
+    toRelease(row) {
+      this.current = row;
+      this.visible = true;
+      this.FirstTaskIdFn();
+      this.WorkCenterIdFn();
+      this.form.singleReport = this.clientEnvironmentId == 2 ? 0 : 1;
+    },
+    // 下达
+    confirm() {
+      this.$refs.form.validate((valid) => {
+        if (valid) {
+          const loading = this.$loading({ text: '加载中...' });
+
+          if (this.form.assignType * 1 == 2) {
+            this.form.workstationIds = [];
+          } else {
+            this.form.crewIds = [];
+          }
 
-      // 下达
-      toRelease(row) {
-        this.current = row;
-        this.visible = true;
-        this.FirstTaskIdFn();
-        this.WorkCenterIdFn();
-        this.form.singleReport = this.clientEnvironmentId == 2 ? 0 : 1;
-      },
-      // 下达
-      confirm() {
-        this.$refs.form.validate((valid) => {
-          if (valid) {
-            const loading = this.$loading({ text: '加载中...' });
-
-            if (this.form.assignType * 1 == 2) {
-              this.form.workstationIds = [];
-            } else {
-              this.form.crewIds = [];
-            }
-
-            releaseWorkOrder({
-              id: this.current.id,
-              ...this.form
+          releaseWorkOrder({
+            id: this.current.id,
+            ...this.form
+          })
+            .then((res) => {
+              if (res) {
+                this.$message.success('成功');
+
+                this.reData();
+                this.reload();
+                this.visible = false;
+              }
             })
-              .then((res) => {
-                if (res) {
-                  this.$message.success('成功');
-
-                  this.reData();
-                  this.reload();
-                  this.visible = false;
-                }
-              })
-              .finally(() => {
-                loading.close();
-              });
-          }
-        });
-      },
-      close() {
-        this.visible = false;
-        this.reData();
-      },
-      reData() {
-        this.form = {
-          assignType: 1,
-          crewIds: '',
-          workstationIds: '',
-          teamId: '',
-          singleReport: this.clientEnvironmentId == 2 ? 0 : 1
-        };
-      },
+            .finally(() => {
+              loading.close();
+            });
+        }
+      });
+    },
+    close() {
+      this.visible = false;
+      this.reData();
+    },
+    reData() {
+      this.form = {
+        assignType: 1,
+        crewIds: '',
+        workstationIds: '',
+        teamId: '',
+        singleReport: this.clientEnvironmentId == 2 ? 0 : 1
+      };
+    },
 
-      /* 刷新表格 */
-      reload(where) {
-        this.$nextTick(() => {
-          this.$refs.table.reload({ page: 1, where });
-        });
-      },
+    /* 刷新表格 */
+    reload(where) {
+      this.$nextTick(() => {
+        this.$refs.table.reload({ page: 1, where });
+      });
+    },
 
-      onSortChange(e) {
-        let sort = {
-          orderBy: e.order,
-          sortName: e.prop
-        };
-        this.sort = sort;
-        this.reload();
-      },
+    onSortChange(e) {
+      let sort = {
+        orderBy: e.order,
+        sortName: e.prop
+      };
+      this.sort = sort;
+      this.reload();
+    },
 
-      sortTop(row) {
-        row.priority = Number(row.priority) + 1;
-        this.priorityChange(row);
-      },
-      sortBottom(row) {
-        if (row.priority <= 1) {
-          return;
-        }
-        row.priority = Number(row.priority) - 1;
-        this.priorityChange(row);
-      },
+    sortTop(row) {
+      row.priority = Number(row.priority) + 1;
+      this.priorityChange(row);
+    },
+    sortBottom(row) {
+      if (row.priority <= 1) {
+        return;
+      }
+      row.priority = Number(row.priority) - 1;
+      this.priorityChange(row);
+    },
 
-      FirstTaskIdFn() {
-        listByFirstTaskId(this.current.firstTaskId).then((res) => {
-          this.stationList = res;
-        });
-      },
+    FirstTaskIdFn() {
+      listByFirstTaskId(this.current.firstTaskId).then((res) => {
+        this.stationList = res;
+      });
+    },
 
-      WorkCenterIdFn() {
-        listByWorkCenterId(this.current.workCenterId).then((res) => {
-          this.teamsList = res;
+    WorkCenterIdFn() {
+      listByWorkCenterId(this.current.workCenterId).then((res) => {
+        this.teamsList = res;
 
-          this.$nextTick(() => {
-            if (this.teamId) {
-              this.$set(this.form, 'teamId', this.teamId);
-              this.stationChange();
-            }
+        this.$nextTick(() => {
+          if (this.teamId) {
+            this.$set(this.form, 'teamId', this.teamId);
+            this.stationChange();
+          }
 
-            // this.$refs.form.clearValidate();
-          });
+          // this.$refs.form.clearValidate();
         });
-      },
+      });
+    },
 
-      // 拆分
-      toUnpack(row) {
-        this.$refs.unpackRef.open(row);
-      },
-      //派单
-      toReleaseOpen(row) {
-        this.dispatchRow = { ...row };
-        this.dispatchRow.initialWeight = row.formingWeight
-          ? row.formingWeight + row.newWeightUnit
-          : '';
-        this.dispatchVisible = true;
-        // getTaskIdByInstanceId(row.firstTaskId)
-        //   .then((res) => {
-        //     if (res) {
-        // }
-        // })
-        // .catch((err) => {
-        //   this.$message.error(err.message);
-        // });
-      },
+    // 拆分
+    toUnpack(row) {
+      this.$refs.unpackRef.open(row);
+    },
+    //派单
+    toReleaseOpen(row) {
+      this.dispatchRow = { ...row };
+      this.dispatchRow.initialWeight = row.formingWeight
+        ? row.formingWeight + row.newWeightUnit
+        : '';
+      this.dispatchVisible = true;
+      // getTaskIdByInstanceId(row.firstTaskId)
+      //   .then((res) => {
+      //     if (res) {
+      // }
+      // })
+      // .catch((err) => {
+      //   this.$message.error(err.message);
+      // });
+    },
 
-      createSuccess() {
-        this.reload();
-      },
+    createSuccess() {
+      this.reload();
+    },
 
-      stationChange() {
-        this.crewList = [];
-        this.crewIds = [];
+    stationChange() {
+      this.crewList = [];
+      this.crewIds = [];
 
-        listUserByIds([this.form.teamId]).then((res) => {
-          this.crewList = res;
-        });
-      },
+      listUserByIds([this.form.teamId]).then((res) => {
+        this.crewList = res;
+      });
+    },
 
-      priorityChange(row) {
-        if (row.priority > 10) {
-          row.priority = 10; // 如果大于 10,则设置为 10
-        } else if (row.priority < 0) {
-          row.priority = 0; // 如果小于 0,则设置为 0
-        }
+    priorityChange(row) {
+      if (row.priority > 10) {
+        row.priority = 10; // 如果大于 10,则设置为 10
+      } else if (row.priority < 0) {
+        row.priority = 0; // 如果小于 0,则设置为 0
+      }
 
-        this.priorityFn(row);
-      },
+      this.priorityFn(row);
+    },
 
-      priorityFn: debounce(function (row) {
-        let params = {
-          id: row.id,
-          priority: row.priority
-        };
-        updatePriority(params).then((res) => {});
-      }, 800)
-    }
-  };
+    priorityFn: debounce(function(row) {
+      let params = {
+        id: row.id,
+        priority: row.priority
+      };
+      updatePriority(params).then((res) => {
+      });
+    }, 800)
+  }
+};
 </script>
 
 <style lang="scss" scoped>
-  // ::v-deep .el-table__row {
-  //   height: 51px !important;
-  // }
+// ::v-deep .el-table__row {
+//   height: 51px !important;
+// }
+
+::v-deep thead {
+  .cell {
+    .el-checkbox {
+      display: none;
+    }
+  }
+}
 </style>

+ 922 - 0
src/views/workOrder/mixins/release.js

@@ -0,0 +1,922 @@
+import {
+  listByFirstTaskId,
+  listUserByIds,
+  listWorkCenter,
+  listByWorkCenter,
+  lineByCurrentUser,
+  taskSave,
+  taskRevoked,
+  taskAssignment,
+  listAssign,
+  checkAssignConfirm,
+  resetAssignee,
+  listByRoutingIds,
+  listByFactoryId,
+  checkExists
+} from '@/api/mainData/index.js';
+import { releaseWorkOrder } from '@/api/workOrder/index.js';
+export default {
+  data() {
+    return {};
+  },
+  methods: {
+    // 查询班次
+    getClassesData() {
+      if (!this.current.factoriesId) return;
+      listByFactoryId(this.current.factoriesId).then((res) => {
+        if (!res) return;
+        this.shiftList = res;
+      });
+    },
+    // 查询是否派单
+    queryCheckExists() {
+      let params = {
+        workOrderId: this.current.id,
+        workCenterId: 123,
+        teamId: 345
+      };
+      checkExists(params)
+        .then((res) => {
+          if (!res) return;
+          this.isDispatchRow = res;
+          if (res.hasExists) {
+            this.form.taskAss = 0;
+            this.orderDis = true;
+            this.procTaskDis = false;
+            // 报工类型 判断
+            this.form.singleReport = res.dispatchType;
+            if (res.dispatchType == 1) {
+              this.batchDis = true;
+              this.singleDis = false;
+            } else {
+              this.singleDis = true;
+              this.batchDis = false;
+            }
+          } else {
+            this.batchDis = false;
+            this.singleDis = false;
+            this.orderDis = false;
+            this.procTaskDis = false;
+          }
+        })
+        .catch((err) => {
+          this.$message.error(err.message);
+        });
+    },
+    // 获取当前年月日
+    getFormattedDate() {
+      const now = new Date();
+      const year = now.getFullYear();
+      const month = String(now.getMonth() + 1).padStart(2, '0');
+      const date = String(now.getDate()).padStart(2, '0');
+      return `${year}-${month}-${date}`;
+    },
+    // 查询工作中心
+    async workCenterData() {
+      // const res = await listWorkCenter(this.current.firstTaskId);
+      const res = await listWorkCenter(this.current.firstTaskId);
+      this.workCenterList = res;
+      if (res.length > 0) {
+        this.form.factoryName = res[0].factoryName;
+        this.form.workCenterId = res[0].id;
+        // 查首工序
+        await this.changeWork(res[0].id); // 选择工作中心
+        this.getProductionData(res[0].id); // 查询产线
+        this.FirstTaskIdFn(); // 查询工位数据
+      } else {
+        this.$message.warning(
+          `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
+        );
+      }
+    },
+    // 查询工序列表数据
+    changeDispatch(e) {
+      this.tabsLoading = true;
+      // listByWorkCenter(this.form.workCenterId)
+      listByRoutingIds([this.current.produceRoutingId])
+        .then((res) => {
+          this.tabsLoading = false;
+          // 如果没有首工序的数据 就不能选择工序任务派单
+          if (!res || res.length == 0) {
+            this.processList = [];
+            this.form.taskAss = 1;
+            this.procTaskDis = true;
+            return;
+          }
+          this.procTaskDis = false;
+          let list = [];
+          let isExist = false;
+          let firstTaskindex = '';
+          res.forEach((item, index) => {
+            isExist = isExist
+              ? isExist
+              : item.sourceTaskId === this.current.firstTaskId;
+            // 如果有首工序id 存储它的下标
+            if (isExist) {
+              if (!firstTaskindex && firstTaskindex !== 0) {
+                firstTaskindex = index;
+              }
+            }
+            let obj = {
+              id: item.sourceTaskId, //工序 id
+              name: item.name, //工序 名称
+              assignType: 1, // 默认的指派数据
+              assignName: '工位', // 默认指派数据名称
+              list: [], // 当前工序下面的指派 绑定的表格
+              selection: [], // 当前工序下面的指派 选中的数据
+              code: item.code, // 工序 编码
+              index: index, // 当前工序数据的下标
+              radioBun: {
+                // 指派按钮的操作状态 绑定 默认false(可操作)
+                stationDis: false, // 工位按钮
+                staffDis: false, // 人员按钮
+                lineDis: false // 产线按钮
+              },
+              startDate: '', // 开始日期 (当前工序中最早的计划开始时间)
+              endDate: '' // 结束日期 (当前工序中最晚的计划结束时间)
+            };
+            list.push(obj);
+          });
+          this.firstTaskindex = firstTaskindex;
+          // 存在首工序报工
+          if (isExist) {
+            this.processList = list;
+            this.processId = res[0].sourceTaskId;
+            // this.handleClick({ name: res[0].sourceTaskId });
+            this.initializeQuery();
+          } else {
+            this.processList = [];
+            this.form.taskAss = 1;
+            this.procTaskDis = true;
+            this.$message.warning('当前任务没有首工序报工');
+          }
+        })
+        .catch((err) => {
+          this.processList = [];
+          this.tabsLoading = false;
+          this.$message.error(err.message);
+        });
+    },
+    // 初始化查询 查询全部工序操作过的数据
+    async initializeQuery() {
+      try {
+        // 不存在 班组数据的话 就不调用这个方法
+        if (!this.form.teamId) {
+          return;
+        }
+        let params = {
+          workOrderId: this.current.id,
+          workCenterId: this.form.workCenterId,
+          teamId: this.form.teamId
+        };
+        let processMap = {};
+        this.processList.map((el, index) => (processMap[el.id] = index));
+        const res = await listAssign(params);
+        let isFirstData = false; // 判断默认第一道工序是否操作过
+        if (res && res.length > 0) {
+          res.map((el) => {
+            let index = processMap[el.taskId];
+            if (index === 0 && el.assignees && el.assignees.length > 0) {
+              isFirstData = true; // 操作过
+            }
+            // 这里第三个参数传空数组就好了 会自动计算的
+            setTimeout(() => {
+              this.operationalData(index, [el], []);
+            });
+          });
+          // 没有操作过 默认获取一下表格数据
+          if (!isFirstData) {
+            this.handleClick({ name: this.processId });
+          }
+        } else {
+          this.handleClick({ name: this.processId });
+        }
+        console.log(this.processList, '工序列表');
+      } catch (err) {}
+    },
+    // 选择工作中心
+    async changeWork(e) {
+      this.form.workCenterId = e;
+      // this.changeDispatch(); // 查询工序列表
+      let data = this.workCenterList.find((item) => item.id == e);
+      this.form.workCenterName = data.name;
+      this.teamList = data.teamList || []; // 重新获取 班组数据
+      if (this.teamList.length > 0) {
+        this.form.teamId = this.teamList[0].id;
+        await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
+      } else {
+        // 如果没有 班组数据 将人员数据清空 并且判断
+        this.crewList = [];
+        this.form.teamId = '';
+        let data = this.processList.find((item) => item.id == this.processId);
+        if (data.assignType == 2) {
+          this.$set(data, 'list', []);
+        }
+      }
+    },
+    // 选择班组 查询人员的数据
+    async changeGroups(e) {
+      let data = this.teamList.find((item) => item.id == e);
+      this.form.teamName = data.name;
+      try {
+        const res = await listUserByIds([e]);
+        this.crewList =
+          res &&
+          res.map((el) => {
+            return {
+              code: el.code,
+              name: el.name,
+              id: el.id
+            };
+          });
+        // 查看当前的工序数据是不是 选择的人员 是的话同步更改
+        if (!this.processId || this.processId == 0) {
+          return;
+        }
+
+        // if (data.assignType == 2) {
+
+        this.handleClick({ name: this.processId });
+        this.btnInit();
+        // this.$set(data, 'list', res);
+        // }
+      } catch {
+        this.crewList = [];
+      }
+    },
+    // 工序按钮初始化
+    btnInit() {
+      let data = this.processList.find((item) => item.id == this.processId);
+      this.$set(data.radioBun, 'lineDis', false);
+      this.$set(data.radioBun, 'staffDis', false);
+      this.$set(data.radioBun, 'stationDis', false);
+      this.$set(data, 'assignName', '工位');
+      this.$set(data, 'assignType', 1);
+    },
+    // 获取产线数据
+    async getProductionData() {
+      const res = await lineByCurrentUser(this.form.workCenterId);
+      this.productionList =
+        res &&
+        res.map((el) => {
+          return {
+            name: el.name,
+            code: el.code,
+            id: el.id
+          };
+        });
+    },
+    // 查询工位数据
+    FirstTaskIdFn() {
+      listByFirstTaskId(this.current.firstTaskId)
+        .then((res) => {
+          this.stationList = res;
+          this.changeDispatch();
+        })
+        .catch((err) => {
+          this.stationList = [];
+          this.$message.error(err.message);
+        });
+    },
+    // 重置(单个)
+    resetData(row, item) {
+      if (!row.changeId) {
+        return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
+      }
+      this.toolbarLoading = true;
+      resetAssignee(row.changeId)
+        .then((res) => {
+          this.toolbarLoading = false;
+          if (res) {
+            this.$message.success('操作成功');
+            // 更改当前表格数据
+            this.setCurrentTab(item);
+          }
+        })
+        .catch((err) => {
+          this.toolbarLoading = false;
+          this.$message.error(err.message);
+        });
+    },
+    // 撤回的逻辑
+    getWithdrawT(row, type) {
+      if (type != 2) {
+        return true;
+      }
+      let isFlag = true;
+      row.selection.forEach((item) => {
+        if (!item.status) {
+          isFlag = false;
+          return;
+        }
+        if (!item.status.code) {
+          isFlag = false;
+        }
+      });
+      return isFlag;
+    },
+    // 派单
+    dispatch(row, type) {
+      if (row.selection.length == 0) {
+        return this.$message.warning('请最少选择一条数据');
+      }
+      let isWithdraw = this.getWithdrawT(row, type);
+      if (!isWithdraw) {
+        this.$message.warning('只有状态为派单的数据才能进行撤回');
+        return;
+      }
+      let assignees = [];
+      let changeIds = [];
+      let flag = true; // 是否填写 校验
+      row.selection.forEach((item) => {
+        if (!item.quantity || !item.startTime || !item.endTime) {
+          flag = false;
+          return;
+        }
+
+        let Aobj = {
+          assigneeId: item.id,
+          quantity: item.quantity,
+          weight: item.weight,
+          startTime: item.startTime,
+          endTime: item.endTime,
+          assigneeType: row.assignType,
+          assigneeName: item.name
+        };
+        if (item.teamTimeDetailId) {
+          Aobj.teamTimeDetailId = item.teamTimeDetailId;
+        }
+        assignees.push(Aobj);
+        changeIds.push(item.changeId);
+      });
+      // 校验没过 就不往下进行
+      if (!flag) {
+        this.$message.warning('请将所选数据的 数量,开始时间,完成时间 填写完毕');
+        return;
+      }
+      let data = null;
+      this.toolbarLoading = true;
+      if (type == 2) {
+        data = changeIds;
+      } else {
+        data = {
+          taskId: this.processId,
+          taskName: row.name,
+          taskCode: row.code,
+          teamName: this.form.teamName,
+          teamId: this.form.teamId,
+          workCenterId: this.form.workCenterId,
+          workCenterName: this.form.workCenterName,
+          workOrderId: this.current.id,
+          dispatchMethod: 0,
+          assignees
+        };
+        // 先判断是否派单过 有的话直接用前面派单的 类型数据 否则就是自己选择的数据
+        if (this.isDispatchRow.hasExists) {
+          data.dispatchType = this.isDispatchRow.dispatchType;
+        } else {
+          data.dispatchType = this.form.singleReport;
+        }
+      }
+      const api =
+        type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
+      api(data)
+        .then((res) => {
+          this.toolbarLoading = false;
+          if (res) {
+            this.$message.success('操作成功');
+            // 更改当前表格数据
+            this.setCurrentTab(row);
+            // 查询是否派单
+            this.queryCheckExists();
+          }
+        })
+        .catch((err) => {
+          this.toolbarLoading = false;
+          this.$message.error(err.message);
+        });
+    },
+    cancel() {
+      this.$emit('update:dispatchVisible', false);
+    },
+    // 按钮操作成功后 更改当前的表格数据
+    setCurrentTab(row) {
+      let arr = [];
+      if (row.assignType == 1) {
+        arr = this.stationList;
+      } else if (row.assignType == 2) {
+        arr = this.crewList;
+      } else {
+        arr = this.productionList;
+      }
+      this.getAssignData(row.index, arr);
+    },
+    // 最后提交
+    async confirm() {
+      if (this.form.singleReport != 1 && this.form.singleReport != 0) {
+        this.$message.warning('请先选择报工类型');
+        return;
+      }
+      // if (!this.form.singleReport) {
+
+      // }
+      if (!this.form.teamId) {
+        this.$message.warning('请先选择班组');
+        return;
+      }
+      if (this.form.taskAss == 1) {
+        this.issue();
+        // 按原来的逻辑
+        return;
+      }
+      // 获取到首工序id 的 绑定表格数据
+      let data = this.processList[this.firstTaskindex];
+      // 是否进行首工序派单
+      let isFirstDispatch = false;
+      let dispatchArr = []; // 已派单数据
+      data.list.map((item) => {
+        if (!item.status) {
+          return;
+        }
+        if (item.status.code == 1) {
+          isFirstDispatch = true;
+          dispatchArr.push(item.id);
+        }
+      });
+      // 判断是否进行首工序派单
+      if (!isFirstDispatch) {
+        this.$message.warning(`请您先进行首工序任务(${data.name}工序)派单`);
+        this.handleClick({ name: data.id });
+        return;
+      }
+      let totalSum = 0;
+      // 判断派单的数据 数量相加是否为 要求生产数量
+      data.list.map((item) => {
+        if (item.status && item.status.code == 1) {
+          totalSum += item.quantity - 0;
+        }
+      });
+      if (totalSum != this.current.formingNum - 0) {
+        this.$message.warning(
+          `首工序已派单的数据数量相加需要等于要求生产数量${this.current.formingNum}`
+        );
+        this.handleClick({ name: data.id });
+        return;
+      }
+      let params = {
+        teamId: this.form.teamId,
+        workCenterId: this.form.workCenterId,
+        workOrderId: this.current.id
+      };
+      this.toolbarLoading = true;
+      try {
+        const res = await checkAssignConfirm(params);
+        if (!res) {
+          this.toolbarLoading = false;
+          return;
+        }
+        let paramsD = {
+          assignType: data.assignType,
+          singleReport: this.form.singleReport,
+          teamId: this.form.teamId,
+          crewIds: data.assignType == 2 ? dispatchArr : [], // 人员 2
+          workstationIds: data.assignType == 1 ? dispatchArr : [], // 工位 1
+          id: this.current.id
+        };
+        const response = await releaseWorkOrder(paramsD);
+        this.toolbarLoading = false;
+        if (response) {
+          this.$message.success('操作成功');
+          this.cancel();
+          this.$emit('createSuccess');
+        }
+      } catch (err) {
+        this.toolbarLoading = false;
+        this.$message.error(err.message);
+      }
+    },
+    // 下达
+    issue() {
+      if (this.form.assignType == 1) {
+        if (!this.form.workstationIds || this.form.workstationIds.length == 0) {
+          this.$message.warning('请选择工位数据');
+          return;
+        }
+      }
+      if (this.form.assignType == 3) {
+        if (!this.form.factoryLineIds || this.form.factoryLineIds.length == 0) {
+          this.$message.warning('请选择产线数据');
+          return;
+        }
+      }
+      let data = {
+        assignType: this.form.assignType,
+        singleReport: this.form.singleReport,
+        teamId: this.form.teamId,
+        crewIds: [],
+        workstationIds: [],
+        id: this.current.id,
+        factoryLineIds: []
+      };
+      if (this.form.assignType == 1) {
+        data.workstationIds = this.form.workstationIds || [];
+      } else if (this.form.assignType == 2) {
+        data.crewIds = this.form.crewIds || [];
+      } else {
+        data.factoryLineIds = this.form.factoryLineIds || [];
+      }
+      this.toolbarLoading = true;
+      releaseWorkOrder(data)
+        .then((res) => {
+          this.toolbarLoading = false;
+          if (res) {
+            this.$message.success('操作成功');
+            this.cancel();
+            this.$emit('createSuccess');
+          }
+        })
+        .catch((err) => {
+          this.toolbarLoading = false;
+          this.$message.error(err.message);
+        });
+    },
+    // 工序选择
+    async handleClick(tab) {
+      let id = tab.name;
+      this.processId = id;
+      let data = this.processList.find((item) => item.id == this.processId);
+      await this.changeRadio(data.assignType, data.index);
+    },
+    // 指派选择
+    async changeRadio(e, index) {
+      let data = this.processList[index];
+      if (e == 1) {
+        this.dynamicName = '工位名称';
+        data.assignName = '工位';
+        await this.getAssignData(index, this.stationList);
+      } else if (e == 2) {
+        this.dynamicName = '人员名称';
+        data.assignName = '人员';
+        await this.getAssignData(index, this.crewList);
+      } else {
+        this.dynamicName = '产线名称';
+        data.assignName = '产线';
+        await this.getAssignData(index, this.productionList);
+      }
+    },
+    // 指派数据处理
+    async getAssignData(index, arr) {
+      let list = JSON.parse(JSON.stringify(arr));
+      let dataRow = this.processList[index];
+      // 不存在 班组数据的话 就不调用这个方法
+      if (!this.form.teamId) {
+        return;
+      }
+      let params = {
+        workOrderId: this.current.id,
+        workCenterId: this.form.workCenterId,
+        teamId: this.form.teamId,
+        taskId: dataRow.id
+      };
+      this.tabLoading = true;
+      try {
+        const res = await listAssign(params);
+        this.tabLoading = false;
+        // 如果 res 没有数据 说明未对数据进行操作 直接赋值
+        if (res.length == 0) {
+          this.$set(dataRow, 'list', list);
+          return;
+        }
+        // 对有操作过的数据进行赋值
+        this.operationalData(index, res, list);
+      } catch (err) {
+        this.tabLoading = false;
+        this.$message.warning(err.message);
+      }
+    },
+    // 操作过的数据 赋值
+    operationalData(index, res, list) {
+      const dataRow = this.processList[index];
+      // 键值对存储 当前工序 操作的数据  指派的code(键) 数据(list:值)
+      let arrMap = {};
+      // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
+      let codeT = null; // 表示有已操作的数据(对应的 code)
+      res[0].assignees.map((el) => {
+        let code = el.assigneeType.code;
+        if (arrMap[code]) {
+          arrMap[code].arr.push(el);
+          arrMap[code].bunDis = arrMap[code].bunDis
+            ? arrMap[code].bunDis
+            : el.status.desc
+            ? true
+            : false;
+        } else {
+          arrMap[code] = {
+            arr: [el],
+            bunDis: el.status.desc ? true : false
+          };
+        }
+        codeT = codeT ? codeT : el.status.desc ? code : '';
+      });
+      let radioBun = {
+        lineDis: false, // 产线 3
+        staffDis: false, // 人员 2
+        stationDis: false // 工位 1
+      };
+      // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
+      // 需要自动切换过去
+      let listArr = list;
+      if (codeT) {
+        if (codeT == 1) {
+          radioBun.staffDis = true;
+          radioBun.lineDis = true;
+          radioBun.stationDis = false;
+          listArr = JSON.parse(JSON.stringify(this.stationList));
+          dataRow.assignType = 1;
+          dataRow.assignName = '工位';
+        } else if (codeT == 2) {
+          radioBun.stationDis = true;
+          radioBun.lineDis = true;
+          radioBun.staffDis = false;
+          listArr = JSON.parse(JSON.stringify(this.crewList));
+          dataRow.assignType = 2;
+          dataRow.assignName = '人员';
+        } else {
+          radioBun.stationDis = true;
+          radioBun.staffDis = true;
+          radioBun.lineDis = false;
+          listArr = JSON.parse(JSON.stringify(this.productionList));
+          dataRow.assignType = 3;
+          dataRow.assignName = '产线';
+        }
+      }
+      // 切换完后 对 指派的数组数据进行赋值
+      let listMap = {};
+      listArr.map((el, index) => (listMap[el.id] = index));
+      let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
+      dataRow.startDate = ''; // 每次计算的时候清空之前的
+      dataRow.endDate = '';
+      arrList.map((item) => {
+        if (item.assigneeType.code == dataRow.assignType) {
+          let idx = listMap[item.assigneeId];
+          if (!idx && idx !== 0) {
+            return;
+          }
+          listArr[idx].status = item.status;
+          listArr[idx].startTime = item.startTime;
+          listArr[idx].endTime = item.endTime;
+          listArr[idx].quantity = item.quantity;
+          listArr[idx].weight = item.weight;
+          listArr[idx].changeId = item.id;
+          listArr[idx].teamTimeDetailId = item.teamTimeDetailId;
+          this.compareAndSetTime(listArr[idx], dataRow);
+          this.compareEndSetTime(listArr[idx], dataRow);
+        }
+      });
+      // 这里重新调用一个方法 计算出 startDate endDate
+      this.$set(dataRow, 'list', listArr);
+      this.$set(dataRow, 'radioBun', radioBun);
+    },
+    // 时间比较与赋值方法 开始时间
+    compareAndSetTime(data, dataRow) {
+      // 如果startDate为空,直接赋值为startTime
+      if (!dataRow.startDate) {
+        dataRow.startDate = data['startTime'];
+        return;
+      }
+
+      // 转换为Date对象进行比较
+      const startTimeDate = new Date(data['startTime']);
+      const startDateDate = new Date(dataRow.startDate);
+
+      // 比较时间(getTime()获取时间戳)
+      if (startTimeDate.getTime() < startDateDate.getTime()) {
+        dataRow.startDate = data['startTime'];
+      }
+    },
+    // 时间比较与赋值方法 结束时间时间
+    compareEndSetTime(data, dataRow) {
+      // 如果startDate为空,直接赋值为endTime
+      if (!dataRow.endDate) {
+        dataRow.endDate = data['endTime'];
+        return;
+      }
+      // 转换为Date对象进行比较
+      const endTimeDate = new Date(data['endTime']);
+      const endDateDate = new Date(dataRow.endDate);
+      // 比较时间(getTime()获取时间戳)
+      if (endTimeDate.getTime() > endDateDate.getTime()) {
+        dataRow.endDate = data['endTime'];
+      }
+    },
+    assignRadio(e) {},
+    // 数量正则 quantity
+    handleQuantityInput(e, row, item) {
+      // 过滤非数字字符(包括负号)
+      let value = e.replace(/[^\d]/g, '');
+      // 限制不能以 0 开头(除非是 0 本身)
+      if (value.startsWith('0') && value.length > 1) {
+        value = value.slice(1);
+      }
+      // 更新绑定值
+      row.quantity = value;
+      this.calculateQuantity(row, item);
+      this.bringWeight(row.quantity, row);
+    },
+    // 自动算重量
+    bringWeight(value, row) {
+      if (!this.current.formingWeight) {
+        this.$set(row, 'weight', 0);
+        return;
+      }
+      let weight =
+        (this.current.formingWeight / this.current.formingNum) * value;
+      if (weight > 0) {
+        weight = weight.toFixed(4) - 0;
+      }
+      this.$set(row, 'weight', weight);
+    },
+    calculateQuantity(row, item) {
+      // 如果没有该字段 就不做判断
+      if (!this.current.formingNum) {
+        return;
+      }
+      let total = 0;
+      item.list.forEach((el) => {
+        if (el.quantity) {
+          total = total + (el.quantity - 0);
+        }
+      });
+      if (total > this.current.formingNum - 0) {
+        this.$message.warning('列表数量相加不能大于目标要求生产数量');
+        row.quantity = 0;
+      }
+    },
+    // 计算重量
+    calculateWeight(row, item) {
+      // 如果没有该字段 就不做判断
+      if (!this.current.formingWeight) {
+        return;
+      }
+      let total = 0;
+      item.list.forEach((el) => {
+        if (el.weight) {
+          total = total + (el.weight - 0);
+        }
+      });
+      if (total > this.current.formingWeight - 0) {
+        this.$message.warning('列表数量相加不能大于目标要求生产数量');
+        row.weight = 0;
+      }
+    },
+    // 重量正则 weight
+    handleWeightInput(e, row, item) {
+      // 过滤非数字和非小数点字符(包括负号)
+      let value = e.replace(/[^\d.]/g, '');
+      // 限制只能有一个小数点
+      const dotCount = (value.match(/\./g) || []).length;
+      if (dotCount > 1) {
+        value = value.slice(0, value.lastIndexOf('.'));
+      }
+      // 限制不能以小数点开头
+      if (value.startsWith('.')) {
+        value = '0' + value;
+      }
+      // 更新绑定值
+      row.weight = value;
+      this.calculateWeight(row, item);
+    },
+    // 选中班次
+    shiftSelection(e, row, item) {
+      let data = this.shiftList.find((item) => item.id == e);
+      let startTime = `${this.dateValue} ${data.startTime}`;
+      let endTime = `${this.dateValue} ${data.endTime}`;
+      this.$set(row, 'startTime', startTime);
+      this.$set(row, 'endTime', endTime);
+      this.handleStartTimeChange(row, item);
+      this.handleEndTimeChange(row, item);
+    },
+    // 【开始时间变化时】触发
+    handleStartTimeChange(row, item) {
+      if (!row.startTime) {
+        return;
+      }
+      // 这一道工序的开始时间 不能小于前一道工序的结束时间
+      const startTime = new Date(row.startTime); // 开始时间
+      if (item.index !== 0) {
+        // let frontIdx = item.index - 1;
+        let frontIdx = this.calculateIndex(item.index).startIdx;
+        if (frontIdx !== 'none') {
+          let frontName = this.processList[frontIdx].name;
+          let time = this.processList[frontIdx].endDate;
+          const frontTime = new Date(time); // 前面工序的结束时间
+          if (time && startTime < frontTime) {
+            this.$message.closeAll();
+            this.$message.info(
+              `开始时间不能小于前面工序${frontName}的结束时间${time}`
+            );
+            row.startTime = time;
+            return;
+          }
+        }
+      }
+      // 这一道工序的开始时间更不能大于后一道工序的开始时间
+      if (item.index !== this.processList.length - 1) {
+        // let latterIdx = item.index + 1;
+        let latterIdx = this.calculateIndex(item.index).endIdx;
+        let time = this.processList[latterIdx].startDate;
+        let latterName = this.processList[latterIdx].name;
+        const latterTime = new Date(time); // 下一道工序的结束时间
+        if (time && startTime > latterTime) {
+          this.$message.closeAll();
+          this.$message.info(
+            `开始时间不能大于后面工序${latterName}的开始时间${time}`
+          );
+          row.startTime = '';
+          return;
+        }
+      }
+      // 校验 是否 大于结束时间  wda
+      this.checkEndTimeValid(row);
+    },
+    // 当更改一个工序开始时间 结束时间的时候
+    // 开始时间 不能小于之前工序的结束时间 ( 要先去上一道工序找 是否存在结束时间 不存在就再往前找 直到 第一道工序 )
+    // 结束时间 不能大于后面工序的开始时间 ( 要先去后一道工序找 是否存在开始时间 不存在就再往后找 直到 最后一道工序 )
+    // 计算出当前下标数据 的前后 有 开始时间 结束时间的数据下标
+    calculateIndex(index) {
+      let startIdx = 'none';
+      let endIdx = 'none';
+      // 前面工序下标
+      for (let i = index - 1; i >= 0; i--) {
+        let row = this.processList[i];
+        if (row && row.endDate) {
+          startIdx = i;
+          break;
+        }
+      }
+      // 后面工序的下标
+      for (let i = index + 1; i <= this.processList.length; i++) {
+        let row = this.processList[i];
+        if (row && row.startDate) {
+          endIdx = i;
+          break;
+        }
+      }
+      return {
+        startIdx,
+        endIdx
+      };
+    },
+    // 【结束时间变化时】触发
+    handleEndTimeChange(row, item) {
+      if (!row.endTime) {
+        return;
+      }
+      const endTime = new Date(row.endTime); // 结束时间
+      // 当前工序的结束时间 不能大于后一道工序的开始时间
+      if (item.index !== this.processList.length - 1) {
+        // let latterIdx = item.index + 1;
+        let latterIdx = this.calculateIndex(item.index).endIdx;
+        let latterName = this.processList[latterIdx].name;
+        let time = this.processList[latterIdx].startDate;
+        const latterTime = new Date(time); // 后面工序的开始时间
+        if (time && endTime > latterTime) {
+          this.$message.closeAll();
+          this.$message.info(
+            `结束时间不能大于后面工序${latterName}的开始时间${time}`
+          );
+          row.endTime = time;
+          return;
+        }
+      }
+      // 这一道工序的开始时间更不能小于于前一道工序的结束时间
+      if (item.index !== 0) {
+        // let frontIdx = item.index - 1;
+        let frontIdx = this.calculateIndex(item.index).startIdx;
+        let frontName = this.processList[frontIdx].name;
+        let time = this.processList[frontIdx].endDate;
+        const frontTime = new Date(time); // 上一道工序的结束时间
+        if (time && endTime < frontTime) {
+          this.$message.closeAll();
+          this.$message.info(
+            `结束时间不能小于前面工序${frontName}的结束时间${time}`
+          );
+          row.endTime = '';
+          return;
+        }
+      }
+      this.checkEndTimeValid(row, item);
+    },
+    // 时间校验
+    checkEndTimeValid(row) {
+      const { startTime: start, endTime: end } = row;
+      // if (!start || !end) return; // 开始/结束时间未填,跳过
+      const startTime = new Date(start); // 开始时间
+      const endTime = new Date(end); // 结束时间
+      if (endTime < startTime) {
+        row.endTime = new Date(startTime); // 修正为开始时间
+        this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
+      }
+    }
+  }
+};