Newer
Older
urbanLifeline_YanAn / src / views / DialogTabs / component / GongDanPaiFa.vue
@jimengfei jimengfei 4 days ago 9 KB updata
<template>
  <div id="GongDanPaiFa">
    <el-form :model="form" label-width="auto" style="max-width: 100%; padding: 0 40px 0 0px" class="GongDanPaiForm">
      <el-form-item label="工单类型:" class="cell2">
        <!-- <el-input v-model="form.moduleTypeName" /> -->
        <el-select v-model="form.orderType" placeholder="" style="width: 100%">
          <el-option v-for="item in work_order_type" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="警情时间:" class="cell2">
        <el-input v-model="form.requestFeedbackTime" />
      </el-form-item>
      <el-form-item label="风险位置:" class="cell2">
        <el-input v-model="form.eventAddress" />
      </el-form-item>
      <el-form-item label="报警等级:" class="cell2">
        <!-- <el-input v-model="form.warnLevel" /> -->
        <el-select v-model="form.warnLevel" placeholder="" style="width: 100%">
          <el-option v-for="item in warn_level" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="辅助研判:" class="cell1">
        <el-input v-model="form.eventDetails" />
      </el-form-item>
      <el-form-item label="要求反馈时间:" class="cell2">
        <el-input v-model="form.requestFeedbackHourNum" disabled />
      </el-form-item>
      <el-form-item label="要求完成时间:" class="cell2">
        <el-input v-model="form.requiredCompletionTime" />
      </el-form-item>
    </el-form>
    <el-button color="#158CFD" style="width: 110px; height: 34px" @click="CloseDialog()">派发工单</el-button>
  </div>
</template>

<script setup name="GongDanPaiFa">
import { ref, reactive, toRefs, onMounted, watch } from 'vue';
import bus from '@/bus';
import { unitVoiceTemplateCall } from '@/api/OutgoingCall/templateList';
import { addWorkOrder } from '@/api/order';

// 辅助决策
import { commonWarningGet, alarmWorkOrderAdd, alarmWorkOrderList } from '@/api/RQWarning';

import useUserStore from '@/store/modules/user';
const userStore = useUserStore();
// console.log('🚀 ~ userStore:----------', userStore.userInfo);

const props = defineProps({
  // 数据id
  dataID: {
    type: String,
  },
});
const { proxy } = getCurrentInstance();
const { module_type } = proxy.useDict('module_type');
const { order_type } = proxy.useDict('order_type');
const { work_order_type, work_order_status, work_order_source, warn_level } = proxy.useDict(
  'work_order_type',
  'work_order_status',
  'work_order_source',
  'warn_level'
);
// console.log('🚀 ~ module_type,order_type:', module_type, order_type, work_order_source);
const AllData = reactive({
  form: {
    // GDType: '预警工单',
    // JQTimer: '2024-09-26 17:26:00',
    // FXWZ: '宝塔区凤凰山街道二道街',
    // FZYP: '压力检测超标,并且该地点管网发生过管道泄漏事件',
    // FKSJ: '2小时内',
    // WCSJ: '2024-09-30',
  },
  orderForm: {
    orderNumber: '',
    orderType: '',
    orderSource: '1',
    reportPerson: userStore.userInfo.userName,
    reportPersonPhone: userStore.userInfo.phonenumber,
    alarmTime: '',
    registerTime: proxy.moment().format('YYYY-MM-DD HH:mm:ss'),
    customFinishTime: '',
    reportLocation: '',
    requireFinishTime: '',
    orderFileList: [],
    message: '',
    nextTaskApproveUserId: userStore.userInfo.userId,
  },
  needTime: [
    { value: '1', label: '2小时', timeValue: '2' },
    { value: '2', label: '8小时', timeValue: '8' },
    { value: '3', label: '16小时', timeValue: '16' },
    { value: '4', label: '24小时', timeValue: '24' },
  ],
});
const { form, orderForm, needTime } = toRefs(AllData);
// 工单派发
const CloseDialog = () => {
  console.log(
    `在${form.value.eventAddress}出现了${form.value.eventDetails},请于${form.value.requestFeedbackHourNum}进行确认与反馈`
  );
  orderForm.value.orderType = form.value.orderType;
  orderForm.value.alarmTime = form.value.requestFeedbackTime;
  orderForm.value.reportLocation = form.value.eventAddress;
  orderForm.value.warnLevel = form.value.warnLevel;
  orderForm.value.warnId = form.value.warnId;
  orderForm.value.message = form.value.eventDetails;
  orderForm.value.requireFeedbackHour = form.value.requestFeedbackHour;
  orderForm.value.requireFinishTime = form.value.requiredCompletionTime;
  orderForm.value.customFinishTime = orderForm.value.registerTime;
  orderForm.value.registerTime = proxy.moment().format('YYYY-MM-DD HH:mm:ss');

  addWorkOrder(orderForm.value)
    .then(res => {
      console.log('🚀 ~ CloseDialog ~ res:---------派发成功', res);
      // unitVoiceTemplateCall({
      //   robotId: '2c922fb8-40f1-47e9-afc0-dc3c7b6bb3cd',
      //   phones: '13129919657,13638648812,13332926003',
      //   templateDesc: {
      //     title: '延安城市生命线通知',
      //     // notice: `在${form.value.FXWZ}出现了${form.value.FZYP},请于${form.value.FKSJ}进行确认与反馈`,
      //     notice: `在${form.value.eventAddress}出现了${form.value.eventDetails},请于${form.value.requestFeedbackHourNum}进行确认与反馈`,
      //   },
      // }).then(response => {
      //   proxy.$modal.msgSuccess('派发成功');
      //   bus.emit('nowDynamic');
      //   bus.emit('publicDialog_Close');
      // });

      proxy.$modal.msgSuccess('派发成功');
      bus.emit('nowDynamic');
      bus.emit('publicDialog_Close');

      //  关闭 当前预警点
      bus.emit('changeOnePointShow', form.value.warnId);
    })
    .catch(err => {
      console.log('🚀 ~ alarmWorkOrderAdd ~ err:', err);
    });
};

