form.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <script setup>
  2. import { ref, computed, watch, nextTick, reactive } from 'vue';
  3. import { onLoad } from '@dcloudio/uni-app';
  4. import { getRuiYingReportDetail } from '@/api/ruiying';
  5. import { useDataDictStore } from '@/store/modules/dataDict';
  6. const props = defineProps({
  7. type: {
  8. type: String,
  9. default: 'edit',
  10. },
  11. });
  12. const FORM_KEYS = [
  13. 'id',
  14. 'deptId',
  15. 'projectId',
  16. 'taskId',
  17. 'deptName',
  18. 'contractName',
  19. 'taskName',
  20. 'repairStatus',
  21. 'technique',
  22. 'wellCategory',
  23. 'designWellDepth',
  24. 'casingPipeSize',
  25. 'wellControlLevel',
  26. 'currentOperation',
  27. 'nextPlan',
  28. 'transitTime',
  29. 'ratedProductionTime',
  30. 'productionTime',
  31. 'nonProductionTime',
  32. 'ryNptReason',
  33. 'productionStatus',
  34. 'totalStaffNum',
  35. 'onDutyStaffNum',
  36. 'leaveStaffNum',
  37. 'dailyFuel',
  38. 'remark',
  39. 'createTime',
  40. 'opinion',
  41. 'status',
  42. 'auditStatus',
  43. ];
  44. const formType = ref('edit');
  45. const initFormData = () => ({});
  46. const form = ref(initFormData());
  47. async function loadDetail(id) {
  48. try {
  49. const { data } = await getRuiYingReportDetail({ id });
  50. FORM_KEYS.forEach(key => {
  51. form.value[key] = data[key] ?? form.value[key];
  52. });
  53. form.value.id = id;
  54. if (props.type.includes('approval') && data.auditStatus !== 10) {
  55. formType.value = 'readonly';
  56. }
  57. if (props.type.includes('edit') && data.status !== 0) {
  58. formType.value = 'readonly';
  59. }
  60. if (props.type.includes('detail')) {
  61. formType.value = 'readonly';
  62. }
  63. } finally {
  64. }
  65. }
  66. const dictStore = useDataDictStore();
  67. const nptReasonOptions = ref([]);
  68. const rigStatusOptions = ref([]);
  69. const techniqueOptions = ref([]);
  70. const loadOptions = () => {
  71. nptReasonOptions.value = dictStore.getStrDictOptions('ryNptReason').map(v => ({
  72. text: v.label,
  73. value: v.value,
  74. }));
  75. rigStatusOptions.value = dictStore.getStrDictOptions('repairStatus').map(v => ({
  76. text: v.label,
  77. value: v.value,
  78. }));
  79. techniqueOptions.value = dictStore.getStrDictOptions('rq_iot_project_technology_ry').map(v => ({
  80. text: v.label,
  81. value: v.value,
  82. }));
  83. };
  84. onLoad(options => {
  85. if (dictStore.dataDict.length <= 0) {
  86. dictStore.loadDataDictList().then(() => {
  87. loadOptions();
  88. });
  89. } else loadOptions();
  90. loadDetail(options.id);
  91. });
  92. const defaultProps = computed(() => ({
  93. inputBorder: false,
  94. clearable: false,
  95. placeholder: '请输入',
  96. style: {
  97. 'text-align': 'right',
  98. },
  99. styles: {
  100. disableColor: '#fff',
  101. },
  102. }));
  103. const disabled = computed(() => field => {
  104. if (field === 'edit')
  105. return formType.value === 'readonly' || props.type.includes('approval') || props.type.includes('detail');
  106. else return formType.value === 'readonly';
  107. });
  108. const transitTime = computed(() => {
  109. const cap = form.value.productionTime ?? 0;
  110. const gas = form.value.ratedProductionTime ?? 0;
  111. if (!gas) return { original: 0, value: '0%' };
  112. const original = cap / gas;
  113. return { original, value: (original * 100).toFixed(2) + '%' };
  114. });
  115. const formRef = ref(null);
  116. const onDutyStaffNum = computed(() => {
  117. return (form.value.totalStaffNum ?? 0) - (form.value.leaveStaffNum ?? 0);
  118. });
  119. // 辅助函数:计算总时间
  120. const sumTimes = () => {
  121. const { productionTime = 0, nonProductionTime = 0 } = form.value;
  122. return Number(productionTime) + Number(nonProductionTime);
  123. };
  124. // 校验函数:总时间必须为 24
  125. const validateTotalTime = (rule, value, data, callback) => {
  126. const total = sumTimes();
  127. if (total !== Number(form.value.ratedProductionTime)) {
  128. callback(`生产时间和非生产时间之和必须等于额定生产时间`);
  129. } else {
  130. callback();
  131. }
  132. };
  133. // // 校验函数:非生产时间原因
  134. // const validateNptReason = (rule, value, data, callback) => {
  135. // const npt = Number(form.value.nonProductionTime) || 0;
  136. // console.log('npt :>> ', npt);
  137. // console.log('value :>> ', value);
  138. // if (npt > 0 && !value) {
  139. // callback('非生产时间大于 0 时,必须选择原因');
  140. // }
  141. // return true;
  142. // };
  143. // 复用的时间规则
  144. // const timeRuleItem = {
  145. // rules: [
  146. // { required: true, errorMessage: '请输入时间' },
  147. // { validateFunction: validateTotalTime }, // 关联自定义校验
  148. // ],
  149. // };
  150. // uni-forms 规则定义
  151. const rules = reactive({
  152. repairStatus: {
  153. rules: [{ required: true, errorMessage: '请输入施工状态' }],
  154. },
  155. productionStatus: {
  156. rules: [{ required: true, errorMessage: '请输入生产动态' }],
  157. },
  158. // 时间字段应用复用规则
  159. // productionTime: timeRuleItem,
  160. // nonProductionTime: timeRuleItem,
  161. // ratedProductionTime: timeRuleItem,
  162. // nptReason: {
  163. // rules: [{ validateFunction: validateNptReason }],
  164. // },
  165. });
  166. watch(
  167. [() => form.value.dailyInjectGasTime, () => form.value.dailyInjectWaterTime, () => form.value.nonProductionTime],
  168. () => {
  169. nextTick(() => {
  170. formRef.value?.validateField(['ryNptReason']).catch(() => {});
  171. if (sumTimes() === 24) {
  172. formRef.value?.clearValidate(['dailyInjectGasTime', 'dailyInjectWaterTime', 'nonProductionTime']);
  173. }
  174. });
  175. }
  176. );
  177. defineExpose({ formRef, form, loadDetail });
  178. </script>
  179. <template>
  180. <view class="content">
  181. <view class="tip">
  182. <view class="item">
  183. <view class="left">
  184. <span>运行时效:</span>
  185. 生产时间/额定生产时间
  186. </view>
  187. <span class="right red"> >100% 红色预警 </span>
  188. </view>
  189. <view class="item">
  190. <view class="left">
  191. <span>时间平衡:</span>
  192. 生产 + 非生产 = 额定生产
  193. </view>
  194. <span class="right orange"> ≠额定生产 橙色预警 </span>
  195. </view>
  196. </view>
  197. <view v-if="!type.includes('approval') && form.opinion" class="opinion">
  198. <span class="left">审批意见:</span>
  199. <span class="right"> {{ form.opinion }} </span>
  200. </view>
  201. <uni-forms
  202. ref="formRef"
  203. labelWidth="auto"
  204. :model="form"
  205. :rules="rules"
  206. validateTrigger="blur"
  207. err-show-type="toast">
  208. <uni-forms-item label="施工队伍" name="deptName">
  209. <span class="readOnly">{{ form.deptName }}</span>
  210. </uni-forms-item>
  211. <uni-forms-item label="项目" name="contractName">
  212. <span class="readOnly">{{ form.contractName }}</span>
  213. </uni-forms-item>
  214. <uni-forms-item label="任务" name="taskName">
  215. <span class="readOnly">{{ form.taskName }}</span>
  216. </uni-forms-item>
  217. <uni-forms-item label="施工状态" name="repairStatus" required>
  218. <uni-data-select
  219. :clear="true"
  220. align="right"
  221. placeholder="请选择"
  222. :localdata="rigStatusOptions"
  223. placement="top"
  224. :disabled="disabled('edit')"
  225. v-model="form.repairStatus" />
  226. </uni-forms-item>
  227. <uni-forms-item label="施工工艺" name="technique">
  228. <uni-data-select
  229. :clear="true"
  230. align="right"
  231. placeholder="请选择"
  232. :localdata="techniqueOptions"
  233. placement="top"
  234. :disabled="disabled('edit')"
  235. v-model="form.technique" />
  236. </uni-forms-item>
  237. <uni-forms-item label="井别" name="wellCategory">
  238. <uni-easyinput v-bind="defaultProps" v-model="form.wellCategory" :disabled="disabled('edit')" />
  239. </uni-forms-item>
  240. <uni-forms-item label="设计井深(m)" name="designWellDepth">
  241. <uni-easyinput v-bind="defaultProps" v-model="form.designWellDepth" :disabled="disabled('edit')" />
  242. </uni-forms-item>
  243. <uni-forms-item label="井控级别" name="wellControlLevel">
  244. <uni-easyinput v-bind="defaultProps" v-model="form.wellControlLevel" :disabled="disabled('edit')" />
  245. </uni-forms-item>
  246. <uni-forms-item label="套生段产管尺寸(mm)" name="casingPipeSize">
  247. <uni-easyinput v-bind="defaultProps" v-model="form.casingPipeSize" :disabled="disabled('edit')" />
  248. </uni-forms-item>
  249. <uni-forms-item label="当日油耗(L)" name="dailyFuel">
  250. <uni-easyinput type="number" v-bind="defaultProps" :disabled="disabled('edit')" v-model="form.dailyFuel" />
  251. </uni-forms-item>
  252. <uni-forms-item label="目前工序" name="currentOperation">
  253. <uni-easyinput
  254. type="textarea"
  255. autoHeight
  256. v-bind="defaultProps"
  257. v-model="form.currentOperation"
  258. :disabled="disabled('edit')"
  259. :maxlength="1000" />
  260. </uni-forms-item>
  261. <uni-forms-item label="下步工序" name="nextPlan">
  262. <uni-easyinput
  263. type="textarea"
  264. autoHeight
  265. v-bind="defaultProps"
  266. v-model="form.nextPlan"
  267. :disabled="disabled('edit')"
  268. :maxlength="1000" />
  269. </uni-forms-item>
  270. <uni-forms-item label="运行时效" name="transitTime">
  271. <span class="readOnly" :class="{ 'red-text': transitTime.original > 1.0 }">{{ transitTime.value }}</span>
  272. </uni-forms-item>
  273. <uni-forms-item label="额定生产时间(H)" name="ratedProductionTime" required>
  274. <uni-easyinput
  275. type="number"
  276. v-bind="defaultProps"
  277. :class="{ 'orange-text': sumTimes() !== Number(form.ratedProductionTime) }"
  278. :disabled="disabled('edit')"
  279. v-model="form.ratedProductionTime" />
  280. </uni-forms-item>
  281. <uni-forms-item label="生产时间(H)" name="productionTime" required>
  282. <uni-easyinput
  283. type="number"
  284. v-bind="defaultProps"
  285. :class="{ 'orange-text': sumTimes() !== Number(form.ratedProductionTime) }"
  286. :disabled="disabled('edit')"
  287. v-model="form.productionTime" />
  288. </uni-forms-item>
  289. <uni-forms-item label="非生产时间(H)" name="nonProductionTime" required>
  290. <uni-easyinput
  291. type="number"
  292. v-bind="defaultProps"
  293. :class="{ 'orange-text': sumTimes() !== Number(form.ratedProductionTime) }"
  294. :disabled="disabled('edit')"
  295. v-model="form.nonProductionTime" />
  296. </uni-forms-item>
  297. <uni-forms-item label="非生产时间原因" name="ryNptReason">
  298. <uni-data-select
  299. :clear="true"
  300. align="right"
  301. placeholder="请选择"
  302. :localdata="nptReasonOptions"
  303. placement="top"
  304. :disabled="disabled('edit')"
  305. v-model="form.ryNptReason" />
  306. </uni-forms-item>
  307. <uni-forms-item label="全员数量" name="totalStaffNum">
  308. <uni-easyinput type="number" v-bind="defaultProps" :disabled="disabled('edit')" v-model="form.totalStaffNum" />
  309. </uni-forms-item>
  310. <uni-forms-item label="在岗人数" name="onDutyStaffNum">
  311. <uni-easyinput type="number" v-bind="defaultProps" disabled v-model="onDutyStaffNum" />
  312. </uni-forms-item>
  313. <uni-forms-item label="休假人员数量" name="leaveStaffNum">
  314. <uni-easyinput type="number" v-bind="defaultProps" :disabled="disabled('edit')" v-model="form.leaveStaffNum" />
  315. </uni-forms-item>
  316. <uni-forms-item label="生产动态" name="productionStatus" required>
  317. <uni-easyinput
  318. type="textarea"
  319. autoHeight
  320. v-bind="defaultProps"
  321. v-model="form.productionStatus"
  322. :disabled="disabled('edit')"
  323. :maxlength="1000" />
  324. </uni-forms-item>
  325. <uni-forms-item label="备注" name="remark">
  326. <uni-easyinput
  327. type="textarea"
  328. autoHeight
  329. v-bind="defaultProps"
  330. :disabled="disabled('edit')"
  331. v-model="form.remark"
  332. :maxlength="1000" />
  333. </uni-forms-item>
  334. <uni-forms-item v-if="type.includes('approval')" label="审批意见" name="opinion">
  335. <uni-easyinput
  336. type="textarea"
  337. autoHeight
  338. v-bind="defaultProps"
  339. :disabled="disabled('approval')"
  340. v-model="form.opinion"
  341. :maxlength="1000" />
  342. </uni-forms-item>
  343. </uni-forms>
  344. </view>
  345. </template>
  346. <style lang="scss" scoped>
  347. .content {
  348. background-color: white;
  349. padding: 16px 16px;
  350. border-radius: 8px;
  351. box-sizing: border-box;
  352. }
  353. .uni-forms {
  354. margin-top: 10px;
  355. height: 100%;
  356. .uni-form {
  357. height: 100%;
  358. }
  359. .uni-forms-item {
  360. display: flex;
  361. align-items: center;
  362. flex: 1;
  363. margin-bottom: 6px;
  364. border-bottom: 1px dashed #cacccf;
  365. }
  366. :deep(.uni-forms-item__content) {
  367. text-align: right;
  368. .readOnly {
  369. padding-right: 10px;
  370. }
  371. }
  372. :deep(.uni-forms-item__label) {
  373. height: 44px;
  374. font-weight: 500;
  375. font-size: 14px;
  376. color: #333333 !important;
  377. width: max-content !important;
  378. }
  379. :deep(.uni-select) {
  380. border: none;
  381. text-align: right;
  382. padding-right: 0;
  383. .uniui-bottom:before {
  384. content: '\e6b5' !important;
  385. font-size: 16px !important;
  386. }
  387. }
  388. :deep(.uni-easyinput__content-textarea) {
  389. min-height: inherit;
  390. margin: 10px;
  391. }
  392. :deep(.is-disabled) {
  393. color: #333333 !important;
  394. }
  395. :deep(.red-text > .is-disabled) {
  396. color: rgb(220 38 38 / 0.8) !important;
  397. }
  398. :deep(.orange-text > .is-disabled) {
  399. color: rgb(234 88 12 / 0.8) !important;
  400. }
  401. :deep(.uni-select--disabled) {
  402. background-color: #fff;
  403. }
  404. }
  405. .red-text {
  406. color: rgb(220 38 38 / 0.8) !important;
  407. }
  408. .orange-text {
  409. color: rgb(234 88 12 / 0.8) !important;
  410. }
  411. .red {
  412. border: 1px solid rgb(254 226 226);
  413. color: rgb(220 38 38 / 0.8);
  414. background-color: rgb(254 226 226);
  415. }
  416. .orange {
  417. border: 1px solid rgb(254 215 170);
  418. color: rgb(234 88 12 / 0.8);
  419. background-color: rgb(254 215 170);
  420. }
  421. .tip {
  422. border-radius: 8px;
  423. border: 1px solid #e5e5e5;
  424. background-color: rgba(239, 246, 255, 0.8);
  425. box-sizing: border-box;
  426. padding: 10px;
  427. display: flex;
  428. flex-direction: column;
  429. gap: 6px;
  430. .item {
  431. display: flex;
  432. align-items: center;
  433. justify-content: space-between;
  434. font-size: 12px;
  435. .left {
  436. color: rgb(75 85 99);
  437. span {
  438. color: rgb(31 41 55);
  439. font-weight: 600;
  440. }
  441. }
  442. .right {
  443. display: inline-flex;
  444. align-items: center;
  445. border-radius: 4px;
  446. padding: 2px 4px;
  447. font-weight: 500;
  448. }
  449. }
  450. }
  451. .opinion {
  452. border-radius: 8px;
  453. border: 1px solid rgb(254 240 138);
  454. background-color: rgb(254 252 232);
  455. box-sizing: border-box;
  456. padding: 10px;
  457. display: flex;
  458. align-items: center;
  459. justify-content: space-between;
  460. font-size: 12px;
  461. margin-top: 10px;
  462. .left {
  463. font-weight: 600;
  464. color: rgb(133 77 14);
  465. }
  466. .right {
  467. font-weight: 500;
  468. color: rgb(75 85 99);
  469. }
  470. }
  471. </style>