zhanghua
2022-10-20 bb036407bcc0f26a9a0f246aca100d87db2f6e76
src/components/dispatch/index.vue
@@ -15,7 +15,12 @@
            <!-- 选择执法车 -->
            <el-form-item label="选择执法车:" prop="enforcementCar">
                <el-select v-model="dispatch.enforcementCar" placeholder="请选择">
                    <el-option v-for="item in carOptions" :key="item.id" :label="item.carNumber" :value="item.id">
          <el-option
            v-for="item in carOptions"
            :key="item.id"
            :label="item.carNumber"
            :value="item.id"
          >
                    </el-option>
                </el-select>
            </el-form-item>
@@ -23,26 +28,55 @@
            <div class="form-person">
                <!-- 部门 -->
                <el-form-item label="选择人员:" prop="createUser">
                    <el-select v-model="dispatch.createUser" placeholder="请选择部门" @change="handleTopChange">
                        <el-option v-for="item in departOptions" :key="item.id" :label="item.departName"
                            :value="item.id">
          <el-select
            v-model="dispatch.createUser"
            placeholder="请选择部门"
            @change="handleTopChange"
          >
            <el-option
              v-for="item in departOptions"
              :key="item.id"
              :label="item.departName"
              :value="item.id"
            >
                        </el-option>
                    </el-select>
                </el-form-item>
                <!-- 中队 -->
                <el-form-item prop="enforcementTeam" class="person-item">
                    <el-select v-model="dispatch.enforcementTeam" placeholder="选择中队"
                        :disabled="squadronOptions.length!==0 && squadronOptions?false:true" @change="handleMidChange">
                        <el-option v-for="item in squadronOptions" :key="item.id" :label="item.departName"
                            :value="item.id">
          <el-select
            v-model="dispatch.enforcementTeam"
            placeholder="选择中队"
            :disabled="
              squadronOptions.length !== 0 && squadronOptions ? false : true
            "
            @change="handleMidChange"
          >
            <el-option
              v-for="item in squadronOptions"
              :key="item.id"
              :label="item.departName"
              :value="item.id"
            >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item prop='lawEnforcer' class="person-item">
        <el-form-item prop="lawEnforcer" class="person-item">
                    <!-- 人员 -->
                    <el-select v-model="dispatch.lawEnforcer" placeholder="请选择人员"
                        :disabled="personOptions.length !== 0 && personOptions? false:true" @change="handlePerChange">
                        <el-option v-for="item in personOptions" :key="item.id" :label="item.username" :value="item.id">
          <el-select
            v-model="dispatch.lawEnforcer"
            placeholder="请选择人员"
            :disabled="
              personOptions.length !== 0 && personOptions ? false : true
            "
            @change="handlePerChange"
          >
            <el-option
              v-for="item in personOptions"
              :key="item.id"
              :label="item.username"
              :value="item.id"
            >
                        </el-option>
                    </el-select>
                </el-form-item>
@@ -60,10 +94,18 @@
            </div>
            <div class="form-time">
                <el-form-item label="派遣意见" prop="dispatchOpinion">
                    <el-input v-model="dispatch.dispatchOpinion" placeholder="请输入派遣意见"></el-input>
          <el-input
            v-model="dispatch.dispatchOpinion"
            placeholder="请输入派遣意见"
          ></el-input>
                </el-form-item>
                <el-form-item label="处置日期" prop="disposeDate">
                    <el-date-picker v-model="dispatch.disposeDate" type="datetime" placeholder="选择日期时间">
          <el-date-picker
            v-model="dispatch.disposeDate"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
                    </el-date-picker>
                </el-form-item>
            </div>
@@ -78,13 +120,13 @@
    </div>
