Files
2024-07-05 16:49:56 +08:00

378 lines
8.6 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="box-container">
<!-- 功能筛选区 -->
<uni-card :is-shadow="false" is-full>
<uni-forms label-width="100">
<!-- 选择小车 -->
<uni-forms-item label="AGV小车">
<uni-data-select v-model="agvCode" :localdata="agvChouseOptions" :clear="false"></uni-data-select>
</uni-forms-item>
<!-- 点位筛选 -->
<uni-forms-item label="起点筛选">
<uni-data-select v-model="startAreaCode" :localdata="areaOptions" :clear="false"
@change="getStartLocationDict()"></uni-data-select>
</uni-forms-item>
<!-- 起始点位 -->
<uni-forms-item label="起始点位">
<uni-data-select v-model="start_point" :localdata="startLocationOptions"
:clear="false"></uni-data-select>
</uni-forms-item>
<!-- 点位筛选 -->
<uni-forms-item label="终点筛选">
<uni-data-select v-model="endAreaCode" :localdata="areaOptions" :clear="false"
@change="getEndLocationDict()"></uni-data-select>
</uni-forms-item>
<!-- 结束点位 -->
<uni-forms-item label="结束点位">
<uni-data-select v-model="end_point" :localdata="endLocationOptions"
:clear="false"></uni-data-select>
</uni-forms-item>
<!-- 任务状态 -->
<uni-forms-item label="当前任务">
<view v-if="reqCode === ''">
<u-tag text="无任务" size="large" type="info"></u-tag>
</view>
<view v-else>
<u-tag :text="reqCode" size="large" type="primary"></u-tag>
</view>
</uni-forms-item>
<!-- 按钮区域 -->
<u-row customStyle="margin-bottom: 10px" :gutter="40">
<u-col span="6">
<u-button :disabled="loading" :loading="loading" shape="circle" type="success" text="执行任务"
@click="doStartAgv"></u-button>
</u-col>
<u-col span="6">
<u-button :disabled="loading" :loading="loading" shape="circle" type="error" text="取消任务"
@click="doStopAgv"></u-button>
</u-col>
</u-row>
<view style="margin-top: 60px;">
<u-button :disabled="loading" :loading="loading" shape="circle" type="info" text="清空任务记录"
@click="clearTask"></u-button>
</view>
</uni-forms>
</uni-card>
<u-toast ref="uToast"></u-toast>
</view>
</template>
<script>
import {
go_workshop,
emergency_stop_agv
} from '@/api/materialManagement/MaterialRequsition.js';
import {
queryMmAgvLocation
} from '@/api/materialManagement/MmAgvLocation.js';
export default {
data() {
return {
loading: false,
// 区域区分
startAreaCode: 0,
endAreaCode: 0,
areaOptions: [{
value: 0,
text: '全部'
},
{
value: 2,
text: '毛坯上料起点'
},
{
value: 3,
text: '毛坯上料终点'
},
{
value: 4,
text: '成品下线起点'
},
{
value: 5,
text: '成品下线终点'
},
{
value: 6,
text: '成品下线区二楼终点'
},
{
value: 7,
text: '一楼成品仓库交接区'
},
{
value: 8,
text: '二楼成品仓库交接区'
},
{
value: 9,
text: '外箱上料起点'
},
{
value: 10,
text: '外箱上料终点'
},
],
// 开始点位
start_point: '',
// 结束点位
end_point: '',
// AGV点位地址
startLocationOptions: [],
endLocationOptions: [],
// 任务code
reqCode: '',
// AGV小车选择列表
agvChouseOptions: [{
value: '1743',
text: '涂装1号AGV'
},
{
value: '1744',
text: '涂装2号AGV'
}
],
// AGV小车选择
agvCode: '1743'
};
},
watch: {},
filters: {},
mounted() {
// this.init();
},
onShow() {
this.init();
},
methods: {
init() {
this.loading = true;
this.getDict();
this.getTaskStorage();
this.loading = false;
},
getDict() {
this.getAreaOptions();
this.getStartLocationDict();
this.getEndLocationDict();
},
getAreaOptions() {
const query = {
pageNum: 1,
pageSize: 1000,
areaCode: 0
}
queryMmAgvLocation(query).then((res) => {
const {
code,
data
} = res;
if (code === 200) {
let options = [{
value: 0,
text: '全部'
}];
this.areaOptions = options.concat(this.formatAreaDict(data.result));
}
});
},
formatAreaDict(list) {
try {
const newList = list.map(item => {
return {
value: item.areaCode,
text: item.area
}
})
const _newList = newList
.filter((item, index) => newList
.findIndex(i => i.value === item.value) ===
index);
return _newList;
} catch (e) {
this.$refs.uToast.show({
type: 'error',
message: '字典数据解析异常!' + e.message
});
return [];
}
},
getStartLocationDict() {
const query = {
pageNum: 1,
pageSize: 1000,
areaCode: this.startAreaCode
}
queryMmAgvLocation(query).then((res) => {
const {
code,
data
} = res;
if (code === 200) {
this.startLocationOptions = this.formatDict(data.result);
if (this.startLocationOptions.length > 0) {
this.start_point = this.startLocationOptions[0].value;
} else {
this.start_point = '';
}
}
});
},
getEndLocationDict() {
const query = {
pageNum: 1,
pageSize: 1000,
areaCode: this.endAreaCode
}
queryMmAgvLocation(query).then((res) => {
const {
code,
data
} = res;
if (code === 200) {
this.endLocationOptions = this.formatDict(data.result);
if (this.endLocationOptions.length > 0) {
this.end_point = this.endLocationOptions[0].value;
} else {
this.end_point = '';
}
}
});
},
formatDict(list) {
try {
const newList = list.map(item => {
return {
value: item.coordinate,
text: item.coordinate
}
})
return newList;
} catch (e) {
this.$refs.uToast.show({
type: 'error',
message: '字典数据解析异常!' + e.message
});
return [];
}
},
// 任务启动
doStartAgv() {
if (this.loading) {
return;
}
if (this.start_point == '' || this.end_point == '') {
this.$refs.uToast.show({
type: 'error',
message: '起点或者终点不能为空'
});
return;
}
const query = {
start_point: this.start_point,
end_point: this.end_point,
agvCode: this.agvCode
};
this.loading = true;
setTimeout(() => {
this.loading = false;
}, 30000);
go_workshop(query).then((res) => {
if (res.code == 200) {
try {
let json = JSON.parse(res.data);
this.reqCode = json.data;
this.$refs.uToast.show({
type: 'success',
message: 'agv起动成功' + this.reqCode
});
this.saveTaskStorage();
} catch (e) {
this.$refs.uToast.show({
type: 'error',
message: 'agv起动失败' + this.reqCode
});
}
}
this.loading = false;
});
},
// 取消任务
doStopAgv() {
if (this.loading) {
return;
}
if (this.reqCode === '') {
this.$refs.uToast.show({
type: 'error',
message: '无任务编号,无法取消!'
});
return;
}
const query = {
reqCode: this.reqCode
};
this.loading = true;
setTimeout(() => {
this.loading = false;
}, 30000);
emergency_stop_agv(query).then((res) => {
if (res.code == 200) {
this.reqCode = '';
this.$refs.uToast.show({
type: 'success',
message: '成功取消任务:' + res.data
});
this.cancelTaskStorage();
}
this.loading = false;
});
},
// 保存任务缓存
saveTaskStorage() {
try {
const data = {
start_point: this.start_point,
end_point: this.end_point,
agvCode: this.agvCode,
reqCode: this.reqCode
}
uni.setStorageSync('AGVRemoteControlTaskData', JSON.stringify(data))
} catch (err) {
}
},
// 获取任务缓存
getTaskStorage() {
try {
const data = JSON.parse(uni.getStorageSync('AGVRemoteControlTaskData'));
if (data != null) {
this.start_point = data.start_point;
this.end_point = data.end_point;
this.agvCode = data.agvCode;
this.reqCode = data.reqCode;
}
} catch (err) {
}
},
// 清空任务缓存
cancelTaskStorage() {
uni.removeStorageSync('AGVRemoteControlTaskData');
},
// 清空任务记录
clearTask() {
this.cancelTaskStorage();
this.reqCode = '';
}
}
};
</script>
<style scoped>
.box-container{
background-color: white;
height: 644px;
}
</style>