| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <template>
- <uni-popup
- class="repairs-popup"
- ref="repairAddPopRef"
- type="bottom"
- :is-mask-click="false"
- borderRadius="10px 10px 0 0 "
- background-color="#fff"
- >
- <uni-row class="head-row align-center">
- <uni-col
- :span="6"
- class="head-cancel align-center justify-start"
- @click="oncancel"
- >
- {{ $t("operation.cancel") }}
- </uni-col>
- <uni-col :span="12" class="head-title justify-center">
- {{ $t("operation.add")
- }}{{ $t("equipmentMaintenance.maintenanceItems") }}
- </uni-col>
- <uni-col
- :span="6"
- class="head-add align-center justify-end"
- @click="onConfirm(repairAddFormRef)"
- >
- {{ $t("operation.confirm") }}
- </uni-col>
- </uni-row>
- <view class="repair-add-section">
- <uni-forms
- ref="repairAddFormRef"
- labelWidth="140px"
- :modelValue="addInfo"
- :rules="formRules"
- >
- <!-- 设备编码 -->
- <uni-forms-item
- class="form-item"
- :label="$t('device.deviceCode')"
- name="deviceCode"
- :required="true"
- >
- <uni-easyinput
- style="text-align: right"
- :inputBorder="false"
- :clearable="false"
- :disabled="true"
- :styles="{ disableColor: '#fff' }"
- v-model="addInfo.deviceCode"
- :placeholder="$t('operation.PleaseFillIn')"
- />
- </uni-forms-item>
- <!-- 设备名称 -->
- <uni-forms-item
- class="form-item"
- :label="$t('device.deviceName')"
- name="deviceName"
- :required="true"
- >
- <uni-easyinput
- style="text-align: right"
- :inputBorder="false"
- :clearable="false"
- :disabled="true"
- :styles="{ disableColor: '#fff' }"
- v-model="addInfo.deviceName"
- :placeholder="$t('operation.PleaseFillIn')"
- />
- </uni-forms-item>
- <!-- 维修项 -->
- <uni-forms-item
- class="form-item"
- :label="$t('equipmentMaintenance.maintenanceItems')"
- name="name"
- :required="false"
- >
- <uni-easyinput
- style="text-align: right"
- :inputBorder="false"
- :clearable="false"
- :disabled="false"
- :styles="{ disableColor: '#fff' }"
- v-model="addInfo.name"
- :placeholder="$t('operation.PleaseFillIn')"
- />
- </uni-forms-item>
- </uni-forms>
- </view>
- </uni-popup>
- </template>
- <script setup>
- import dayjs from "dayjs";
- import { computed, ref, reactive, watch, onMounted } from "vue";
- import { useI18n } from "vue-i18n";
- import { getDeptId } from "@/utils/auth";
- const { t, locale } = useI18n({
- useScope: "global",
- });
- // 接收父组件传递的参数
- const props = defineProps({});
- const allBoms = ref([]);
- const addInfo = ref({});
- const repairAddFormRef = ref(null);
- const formRules = ref({
- name: {
- rules: [
- {
- required: true,
- errorMessage: t("operation.PleaseFillIn"),
- },
- ],
- },
- });
- const oncancel = () => {
- addInfo.value = {};
- close();
- };
- const onConfirm = async (formEl) => {
- if (!formEl) return;
- await formEl
- .validate()
- .then((res) => {
- console.log("onConfirm res-", res);
- addInfo.value.chooseKey = `${addInfo.value.deviceCode}_${addInfo.value.deviceName}_${addInfo.value.name}`; // 手动拼接chooseKey
- // 生成8位随机数字作为bomNodeId
- addInfo.value.bomNodeId = Math.floor(Math.random() * 100000000); //.toString();
- // 判断addInfo.value.chooseKey是否在allBoms.value中
- if (allBoms.value.includes(addInfo.value.chooseKey)) {
- uni.showToast({
- title:
- t("equipmentMaintenance.maintenanceItems") + t("operation.repeat"),
- icon: "none",
- });
- } else {
- emit("add-set", addInfo.value);
- oncancel();
- }
- })
- .catch((err) => {
- console.error("onConfirm err-", err);
- });
- };
- onMounted(() => {});
- const repairAddPopRef = ref(null);
- // 打开弹窗
- const open = (info) => {
- const { bom, ...device } = info;
- console.log("repair-open", info, bom);
- addInfo.value = device;
- // 遍历bom,返回deviceCode,deviceName,name拼接成的字符串形成新数组赋值allBoms
- allBoms.value = bom.map(
- (item) => `${item.deviceCode}_${item.deviceName}_${item.name}`
- );
- console.log("allBoms.value-", allBoms.value);
- repairAddPopRef.value.open();
- };
- // 关闭弹窗
- const close = () => {
- repairAddPopRef.value.close();
- };
- const emit = defineEmits(["add-set"]);
- // 提供外部方法
- const expose = {
- open,
- };
- defineExpose(expose);
- </script>
- <style lang="scss" scoped>
- @import "@/style/work-order-detail.scss";
- .repairs-popup {
- width: 100%;
- height: 100%;
- min-height: 411px;
- background-color: #fff;
- padding: 20px;
- }
- :deep(.uni-popup__wrapper) {
- padding: 20px;
- }
- .head-row {
- margin-bottom: 20px;
- font-size: 16px;
- line-height: 21px;
- color: #a3a3a3;
- height: 40px;
- border-bottom: 1px dashed #cacccf;
- }
- .head-title {
- color: #333333;
- font-weight: bold;
- }
- .head-add {
- color: #004098;
- }
- </style>
|