EmailFormField.vue
1 day ago
EmployeeFormField.vue
1 day ago
FirstNameFormField.vue
1 day ago
LastNameFormField.vue
1 day ago
LocationFormField.vue
1 day ago
PhoneFormField.vue
1 day ago
ServiceFormField.vue
1 day ago
ServiceFormField.vue
207 lines
| 1 | <template> |
| 2 | <el-form-item class="am-fs__init-form__item" prop="service" label-position="top"> |
| 3 | <template #label> |
| 4 | <span class="am-fs__init-form__label"> |
| 5 | {{ `${labelsDisplay('service_colon')}:` }} |
| 6 | </span> |
| 7 | </template> |
| 8 | <AmAdvancedSelect |
| 9 | v-model="formData.service" |
| 10 | :options="categoryOptions" |
| 11 | :props-data="advSelectProps" |
| 12 | :filterable="amCustomize[pageRenderKey].initStep.options.service.filterable" |
| 13 | :placeholder="labelsDisplay('select_service')" |
| 14 | :category-name="labelsDisplay('dropdown_category_heading')" |
| 15 | :sub-category-name="labelsDisplay('dropdown_items_heading')" |
| 16 | :empty-state-string="labelsDisplay('dropdown_empty')" |
| 17 | @change="changeService" |
| 18 | ></AmAdvancedSelect> |
| 19 | </el-form-item> |
| 20 | </template> |
| 21 | |
| 22 | <script setup> |
| 23 | import AmAdvancedSelect from '../../../_components/advanced-select/AmAdvancedSelect.vue' |
| 24 | import { computed, inject, reactive, ref } from 'vue' |
| 25 | import { useReactiveCustomize } from '../../../../assets/js/admin/useReactiveCustomize.js' |
| 26 | |
| 27 | let langKey = inject('langKey') |
| 28 | let amLabels = inject('labels') |
| 29 | |
| 30 | let pageRenderKey = inject('pageRenderKey') |
| 31 | const { amCustomize } = useReactiveCustomize() |
| 32 | |
| 33 | // * Label computed function |
| 34 | function labelsDisplay(label) { |
| 35 | let computedLabel = computed(() => { |
| 36 | return amCustomize.value[pageRenderKey.value].initStep.translations && |
| 37 | amCustomize.value[pageRenderKey.value].initStep.translations[label] && |
| 38 | amCustomize.value[pageRenderKey.value].initStep.translations[label][langKey.value] |
| 39 | ? amCustomize.value[pageRenderKey.value].initStep.translations[label][langKey.value] |
| 40 | : amLabels[label] |
| 41 | }) |
| 42 | |
| 43 | return computedLabel.value |
| 44 | } |
| 45 | |
| 46 | // * Sidebar steps |
| 47 | let { sidebarDataCollector } = inject('sidebarStepsFunctions', { |
| 48 | sidebarDataCollector: () => {}, |
| 49 | }) |
| 50 | |
| 51 | // * Form field data |
| 52 | let formData = inject('formData') |
| 53 | |
| 54 | /** |
| 55 | * * Category - Service Block |
| 56 | */ |
| 57 | // * Service select props |
| 58 | let advSelectProps = reactive({ |
| 59 | expandTrigger: 'hover', |
| 60 | multiple: false, |
| 61 | checkStrictly: false, |
| 62 | emitPath: true, |
| 63 | lazy: false, |
| 64 | value: 'id', |
| 65 | label: 'name', |
| 66 | children: 'serviceList', |
| 67 | disabled: 'disabled', |
| 68 | leaf: 'leaf', |
| 69 | }) |
| 70 | |
| 71 | // * Set Category Options from entities |
| 72 | let categoryOptions = ref([ |
| 73 | { |
| 74 | id: 1, |
| 75 | name: 'Category 1', |
| 76 | serviceList: [ |
| 77 | { |
| 78 | id: 10, |
| 79 | name: 'Service 11', |
| 80 | price: 125, |
| 81 | }, |
| 82 | { |
| 83 | id: 11, |
| 84 | name: 'Service 12', |
| 85 | price: 125, |
| 86 | }, |
| 87 | { |
| 88 | id: 12, |
| 89 | name: 'Service 13', |
| 90 | price: 125, |
| 91 | }, |
| 92 | ], |
| 93 | }, |
| 94 | { |
| 95 | id: 2, |
| 96 | name: 'Category 2', |
| 97 | serviceList: [ |
| 98 | { |
| 99 | id: 10, |
| 100 | name: 'Service 21', |
| 101 | price: 125, |
| 102 | }, |
| 103 | { |
| 104 | id: 11, |
| 105 | name: 'Service 22', |
| 106 | price: 125, |
| 107 | }, |
| 108 | { |
| 109 | id: 12, |
| 110 | name: 'Service 23', |
| 111 | price: 125, |
| 112 | }, |
| 113 | ], |
| 114 | }, |
| 115 | { |
| 116 | id: 3, |
| 117 | name: 'Category 3', |
| 118 | serviceList: [ |
| 119 | { |
| 120 | id: 10, |
| 121 | name: 'Service 31', |
| 122 | price: 125, |
| 123 | }, |
| 124 | { |
| 125 | id: 11, |
| 126 | name: 'Service 32', |
| 127 | price: 125, |
| 128 | }, |
| 129 | { |
| 130 | id: 12, |
| 131 | name: 'Service 33', |
| 132 | price: 125, |
| 133 | }, |
| 134 | ], |
| 135 | }, |
| 136 | { |
| 137 | id: 4, |
| 138 | name: 'Category 4', |
| 139 | serviceList: [ |
| 140 | { |
| 141 | id: 10, |
| 142 | name: 'Service 41', |
| 143 | price: 125, |
| 144 | }, |
| 145 | { |
| 146 | id: 11, |
| 147 | name: 'Service 42', |
| 148 | price: 125, |
| 149 | }, |
| 150 | { |
| 151 | id: 12, |
| 152 | name: 'Service 43', |
| 153 | price: 125, |
| 154 | }, |
| 155 | ], |
| 156 | }, |
| 157 | { |
| 158 | id: 5, |
| 159 | name: 'Category 5', |
| 160 | serviceList: [ |
| 161 | { |
| 162 | id: 10, |
| 163 | name: 'Service 51', |
| 164 | price: 125, |
| 165 | }, |
| 166 | { |
| 167 | id: 11, |
| 168 | name: 'Service 52', |
| 169 | price: 125, |
| 170 | }, |
| 171 | { |
| 172 | id: 12, |
| 173 | name: 'Service 53', |
| 174 | price: 125, |
| 175 | }, |
| 176 | ], |
| 177 | }, |
| 178 | ]) |
| 179 | |
| 180 | /** |
| 181 | * Change Service function |
| 182 | * @param val |
| 183 | */ |
| 184 | let changeService = (val) => { |
| 185 | let serviceData = reactive({ |
| 186 | reference: 'service', |
| 187 | // position will depends on fields order |
| 188 | position: 0, |
| 189 | value: '', |
| 190 | }) |
| 191 | |
| 192 | if (Array.isArray(val)) { |
| 193 | serviceData.value = categoryOptions.value |
| 194 | .find((item) => item.id === val[0]) |
| 195 | .serviceList.find((item) => item.id === val[1]).name |
| 196 | } |
| 197 | |
| 198 | sidebarDataCollector(serviceData) |
| 199 | } |
| 200 | </script> |
| 201 | |
| 202 | <script> |
| 203 | export default { |
| 204 | name: 'ServiceFormField', |
| 205 | } |
| 206 | </script> |
| 207 |