This commit is contained in:
2021-08-23 20:14:38 +00:00
parent 6cdcb8b012
commit 028caf66a7
5 changed files with 80 additions and 58 deletions

View File

@@ -128,6 +128,11 @@
"
@update:name="unitChange"
></gz-pick-list>
<template v-slot:append v-if="canOpenMeter()">
<v-btn outlined small color="primary" @click="openMeter">
<v-icon>$ayiWeight</v-icon></v-btn
>
</template>
</v-col>
<v-col
@@ -355,7 +360,8 @@ export default {
availableBulkUnits: [],
selectedBulkUnits: [],
selectedBulkUnitTags: [],
bulkUnitTableHeaders: []
bulkUnitTableHeaders: [],
isMetered: false
};
},
props: {
@@ -405,46 +411,81 @@ export default {
}
},
methods: {
async updateContractIfApplicable() {
canOpenMeter: function() {
return (
this.isMetered == true &&
this.value.items[this.activeWoItemIndex].units[this.activeItemIndex]
.id != 0
);
},
openMeter: function() {
if (this.canOpenMeter()) {
this.$router.push({
name: "meter-readings",
params: {
workorderitemunitid: this.value.items[this.activeWoItemIndex].units[
this.activeItemIndex
].id,
unitid: this.value.items[this.activeWoItemIndex].units[
this.activeItemIndex
].unitId,
unitname: this.value.items[this.activeWoItemIndex].units[
this.activeItemIndex
].unitViz
}
});
// this.$router.push({
// name: "meter-readings",
// params: {
// aType: window.$gz.type.Unit,
// objectId: this.$route.params.recordid
// }
// });
}
},
async handleUnitChange() {
const id = this.value.items[this.activeWoItemIndex].units[
this.activeItemIndex
].unitId;
if (!id || id == 0) {
return;
}
let res = await window.$gz.api.get(`unit/active-contract/${id}`);
let res = await window.$gz.api.get(`unit/work-order-info/${id}`);
if (res.error) {
window.$gz.eventBus.$emit(
"notify-warning",
window.$gz.errorHandler.errorToString(res, this)
);
} else {
if (res.data.id == 0) {
//no contract, just bail
return;
}
//has contract, if it differs from main work order contract then offer to set it
if (res.data.id == this.value.contractId) {
//same contract, just bail
//yes the date could not be different but we're not going to pick that nit, they can just unset and set if it matters
return;
}
//Prompt user to use new contract
const prompt = this.$ay
.t("ApplyUnitContract")
.replace("{0}", res.data.name);
//METER READING
this.isMetered = res.data.isMetered;
let dialogResult = await window.$gz.dialog.confirmGenericPreTranslated(
prompt,
"question"
);
if (dialogResult == false) {
return;
} else {
this.value.contractId = res.data.id;
this.value.isDirty = true;
this.pvm.formState.dirty = true;
this.$emit("change");
//CONTRACT
if (res.data.contract.id != 0) {
//has contract, if it differs from main work order contract then offer to set it
if (res.data.id == this.value.contractId) {
//same contract, just bail
//yes the date could not be different but we're not going to pick that nit, they can just unset and set if it matters
return;
}
//Prompt user to use new contract
const prompt = this.$ay
.t("ApplyUnitContract")
.replace("{0}", res.data.name);
let dialogResult = await window.$gz.dialog.confirmGenericPreTranslated(
prompt,
"question"
);
if (dialogResult == false) {
return;
} else {
this.value.contractId = res.data.id;
this.value.isDirty = true;
this.pvm.formState.dirty = true;
this.$emit("change");
}
}
}
},
@@ -607,7 +648,7 @@ export default {
this.value.items[this.activeWoItemIndex].units[
this.activeItemIndex
].warrantyViz = null;
await this.updateContractIfApplicable();
await this.handleUnitChange();
},
newItem() {
let newIndex = this.value.items[this.activeWoItemIndex].units.length;