From ff817dab1f7b3e762896446afbcd68579381adcf Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期一, 02 二月 2026 16:52:10 +0800
Subject: [PATCH] 危险作业审批模块开发

---
 src/pages/safeProduction/hazardSourceLedger/detail.vue |  431 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 431 insertions(+), 0 deletions(-)

diff --git a/src/pages/safeProduction/hazardSourceLedger/detail.vue b/src/pages/safeProduction/hazardSourceLedger/detail.vue
new file mode 100644
index 0000000..d9ffde2
--- /dev/null
+++ b/src/pages/safeProduction/hazardSourceLedger/detail.vue
@@ -0,0 +1,431 @@
+<template>
+  <view class="hazard-source-detail">
+    <PageHeader :title="isEdit ? '缂栬緫鍗遍櫓婧�' : '鏂板鍗遍櫓婧�'"
+                @back="goBack" />
+    <u-form @submit="handleSubmit"
+            ref="formRef"
+            label-width="110">
+      <!-- 鍗遍櫓婧愪俊鎭� -->
+      <u-cell-group title="鍗遍櫓婧愪俊鎭�">
+        <u-form-item label="鍗遍櫓婧愬悕绉�"
+                     prop="name"
+                     required
+                     border-bottom>
+          <u-input v-model="form.name"
+                   placeholder="璇疯緭鍏ュ嵄闄╂簮鍚嶇О" />
+        </u-form-item>
+        <u-form-item label="鍗遍櫓婧愮紪鐮�"
+                     prop="code"
+                     required
+                     border-bottom>
+          <u-input v-model="form.code"
+                   placeholder="璇疯緭鍏ュ嵄闄╂簮缂栫爜" />
+        </u-form-item>
+        <u-form-item label="鍗遍櫓婧愮被鍨�"
+                     prop="type"
+                     required
+                     border-bottom>
+          <u-input v-model="typeName"
+                   placeholder="璇烽�夋嫨鍗遍櫓婧愮被鍨�"
+                   @click="showTypeSheet"
+                   readonly />
+          <template #right>
+            <up-icon name="arrow-right"
+                     @click="showTypeSheet"></up-icon>
+          </template>
+        </u-form-item>
+        <u-form-item label="椋庨櫓绛夌骇"
+                     prop="riskLevel"
+                     required
+                     border-bottom>
+          <u-input v-model="riskLevelName"
+                   placeholder="璇烽�夋嫨椋庨櫓绛夌骇"
+                   @click="showRiskLevelSheet"
+                   readonly />
+          <template #right>
+            <up-icon name="arrow-right"
+                     @click="showRiskLevelSheet"></up-icon>
+          </template>
+        </u-form-item>
+        <u-form-item label="鎵�鍦ㄤ綅缃�"
+                     prop="location"
+                     required
+                     border-bottom>
+          <u-input v-model="form.location"
+                   placeholder="璇疯緭鍏ユ墍鍦ㄤ綅缃�" />
+        </u-form-item>
+        <u-form-item label="绠℃帶鎺柦"
+                     prop="controlMeasures"
+                     required
+                     border-bottom>
+          <u-textarea v-model="form.controlMeasures"
+                      placeholder="璇疯緭鍏ョ鎺ф帾鏂�"
+                      :maxlength="200"
+                      count
+                      :autoHeight="true" />
+        </u-form-item>
+        <u-form-item label="搴撳瓨鏁伴噺"
+                     prop="stockQty"
+                     border-bottom>
+          <u-input v-model="form.stockQty"
+                   type="number"
+                   min="0"
+                   @blur="validateStockQty"
+                   placeholder="璇疯緭鍏ュ簱瀛樻暟閲�" />
+        </u-form-item>
+        <u-form-item label="绠℃帶璐d换浜�"
+                     prop="principalUser"
+                     required
+                     border-bottom>
+          <u-input v-model="form.principalUser"
+                   placeholder="璇烽�夋嫨绠℃帶璐d换浜�"
+                   @click="showPrincipalSheet"
+                   readonly />
+          <template #right>
+            <up-icon name="arrow-right"
+                     @click="showPrincipalSheet"></up-icon>
+          </template>
+        </u-form-item>
+        <u-form-item label="璐d换浜鸿仈绯荤數璇�"
+                     prop="principalMobile"
+                     required
+                     border-bottom>
+          <u-input v-model="form.principalMobile"
+                   placeholder="璇疯緭鍏ヨ矗浠讳汉鑱旂郴鐢佃瘽" />
+        </u-form-item>
+        <u-form-item label="瑙勬牸 / 椋庨櫓鎻忚堪"
+                     prop="specInfo"
+                     border-bottom>
+          <u-textarea v-model="form.specInfo"
+                      placeholder="璇疯緭鍏ヨ鏍� / 椋庨櫓鎻忚堪"
+                      :maxlength="200"
+                      count
+                      :autoHeight="true" />
+        </u-form-item>
+      </u-cell-group>
+      <!-- 鎻愪氦鎸夐挳 -->
+      <view class="footer-btns">
+        <u-button class="cancel-btn"
+                  @click="goBack">鍙栨秷</u-button>
+        <u-button class="sign-btn"
+                  type="primary"
+                  @click="handleSubmit"
+                  :loading="loading">{{ isEdit ? '淇濆瓨淇敼' : '鎻愪氦' }}</u-button>
+      </view>
+    </u-form>
+    <!-- 鍗遍櫓婧愮被鍨嬮�夋嫨鍣� -->
+    <up-action-sheet :show="typeSheetVisible"
+                     :actions="typeOptions"
+                     @select="handleTypeSelect"
+                     title="閫夋嫨鍗遍櫓婧愮被鍨�" />
+    <!-- 椋庨櫓绛夌骇閫夋嫨鍣� -->
+    <up-action-sheet :show="riskLevelSheetVisible"
+                     :actions="riskLevelOptions"
+                     @select="handleRiskLevelSelect"
+                     title="閫夋嫨椋庨櫓绛夌骇" />
+    <!-- 绠℃帶璐d换浜洪�夋嫨鍣� -->
+    <up-action-sheet :show="principalSheetVisible"
+                     :actions="principalOptions"
+                     @select="handlePrincipalSelect"
+                     title="閫夋嫨绠℃帶璐d换浜�" />
+  </view>
+</template>
+
+<script setup>
+  // 鏇挎崲 toast 鏂规硶
+  defineOptions({ name: "hazard-source-detail" });
+  const showToast = message => {
+    uni.showToast({
+      title: message,
+      icon: "none",
+    });
+  };
+
+  import { ref, onMounted, nextTick } from "vue";
+  import PageHeader from "@/components/PageHeader.vue";
+  import {
+    safeHazardAdd,
+    safeHazardUpdate,
+  } from "@/api/safeProduction/hazardSourceLedger";
+  import { userListNoPageByTenantId } from "@/api/system/user";
+  import useUserStore from "@/store/modules/user";
+  import { useDict } from "@/utils/dict";
+  import { onLoad } from "@dcloudio/uni-app";
+
+  // 鑾峰彇瀛楀吀鏁版嵁
+  const { hazard_source_type } = useDict("hazard_source_type");
+
+  const userStore = useUserStore();
+
+  // 琛ㄥ崟鏁版嵁
+  const form = ref({
+    name: "",
+    code: "",
+    type: "",
+    riskLevel: "",
+    location: "",
+    controlMeasures: "",
+    stockQty: "",
+    principalUser: "",
+    principalUserId: "",
+    principalMobile: "",
+    specInfo: "",
+  });
+
+  // 椤甸潰鐘舵��
+  const loading = ref(false);
+  const formRef = ref(null);
+  const isEdit = ref(false);
+
+  // 鍗遍櫓婧愮被鍨嬮�夋嫨鍣�
+  const typeSheetVisible = ref(false);
+  const typeName = ref("");
+  const typeOptions = ref([]);
+  const showTypeSheet = () => {
+    typeSheetVisible.value = true;
+  };
+  const handleTypeSelect = item => {
+    form.value.type = item.value;
+    typeName.value = item.name;
+    typeSheetVisible.value = false;
+  };
+  const validateStockQty = val => {
+    let numVal = Number(val);
+    if (isNaN(numVal)) {
+      numVal = 0;
+    }
+    if (numVal < 0) {
+      showToast("搴撳瓨鏁伴噺涓嶈兘灏忎簬0");
+      numVal = 0;
+    }
+    // 浣跨敤 nextTick 纭繚瑙嗗浘鏇存柊
+    nextTick(() => {
+      form.value.stockQty = numVal;
+    });
+  };
+
+  // 椋庨櫓绛夌骇閫夋嫨鍣�
+  const riskLevelSheetVisible = ref(false);
+  const riskLevelName = ref("");
+  const riskLevelOptions = ref([]);
+  const showRiskLevelSheet = () => {
+    riskLevelSheetVisible.value = true;
+  };
+  const handleRiskLevelSelect = item => {
+    form.value.riskLevel = item.value;
+    riskLevelName.value = item.name;
+    riskLevelSheetVisible.value = false;
+  };
+
+  // 绠℃帶璐d换浜洪�夋嫨鍣�
+  const principalSheetVisible = ref(false);
+  const userList = ref([]);
+  const principalOptions = ref([]);
+  const showPrincipalSheet = () => {
+    if (principalOptions.value.length === 0) {
+      getUserList();
+    } else {
+      principalSheetVisible.value = true;
+    }
+  };
+  const handlePrincipalSelect = item => {
+    console.log(item, "item");
+    form.value.principalUser = item.name;
+    form.value.principalUserId = item.value;
+    form.value.principalMobile = item.phonenumber;
+    principalSheetVisible.value = false;
+  };
+
+  // 鑾峰彇鐢ㄦ埛鍒楄〃
+  const getUserList = () => {
+    userListNoPageByTenantId().then(res => {
+      if (res.code === 200) {
+        userList.value = res.data;
+        principalOptions.value = res.data.map(user => ({
+          value: user.userId,
+          name: user.nickName,
+          phonenumber: user.phonenumber,
+        }));
+        principalSheetVisible.value = true;
+      }
+    });
+  };
+
+  // 杩斿洖涓婁竴椤�
+  const goBack = () => {
+    // 杩斿洖鏃舵竻闄ゆ湰鍦板瓨鍌ㄧ殑鏁版嵁
+    uni.removeStorageSync("hazardSourceLedger");
+    uni.navigateBack();
+  };
+
+  // 鎻愪氦琛ㄥ崟
+  const handleSubmit = async () => {
+    if (!form.value.name) {
+      showToast("璇疯緭鍏ュ嵄闄╂簮鍚嶇О");
+      return;
+    }
+
+    if (!form.value.code) {
+      showToast("璇疯緭鍏ュ嵄闄╂簮缂栫爜");
+      return;
+    }
+
+    if (!form.value.type) {
+      showToast("璇烽�夋嫨鍗遍櫓婧愮被鍨�");
+      return;
+    }
+
+    if (!form.value.riskLevel) {
+      showToast("璇烽�夋嫨椋庨櫓绛夌骇");
+      return;
+    }
+
+    if (!form.value.location) {
+      showToast("璇疯緭鍏ユ墍鍦ㄤ綅缃�");
+      return;
+    }
+
+    if (!form.value.controlMeasures) {
+      showToast("璇疯緭鍏ョ鎺ф帾鏂�");
+      return;
+    }
+
+    if (!form.value.principalUser) {
+      showToast("璇疯緭鍏ョ鎺ц矗浠讳汉");
+      return;
+    }
+
+    if (!form.value.principalMobile) {
+      showToast("璇疯緭鍏ヨ矗浠讳汉鑱旂郴鐢佃瘽");
+      return;
+    }
+
+    try {
+      loading.value = true;
+
+      // 浣跨敤瀹夊叏娴呮嫹璐濓紝閬垮厤瀵硅薄灞曞紑鍦ㄦ煇浜涜繍琛屾椂鎶涢敊
+      const source =
+        form.value && typeof form.value === "object" ? form.value : {};
+      const submitData = {};
+      Object.keys(source).forEach(k => {
+        submitData[k] = source[k];
+      });
+      console.log("submitData", submitData);
+      if (isEdit.value) {
+        const { code } = await safeHazardUpdate(submitData);
+        if (code === 200) {
+          showToast("淇敼鎴愬姛");
+          setTimeout(() => {
+            goBack();
+          }, 500);
+        } else {
+          loading.value = false;
+          showToast("淇敼澶辫触锛岃閲嶈瘯");
+        }
+      } else {
+        const { code } = await safeHazardAdd(submitData);
+        if (code === 200) {
+          showToast("鏂板鎴愬姛");
+          setTimeout(() => {
+            goBack();
+          }, 500);
+        } else {
+          loading.value = false;
+          showToast("鏂板澶辫触锛岃閲嶈瘯");
+        }
+      }
+    } catch (e) {
+      loading.value = false;
+      console.error("鎻愪氦澶辫触:", e);
+      showToast("鎻愪氦澶辫触锛岃閲嶈瘯");
+    }
+  };
+
+  onLoad(() => {
+    // 缂栬緫鍗遍櫓婧愭椂锛屼粠鏈湴瀛樺偍鑾峰彇鏁版嵁
+    const hazardSource = uni.getStorageSync("hazardSourceLedger");
+    console.log("hazardSource", hazardSource);
+    if (hazardSource.id) {
+      form.value = hazardSource;
+      isEdit.value = true;
+      console.log("form.value", form.value);
+    } else {
+      isEdit.value = false;
+    }
+  });
+
+  onMounted(() => {
+    // 鍒濆鍖栭�夐」鏁版嵁
+    typeOptions.value = hazard_source_type.value.map(item => ({
+      value: item.value,
+      name: item.label,
+    }));
+    riskLevelOptions.value = [
+      { value: "浣庨闄�", name: "浣庨闄�" },
+      { value: "涓�鑸闄�", name: "涓�鑸闄�" },
+      { value: "杈冨ぇ椋庨櫓", name: "杈冨ぇ椋庨櫓" },
+      { value: "閲嶅ぇ椋庨櫓", name: "閲嶅ぇ椋庨櫓" },
+    ];
+
+    // 璁剧疆宸查�夊�肩殑鏄剧ず鏂囨湰
+    if (form.value.type) {
+      typeName.value =
+        typeOptions.value.find(item => item.value == form.value.type)?.name || "";
+    }
+    if (form.value.riskLevel) {
+      riskLevelName.value =
+        riskLevelOptions.value.find(item => item.value == form.value.riskLevel)
+          ?.name || "";
+    }
+  });
+</script>
+
+<style scoped lang="scss">
+  @import "@/static/scss/form-common.scss";
+  .client-visit {
+    min-height: 100vh;
+    background: #f8f9fa;
+    padding-bottom: 5rem;
+  }
+
+  .footer-btns {
+    position: fixed;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    background: #fff;
+    display: flex;
+    justify-content: space-around;
+    align-items: center;
+    padding: 0.75rem 0;
+    box-shadow: 0 -0.125rem 0.5rem rgba(0, 0, 0, 0.05);
+    z-index: 1000;
+  }
+
+  .cancel-btn {
+    font-weight: 400;
+    font-size: 1rem;
+    color: #666;
+    background: #f5f5f5;
+    border: 1px solid #ddd;
+    width: 45%;
+    height: 2.5rem;
+    border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
+  }
+
+  .sign-btn {
+    font-weight: 500;
+    font-size: 1rem;
+    color: #fff;
+    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
+    border: none;
+    width: 45%;
+    height: 2.5rem;
+    border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
+  }
+
+  .location-icon {
+    color: #1989fa;
+    font-size: 1.2rem;
+  }
+</style>
\ No newline at end of file

--
Gitblit v1.9.3