Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x | <template>
<div class="q-ma-lg">
<!-- Title -->
<HeaderTitleWithBackButton title="Create New Withdrawal Bank"/>
<q-form
data-test="bank-form"
class="q-pa-lg q-mt-xl brx-shadow-sm brx-rounded-8"
@submit="submit"
style="background-color: white"
>
<q-input
data-test="bank-code"
v-model="bank.code"
label="Bank Code *"
outlined
color="blue-brand"
:rules="[isRequired, lenghthRuleCode, numberOnly]"
/>
<q-input
data-test="bank-name"
class="q-mt-md"
v-model="bank.name"
label="Bank Name *"
outlined
color="blue-brand"
:rules="[alphabetOnly, isRequired, trimSpaceRule, lenghthRuleBank]"
/>
<div class="row full-width q-my-md">
<q-file
data-test="bank-logo"
outlined
color="blue-brand"
class="col-6 q-pr-md"
v-model="logo"
label="Bank Logo"
accept=".jpg,.png,.webp,.jpeg"
:rules="[isRequired]"
>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
</q-file>
<q-select
ref="bank-status"
label="Status *"
class="col-6 q-pl-md"
outlined
v-model="status"
:options="optionStatus"
color="blue-brand"
:rules="[selectRequiredRule]"
/>
</div>
<q-input
data-test="bank-description"
v-model="bank.description"
label="Bank Description *"
type="textarea"
outlined
color="blue-brand"
:rules="[isRequired, lenghthRuleDesc, preventEmoticonRule]"
/>
<div class="q-mt-lg display-content text-left">
<q-btn
class="btn q-mr-md text-white brx-rounded-8 bg-blue-brand"
:disable="isSubmit"
v-if="!read"
flat
type="submit"
label="Add"
size="initial"
no-caps
/>
<q-btn
class="btn q-ml-md cancel-btn brx-rounded-8"
outline
color="blue-brand"
@click="onCancel()"
label="Cancel"
size="initial"
/>
</div>
</q-form>
<GlobalPopupV2
:isOpen="isOpen"
:status="statusPopup"
@on-close="(val: any)=>close(val)"
/>
</div>
</template>
<script lang="ts">
import { useRouter } from "vue-router";
import { defineComponent, ref } from "vue";
import { Bank } from "@/common/models";
import { readOnly } from "@/common/session/user";
import { required, propertyPublishOptions } from "@/common/enums";
import { postBankImage, postBanks, deleteBank } from "@/common/api/api";
import { useQuasar } from "quasar";
import { getEnumValue } from "@/common/function";
import {
requiredRules,
numberOnlyRules,
alphabetOnlyRules,
lenghthRules,
trimSpace,
selectRequiredRules,
preventEmoticon,
} from "@/utils/validate";
import HeaderTitleWithBackButton from "@/components/HeaderTitleWithBackButton.vue";
import GlobalPopupV2 from "@/components/popup/GlobalPopupV2.vue";
export default defineComponent({
name: "add",
components: { HeaderTitleWithBackButton, GlobalPopupV2 },
setup() {
const $q = useQuasar();
const bank = ref({} as Bank);
const toList = ref("");
const logo = ref(null);
const read = ref(readOnly());
const isSubmit = ref(false);
const status = ref([]);
const optionStatus = ref(propertyPublishOptions);
// popup
const isOpen = ref(false);
const statusPopup = ref('')
const isRequired = (v: any) => requiredRules(v);
const numberOnly = (v: any) => numberOnlyRules(v);
const alphabetOnly = (v: any) => alphabetOnlyRules(v);
const lenghthRuleCode = (v: any) => lenghthRules(v, 3, 3);
const lenghthRuleDesc = (v: any) => lenghthRules(v, 0, 500);
const lenghthRuleBank = (v: any) => lenghthRules(v, 2, 50);
const trimSpaceRule = (v: any) => trimSpace(v);
const selectRequiredRule = (v: any) => selectRequiredRules(v)
const preventEmoticonRule = (v: any) => preventEmoticon(v)
const router = useRouter();
return {
preventEmoticonRule,
selectRequiredRule,
lenghthRuleBank,
lenghthRuleDesc,
trimSpaceRule,
lenghthRuleCode,
alphabetOnly,
numberOnly,
isRequired,
isOpen,
statusPopup,
isSubmit,
bank,
read,
toList,
logo,
status,
optionStatus,
async submit() {
$q.loading.show();
isSubmit.value = true;
// Set status bank
bank.value.status = Number(getEnumValue(status.value));
try {
const response = await postBanks([bank.value]);
const code = response.data.at(0).code;
$q.loading.show({
message: "Waiting for upload photo",
});
await postBankImage(code, logo.value);
$q.loading.hide();
// show success popup
statusPopup.value = 'success'
isOpen.value = true;
} catch (err) {
// show fail popup
if(err.response.status ==400){
statusPopup.value = 'fail'
}else{
statusPopup.value = 'error'
}
isOpen.value = true;
console.log(err);
}
$q.loading.hide();
isSubmit.value = false;
},
close(e: boolean) {
isOpen.value = e;
},
onCancel() {
router.push({
name: "bank",
});
},
};
},
});
</script>
|