approval.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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('🚀 ~ getReportDetail ~ detailData.value:', detailData.value);
  44. }
  45. })
  46. .catch(res => {});
  47. };
  48. const infoRef = ref(null);
  49. const loading = ref(false);
  50. const handleApproval = async type => {
  51. loading.value = true;
  52. try {
  53. const data = {
  54. attachments: detailData.value.attachments || [],
  55. opinion: infoRef.value.approvalOpinion,
  56. auditStatus: type === 'pass' ? 20 : 30,
  57. companyId: detailData.value.companyId,
  58. costCenter: detailData.value.costCenter || '',
  59. dynamicFields: detailData.value.dynamicFields || {},
  60. deptId: detailData.value.deptId,
  61. deviceIds: detailData.value.deviceIds,
  62. startTime: `${detailData.value.startTime[0].toString().padStart(2, '0')}:${detailData.value.startTime[1]
  63. .toString()
  64. .padStart(2, '0')}`,
  65. endTime: `${detailData.value.endTime[0].toString().padStart(2, '0')}:${detailData.value.endTime[1]
  66. .toString()
  67. .padStart(2, '0')}`,
  68. externalRental: detailData.value.externalRental,
  69. faultDowntime: detailData.value.faultDowntime || '',
  70. malfunction: detailData.value.malfunction,
  71. nextPlan: detailData.value.nextPlan,
  72. id: detailData.value.id,
  73. ...(detailData.value.platformId ? { platformId: detailData.value.platformId } : {}),
  74. platformWell: detailData.value.platformWell,
  75. productionStatus: detailData.value.productionStatus,
  76. projectDepartment: detailData.value.projectDepartment || '',
  77. rdStatus: detailData.value.rdStatus,
  78. techniqueIds: detailData.value.techniqueIds,
  79. taskId: detailData.value.taskId,
  80. timeRange: ['1970-01-01T00:00:00.008Z', '1970-01-01T00:00:00.008Z'],
  81. };
  82. await approveRdDailyReport(data);
  83. uni.showToast({
  84. title: type === 'pass' ? '审批通过' : '审批驳回',
  85. icon: 'success',
  86. });
  87. uni.reLaunch({ url: '/pages/home/index' });
  88. } catch (error) {
  89. console.log('🚀 ~ handleApproval ~ error:', error);
  90. uni.showToast({ title: t('operation.failed'), icon: 'none' });
  91. } finally {
  92. loading.value = false;
  93. }
  94. };
  95. // -------------------------- 页面方法 end --------------------------
  96. </script>
  97. <template>
  98. <view class="page ridu-edit-page">
  99. <view class="segmented-header">
  100. <uni-segmented-control
  101. :current="currentTab"
  102. :values="tabTitles"
  103. :style-type="styleType"
  104. :active-color="activeColor"
  105. @clickItem="onClickTabItem" />
  106. </view>
  107. <scroll-view scroll-y="true" class="segmented-content">
  108. <!-- 工单信息 -->
  109. <view class="work-order-info" v-show="currentTab === 0">
  110. <report-info
  111. ref="infoRef"
  112. :report-id="reportId"
  113. :report-data="detailData"
  114. approval
  115. :form-disable="detailData.auditStatus !== 10" />
  116. </view>
  117. <!-- 保养项列表 -->
  118. <view class="work-order-bom-list" v-show="currentTab === 1">
  119. <report-form ref="reportFormEditRef" :report-id="reportId" :report-data="detailData" :form-disable="true" />
  120. </view>
  121. </scroll-view>
  122. <view class="segmented-footer" v-if="detailData.auditStatus === 10">
  123. <view class="footer-btn">
  124. <button :disabled="loading" :loading="loading" class="mini-btn" type="primary" @click="handleApproval('pass')">
  125. 审批通过
  126. </button>
  127. <button :disabled="loading" :loading="loading" class="mini-btn" type="warn" @click="handleApproval('reject')">
  128. 审批驳回
  129. </button>
  130. </view>
  131. </view>
  132. </view>
  133. </template>
  134. <style lang="scss" scoped>
  135. @import '@/style/work-order-segmented.scss';
  136. .page {
  137. padding-bottom: 0;
  138. }
  139. .footer-btn {
  140. display: flex;
  141. justify-content: flex-end;
  142. padding: 0 32px;
  143. gap: 0 32px;
  144. & > uni-button {
  145. margin: 0;
  146. }
  147. }
  148. </style>