workOrderReport.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <u-popup :show="visible" :round="0" :closeOnClickOverlay="false" :zIndex="99999" @close="handleCancel"
  3. class="u-popup-my">
  4. <view class="popup-content">
  5. <view class="popup-header">
  6. <text class="popup-title">{{ title }}</text>
  7. <view class="close-btn" @click="handleCancel">×</view>
  8. </view>
  9. <scroll-view class="popup-body" scroll-y>
  10. <view class="page">
  11. <view class="card-a">
  12. <!-- 头部 -->
  13. <view class="a-header">
  14. <text class="a-main-title">{{ '抄表记录' }}</text>
  15. <!-- <view class="a-sub">
  16. <text>📋 {{ title }}</text>
  17. </view> -->
  18. </view>
  19. <!-- 设备信息 -->
  20. <view class="card-section">
  21. <view class="section-title">🔧 设备信息</view>
  22. <view class="info-grid">
  23. <view class="info-item">
  24. <text class="info-label">表计设备名称</text>
  25. <view class="info-value" :class="{ disabled: isView }"
  26. @click="!isView && openMaterialAdd()">
  27. {{ form.substanceName || '请选择' }}
  28. </view>
  29. </view>
  30. <view class="info-item">
  31. <text class="info-label">表计设备编号</text>
  32. <view class="info-value disabled">
  33. {{ form.meterEquipmentNumber || '-' }}
  34. </view>
  35. </view>
  36. <view class="info-item">
  37. <text class="info-label">用能分类</text>
  38. <view class="info-value disabled">
  39. {{ form.energyClassificationName || '-' }}
  40. </view>
  41. </view>
  42. <view class="info-item">
  43. <text class="info-label">能源名称</text>
  44. <view class="info-value disabled">
  45. {{ form.energyTypeName || '-' }}
  46. </view>
  47. </view>
  48. <view class="info-item">
  49. <text class="info-label">表计单位</text>
  50. <view class="info-value disabled">
  51. {{ form.unit || '-' }}
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 抄表信息 -->
  57. <view class="card-section">
  58. <view class="section-title">📝 抄表信息</view>
  59. <view class="info-grid">
  60. <view class="info-item">
  61. <text class="info-label">抄表人</text>
  62. <input class="info-input" v-model="form.meterReadingName" placeholder="请输入抄表人"
  63. :disabled="true" />
  64. </view>
  65. <view class="info-item">
  66. <text class="info-label">本期抄表时间</text>
  67. <uni-datetime-picker type="datetime" v-model="form.currentMeterReadingTime"
  68. returnType="timestamp" :disabled="isView">
  69. <view class="info-value">
  70. {{
  71. form.currentMeterReadingTime
  72. ? dayjs(form.currentMeterReadingTime).format('YYYY-MM-DD HH:mm:ss')
  73. : '请选择'
  74. }}
  75. </view>
  76. </uni-datetime-picker>
  77. </view>
  78. <view class="info-item">
  79. <text class="info-label">本期抄表数</text>
  80. <input class="info-input" v-model="form.currentMeterReadingNum" type="number"
  81. placeholder="请输入本期抄表数" :disabled="isView" />
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </scroll-view>
  88. <view class="popup-footer">
  89. <u-button type="default" @click="handleCancel">
  90. {{ isView ? '关闭' : '取消' }}
  91. </u-button>
  92. <u-button type="primary" @click="handleSubmit" v-if="!isView" :loading="loading">确定</u-button>
  93. </view>
  94. </view>
  95. <u-toast ref="uToast"></u-toast>
  96. <materialDialog ref="materialAddRef" @affirm="handleChooseEquipment"></materialDialog>
  97. </u-popup>
  98. </template>
  99. <script>
  100. import {
  101. save,
  102. update,
  103. getById
  104. } from '@/api/centralizedMeterReading/index.js';
  105. import dayjs from 'dayjs';
  106. import {
  107. energyConsumingUnitList
  108. } from '@/enum/dict.js';
  109. import materialDialog from '@/components/MaterialSelector/materialDialog.vue';
  110. const defForm = {
  111. id: '',
  112. substanceId: '',
  113. substanceName: '',
  114. substanceCode: '',
  115. meterEquipmentNumber: '',
  116. energyClassificationName: '',
  117. energyTypeName: '',
  118. unit: '',
  119. meterReadingName: '',
  120. meterReadingId: '',
  121. currentMeterReadingTime: '',
  122. currentMeterReadingNum: '',
  123. meterReadingMethod: 1,
  124. };
  125. export default {
  126. name: 'MeterReadingDialog',
  127. data() {
  128. return {
  129. visible: false,
  130. loading: false,
  131. title: '新增',
  132. type: 'add',
  133. form: {
  134. ...defForm
  135. },
  136. dayjs,
  137. };
  138. },
  139. computed: {
  140. isView() {
  141. return this.type === 'view';
  142. },
  143. },
  144. components: {
  145. materialDialog
  146. },
  147. methods: {
  148. // 打开弹窗
  149. async open(row, type = 'add') {
  150. this.type = type;
  151. if (type === 'add') {
  152. this.title = '新增';
  153. this.resetForm();
  154. const currentUser = uni.getStorageSync("userInfo");
  155. this.form.meterReadingName = currentUser?.name || '';
  156. this.form.meterReadingId = currentUser?.userId || '';
  157. this.form.currentMeterReadingTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
  158. } else {
  159. this.title = type === 'edit' ? '编辑' : '详情';
  160. try {
  161. const res = await getById(row.id);
  162. this.form = {
  163. ...defForm,
  164. ...res
  165. };
  166. } catch (e) {
  167. console.error('获取详情失败', e);
  168. }
  169. }
  170. this.visible = true;
  171. },
  172. // 关闭弹窗
  173. handleCancel() {
  174. this.visible = false;
  175. this.resetForm();
  176. },
  177. // 重置表单
  178. resetForm() {
  179. this.form = {
  180. ...defForm
  181. };
  182. },
  183. // 打开设备选择(uni-app 中可替换为 navigateTo 或 picker)
  184. openMaterialAdd() {
  185. if (this.isView) return;
  186. // TODO: 接入设备选择页面
  187. this.$refs.materialAddRef.open()
  188. },
  189. // 选择设备回调
  190. handleChooseEquipment(data) {
  191. let row = data[0] || {}
  192. this.form.substanceId = row.id;
  193. this.form.substanceName = row?.category?.name;
  194. this.form.substanceCode = row.code;
  195. this.form.meterEquipmentNumber = row.codeNumber;
  196. this.form.energyClassificationName = row.energyClassificationName;
  197. this.form.energyClassificationCode = row.energyClassificationCode;
  198. this.form.energyTypeName = row.energyTypeName || '';
  199. this.form.energyTypeId = row.energyTypeId || '';
  200. this.form.energyTypeCode = row.energyTypeCode || '';
  201. this.form.unit = energyConsumingUnitList
  202. .find((item) => item.value == row.energyClassificationCode)
  203. ?.unit.find((item) => item.value == row.energyUnit)?.label;
  204. },
  205. // 提交
  206. async handleSubmit() {
  207. // 必填校验
  208. if (!this.form.substanceId) {
  209. this.$refs.uToast.show({
  210. type: 'error',
  211. icon: false,
  212. message: '请选择表计设备'
  213. });
  214. return;
  215. }
  216. if (!this.form.meterReadingName) {
  217. this.$refs.uToast.show({
  218. type: 'error',
  219. icon: false,
  220. message: '请输入抄表人'
  221. });
  222. return;
  223. }
  224. if (!this.form.currentMeterReadingTime) {
  225. this.$refs.uToast.show({
  226. type: 'error',
  227. icon: false,
  228. message: '请选择本期抄表时间'
  229. });
  230. return;
  231. }
  232. if (this.form.currentMeterReadingNum === '' || this.form.currentMeterReadingNum == null) {
  233. this.$refs.uToast.show({
  234. type: 'error',
  235. icon: false,
  236. message: '请输入本期抄表数'
  237. });
  238. return;
  239. }
  240. // 时间格式补齐
  241. const formatTime = (timeStr) => {
  242. if (!timeStr) return timeStr;
  243. if (/^\d{4}-\d{2}-\d{2}$/.test(timeStr)) {
  244. return timeStr + ' 00:00:00';
  245. }
  246. return timeStr;
  247. };
  248. this.form.currentMeterReadingTime = formatTime(this.form.currentMeterReadingTime);
  249. const api = this.type === 'edit' ? update : save;
  250. this.loading = true;
  251. try {
  252. await api(this.form);
  253. this.$refs.uToast.show({
  254. type: 'success',
  255. message: this.type === 'edit' ? '编辑成功' : '新增成功',
  256. });
  257. this.visible = false;
  258. this.$emit('refresh');
  259. this.resetForm();
  260. } catch (error) {
  261. console.error(error);
  262. } finally {
  263. this.loading = false;
  264. }
  265. },
  266. },
  267. };
  268. </script>
  269. <style scoped lang="scss">
  270. .popup-content {
  271. width: 100vw;
  272. height: calc(100vh - 100px);
  273. background: #fff;
  274. border-radius: 0;
  275. display: flex;
  276. flex-direction: column;
  277. background-color: #eff2f7;
  278. }
  279. .popup-header {
  280. display: flex;
  281. justify-content: space-between;
  282. align-items: center;
  283. padding: 30rpx;
  284. border-bottom: 1rpx solid #e5e5e5;
  285. background: #fff;
  286. .popup-title {
  287. font-size: 36rpx;
  288. font-weight: bold;
  289. color: #333;
  290. }
  291. .close-btn {
  292. width: 60rpx;
  293. height: 60rpx;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. font-size: 60rpx;
  298. color: #999;
  299. line-height: 1;
  300. }
  301. }
  302. .popup-body {
  303. flex: 1;
  304. overflow-y: auto;
  305. padding: 28rpx;
  306. }
  307. .page {
  308. font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, sans-serif;
  309. }
  310. .card-a {
  311. background: #ffffff;
  312. border-radius: 48rpx;
  313. box-shadow: 0 12rpx 40rpx rgba(0, 0, 0, 0.05);
  314. overflow: hidden;
  315. }
  316. .a-header {
  317. background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 100%);
  318. padding: 40rpx 32rpx 24rpx;
  319. text-align: center;
  320. }
  321. .a-main-title {
  322. font-size: 36rpx;
  323. font-weight: 800;
  324. color: #2e7d32;
  325. }
  326. .a-sub {
  327. font-size: 24rpx;
  328. color: #558b2f;
  329. margin-top: 12rpx;
  330. }
  331. .card-section {
  332. padding: 30rpx 32rpx;
  333. border-bottom: 2rpx solid #f0f2f5;
  334. &:last-child {
  335. border-bottom: none;
  336. }
  337. }
  338. .section-title {
  339. font-size: 30rpx;
  340. font-weight: 700;
  341. color: #1f2a44;
  342. margin-bottom: 24rpx;
  343. padding-left: 16rpx;
  344. border-left: 6rpx solid #4caf50;
  345. }
  346. .info-grid {
  347. display: grid;
  348. grid-template-columns: 1fr 1fr;
  349. gap: 28rpx 20rpx;
  350. }
  351. .info-item {
  352. display: flex;
  353. flex-direction: column;
  354. gap: 8rpx;
  355. }
  356. .info-label {
  357. font-size: 26rpx;
  358. font-weight: 600;
  359. color: #6c7a91;
  360. }
  361. .info-value {
  362. font-size: 28rpx;
  363. font-weight: 500;
  364. color: #1e2a3a;
  365. padding: 16rpx 20rpx;
  366. border-radius: 24rpx;
  367. border: 2rpx solid #e9edf2;
  368. background: #fff;
  369. &.disabled {
  370. color: #999;
  371. background: #f5f5f5;
  372. }
  373. }
  374. .info-input {
  375. font-size: 28rpx;
  376. color: #1e2a3a;
  377. padding: 16rpx 20rpx;
  378. border-radius: 24rpx;
  379. border: 2rpx solid #e9edf2;
  380. background: #fff;
  381. height: 76rpx;
  382. &:disabled {
  383. color: #999;
  384. background: #f5f5f5;
  385. }
  386. }
  387. .popup-footer {
  388. display: flex;
  389. padding: 20rpx 30rpx;
  390. border-top: 1rpx solid #e5e5e5;
  391. background: #fff;
  392. gap: 20rpx;
  393. /deep/ .u-button {
  394. flex: 1;
  395. }
  396. }
  397. </style>