riku
2025-02-13 660021a28de9b84b4362c171fdbbf89587f0c5af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<template>
  <CardDialog v-model="visible" title="新建走航任务">
    <el-form
      :inline="false"
      :model="formObj"
      ref="formRef"
      :rules="rules"
      label-position="right"
      label-width="100px"
    >
      <el-form-item label="区县" prop="location">
        <OptionLocation2
          :level="3"
          :initValue="false"
          :checkStrictly="false"
          :allOption="false"
          v-model="formObj.location"
        ></OptionLocation2>
      </el-form-item>
      <el-form-item label="任务编号" prop="missionCode">
        <el-input
          size="small"
          clearable
          v-model="formObj.missionCode"
          placeholder="任务编号"
        />
      </el-form-item>
      <OptionType v-model="formObj.deviceType"></OptionType>
      <OptionDevice
        :type="formObj.deviceType"
        v-model="formObj.deviceCode"
      ></OptionDevice>
      <OptionTime v-model="formObj.timeArray"></OptionTime>
      <el-form-item>
        <el-button
          :disabled="!edit"
          type="primary"
          @click="onSubmit"
          :loading="loading"
          >提交</el-button
        >
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </CardDialog>
  <el-button
    v-if="mode == 'create'"
    type="primary"
    class="el-button-custom"
    @click="visible = !visible"
  >
    新建任务
  </el-button>
  <el-button
    v-else
    type="primary"
    size="small"
    icon="EditPen"
    class="el-button-custom"
    @click="visible = !visible"
  ></el-button>
</template>
<script setup>
import moment from 'moment';
import { ref, reactive, computed } from 'vue';
import missionApi from '@/api/missionApi';
import thirdPartyDataApi from '@/api/thirdPartyDataApi';
import { useFormConfirm } from '@/composables/formConfirm';
import { useFetchData } from '@/composables/fetchData';
import { useMissionStore } from '@/stores/mission';
 
const props = defineProps({
  // 走航任务编辑模式,新建或更新
  mode: {
    type: String,
    default: 'create'
  }
  // visible: {
  //   type: String,
  //   default: 'create'
  // }
});
 
const missionStore = useMissionStore();
const visible = ref(false);
const { loading, fetchData } = useFetchData();
const rules = reactive({
  location: [
    {
      required: true,
      message: '区县不能为空',
      trigger: 'change'
    }
  ],
  missionCode: [
    {
      required: true,
      message: '任务编号不能为空',
      trigger: 'blur'
    }
  ],
  timeArray: [
    {
      required: true,
      // message: '时间不能为空',
      trigger: 'change',
      validator: (rule, value, callback) => {
        if (value == null) {
          callback(new Error('时间不能为空'));
        } else {
          const st = moment(value[0]);
          const et = moment(value[1]);
          const range = et.diff(st, 'second');
          if (range > 12 * 60 * 60) {
            callback(new Error('任务时长最多为12小时'));
          }
        }
        callback();
      }
    }
  ]
});
const param = computed(() => {
  return {
    districtName: formObj.value.location.dName,
    missionCode: formObj.value.missionCode,
    deviceType: formObj.value.deviceType,
    deviceCode: formObj.value.deviceCode,
    startTime: formObj.value.timeArray[0],
    endTime: formObj.value.timeArray[1]
  };
});
// 创建任务
function createMission() {
  fetchData((page, pageSize) => {
    return missionApi.putNewMission(param.value).then((res) => {
      visible.value = false;
      missionStore.fetchMission();
      // 通知服务端启动任务范围内的第三方数据获取任务
      thirdPartyDataApi.fetchMissionData(param.value.missionCode);
    });
  });
}
const { formObj, formRef, edit, onSubmit, onCancel } = useFormConfirm({
  submit: {
    do: createMission
  },
  cancel: {
    do: () => {
      visible.value = false;
    }
  }
});
 
if (import.meta.env.VITE_DATA_MODE == 'jingan') {
  formObj.value.location = {
    pCode: '31',
    pName: '上海市',
    cCode: '3100',
    cName: '上海市',
    dCode: '310106',
    dName: '静安区'
  };
}
</script>
<style scoped>
/* .el-form-item {
  margin-bottom: 0px;
} */
</style>