// 工单信息
const getWarningData = async () => {
  try {
    const res = await commonWarningGet(props.dataID);

    form.value.requestFeedbackTime = res.data.warnTime;
    form.value.warnId = res.data.id;
    form.value.eventAddress = res.data.wranLocation;
    form.value.eventDetails = res.data.riskProfile + ',' + res.data.assessment;
    form.value.orderType = res.data.orderType;
    form.value.warnLevel = res.data.warnLevel;
    form.value.moduleTypeName = module_type.value.find(item => item.value == res.data.moduleType)?.label;
    form.value.moduleType = res.data.moduleType;
    form.value.requestFeedbackHour = needTime.value.find(item => item.value == res.data.warnLevel)?.timeValue;
    form.value.requestFeedbackHourNum = needTime.value.find(item => item.value == res.data.warnLevel)?.label;
    form.value.requiredCompletionTime = getCalculatedTime(form.value.requestFeedbackTime, form.value.requestFeedbackHourNum);
    console.log('🚀 ~ getWarningData ~ res:', res);
  } catch (error) {
    console.log('🚀 ~ getWarningData ~ error:', error);
  }
};

watch(
  () => form.value.warnLevel,
  val => {
    // const num = val.match(/(\d+)\s*(小时|分钟|秒)/);
    // if (num) {
    //   const value = parseInt(num, 10);
    //   form.value.requestFeedbackHour = value;
    //   form.value.requiredCompletionTime = getCalculatedTime(form.value.requestFeedbackTime, val);
    // }
    form.value.requestFeedbackHour = needTime.value.find(item => item.value == val)?.timeValue;
    form.value.requestFeedbackHourNum = needTime.value.find(item => item.value == val)?.label;
    form.value.requiredCompletionTime = getCalculatedTime(form.value.requestFeedbackTime, form.value.requestFeedbackHourNum);
  },
  {}
);

// 定义一个方法来计算新的时间
const getCalculatedTime = (v1, v2) => {
  const time = proxy.moment(v1);
  const durationParts = v2.match(/(\d+)\s*(小时|分钟|秒)/);
  // console.log("🚀 ~ getCalculatedTime ~ durationParts:", durationParts)
  if (durationParts) {
    const value = parseInt(durationParts[1], 10);
    const unit = durationParts[2];
    // console.log(value, unit);

    switch (unit) {
      case '小时':
        return time.add(value, 'hours').format('YYYY-MM-DD HH:mm:ss');
      case '分钟':
        return time.add(value, 'minutes').format('YYYY-MM-DD HH:mm:ss');
      case '秒':
        return time.add(value, 'seconds').format('YYYY-MM-DD HH:mm:ss');
      default:
        return time.format('YYYY-MM-DD HH:mm:ss');
    }
  }
  return time.format('YYYY-MM-DD HH:mm:ss');
};

onMounted(() => {
  console.log(123123123, props.dataID);
  getWarningData();
  // if (props.dataID == '001') {
  //   form.value.FZYP = '压力监测异常波动,可能是设施故障';
  // } else if (props.dataID == '002') {
  //   form.value.FZYP = '燃气管道压力过大,会存在燃气爆管风险';
  // } else if (props.dataID == '003') {
  //   form.value.FZYP = '高峰期流量持续降低,会存在燃气泄漏风险';
  // } else if (props.dataID == '004') {
  //   form.value.FXWZ = '东大街管网';
  //   form.value.FZYP = '高水位,水深250mm';
  // } else if (props.dataID == '005') {
  //   form.value.FXWZ = '枣园南路与枣园五路管网';
  //   form.value.FZYP = '满管,水深400mm';
  // } else if (props.dataID == '006') {
  //   form.value.FXWZ = '王家坪旧址门口';
  //   form.value.FZYP = '积水,水深120mm';
  // }
});
</script>

<style lang="scss" scoped>
#GongDanPaiFa {
  width: 100%;
  height: 100%;
  text-align: center;
  padding-top: 20px;

  :deep(.GongDanPaiForm) {
    width: 100%;
    height: calc(100% - 60px);
    overflow: auto;

    .cell1 {
      float: left;
      width: 100%;
    }
    .cell2 {
      float: left;
      width: 50%;

      .el-form-item__label {
        width: 200px !important;
      }
    }
    .el-form-item__label {
      font-family: Source Han Sans CN;
      font-weight: 400;
      font-size: 16px;
      color: #ffffff;
    }
    .el-input__wrapper {
      background: rgba(13, 42, 84, 0.9);
      border: 1px solid #1cb1fc;
      box-shadow: none;

      .el-input__inner {
        font-family: Source Han Sans CN;
        font-weight: 400;
        font-size: 16px;
        color: #c1d3d4;
      }
    }
  }
}
</style>