approval.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <script setup>
  2. import { onLoad } from "@dcloudio/uni-app";
  3. import { ref, getCurrentInstance } from "vue";
  4. // -------------------------- 引入api接口 start--------------------------
  5. import { getRuiDuReportDetail, approveRdDailyReport } from "@/api/ruiDu.js";
  6. // -------------------------- 引入api接口 end--------------------------
  7. // --------------------------引入组件----------------------------------
  8. import reportInfo from "./compontents/report-info.vue";
  9. import reportForm from "./compontents/report-form.vue";
  10. // --------------------------引用全局变量$t-------------------------------
  11. const { appContext } = getCurrentInstance();
  12. const t = appContext.config.globalProperties.$t;
  13. // ----------------------------选项卡----------------------------------
  14. // 选项卡标题
  15. const tabTitles = ref([t("ruiDu.taskInfo"), t("ruiDu.reportInfo")]);
  16. const currentTab = ref(0);
  17. const styleType = ref("text");
  18. const activeColor = ref("#004098");
  19. const onClickTabItem = e => {
  20. currentTab.value = e.currentIndex;
  21. };
  22. // --------------------------页面变量----------------------------------
  23. // 报告ID
  24. const reportId = ref("");
  25. // 报告详情数据
  26. const detailData = ref({});
  27. // 表单组件ref
  28. const reportFormEditRef = ref(null);
  29. // --------------------------生命周期函数----------------------------------
  30. onLoad(option => {
  31. // 页面加载
  32. reportId.value = option.id; // 获取页面参数
  33. // 获取日报详情
  34. getReportDetail();
  35. });
  36. // -------------------------- 页面方法 --------------------------
  37. // 获取日报详情
  38. const getReportDetail = () => {
  39. getRuiDuReportDetail({ id: reportId.value })
  40. .then(res => {
  41. if (res.code === 0) {
  42. detailData.value = Object.assign(detailData.value, res.data || {});
  43. console.log(
  44. "🚀 ~ getReportDetail ~ detailData.value:",
  45. detailData.value
  46. );
  47. }
  48. })
  49. .catch(res => {});
  50. };
  51. const infoRef = ref(null);
  52. const loading = ref(false);
  53. const handleApproval = async type => {
  54. loading.value = true;
  55. try {
  56. const data = {
  57. attachments: detailData.value.attachments || [],
  58. opinion: infoRef.value.approvalOpinion,
  59. auditStatus: type === "pass" ? 20 : 30,
  60. companyId: detailData.value.companyId,
  61. costCenter: detailData.value.costCenter || "",
  62. dynamicFields: detailData.value.dynamicFields || {},
  63. deptId: detailData.value.deptId,
  64. deviceIds: detailData.value.deviceIds,
  65. startTime: `${detailData.value.startTime[0].toString().padStart(2, "0")}:${detailData.value.startTime[1]
  66. .toString()
  67. .padStart(2, "0")}`,
  68. endTime: `${detailData.value.endTime[0].toString().padStart(2, "0")}:${detailData.value.endTime[1]
  69. .toString()
  70. .padStart(2, "0")}`,
  71. externalRental: detailData.value.externalRental,
  72. faultDowntime: detailData.value.faultDowntime || "",
  73. malfunction: detailData.value.malfunction,
  74. nextPlan: detailData.value.nextPlan,
  75. id: detailData.value.id,
  76. ...(detailData.value.platformId
  77. ? { platformId: detailData.value.platformId }
  78. : {}),
  79. platformWell: detailData.value.platformWell,
  80. productionStatus: detailData.value.productionStatus,
  81. projectDepartment: detailData.value.projectDepartment || "",
  82. rdStatus: detailData.value.rdStatus,
  83. techniqueIds: detailData.value.techniqueIds,
  84. taskId: detailData.value.taskId,
  85. timeRange: ["1970-01-01T00:00:00.008Z", "1970-01-01T00:00:00.008Z"],
  86. };
  87. await approveRdDailyReport(data);
  88. uni.showToast({
  89. title: type === "pass" ? "审批通过" : "审批驳回",
  90. icon: "success",
  91. });
  92. uni.reLaunch({ url: "/pages/home/index" });
  93. } catch (error) {
  94. console.log("🚀 ~ handleApproval ~ error:", error);
  95. uni.showToast({ title: t("operation.failed"), icon: "none" });
  96. } finally {
  97. loading.value = false;
  98. }
  99. };
  100. // -------------------------- 页面方法 end --------------------------
  101. </script>
  102. <template>
  103. <view class="page ridu-edit-page">
  104. <view class="segmented-header">
  105. <uni-segmented-control
  106. :current="currentTab"
  107. :values="tabTitles"
  108. :style-type="styleType"
  109. :active-color="activeColor"
  110. @clickItem="onClickTabItem" />
  111. </view>
  112. <scroll-view scroll-y="true" class="segmented-content">
  113. <!-- 工单信息 -->
  114. <view class="work-order-info" v-show="currentTab === 0">
  115. <report-info
  116. ref="infoRef"
  117. :report-id="reportId"
  118. :report-data="detailData"
  119. approval
  120. :form-disable="detailData.auditStatus !== 10" />
  121. </view>
  122. <!-- 保养项列表 -->
  123. <view class="work-order-bom-list" v-show="currentTab === 1">
  124. <report-form
  125. ref="reportFormEditRef"
  126. :report-id="reportId"
  127. :report-data="detailData"
  128. :form-disable="true"
  129. type="approval" />
  130. </view>
  131. </scroll-view>
  132. <view class="segmented-footer" v-if="detailData.auditStatus === 10">
  133. <view class="footer-btn">
  134. <button
  135. :disabled="loading"
  136. :loading="loading"
  137. class="mini-btn"
  138. type="primary"
  139. @click="handleApproval('pass')">
  140. 审批通过
  141. </button>
  142. <button
  143. :disabled="loading"
  144. :loading="loading"
  145. class="mini-btn"
  146. type="warn"
  147. @click="handleApproval('reject')">
  148. 审批驳回
  149. </button>
  150. </view>
  151. </view>
  152. </view>
  153. </template>
  154. <style lang="scss" scoped>
  155. @import "@/style/work-order-segmented.scss";
  156. .page {
  157. padding-bottom: 0;
  158. }
  159. .footer-btn {
  160. display: flex;
  161. justify-content: flex-end;
  162. padding: 0 32px;
  163. gap: 0 32px;
  164. & > uni-button {
  165. margin: 0;
  166. }
  167. }
  168. </style>