| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527 |
- <template>
- <ele-modal
- :width="modelWidth"
- :visible.sync="dispatchVisible"
- :close-on-click-modal="false"
- custom-class="ele-dialog-form"
- :maxable="true"
- :title="'派单'"
- append-to-body
- :before-close="cancel"
- >
- <div class="form-wrapper">
- <el-form
- ref="form"
- :model="form"
- :inline="true"
- label-position="right"
- label-width="100px"
- >
- <el-row :gutter="10" class="basic" type="flex" style="flex-wrap: wrap">
- <el-col
- :xs="12"
- :sm="12"
- :md="12"
- :lg="8"
- :xl="6"
- v-for="item in fieldList"
- :key="item.prop"
- >
- <el-form-item :label="item.label">
- <!-- <div class="item_label">{{ current[item.prop] }}</div> -->
- <el-input :value="fieldValue(item.prop)" disabled />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="10">
- <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
- <el-form-item label="所属工厂:">
- <el-input v-model="form.factoryName" :disabled="true"> </el-input>
- </el-form-item>
- </el-col>
- <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
- <el-form-item label="所属工作中心:">
- <el-select
- style="width: 100%"
- v-model="form.workCenterId"
- placeholder="请选择"
- @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 :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
- <el-form-item label="所属班组:" required>
- <el-select
- style="width: 100%"
- v-model="form.teamId"
- placeholder="请选择"
- @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">
- <!-- v-if="clientEnvironmentId != 2" -->
- <el-radio :label="1" :disabled="singleDis">单件报工</el-radio>
- <el-radio :label="0" :disabled="batchDis">批量报工</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item label="派单方式:" prop="taskAss">
- <!-- @change="changeDispatch" -->
- <el-radio-group v-model="form.taskAss">
- <el-radio :label="1" :disabled="orderDis">生产订单派单</el-radio>
- <el-radio :label="0" :disabled="procTaskDis"
- >工序任务派单</el-radio
- >
- </el-radio-group>
- </el-form-item>
- </el-row>
- <el-row v-if="form.taskAss == 1">
- <el-col :span="24">
- <el-form-item label="指派:" prop="assignType">
- <el-radio-group
- v-model="form.assignType"
- size="mini"
- @change="assignRadio"
- >
- <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-form-item required label="工位:" 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="人员:" 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-item label="产线:" v-if="form.assignType == 3" required>
- <el-select
- class="ele-block"
- v-model="form.factoryLineIds"
- placeholder="请选择产线"
- size="mini"
- filterable
- multiple
- >
- <el-option
- v-for="item in productionList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-row>
- <el-tabs
- class="process_list"
- v-model="processId"
- type="border-card"
- @tab-click="handleClick"
- v-show="form.taskAss == 0"
- v-loading="tabsLoading"
- >
- <el-tab-pane
- v-for="(item, index) in processList"
- :key="item.id"
- :label="item.name"
- :name="item.id"
- >
- <ele-pro-table
- class="table"
- ref="tableRef"
- :columns="columns"
- :datasource="item.list"
- cache-key="systemRoleTable"
- :pageSize="20"
- v-loading="tabLoading"
- :selection.sync="item.selection"
- >
- <template v-slot:toolbar>
- <el-button
- type="primary"
- @click="dispatch(item, 1)"
- :loading="toolbarLoading"
- >
- 派单
- </el-button>
- <el-button
- type="primary"
- @click="dispatch(item, 2)"
- :loading="toolbarLoading"
- >
- 撤回
- </el-button>
- <el-button
- type="primary"
- @click="dispatch(item, 3)"
- :loading="toolbarLoading"
- >
- 保存
- </el-button>
- <div style="margin-left: 50px; display: inline-block">
- <span
- class="text"
- style="
- font-weight: bold;
- font-size: 14px;
- margin-right: 8px;
- "
- >指派:</span
- >
- <el-radio-group
- v-model="item.assignType"
- size="mini"
- @change="(e) => changeRadio(e, index)"
- >
- <el-radio-button
- :label="1"
- :disabled="radioBun(item, 'stationDis')"
- >工位</el-radio-button
- >
- <el-radio-button
- :label="2"
- :disabled="radioBun(item, 'staffDis')"
- >人员</el-radio-button
- >
- <el-radio-button
- :label="3"
- :disabled="radioBun(item, 'lineDis')"
- >产线</el-radio-button
- >
- </el-radio-group>
- </div>
- <div
- style="margin-left: 50px; display: inline-block"
- v-if="timeSlot(item)"
- >
- 时间段: {{ item.startDate }} ----- {{ item.endDate }}
- </div>
- </template>
- <template v-slot:quantity="{ row }">
- <el-input
- :disabled="permissions(row)"
- type="number"
- v-model="row.quantity"
- placeholder="请输入数量"
- @input="(e) => handleQuantityInput(e, row, item)"
- ></el-input>
- </template>
- <template v-slot:weight="{ row }">
- <el-input
- :disabled="permissions(row)"
- type="number"
- v-model="row.weight"
- placeholder="请输入重量"
- @input="(e) => handleWeightInput(e, row, item)"
- ></el-input>
- </template>
- <template v-slot:teamTimeDetailId="{ row }">
- <el-select
- :disabled="permissions(row)"
- v-model="row.teamTimeDetailId"
- placeholder="班次"
- @change="(e) => shiftSelection(e, row, item)"
- >
- <el-option
- v-for="item in shiftList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </template>
- <template v-slot:startTime="{ row }">
- <el-date-picker
- :disabled="permissions(row)"
- class="w100"
- v-model="row.startTime"
- type="datetime"
- value-format="yyyy-MM-dd HH:mm:ss"
- placeholder="开始时间"
- @change="handleStartTimeChange(row, item)"
- :picker-options="{
- disabledDate: (time) => {
- const end = row.endTime;
- if (!end) return false; // 无结束时间,不禁用
- // 将结束时间和当前时间都转换为“当天0点”,仅比较年月日
- const endDay = new Date(end);
- endDay.setHours(0, 0, 0, 0);
- const currentDay = new Date(time);
- currentDay.setHours(0, 0, 0, 0);
- return currentDay > endDay; // 仅当天0点更晚时禁用
- }
- }"
- ></el-date-picker>
- </template>
- <template v-slot:endTime="{ row }">
- <el-date-picker
- :disabled="permissions(row)"
- class="w100"
- v-model="row.endTime"
- type="datetime"
- value-format="yyyy-MM-dd HH:mm:ss"
- @change="handleEndTimeChange(row, item)"
- placeholder="完成时间"
- :picker-options="{
- disabledDate: (time) => {
- const start = row.startTime;
- if (!start) return false; // 无开始时间,不禁用
- // 将开始时间和当前时间都转换为“当天0点”,仅比较年月日
- const startDay = new Date(start);
- startDay.setHours(0, 0, 0, 0);
- const currentDay = new Date(time);
- currentDay.setHours(0, 0, 0, 0);
- return currentDay < startDay; // 仅当天0点更早时禁用
- },
- // 新增:限制同一天内的时间必须晚于开始时间
- disabledTime: (date) => {
- const start = row.startTime;
- if (!start) {
- return {
- disabledHours: () => [],
- disabledMinutes: () => [],
- disabledSeconds: () => []
- };
- }
- const startDate = new Date(start);
- const currentDate = new Date(date);
- // 判断是否是同一天
- if (
- currentDate.getFullYear() === startDate.getFullYear() &&
- currentDate.getMonth() === startDate.getMonth() &&
- currentDate.getDate() === startDate.getDate()
- ) {
- const startHour = startDate.getHours();
- const startMinute = startDate.getMinutes();
- const startSecond = startDate.getSeconds();
- return {
- // 禁用比 startHour 早的小时
- disabledHours: () =>
- Array.from({ length: startHour }, (_, i) => i),
- // 若小时相同,禁用比 startMinute 早的分钟
- disabledMinutes: (hour) =>
- hour === startHour
- ? Array.from({ length: startMinute }, (_, i) => i)
- : [],
- // 若小时和分钟都相同,禁用比 startSecond 早的秒
- disabledSeconds: (hour, minute) =>
- hour === startHour && minute === startMinute
- ? Array.from({ length: startSecond }, (_, i) => i)
- : []
- };
- } else {
- // 不同天,时间无限制
- return {
- disabledHours: () => [],
- disabledMinutes: () => [],
- disabledSeconds: () => []
- };
- }
- }
- }"
- ></el-date-picker>
- </template>
- <template v-slot:action="{ row }">
- <!-- :disabled="resetBtnDis(row)" -->
- <el-popconfirm
- title="确定要重置该条数据吗?"
- @confirm="resetData(row, item)"
- v-if="resetBtnDis(row)"
- >
- <template v-slot:reference>
- <el-link type="primary" :underline="false"> 重置 </el-link>
- </template>
- </el-popconfirm>
- </template>
- </ele-pro-table>
- </el-tab-pane>
- </el-tabs>
- </el-form>
- </div>
- <div slot="footer">
- <el-button plain @click="cancel">取消</el-button>
- <el-button type="primary" @click="confirm" :loading="toolbarLoading"
- >确定</el-button
- >
- </div>
- </ele-modal>
- </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';
- export default {
- components: {},
- props: {
- current: {
- type: Object,
- default: () => {}
- },
- dispatchVisible: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- processId: '',
- tabLoading: false,
- dynamicName: '工位名称',
- form: {
- assignType: 1,
- crewIds: '',
- workstationIds: '',
- teamId: '',
- singleReport: '',
- workCenterId: '',
- taskAss: 1,
- factoryName: '',
- factoryLineIds: ''
- },
- toolbarLoading: false,
- processList: [],
- workCenterList: [],
- teamList: [],
- tabsLoading: false,
- stationList: [], // 工位的数据
- productionList: [], // 产线的数据
- crewList: [], // 人员的数据
- procTaskDis: false, // 工序任务派单选择
- firstTaskindex: '', // 首工序id 对应的工序列表数据下标
- fieldList: [
- { label: '生产订单号:', prop: 'code' },
- { label: '计划编号:', prop: 'productionPlanCode' },
- { label: '工艺路线:', prop: 'produceRoutingName' },
- // { label: '编码', prop: 'productCode' },
- { label: '名称:', prop: 'productName' },
- { label: '生产编号:', prop: 'productionCodes' },
- { label: '牌号:', prop: 'brandNo' },
- { label: '批次号:', prop: 'batchNo' },
- { label: '型号:', prop: 'model' },
- { label: '要求生产数量:', prop: 'formingNum' },
- { label: '要求生产重量:', prop: 'initialWeight' },
- { label: '计划开始时间:', prop: 'planStartTime' },
- { label: '计划结束时间:', prop: 'planCompleteTime' }
- ],
- shiftList: [],
- dateValue: '',
- orderDis: false, // 生产订单派单
- singleDis: false, // 单个报工
- batchDis: false, // 批量报工
- isDispatchRow: {}
- };
- },
- computed: {
- fieldValue() {
- return (field) => {
- return this.current[field];
- };
- },
- clientEnvironmentId() {
- return this.$store.state.user.info.clientEnvironmentId;
- },
- userInfo() {
- return this.$store.state.user.info;
- },
- modelWidth() {
- // if(this.form.taskAss == 1){
- // return '1000px'
- // }
- return '75vw';
- },
- // 重置按钮 的置灰权限 没有进行操作跟派单的数据 置灰
- resetBtnDis() {
- return (row) => {
- if (!row.status) return false;
- let flag = row.status.code != 1;
- return flag;
- };
- },
- // 指派单选框操作 已派单的 其它两个按钮不能操作
- radioBun() {
- return (row, type) => {
- if (!row.radioBun) return false;
- let flag = row.radioBun[type];
- return flag;
- };
- },
- // 列表输入框操作 已派单的不能操作
- permissions() {
- return (row) => {
- if (!row.status) return false;
- if (row.status.code == 1) return true;
- };
- },
- // 时间段显示
- timeSlot() {
- return (item) => {
- if (!item.startDate || !item.endDate) {
- return false;
- }
- return true;
- };
- },
- columns() {
- return [
- {
- columnKey: 'index',
- label: '序号',
- type: 'index',
- width: 55,
- align: 'center',
- fixed: 'left'
- },
- {
- width: 45,
- type: 'selection',
- columnKey: 'selection',
- align: 'center',
- fixed: 'left'
- },
- {
- prop: 'name',
- label: this.dynamicName,
- align: 'center',
- width: 200
- },
- {
- prop: 'code',
- label: '编码',
- align: 'center',
- width: 200
- },
- {
- prop: 'status',
- label: '状态',
- align: 'center',
- width: 150,
- formatter: (row) => {
- if (!row.status) return '';
- return row.status.desc || '';
- }
- },
- {
- slot: 'quantity',
- prop: 'quantity',
- label: '数量',
- align: 'center',
- width: 140
- },
- {
- slot: 'weight',
- prop: 'weight',
- label: `重量(${this.current.newWeightUnit})`,
- align: 'center',
- width: 140
- },
- {
- slot: 'teamTimeDetailId',
- prop: 'teamTimeDetailId',
- label: '班次',
- align: 'center',
- minWidth: 150
- },
- {
- slot: 'startTime',
- prop: 'startTime',
- label: '计划开始时间',
- align: 'center',
- minWidth: 240
- },
- {
- slot: 'endTime',
- prop: 'endTime',
- label: '计划完成时间',
- align: 'center',
- minWidth: 240
- },
- {
- columnKey: 'action',
- label: '操作',
- width: 120,
- align: 'center',
- resizable: false,
- fixed: 'right',
- slot: 'action'
- }
- ];
- }
- },
- watch: {},
- created() {
- this.workCenterData(); // 查询工作中心
- this.getClassesData(); // 查询班次
- this.queryCheckExists(); // 查询是否派单
- 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('结束时间不能早于开始时间,已自动设为开始时间');
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .top-box {
- display: flex;
- margin-bottom: 10px;
- .item-box {
- flex: 1;
- }
- }
- .radio-box {
- margin: 10px 0;
- }
- .table {
- margin-top: 20px;
- }
- ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
- background-color: #10d070;
- border-color: #10d070;
- }
- ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
- box-shadow: none;
- }
- // ::v-deep .ele-block{
- // width: 240px;
- // }
- // ::v-deep .basic {
- // .el-form-item {
- // width: 100%;
- // }
- // .form80 {
- // .el-form-item__content {
- // width: calc(100% - 80px);
- // }
- // }
- // .form65 {
- // .el-form-item__content {
- // width: calc(100% - 65px);
- // }
- // }
- // .el-form-item__label {
- // padding: 0 4px 0 0;
- // }
- // .item_label {
- // white-space: nowrap;
- // overflow: hidden;
- // text-overflow: ellipsis;
- // width: 100%;
- // }
- // }
- </style>
|