Newer
Older
urbanLifeline_YanAn / src / views / DialogTabs / component / GongDanPaiFa.vue
@zhangzhihui zhangzhihui on 22 Oct 7 KB 燃气安全弹窗
<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.moduleType" placeholder="" style="width: 100%">
          <el-option v-for="item in module_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="cell1">
        <el-input v-model="form.eventAddress" />
      </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" />
      </el-form-item>
      <el-form-item label="要求完成时间:" class="cell2">
        <el-input v-model="form.requiredCompletionTime" />
      </el-form-item>
    </el-form>
    <el-button color="#03B6A0" 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 { commonWarningGet, alarmWorkOrderAdd, alarmWorkOrderList } from '@/api/RQWarning';

const props = defineProps({
  // 数据id
  dataID: {
    type: String,
  },
});
import { unitVoiceTemplateCall } from '@/api/OutgoingCall/templateList';
const { proxy } = getCurrentInstance();
const { module_type } = proxy.useDict('module_type');
const { order_type } = proxy.useDict('order_type');
console.log('🚀 ~ module_type,order_type:', module_type, order_type);
const AllData = reactive({
  form: {
    // GDType: '预警工单',
    // JQTimer: '2024-09-26 17:26:00',
    // FXWZ: '宝塔区凤凰山街道二道街',
    // FZYP: '压力检测超标,并且该地点管网发生过管道泄漏事件',
    // FKSJ: '2小时内',
    // WCSJ: '2024-09-30',
  },
});
const { form } = toRefs(AllData);
// 关闭弹窗
const CloseDialog = () => {
  alarmWorkOrderAdd(form.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.wranLocation}出现了${form.value.assessment},请于${form.value.requestFeedbackHour}进行确认与反馈`,
        },
      }).then(response => {
        proxy.$modal.msgSuccess('派发成功');
        bus.emit('publicDialog_Close');
      });
    })
    .catch(err => {
      console.log('🚀 ~ alarmWorkOrderAdd ~ err:', err);
    });

  // 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.wranLocation}出现了${form.value.assessment},请于${form.value.requestFeedbackHour}进行确认与反馈`,
  //   },
  // }).then(response => {
  //   proxy.$modal.msgSuccess('派发成功');
  //   bus.emit('publicDialog_Close');
  // });
};

// 工单信息
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 = 'early_warning';
    form.value.moduleTypeName = module_type.value.find(item => item.value == res.data.moduleType)?.label;
    form.value.moduleType = res.data.moduleType;
    form.value.requestFeedbackHour = '2';
    form.value.requestFeedbackHourNum = '2小时';
    form.value.requiredCompletionTime = getCalculatedTime(form.value.requestFeedbackTime, '2小时');
    console.log('🚀 ~ getWarningData ~ res:', res);
  } catch (error) {
    console.log('🚀 ~ getWarningData ~ error:', error);
  }
};

watch(
  () => form.value.requestFeedbackHourNum,
  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);
    }
  },
  {}
);

// 定义一个方法来计算新的时间
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(14, 69, 89, 0.9);
      border: 1px solid #1cf5fc;
      box-shadow: none;

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