| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div> |
| | | <el-dialog |
| | | v-model="dialogFormVisible" |
| | | title="水费管ç" |
| | | width="70%" |
| | | @close="closeDia" |
| | | > |
| | | <el-form |
| | | :model="form" |
| | | label-width="140px" |
| | | label-position="top" |
| | | :rules="rules" |
| | | ref="formRef" |
| | | > |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="设å¤ï¼" prop="code"> |
| | | <el-select |
| | | v-model="form.code" |
| | | placeholder="è¯·éæ©" |
| | | clearable |
| | | @change="setName" |
| | | :disabled="operationType !== 'add'" |
| | | > |
| | | <el-option |
| | | v-for="item in codeList" |
| | | :key="item.deviceModel" |
| | | :label="item.deviceName" |
| | | :value="item.deviceModel" |
| | | > |
| | | {{item.deviceName + '--' + item.deviceModel}} |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ç¨æ°´éï¼" prop="waterConsumption"> |
| | | <el-input |
| | | v-model="form.waterConsumption" |
| | | placeholder="请è¾å
¥" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="æ°´è´¹åä»·ï¼" prop="waterPrice"> |
| | | <el-input |
| | | v-model="form.waterPrice" |
| | | placeholder="请è¾å
¥" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="æ°´è´¹éé¢ï¼" prop="waterBill"> |
| | | <el-input |
| | | v-model="form.waterBill" |
| | | placeholder="èªå¨è®¡ç®" |
| | | clearable |
| | | disabled |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="è®¡è´¹æ¥æï¼" prop="billDate"> |
| | | <el-date-picker |
| | | style="width: 100%" |
| | | v-model="form.billDate" |
| | | value-format="YYYY-MM-DD" |
| | | format="YYYY-MM-DD" |
| | | type="date" |
| | | placeholder="è¯·éæ©" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ç¨æ°´ç±»åï¼" prop="waterType"> |
| | | <el-select |
| | | v-model="form.waterType" |
| | | placeholder="è¯·éæ©" |
| | | clearable |
| | | > |
| | | <el-option label="å·¥ä¸ç¨æ°´" value="industrial" /> |
| | | <el-option label="çæ´»ç¨æ°´" value="domestic" /> |
| | | <el-option label="æ¶é²ç¨æ°´" value="fire" /> |
| | | <el-option label="绿åç¨æ°´" value="greening" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" @click="submitForm">确认</el-button> |
| | | <el-button @click="closeDia">åæ¶</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import {ref, reactive, nextTick, watch} from "vue"; |
| | | import useUserStore from "@/store/modules/user.js"; |
| | | import {waterDeviceList, waterBillAdd, waterBillUpdate} from "@/api/energyManagement/waterManagement.js"; |
| | | import { getCurrentDate } from "@/utils/index.js"; |
| | | const { proxy } = getCurrentInstance() |
| | | const emit = defineEmits(['close']) |
| | | const dialogFormVisible = ref(false); |
| | | const operationType = ref('') |
| | | const userStore = useUserStore(); |
| | | |
| | | const data = reactive({ |
| | | form: { |
| | | name: "", |
| | | code: "", |
| | | waterConsumption: "", |
| | | waterPrice: "", |
| | | waterBill: "", |
| | | billDate: "", |
| | | waterType: "", |
| | | }, |
| | | rules: { |
| | | code: [{ required: true, message: "è¯·éæ©", trigger: "change" }], |
| | | waterConsumption: [{ required: true, message: "请è¾å
¥", trigger: "blur" }], |
| | | waterPrice: [{ required: true, message: "请è¾å
¥", trigger: "blur" }], |
| | | billDate: [{ required: true, message: "è¯·éæ©", trigger: "change" }], |
| | | waterType: [{ required: true, message: "è¯·éæ©", trigger: "change" }], |
| | | }, |
| | | }) |
| | | const { form, rules } = toRefs(data); |
| | | const codeList = ref([]) |
| | | |
| | | // æå¼å¼¹æ¡ |
| | | const openDialog = (type, row) => { |
| | | operationType.value = type; |
| | | dialogFormVisible.value = true; |
| | | form.value = {} |
| | | proxy.resetForm("formRef"); |
| | | waterDeviceList().then((res) => { |
| | | codeList.value = res.data; |
| | | }); |
| | | if (type === "edit") { |
| | | form.value = {...row} |
| | | } |
| | | } |
| | | const setName = (code) => { |
| | | const index = codeList.value.findIndex(item => item.deviceModel === code); |
| | | if (index > -1) { |
| | | console.log(codeList) |
| | | form.value.name = codeList.value[index].deviceName; |
| | | } |
| | | } |
| | | |
| | | // è®¡ç®æ°´è´¹éé¢ |
| | | const calculateWaterBill = () => { |
| | | if (form.value.waterConsumption && form.value.waterPrice) { |
| | | form.value.waterBill = (parseFloat(form.value.waterConsumption) * parseFloat(form.value.waterPrice)).toFixed(2); |
| | | } |
| | | } |
| | | |
| | | // çå¬ç¨æ°´éåæ°´è´¹åä»·åå |
| | | watch([() => form.value.waterConsumption, () => form.value.waterPrice], () => { |
| | | calculateWaterBill(); |
| | | }); |
| | | |
| | | const submitForm = () => { |
| | | proxy.$refs["formRef"].validate(valid => { |
| | | if (valid) { |
| | | if (operationType.value === "add") { |
| | | waterBillAdd(form.value).then(response => { |
| | | proxy.$modal.msgSuccess("æ°å¢æå") |
| | | closeDia() |
| | | }) |
| | | } else { |
| | | waterBillUpdate(form.value).then(response => { |
| | | proxy.$modal.msgSuccess("ä¿®æ¹æå") |
| | | closeDia() |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | // å
³éå¼¹æ¡ |
| | | const closeDia = () => { |
| | | proxy.resetForm("formRef"); |
| | | dialogFormVisible.value = false; |
| | | emit('close') |
| | | }; |
| | | defineExpose({ |
| | | openDialog, |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped> |
| | | |
| | | </style> |