re-factor / cleanup
This commit is contained in:
@@ -50,10 +50,10 @@
|
||||
<!-- ############################################################### -->
|
||||
<v-col cols="12" class="mb-10">
|
||||
<v-data-table
|
||||
v-model="selectedRow"
|
||||
:headers="headerList"
|
||||
:items="itemList"
|
||||
item-key="index"
|
||||
v-model="selectedRow"
|
||||
class="elevation-1"
|
||||
disable-pagination
|
||||
disable-filtering
|
||||
@@ -62,9 +62,9 @@
|
||||
data-cy="loansTable"
|
||||
dense
|
||||
:item-class="itemRowClasses"
|
||||
@click:row="handleRowClick"
|
||||
:show-select="$vuetify.breakpoint.xs"
|
||||
single-select
|
||||
@click:row="handleRowClick"
|
||||
>
|
||||
</v-data-table>
|
||||
</v-col>
|
||||
@@ -74,8 +74,8 @@
|
||||
<v-btn
|
||||
v-if="canDelete && isDeleted"
|
||||
large
|
||||
@click="unDeleteItem"
|
||||
color="primary"
|
||||
@click="unDeleteItem"
|
||||
>{{ $ay.t("Undelete")
|
||||
}}<v-icon right large>$ayiTrashRestoreAlt</v-icon></v-btn
|
||||
>
|
||||
@@ -88,19 +88,19 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
:aya-type="$ay.ayt().LoanUnit"
|
||||
:show-edit-icon="!value.userIsRestrictedType"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].loanUnitId`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].loanUnitId
|
||||
"
|
||||
:aya-type="$ay.ayt().LoanUnit"
|
||||
:show-edit-icon="!value.userIsRestrictedType"
|
||||
:readonly="
|
||||
formState.readOnly || isDeleted || value.userIsRestrictedType
|
||||
"
|
||||
:disabled="isDeleted"
|
||||
:label="$ay.t('WorkOrderItemLoanUnit')"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].loanUnitId`
|
||||
"
|
||||
data-cy="loans.loanUnitId"
|
||||
:rules="[
|
||||
form().required(
|
||||
@@ -134,6 +134,7 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-select
|
||||
:ref="`Items[${activeWoItemIndex}].loans[${activeItemIndex}].rate`"
|
||||
v-model="value.items[activeWoItemIndex].loans[activeItemIndex].rate"
|
||||
:items="pvm.selectLists.loanUnitRateUnits"
|
||||
item-text="name"
|
||||
@@ -141,7 +142,6 @@
|
||||
:readonly="formState.readOnly || isDeleted"
|
||||
:disabled="isDeleted"
|
||||
:label="$ay.t('WorkOrderItemLoanRate')"
|
||||
:ref="`Items[${activeWoItemIndex}].loans[${activeItemIndex}].rate`"
|
||||
data-cy="loanUnitRateUnit"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -169,15 +169,15 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-decimal
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].quantity`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].quantity
|
||||
"
|
||||
:readonly="formState.readOnly || isDeleted"
|
||||
:disabled="isDeleted"
|
||||
:label="$ay.t('WorkOrderItemLoanQuantity')"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].quantity`
|
||||
"
|
||||
data-cy="loanQuantity"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -211,15 +211,15 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-date-time-picker
|
||||
:label="$ay.t('WorkOrderItemLoanOutDate')"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].outDate
|
||||
"
|
||||
:readonly="formState.readOnly || value.userIsRestrictedType"
|
||||
:disabled="isDeleted"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].outDate`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].outDate
|
||||
"
|
||||
:label="$ay.t('WorkOrderItemLoanOutDate')"
|
||||
:readonly="formState.readOnly || value.userIsRestrictedType"
|
||||
:disabled="isDeleted"
|
||||
data-cy="loanUnitOutDate"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -243,15 +243,15 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-date-time-picker
|
||||
:label="$ay.t('WorkOrderItemLoanDueDate')"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].dueDate
|
||||
"
|
||||
:readonly="formState.readOnly || value.userIsRestrictedType"
|
||||
:disabled="isDeleted"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].dueDate`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].dueDate
|
||||
"
|
||||
:label="$ay.t('WorkOrderItemLoanDueDate')"
|
||||
:readonly="formState.readOnly || value.userIsRestrictedType"
|
||||
:disabled="isDeleted"
|
||||
data-cy="loanUnitDueDate"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -275,15 +275,15 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-date-time-picker
|
||||
:label="$ay.t('WorkOrderItemLoanReturnDate')"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].returnDate
|
||||
"
|
||||
:readonly="formState.readOnly || value.userIsRestrictedType"
|
||||
:disabled="isDeleted"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].returnDate`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].returnDate
|
||||
"
|
||||
:label="$ay.t('WorkOrderItemLoanReturnDate')"
|
||||
:readonly="formState.readOnly || value.userIsRestrictedType"
|
||||
:disabled="isDeleted"
|
||||
data-cy="loanUnitReturnDate"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -310,17 +310,17 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
:aya-type="$ay.ayt().TaxCode"
|
||||
show-edit-icon
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].taxCodeId
|
||||
"
|
||||
:readonly="formState.readOnly || isDeleted"
|
||||
:disabled="isDeleted"
|
||||
:label="$ay.t('WorkOrderItemLoanTaxCodeID')"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].taxCodeId`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].taxCodeId
|
||||
"
|
||||
:aya-type="$ay.ayt().TaxCode"
|
||||
show-edit-icon
|
||||
:readonly="formState.readOnly || isDeleted"
|
||||
:disabled="isDeleted"
|
||||
:label="$ay.t('WorkOrderItemLoanTaxCodeID')"
|
||||
data-cy="loanTaxCodeSaleId"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -348,6 +348,9 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-currency
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].priceOverride`
|
||||
"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex]
|
||||
.priceOverride
|
||||
@@ -356,9 +359,6 @@
|
||||
:readonly="formState.readOnly || isDeleted"
|
||||
:disabled="isDeleted"
|
||||
:label="$ay.t('PriceOverride')"
|
||||
:ref="
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].priceOverride`
|
||||
"
|
||||
data-cy="loanpriceoverride"
|
||||
:error-messages="
|
||||
form().serverErrors(
|
||||
@@ -382,6 +382,7 @@
|
||||
|
||||
<v-col v-if="form().showMe(this, 'WorkOrderItemLoanNotes')" cols="12">
|
||||
<v-textarea
|
||||
:ref="`Items[${activeWoItemIndex}].loans[${activeItemIndex}].notes`"
|
||||
v-model="
|
||||
value.items[activeWoItemIndex].loans[activeItemIndex].notes
|
||||
"
|
||||
@@ -394,14 +395,13 @@
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].notes`
|
||||
)
|
||||
"
|
||||
:ref="`Items[${activeWoItemIndex}].loans[${activeItemIndex}].notes`"
|
||||
data-cy="loanUnitNotes"
|
||||
auto-grow
|
||||
@input="
|
||||
fieldValueChanged(
|
||||
`Items[${activeWoItemIndex}].loans[${activeItemIndex}].notes`
|
||||
)
|
||||
"
|
||||
auto-grow
|
||||
></v-textarea>
|
||||
</v-col>
|
||||
</template>
|
||||
@@ -410,15 +410,6 @@
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
created() {
|
||||
this.setDefaultView();
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
activeItemIndex: null,
|
||||
selectedRow: []
|
||||
};
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
default: null,
|
||||
@@ -437,151 +428,11 @@ export default {
|
||||
type: Number
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
activeWoItemIndex(val, oldVal) {
|
||||
if (val != oldVal) {
|
||||
this.setDefaultView();
|
||||
}
|
||||
},
|
||||
gotoIndex(val, oldVal) {
|
||||
if (val != oldVal) {
|
||||
let gotoIndex = val;
|
||||
if (val < 0) {
|
||||
//it's a create request
|
||||
gotoIndex = this.newItem();
|
||||
}
|
||||
this.selectedRow = [{ index: gotoIndex }];
|
||||
this.activeItemIndex = gotoIndex;
|
||||
this.$nextTick(() => {
|
||||
const el = this.$refs.loantopform;
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: "smooth" });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loanUnitRateUnitChange(newId) {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].unitOfMeasureViz = this.pvm.selectLists.loanUnitRateUnits.find(
|
||||
s => s.id == newId
|
||||
).name;
|
||||
},
|
||||
loanUnitChange(newName) {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].loanUnitViz = newName;
|
||||
},
|
||||
taxCodeChange(newName) {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].taxCodeViz = newName;
|
||||
},
|
||||
newItem() {
|
||||
const newIndex = this.value.items[this.activeWoItemIndex].loans.length;
|
||||
|
||||
this.value.items[this.activeWoItemIndex].loans.push({
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
notes: null,
|
||||
outDate: null,
|
||||
dueDate: null,
|
||||
returnDate: null,
|
||||
taxCodeId: window.$gz.store.state.globalSettings.defaultTaxPartSaleId,
|
||||
loanUnitId: 0, //zero to break rule on new
|
||||
quantity: 1,
|
||||
rate: 1,
|
||||
cost: 0,
|
||||
priceOverride: null,
|
||||
isDirty: true,
|
||||
quoteItemId: this.value.items[this.activeWoItemIndex].id,
|
||||
uid: Date.now(),
|
||||
loanUnitViz: null,
|
||||
taxCodeViz: null,
|
||||
unitOfMeasureViz: null
|
||||
});
|
||||
this.$emit("change");
|
||||
this.selectedRow = [{ index: newIndex }];
|
||||
this.activeItemIndex = newIndex;
|
||||
//trigger rule breaking / validation
|
||||
this.$nextTick(() => {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].loanUnitId = null;
|
||||
this.fieldValueChanged(
|
||||
`Items[${this.activeWoItemIndex}].loans[${this.activeItemIndex}].loanUnitId`
|
||||
);
|
||||
});
|
||||
return newIndex; //for create new on goto
|
||||
},
|
||||
unDeleteItem() {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].deleted = false;
|
||||
this.setDefaultView();
|
||||
},
|
||||
deleteItem() {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].deleted = true;
|
||||
this.setDefaultView();
|
||||
this.$emit("change");
|
||||
},
|
||||
deleteAllItem() {
|
||||
this.value.items[this.activeWoItemIndex].loans.forEach(
|
||||
z => (z.deleted = true)
|
||||
);
|
||||
this.setDefaultView();
|
||||
this.$emit("change");
|
||||
},
|
||||
setDefaultView: function() {
|
||||
//if only one record left then display it otherwise just let the datatable show what the user can click on
|
||||
if (this.value.items[this.activeWoItemIndex].loans.length == 1) {
|
||||
this.selectedRow = [{ index: 0 }];
|
||||
this.activeItemIndex = 0;
|
||||
} else {
|
||||
this.selectedRow = [];
|
||||
this.activeItemIndex = null; //select nothing in essence resetting a child selects and this one too clearing form
|
||||
}
|
||||
},
|
||||
handleRowClick: function(item) {
|
||||
this.activeItemIndex = item.index;
|
||||
this.selectedRow = [{ index: item.index }];
|
||||
},
|
||||
form() {
|
||||
return window.$gz.form;
|
||||
},
|
||||
fieldValueChanged(ref) {
|
||||
if (!this.formState.loading && !this.formState.readonly) {
|
||||
//flag this record dirty so it gets picked up by save
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].isDirty = true;
|
||||
window.$gz.form.fieldValueChanged(this.pvm, ref);
|
||||
}
|
||||
},
|
||||
itemRowClasses: function(item) {
|
||||
let ret = "";
|
||||
const isDeleted =
|
||||
this.value.items[this.activeWoItemIndex].loans[item.index].deleted ===
|
||||
true;
|
||||
|
||||
const hasError = this.form().childRowHasError(
|
||||
this,
|
||||
`Items[${this.activeWoItemIndex}].Loans[${item.index}].`
|
||||
);
|
||||
|
||||
if (isDeleted) {
|
||||
ret += this.form().tableRowDeletedClass();
|
||||
}
|
||||
if (hasError) {
|
||||
ret += this.form().tableRowErrorClass();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//---
|
||||
data() {
|
||||
return {
|
||||
activeItemIndex: null,
|
||||
selectedRow: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isDeleted: function() {
|
||||
@@ -872,6 +723,155 @@ export default {
|
||||
}
|
||||
|
||||
//----
|
||||
},
|
||||
watch: {
|
||||
activeWoItemIndex(val, oldVal) {
|
||||
if (val != oldVal) {
|
||||
this.setDefaultView();
|
||||
}
|
||||
},
|
||||
gotoIndex(val, oldVal) {
|
||||
if (val != oldVal) {
|
||||
let gotoIndex = val;
|
||||
if (val < 0) {
|
||||
//it's a create request
|
||||
gotoIndex = this.newItem();
|
||||
}
|
||||
this.selectedRow = [{ index: gotoIndex }];
|
||||
this.activeItemIndex = gotoIndex;
|
||||
this.$nextTick(() => {
|
||||
const el = this.$refs.loantopform;
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: "smooth" });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.setDefaultView();
|
||||
},
|
||||
methods: {
|
||||
loanUnitRateUnitChange(newId) {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].unitOfMeasureViz = this.pvm.selectLists.loanUnitRateUnits.find(
|
||||
s => s.id == newId
|
||||
).name;
|
||||
},
|
||||
loanUnitChange(newName) {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].loanUnitViz = newName;
|
||||
},
|
||||
taxCodeChange(newName) {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].taxCodeViz = newName;
|
||||
},
|
||||
newItem() {
|
||||
const newIndex = this.value.items[this.activeWoItemIndex].loans.length;
|
||||
|
||||
this.value.items[this.activeWoItemIndex].loans.push({
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
notes: null,
|
||||
outDate: null,
|
||||
dueDate: null,
|
||||
returnDate: null,
|
||||
taxCodeId: window.$gz.store.state.globalSettings.defaultTaxPartSaleId,
|
||||
loanUnitId: 0, //zero to break rule on new
|
||||
quantity: 1,
|
||||
rate: 1,
|
||||
cost: 0,
|
||||
priceOverride: null,
|
||||
isDirty: true,
|
||||
quoteItemId: this.value.items[this.activeWoItemIndex].id,
|
||||
uid: Date.now(),
|
||||
loanUnitViz: null,
|
||||
taxCodeViz: null,
|
||||
unitOfMeasureViz: null
|
||||
});
|
||||
this.$emit("change");
|
||||
this.selectedRow = [{ index: newIndex }];
|
||||
this.activeItemIndex = newIndex;
|
||||
//trigger rule breaking / validation
|
||||
this.$nextTick(() => {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].loanUnitId = null;
|
||||
this.fieldValueChanged(
|
||||
`Items[${this.activeWoItemIndex}].loans[${this.activeItemIndex}].loanUnitId`
|
||||
);
|
||||
});
|
||||
return newIndex; //for create new on goto
|
||||
},
|
||||
unDeleteItem() {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].deleted = false;
|
||||
this.setDefaultView();
|
||||
},
|
||||
deleteItem() {
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].deleted = true;
|
||||
this.setDefaultView();
|
||||
this.$emit("change");
|
||||
},
|
||||
deleteAllItem() {
|
||||
this.value.items[this.activeWoItemIndex].loans.forEach(
|
||||
z => (z.deleted = true)
|
||||
);
|
||||
this.setDefaultView();
|
||||
this.$emit("change");
|
||||
},
|
||||
setDefaultView: function() {
|
||||
//if only one record left then display it otherwise just let the datatable show what the user can click on
|
||||
if (this.value.items[this.activeWoItemIndex].loans.length == 1) {
|
||||
this.selectedRow = [{ index: 0 }];
|
||||
this.activeItemIndex = 0;
|
||||
} else {
|
||||
this.selectedRow = [];
|
||||
this.activeItemIndex = null; //select nothing in essence resetting a child selects and this one too clearing form
|
||||
}
|
||||
},
|
||||
handleRowClick: function(item) {
|
||||
this.activeItemIndex = item.index;
|
||||
this.selectedRow = [{ index: item.index }];
|
||||
},
|
||||
form() {
|
||||
return window.$gz.form;
|
||||
},
|
||||
fieldValueChanged(ref) {
|
||||
if (!this.formState.loading && !this.formState.readonly) {
|
||||
//flag this record dirty so it gets picked up by save
|
||||
this.value.items[this.activeWoItemIndex].loans[
|
||||
this.activeItemIndex
|
||||
].isDirty = true;
|
||||
window.$gz.form.fieldValueChanged(this.pvm, ref);
|
||||
}
|
||||
},
|
||||
itemRowClasses: function(item) {
|
||||
let ret = "";
|
||||
const isDeleted =
|
||||
this.value.items[this.activeWoItemIndex].loans[item.index].deleted ===
|
||||
true;
|
||||
|
||||
const hasError = this.form().childRowHasError(
|
||||
this,
|
||||
`Items[${this.activeWoItemIndex}].Loans[${item.index}].`
|
||||
);
|
||||
|
||||
if (isDeleted) {
|
||||
ret += this.form().tableRowDeletedClass();
|
||||
}
|
||||
if (hasError) {
|
||||
ret += this.form().tableRowErrorClass();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//---
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user