395395 v-model =" values[currentField.uuid]"
396396 :reason =" values[currentField.preferences?.reason_field_uuid]"
397397 :field =" currentField"
398+ :values =" values"
398399 :previous-value =" previousSignatureValueFor(currentField) || previousSignatureValue"
400+ :touch-attachment-uuid =" previousSignatureValue"
399401 :with-typed-signature =" withTypedSignature"
400402 :remember-signature =" rememberSignature"
401403 :attachments-index =" attachmentsIndex"
407409 :submitter =" submitter"
408410 :show-field-names =" showFieldNames"
409411 @update:reason =" values[currentField.preferences?.reason_field_uuid] = $event"
412+ @touch-attachment =" attachmentsIndex[previousSignatureValue] ? attachmentsIndex[previousSignatureValue].created_at = new Date() : null"
410413 @attached =" attachments.push($event)"
411414 @start =" scrollIntoField(currentField)"
412415 @minimize =" minimizeForm"
@@ -926,10 +929,12 @@ export default {
926929 }, {})
927930 },
928931 attachmentConditionsIndex () {
932+ const cache = {}
933+
929934 return this .schema .reduce ((acc , item ) => {
930935 if (item .conditions ? .length ) {
931936 if (item .conditions .every ((c ) => this .fieldsUuidIndex [c .field_uuid ])) {
932- acc[item .attachment_uuid ] = this .checkFieldConditions (item)
937+ acc[item .attachment_uuid ] = this .checkFieldConditions (item, cache )
933938 } else {
934939 acc[item .attachment_uuid ] = true
935940 }
@@ -996,7 +1001,9 @@ export default {
9961001 },
9971002 previousInitialsValue () {
9981003 if (this .reuseSignature !== false ) {
999- const initialsField = [... this .fields ].reverse ().find ((field ) => field .type === ' initials' && !! this .values [field .uuid ])
1004+ const initialsField = this .fields .findLast
1005+ ? this .fields .findLast ((field ) => field .type === ' initials' && !! this .values [field .uuid ])
1006+ : [... this .fields ].reverse ().find ((field ) => field .type === ' initials' && !! this .values [field .uuid ])
10001007
10011008 return this .values [initialsField? .uuid ]
10021009 } else {
@@ -1023,7 +1030,9 @@ export default {
10231030 return this .readonlyFields .filter ((f ) => f .conditions ? .length )
10241031 },
10251032 readonlyFields () {
1026- return this .fields .filter ((f ) => f .readonly && this .checkFieldConditions (f) && this .checkFieldDocumentsConditions (f))
1033+ const cache = {}
1034+
1035+ return this .fields .filter ((f ) => f .readonly && this .checkFieldConditions (f, cache) && this .checkFieldDocumentsConditions (f))
10271036 },
10281037 stepFields () {
10291038 const verificationFields = []
@@ -1078,10 +1087,12 @@ export default {
10781087 sortedFields .push (verificationFields .pop ())
10791088 }
10801089
1090+ const cache = {}
1091+
10811092 return sortedFields .reduce ((acc , f ) => {
10821093 const prevStep = acc[acc .length - 1 ]
10831094
1084- if (this .checkFieldConditions (f) && this .checkFieldDocumentsConditions (f)) {
1095+ if (this .checkFieldConditions (f, cache ) && this .checkFieldDocumentsConditions (f)) {
10851096 if (f .type === ' checkbox' && Array .isArray (prevStep) && prevStep[0 ].type === ' checkbox' && ! f .description ) {
10861097 prevStep .push (f)
10871098 } else {
@@ -1093,7 +1104,9 @@ export default {
10931104 }, [])
10941105 },
10951106 formulaFields () {
1096- return this .fields .filter ((f ) => f .preferences ? .formula && f .type !== ' payment' && this .checkFieldConditions (f) && this .checkFieldDocumentsConditions (f))
1107+ const cache = {}
1108+
1109+ return this .fields .filter ((f ) => f .preferences ? .formula && f .type !== ' payment' && this .checkFieldConditions (f, cache) && this .checkFieldDocumentsConditions (f))
10971110 },
10981111 attachmentsIndex () {
10991112 return this .attachments .reduce ((acc , a ) => {
@@ -1155,7 +1168,9 @@ export default {
11551168 this .currentStep = Math .max (stepIndex, 0 )
11561169 } else if (this .goToLast ) {
11571170 const requiredEmptyStepIndex = this .stepFields .indexOf (this .stepFields .find ((fields ) => fields .some ((f ) => f .required && ! this .submittedValues [f .uuid ])))
1158- const lastFilledStepIndex = this .stepFields .indexOf ([... this .stepFields ].reverse ().find ((fields ) => fields .some ((f ) => !! this .submittedValues [f .uuid ]))) + 1
1171+ const lastFilledStepIndex = this .stepFields .indexOf (this .stepFields .findLast
1172+ ? this .stepFields .findLast ((fields ) => fields .some ((f ) => !! this .submittedValues [f .uuid ]))
1173+ : [... this .stepFields ].reverse ().find ((fields ) => fields .some ((f ) => !! this .submittedValues [f .uuid ]))) + 1
11591174
11601175 const indexesList = [this .stepFields .length - 1 ]
11611176
@@ -1223,27 +1238,33 @@ export default {
12231238 return true
12241239 }
12251240 },
1226- checkFieldConditions (field ) {
1241+ checkFieldConditions (field , cache = {}) {
1242+ if (cache[field .uuid ] !== undefined ) {
1243+ return cache[field .uuid ]
1244+ }
1245+
1246+ cache[field .uuid ] = true
1247+
12271248 if (field .conditions ? .length ) {
12281249 const result = field .conditions .reduce ((acc , cond ) => {
12291250 if (cond .operation === ' or' ) {
1230- acc .push (acc .pop () || this .checkFieldCondition (cond))
1251+ acc .push (acc .pop () || this .checkFieldCondition (cond, cache ))
12311252 } else {
1232- acc .push (this .checkFieldCondition (cond))
1253+ acc .push (this .checkFieldCondition (cond, cache ))
12331254 }
12341255
12351256 return acc
12361257 }, [])
12371258
1238- return ! result .includes (false )
1239- } else {
1240- return true
1259+ cache[field .uuid ] = ! result .includes (false )
12411260 }
1261+
1262+ return cache[field .uuid ]
12421263 },
1243- checkFieldCondition (condition ) {
1264+ checkFieldCondition (condition , cache = {} ) {
12441265 const field = this .fieldsUuidIndex [condition .field_uuid ]
12451266
1246- if ([' not_empty' , ' checked' , ' equal' , ' contains' ].includes (condition .action ) && field && ! this .checkFieldConditions (field)) {
1267+ if ([' not_empty' , ' checked' , ' equal' , ' contains' , ' greater_than ' , ' less_than ' ].includes (condition .action ) && field && ! this .checkFieldConditions (field, cache )) {
12471268 return false
12481269 }
12491270
@@ -1253,6 +1274,22 @@ export default {
12531274 return isEmpty (this .values [condition .field_uuid ] ?? defaultValue)
12541275 } else if ([' not_empty' , ' checked' ].includes (condition .action )) {
12551276 return ! isEmpty (this .values [condition .field_uuid ] ?? defaultValue)
1277+ } else if (field? .type === ' number' && [' equal' , ' not_equal' , ' greater_than' , ' less_than' ].includes (condition .action )) {
1278+ const value = this .values [condition .field_uuid ] ?? defaultValue
1279+
1280+ if (isEmpty (value) || isEmpty (condition .value )) return false
1281+
1282+ const actual = parseFloat (value)
1283+ const expected = parseFloat (condition .value )
1284+
1285+ if (Number .isNaN (actual) || Number .isNaN (expected)) return false
1286+
1287+ if (condition .action === ' equal' ) return Math .abs (actual - expected) < Number .EPSILON
1288+ if (condition .action === ' not_equal' ) return Math .abs (actual - expected) > Number .EPSILON
1289+ if (condition .action === ' greater_than' ) return actual > expected
1290+ if (condition .action === ' less_than' ) return actual < expected
1291+
1292+ return false
12561293 } else if ([' equal' , ' contains' ].includes (condition .action ) && field) {
12571294 if (field .options ) {
12581295 const option = field .options .find ((o ) => o .uuid === condition .value )
@@ -1353,9 +1390,9 @@ export default {
13531390 },
13541391 previousSignatureValueFor (field ) {
13551392 if (this .reuseSignature !== false ) {
1356- const signatureField = [ ... this .fields ]. reverse (). find (( f ) =>
1357- f .type === ' signature' && field .preferences ? .format === f .preferences ? .format && !! this .values [f .uuid ]
1358- )
1393+ const signatureField = this .fields . findLast
1394+ ? this . fields . findLast (( f ) => f .type === ' signature' && field .preferences ? .format === f .preferences ? .format && !! this .values [f .uuid ])
1395+ : [ ... this . fields ]. reverse (). find (( f ) => f . type === ' signature ' && field . preferences ? . format === f . preferences ? . format && !! this . values [ f . uuid ] )
13591396
13601397 return this .values [signatureField? .uuid ]
13611398 } else {
0 commit comments