detail.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <el-dialog v-model="visible" :title="titleMap[mode]" :width="860" :close-on-click-modal="false" @closed="$emit('closed', isDel)">
  3. <el-form ref="formRef" :model="form" :rules="rules" label-width="120">
  4. <el-row v-if="props.projectId != 1">
  5. <el-col :md="12" :xs="24">
  6. <el-form-item label="所属项目" prop="projectId">
  7. <el-select v-model="form.projectId" filterable placeholder="请选择所属项目" @change="form.mountedId = null">
  8. <el-option v-for="item in $TOOL.data.get('PROJECT')" :key="item.fpiId" :label="item.projectName" :value="item.fpiId"></el-option>
  9. </el-select>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :md="12" :xs="24">
  13. <el-form-item label="设备安装点" prop="mountedId">
  14. <el-select v-model="form.mountedId" filterable placeholder="请选择设备安装点">
  15. <el-option v-for="item in filterMounteds" :key="item.id" :label="item.mountedName" :value="item.id"></el-option>
  16. </el-select>
  17. </el-form-item>
  18. </el-col>
  19. </el-row>
  20. <el-row>
  21. <el-col :md="12" :xs="24">
  22. <el-form-item label="监测时间" prop="createTime">
  23. <el-date-picker v-model="form.createTime" type="datetime" :clearable="false" value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择监测时间"></el-date-picker>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :md="12" :xs="24">
  27. <el-form-item label="起重量" prop="features.weight">
  28. <el-input-number v-model="form.features.weight" :controls="false" placeholder="请输入起重量">
  29. <template #suffix>kg</template>
  30. </el-input-number>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :md="12" :xs="24">
  34. <el-form-item label="载重百分比" prop="features.weightRate">
  35. <el-input-number v-model="form.features.weightRate" :precision="2" :controls="false" placeholder="请输入载重百分比">
  36. <template #suffix>%</template>
  37. </el-input-number>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :md="12" :xs="24">
  41. <el-form-item label="高度" prop="features.height">
  42. <el-input-number v-model="form.features.height" :precision="1" :controls="false" placeholder="请输入高度">
  43. <template #suffix>m</template>
  44. </el-input-number>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :md="12" :xs="24">
  48. <el-form-item label="力矩百分比" prop="features.powerRate">
  49. <el-input-number v-model="form.features.powerRate" :precision="2" :controls="false" placeholder="请输入力矩百分比">
  50. <template #suffix>%</template>
  51. </el-input-number>
  52. </el-form-item>
  53. </el-col>
  54. <el-col :md="12" :xs="24">
  55. <el-form-item label="回转角度" prop="features.rotationAngle">
  56. <el-input-number v-model="form.features.rotationAngle" :precision="1" :controls="false" placeholder="请输入回转角度">
  57. <template #suffix>°</template>
  58. </el-input-number>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :md="12" :xs="24">
  62. <el-form-item label="倾角" prop="features.tiltAngle">
  63. <el-input-number v-model="form.features.tiltAngle" :precision="2" :controls="false" placeholder="请输入回转角度">
  64. <template #suffix>°</template>
  65. </el-input-number>
  66. </el-form-item>
  67. </el-col>
  68. <el-col :md="12" :xs="24">
  69. <el-form-item label="风力" prop="features.windSpeed">
  70. <el-input-number v-model="form.features.windSpeed" :precision="1" :controls="false" placeholder="请输入风力">
  71. <template #suffix>级</template>
  72. </el-input-number>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :md="12" :xs="24">
  76. <el-form-item label="幅度" prop="features.workAngle">
  77. <el-input-number v-model="form.features.workAngle" :precision="1" :controls="false" placeholder="请输入幅度">
  78. <template #suffix>m</template>
  79. </el-input-number>
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. </el-form>
  84. <template #footer>
  85. <el-button :loading="isSaving" type="primary" auto-insert-space @click="submit">保存</el-button>
  86. <el-button auto-insert-space @click="visible = false">取消</el-button>
  87. </template>
  88. </el-dialog>
  89. </template>
  90. <script setup>
  91. import XEUtils from "xe-utils";
  92. import API from "@/api";
  93. import TOOL from "@/utils/tool";
  94. import { valueFormatDic } from "@/views/dataMock/tower/main";
  95. const $emit = defineEmits(["success", "closed"]);
  96. const props = defineProps({
  97. projectId: { type: Number, default: TOOL.data.get("PROJECT_ID") }
  98. });
  99. const visible = ref(false);
  100. const isSaving = ref(false);
  101. const isDel = ref(false);
  102. const mode = ref("add");
  103. const titleMap = reactive({
  104. add: "数据录入",
  105. edit: "修改"
  106. });
  107. const form = ref({
  108. id: null,
  109. projectId: props.projectId,
  110. mountedId: null,
  111. createTime: null,
  112. features: {
  113. weight: null,
  114. weightRate: null,
  115. height: null,
  116. powerRate: null,
  117. rotationAngle: null,
  118. tiltAngle: null,
  119. windSpeed: null,
  120. workAngle: null
  121. }
  122. });
  123. const rules = reactive({
  124. projectId: [{ required: true, message: "请选择所属项目" }],
  125. mountedId: [{ required: true, message: "请选择设备安装点" }],
  126. createTime: [{ required: true, message: "请选择监测时间" }],
  127. "features.weight": [{ required: true, message: "请输入起重量" }],
  128. "features.weightRate": [{ required: true, message: "请输入载重百分比" }],
  129. "features.height": [{ required: true, message: "请输入高度" }],
  130. "features.powerRate": [{ required: true, message: "请输入力矩百分比" }],
  131. "features.rotationAngle": [{ required: true, message: "请输入回转角度" }],
  132. "features.tiltAngle": [{ required: true, message: "请输入倾角" }],
  133. "features.windSpeed": [{ required: true, message: "请输入风力" }],
  134. "features.workAngle": [{ required: true, message: "请输入幅度" }]
  135. })
  136. const mounteds = ref([]);
  137. const filterMounteds = computed(() => form.value.projectId ? XEUtils.filter(mounteds.value, item => item.projectId == form.value.projectId) : []);
  138. const fetchMounted = async () => {
  139. const res = await API.tower.mounted.get();
  140. mounteds.value = res || [];
  141. if (props.projectId == 1) form.value.mountedId = XEUtils.get(XEUtils.find(res, item => item.projectId == 1), "id");
  142. }
  143. const open = () => {
  144. visible.value = true;
  145. fetchMounted();
  146. }
  147. const setData = data => {
  148. open();
  149. mode.value = "edit";
  150. XEUtils.objectEach(form.value, (_, key) => {
  151. if (key == "features") {
  152. const features = XEUtils.toStringJSON(XEUtils.get(data, key));
  153. XEUtils.objectEach(valueFormatDic, (item, digits) => XEUtils.arrayEach(item, feaKey => XEUtils.set(features, feaKey, XEUtils.divide(XEUtils.get(features, feaKey), digits))));
  154. XEUtils.merge(form.value.features, features);
  155. } else XEUtils.set(form.value, key, XEUtils.get(data, key));
  156. });
  157. }
  158. const formRef = ref();
  159. const submit = () => {
  160. formRef.value.validate(valid => {
  161. if (valid) {
  162. const data = XEUtils.omit(form.value, "features");
  163. const features = XEUtils.clone(form.value.features, true);
  164. XEUtils.objectEach(valueFormatDic, (item, digits) => XEUtils.arrayEach(item, feaKey => XEUtils.set(features, feaKey, XEUtils.multiply(XEUtils.get(features, feaKey), digits))));
  165. XEUtils.set(data, "features", XEUtils.toJSONString(features));
  166. isSaving.value = true;
  167. API.tower.record[mode.value](data).then(() => {
  168. isSaving.value = false;
  169. ElMessage.success("操作成功");
  170. visible.value = false;
  171. $emit("success", mode.value);
  172. }).catch(() => isSaving.value = false);
  173. } else {
  174. return false;
  175. }
  176. });
  177. }
  178. defineExpose({
  179. open,
  180. setData
  181. })
  182. </script>
  183. <style lang="scss" scoped>
  184. .el-form {
  185. padding-right: calc(var(--el-dialog-padding-primary) + var(--el-message-close-size, 16px));
  186. .el-input-number {width: 100%;}
  187. .el-input-number :deep(.el-input__inner) {text-align: unset;}
  188. .el-input-number :deep(.el-input__suffix) {font-size: 12px;}
  189. }
  190. </style>