</template>
<script>
import MyMap from '@/components/map'
import {parseTime } from '@/utils/index'
import MyMap from "@/components/map";
import { parseTime } from "@/utils/index";
export default {
    components: {
        MyMap
    MyMap,
    },
    props: ['id', 'changeDialog', 'refresh', 'mytype'],
  props: ["id", "changeDialog", "refresh", "mytype"],
    created() {
        // 判断车辆类型
        this.mytype === 1 ? this.getLawCarList() : this.getSoilCarList();
@@ -93,58 +135,58 @@
    data() {
        const checkPhone = (rule, value, callback) => {
            if (value) {
                const rep = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/
        const rep = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/;
                if (!rep.test(value)) {
                    callback("请输入正确的手机号码");
                } else {
                    callback();
                }
            } else {
                callback()
        callback();
            }
        }
    };
        const checkOpinion = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback(new Error('派遣意见不能为空'))
        callback(new Error("派遣意见不能为空"));
            }
        }
    };
        const checkDistance = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback(new Error('距离不能为空'))
        callback(new Error("距离不能为空"));
            }
        }
    };
        const checkTeam = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback(new Error('处置日期不能为空'))
        callback(new Error("处置日期不能为空"));
            }
        }
    };
        const checkPerson = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback()
        callback();
            }
        }
    };
        const checkNumber = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback()
        callback();
            }
        }
    };
        const checkDepart = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback(new Error('请选择部门'))
        callback(new Error("请选择部门"));
            }
        }
    };
        return {
            dispatch: {
                baseCaseId: 0,//案件id
@@ -152,72 +194,74 @@
                dispatchOpinion: "",//处置意见
                disposeDate: "",//处置日期
                distance: 0,//距离
                enforcementCar: '',//执法车
        enforcementCar: "", //执法车
                enforcementTeam: "",//执法中队
                lawEnforcer: '',//执法人员
        lawEnforcer: "", //执法人员
                lawEnforcerName: "",//执法编号,
                createUser: null,
            },
            rules: {
                createUser: [
                    {
                        required: true, trigger: 'change', validator: checkDepart
                    }
            required: true,
            trigger: "change",
            validator: checkDepart,
          },
                ],
                contactWay: [
                    {
                        required: false, trigger: 'blur', validator: checkPhone
                    }
            required: false,
            trigger: "blur",
            validator: checkPhone,
          },
                ],
                dispatchOpinion: [
                    { required: true, trigger: 'change', validator: checkOpinion }
          { required: true, trigger: "change", validator: checkOpinion },
                ],
                distance: [
                    { required: true, trigger: 'change', validator: checkDistance }
                ],
        // distance: [
        //   { required: true, trigger: "change", validator: checkDistance },
        // ],
                // enforcementTeam: [
                //     { required: true, trigger: 'change', validator: checkTeam }
                // ],
                lawEnforcer: [
                    { required: true, trigger: 'change', validator: checkPerson }
          { required: true, trigger: "change", validator: checkPerson },
                ],
                lawEnforcerName: [
                    { required: false, trigger: 'change', validator: checkNumber }
          { required: false, trigger: "change", validator: checkNumber },
                ],
                disposeDate: [
                    {
                        required: true, trigger: 'false', validator: checkTeam
                    }
                ]
            required: true,
            trigger: "false",
            validator: checkTeam,
          },
        ],
            },
            carOptions: [
                {
                    label: '车辆一',
          label: "车辆一",
                    value: 1,
                },
                {
                    label: '车辆二',
          label: "车辆二",
                    value: 2,
                },
            ],
            departOptions: [
            ],
      departOptions: [],
            carOptions: [
                {
                    label: '车辆一',
          label: "车辆一",
                    value: 1,
                },
                {
                    label: '车辆二',
          label: "车辆二",
                    value: 2,
                },
            ],
            squadronOptions: [
            ],
            personOptions: [
            ],
        }
      squadronOptions: [],
      personOptions: [],
    };
    },
    methods: {
        // 执行调度
@@ -227,89 +271,82 @@
                console.log(valid);
                if (valid) {
                    const { dispatch, id } = this;
                    dispatch.disposeDate = new Date();
          // dispatch.disposeDate = new Date();
                    console.log(id);
                    dispatch.baseCaseId = id;
                    console.log(dispatch);
                    this.$axios({
                        method: 'post',
            method: "post",
                        url: `sccg/dispatch_handle/dispatch`,
                        data: {
                            ...dispatch,
                            disposeDate:parseTime(dispatch.disposeDate)
                        }
                    })
                        .then(res => {
            data: dispatch,
          }).then((res) => {
                            this.$message({
                                type: res.code === 200 ? 'success' : 'error',
                                message: res.code === 200 ? '调度成功' : res.message,
                            })
                            this.$emit('changeDialog', { flag: false });
              type: res.code === 200 ? "success" : "error",
              message: res.code === 200 ? "调度成功" : res.message,
            });
            this.$emit("changeDialog", { flag: false });
                            this.refresh();
                        })
          });
                } else {
                    return false;
                }
            })
      });
        },
        // 取消调度
        handleBack() {
            this.$emit('changeDialog', { flag: false })
      this.$emit("changeDialog", { flag: false });
        },
        // 获取执法车辆
        getLawCarList() {
            this.$axios({
                method: 'get',
                url: `sccg/car_Manage/query_enforce?current=1&size=1000`
            })
                .then(res => {
        method: "get",
        url: `sccg/car_Manage/query_enforce?current=1&size=1000`,
      }).then((res) => {
                    this.carOptions = res.data.records;
                    console.log(res, this.carOptions);
                })
      });
        },
        // 获取渣土车辆
        getSoilCarList() {
            this.$axios({
                method: 'get',
                url: `sccg/car_Manage/query_slag?current=1&size=1000`
            })
                .then(res => {
        method: "get",
        url: `sccg/car_Manage/query_slag?current=1&size=1000`,
      }).then((res) => {
                    this.carOptions = res.data.records;
                    console.log(res);
                })
      });
        },
        // 获取顶级部门
        getDepartList() {
            this.$axios({
                method: 'get',
        method: "get",
                url: `sccg/depart/query_father`,
            })
                .then(res => {
      }).then((res) => {
                    this.departOptions = res.data;
                })
      });
        },
        // 获取中队
        async getTeamList(id) {
            console.log(id);
            await this.$axios({
                method: 'get',
                url: `sccg/depart/query_father_children?fatherId=${id}`
        method: "get",
        url: `sccg/depart/query_father_children?fatherId=${id}`,
            })
                .then(res => {
        .then((res) => {
                    this.squadronOptions = res.data;
                })
                .catch(err => {
        .catch((err) => {
                    console.log(err);
                })
        });
        },
        // 获取部门下的用户
        async getDepartUserList(id) {
            console.log(id);
            await this.$axios({
                method: 'get',
        method: "get",
                url: `sccg/admin/getDepartUser/${id}`,
            })
                .then(res => {
        .then((res) => {
                    console.log(res);
                    if (res.code === 200) {
                        this.personOptions = res.data;
@@ -318,24 +355,24 @@
                    }
                    if(this.personOptions.length === 0){
                        this.$message({
                            type: 'warning',
                            message: '该中队下没有人员'
                        })
              type: "warning",
              message: "该中队下没有人员",
            });
                    }
                })
                .catch(err => {
        .catch((err) => {
                    this.$message({
                        type: 'error',
                        message: '该部门人员不足,请换个部门'
                    })
                })
            type: "error",
            message: "该部门人员不足,请换个部门",
          });
        });
        },
        // 部门更改
        async handleTopChange(id) {
            this.dispatch.lawEnforcer = '';
            this.dispatch.enforcementTeam = '';
            this.dispatch.contactWay = '';
            this.dispatch.lawEnforcerName = '';
      this.dispatch.lawEnforcer = "";
      this.dispatch.enforcementTeam = "";
      this.dispatch.contactWay = "";
      this.dispatch.lawEnforcerName = "";
            await this.getTeamList(id);
            // if (this.squadronOptions.length === 0) {
            //     await this.getDepartUserList(id);
@@ -343,9 +380,9 @@
        },
        // 中队更改
        async handleMidChange(id) {
            this.dispatch.lawEnforcer = '';
            this.dispatch.contactWay = '';
            this.dispatch.lawEnforcerName = '';
      this.dispatch.lawEnforcer = "";
      this.dispatch.contactWay = "";
      this.dispatch.lawEnforcerName = "";
            await this.getDepartUserList(id);
        },
        // 人员更改
@@ -356,33 +393,32 @@
        },
        // 获取执法人员信息
        async getLawUser(id) {
            let obj = {}
      let obj = {};
            await this.$axios({
                method: 'get',
                url: `sccg/admin/${id}`
            })
                .then(res => {
        method: "get",
        url: `sccg/admin/${id}`,
      }).then((res) => {
                    obj = res.data;
                })
      });
            return obj;
        }
    },
    },
    watch: {
        'squadronOptions.length': {
    "squadronOptions.length": {
            handler(newval, oldval) {
                console.log(newval);
                if (newval === 0) {
                    console.log(1);
                    this.$message({
                        type: 'warning',
                        message: '该部门下没有中队'
                    })
            type: "warning",
            message: "该部门下没有中队",
          });
                }
            },
            deep: true
      deep: true,
        },
    }
}
  },
};
</script>
<style lang="scss" scoped>
.dispatch {