profile.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <entity-edit v-if="mounted"
  3. ref="entityEdit"
  4. v-model:value="inputs"
  5. title="اطلاعات کاربری"
  6. :api="api"
  7. :after-load-input-data="afterLoadInputData"
  8. :entity-id-key="entityIdKey"
  9. :entity-param-key="entityParamKey"
  10. :show-route-name="showRouteName"
  11. :show-close-button="false"
  12. :show-edit-button="false"
  13. :show-expand-button="false"
  14. :show-save-button="false"
  15. :show-reload-button="false">
  16. <template #after-form-builder>
  17. <div class="flex justify-end q-mt-md">
  18. <q-btn color="primary"
  19. label="تایید اطلاعات تکمیلی"
  20. @click="editEntity" />
  21. </div>
  22. </template>
  23. </entity-edit>
  24. <template v-else>
  25. کمی صبر کنید...
  26. </template>
  27. </template>
  28. <script>
  29. import { shallowRef } from 'vue'
  30. import { EntityEdit } from 'quasar-crud'
  31. import { User } from 'src/models/User.js'
  32. import Enums from 'src/assets/Enums/Enums.js'
  33. import { APIGateway } from 'src/api/APIGateway.js'
  34. import Warning from 'src/components/other/Warning.vue'
  35. import { FormBuilderAssist } from 'quasar-form-builder'
  36. import VerifyEmail from 'src/components/other/VerifyEmail.vue'
  37. import NationalCode from 'src/components/other/NationalCode.vue'
  38. import VerifyMobileNumber from 'src/components/other/VerifyMobileNumber.vue'
  39. import { Provinces, Cities, getCitiesOfProvince } from 'src/assets/js/IranianCities.js'
  40. import FormBuilderBarCode from 'src/components/FormBuilderCustumComponents/FormBuilderBarCode.vue'
  41. const WarningComp = shallowRef(Warning)
  42. const VerifyEmailComp = shallowRef(VerifyEmail)
  43. const NationalCodeComp = shallowRef(NationalCode)
  44. const VerifyMobileNumberComp = shallowRef(VerifyMobileNumber)
  45. const FormBuilderBarCodeComp = shallowRef(FormBuilderBarCode)
  46. export default {
  47. name: 'UserPanel.Profile.UserInfo',
  48. components: { EntityEdit },
  49. data () {
  50. return {
  51. mounted: false,
  52. inputDataLoaded: false,
  53. tab: 'userInfo',
  54. api: APIGateway.user.APIAdresses.current,
  55. entityIdKey: 'id',
  56. entityParamKey: 'id',
  57. showRouteName: 'UserPanel.Profile.UserInfo',
  58. inputs: [
  59. { type: 'separator', name: 'barcode_space', placeholder: ' ', label: 'شناسه ورود به جلسه', className: 'custom-separator require', col: 'col-12' },
  60. { type: FormBuilderBarCodeComp, name: 'national_code_barcode', responseKey: 'national_code', label: '', ignoreValue: true, col: 'col-12' },
  61. { type: 'separator', name: 'space', placeholder: ' ', label: 'اطلاعات ضروری', className: 'custom-separator require', col: 'col-12' },
  62. { type: WarningComp, name: 'WarningComp', label: 'بعد از تایید اطلاعات ضروری، امکان تغییر این اطلاعات وجود ندارد', col: 'col-12' },
  63. { type: VerifyEmailComp, name: 'email', placeholder: ' ', label: 'ایمیل', responseKey: 'email', col: 'col-md-6 col-12' },
  64. { type: VerifyMobileNumberComp, name: 'mobile_number', placeholder: ' ', label: 'تلفن همراه', responseKey: 'mobile_number', col: 'col-md-6 col-12' },
  65. { type: 'optionGroupRadio', name: 'is_valid_national_code', responseKey: 'is_valid_national_code', label: 'اتباع خارجی', options: [{ label: 'نیستم', value: true }, { label: 'هستم', value: false }], value: true, className: 'require', col: 'col-md-6 col-12' },
  66. { type: NationalCodeComp, name: 'national_code', value: '', placeholder: ' ', label: 'کدملی/کد اتباع غیر ایرانی', responseKey: 'national_code', col: 'col-md-6 col-12' },
  67. { type: 'separator', name: 'space', label: 'اطلاعات پروفایل', className: 'custom-separator', col: 'col-12' },
  68. { type: 'file', name: 'picture', placeholder: ' ', label: 'عکس پروفایل', responseKey: 'picture', col: 'col-md-6 col-12' },
  69. { type: 'separator', name: 'space', size: '0', col: 'col-12' },
  70. { type: 'input', name: 'firstname', placeholder: ' ', label: 'نام', responseKey: 'firstname', className: 'require', col: 'col-md-6 col-12' },
  71. { type: 'input', name: 'lastname', placeholder: ' ', label: 'نام خانوادگی', responseKey: 'lastname', className: 'require', col: 'col-md-6 col-12' },
  72. {
  73. type: 'select',
  74. name: 'gender',
  75. responseKey: 'gender',
  76. options: Enums.genders,
  77. value: null,
  78. label: 'جنسیت',
  79. placeholder: ' ',
  80. className: 'require',
  81. col: 'col-md-6 col-12'
  82. },
  83. { type: 'date', name: 'birthdate', outsideLabel: 'تولد', responseKey: 'birthdate', className: 'require', col: 'col-md-6 col-12' },
  84. {
  85. type: 'select',
  86. name: 'marital_status',
  87. responseKey: 'marital_status',
  88. options: Enums.maritalStatuses,
  89. value: null,
  90. label: 'وضعیت تاهل',
  91. placeholder: ' ',
  92. className: 'require',
  93. col: 'col-md-6 col-12'
  94. },
  95. { type: 'input', name: 'on_call_mobile_number', placeholder: ' ', label: 'تلفن همراه جهت تماس', responseKey: 'on_call_mobile_number', className: 'require', col: 'col-md-6 col-12' },
  96. { type: 'input', name: 'on_social_network_mobile_number', placeholder: ' ', label: 'تلفن همراه جهت شبکه های اجتماعی', className: 'require', responseKey: 'on_social_network_mobile_number', col: 'col-md-6 col-12' },
  97. { type: 'input', name: 'phone_number', placeholder: 'با کد شهر وارد شود', label: 'تلفن منزل', responseKey: 'phone_number', className: 'require', col: 'col-md-6 col-12' },
  98. {
  99. type: 'select',
  100. name: 'last_academic_degree',
  101. responseKey: 'last_academic_degree',
  102. options: Enums.academicDegree,
  103. value: null,
  104. label: 'آخرین مقطع تحصیلی',
  105. placeholder: ' ',
  106. className: 'require',
  107. col: 'col-md-6 col-12'
  108. },
  109. { type: 'input', name: 'last_academic_degree_field', placeholder: ' ', label: 'رشته تحصیلی', responseKey: 'last_academic_degree_field', className: 'require', col: 'col-md-6 col-12' },
  110. { type: 'input', name: 'last_academy_name', placeholder: ' ', label: 'نام دانشگاه یا حوزه تحصیلی', responseKey: 'last_academy_name', className: 'require', col: 'col-md-6 col-12' },
  111. {
  112. type: 'select',
  113. name: 'educational_status',
  114. responseKey: 'educational_status',
  115. options: Enums.educationalStatus,
  116. value: null,
  117. label: 'وضعیت تحصیلی',
  118. placeholder: ' ',
  119. className: 'require',
  120. col: 'col-md-6 col-12'
  121. },
  122. { type: 'checkbox', name: 'is_abroad_birth_address', placeholder: ' ', label: 'محل تولد خارج از کشور است؟', responseKey: 'is_abroad_birth_address', className: 'require', col: 'col-12' },
  123. { type: 'input', name: 'birth_country', placeholder: ' ', label: 'کشور محل تولد', responseKey: 'birth_country', className: 'require', col: 'col-md-6 col-12' },
  124. {
  125. type: 'select',
  126. name: 'birth_province',
  127. options: Provinces,
  128. createNewValue: true,
  129. optionLabel: 'name',
  130. optionValue: 'name',
  131. newValueMode: 'add-unique',
  132. placeholder: ' ',
  133. label: 'استان محل تولد',
  134. responseKey: 'birth_province',
  135. className: 'require',
  136. col: 'col-md-6 col-12'
  137. },
  138. {
  139. type: 'select',
  140. name: 'birth_city',
  141. options: Cities,
  142. createNewValue: true,
  143. optionLabel: 'name',
  144. optionValue: 'name',
  145. newValueMode: 'add-unique',
  146. placeholder: ' ',
  147. label: 'شهر محل تولد',
  148. responseKey: 'birth_city',
  149. className: 'require',
  150. col: 'col-md-6 col-12'
  151. },
  152. { type: 'checkbox', name: 'is_abroad_living_address', placeholder: ' ', label: 'محل زندگی فعلی خارج از کشور است؟', responseKey: 'is_abroad_living_address', className: 'require', col: 'col-12' },
  153. { type: 'input', name: 'living_country', placeholder: ' ', label: 'کشور محل زندگی فعلی', responseKey: 'living_country', className: 'require', col: 'col-md-6 col-12' },
  154. {
  155. type: 'select',
  156. name: 'living_province',
  157. options: Provinces,
  158. createNewValue: true,
  159. optionLabel: 'name',
  160. optionValue: 'name',
  161. newValueMode: 'add-unique',
  162. placeholder: ' ',
  163. label: 'استان محل زندگی فعلی',
  164. responseKey: 'living_province',
  165. className: 'require',
  166. col: 'col-md-6 col-12'
  167. },
  168. {
  169. type: 'select',
  170. name: 'living_city',
  171. options: Cities,
  172. createNewValue: true,
  173. optionLabel: 'name',
  174. optionValue: 'name',
  175. newValueMode: 'add-unique',
  176. placeholder: ' ',
  177. label: 'شهر محل زندگی فعلی',
  178. responseKey: 'living_city',
  179. className: 'require',
  180. col: 'col-md-6 col-12'
  181. },
  182. { type: 'input', name: 'living_postal_code', placeholder: ' ', label: 'کد پستی محل زندگی', responseKey: 'living_postal_code', className: 'require', col: 'col-md-6 col-12' },
  183. { type: 'input', name: 'living_address', placeholder: ' ', label: 'آدرس پستی محل زندگی', responseKey: 'living_address', className: 'require', col: 'col-md-6 col-12' },
  184. { type: 'hidden', name: 'id', responseKey: 'id', label: 'id', col: 'col-12' }
  185. ]
  186. }
  187. },
  188. computed: {
  189. isAbroadBirthAddress () {
  190. return FormBuilderAssist.getInputsByName(this.inputs, 'is_abroad_birth_address').value
  191. },
  192. isAbroadLivingAddress () {
  193. return FormBuilderAssist.getInputsByName(this.inputs, 'is_abroad_living_address').value
  194. },
  195. selectedBirthProvince () {
  196. return FormBuilderAssist.getInputsByName(this.inputs, 'birth_province').value
  197. },
  198. selectedLivingProvince () {
  199. return FormBuilderAssist.getInputsByName(this.inputs, 'living_province').value
  200. }
  201. },
  202. watch: {
  203. isAbroadBirthAddress: {
  204. immediate: true,
  205. handler (newValue) {
  206. this.$nextTick(() => {
  207. if (!newValue) {
  208. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_country', 'value', 'ایران')
  209. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_country', 'readonly', true)
  210. if (this.inputDataLoaded) {
  211. // province
  212. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'type', 'select')
  213. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'disable', false)
  214. // FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'value', null)
  215. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'options', Provinces)
  216. // city
  217. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'type', 'select')
  218. // FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'disable', true)
  219. // FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'value', null)
  220. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'options', getCitiesOfProvince(this.selectedBirthProvince))
  221. }
  222. } else {
  223. // FormBuilderAssist.setAttributeByName(this.inputs, 'birth_country', 'value', null)
  224. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_country', 'readonly', false)
  225. if (this.inputDataLoaded) {
  226. // province
  227. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'type', 'input')
  228. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'disable', false)
  229. // city
  230. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'type', 'input')
  231. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'disable', false)
  232. // FormBuilderAssist.setAttributeByName(this.inputs, 'birth_province', 'value', null)
  233. // FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'value', null)
  234. }
  235. }
  236. })
  237. }
  238. },
  239. isAbroadLivingAddress: {
  240. immediate: true,
  241. handler (newValue) {
  242. this.$nextTick(() => {
  243. if (!newValue) {
  244. FormBuilderAssist.setAttributeByName(this.inputs, 'living_country', 'value', 'ایران')
  245. FormBuilderAssist.setAttributeByName(this.inputs, 'living_country', 'readonly', true)
  246. if (this.inputDataLoaded) {
  247. // province
  248. FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'type', 'select')
  249. FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'disable', false)
  250. // FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'value', null)
  251. FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'options', Provinces)
  252. // city
  253. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'type', 'select')
  254. // FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'disable', true)
  255. // FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'value', null)
  256. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'options', getCitiesOfProvince(this.selectedLivingProvince))
  257. }
  258. } else {
  259. // FormBuilderAssist.setAttributeByName(this.inputs, 'living_country', 'value', null)
  260. FormBuilderAssist.setAttributeByName(this.inputs, 'living_country', 'readonly', false)
  261. if (this.inputDataLoaded) {
  262. // province
  263. FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'type', 'input')
  264. FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'disable', false)
  265. // city
  266. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'type', 'input')
  267. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'disable', false)
  268. // FormBuilderAssist.setAttributeByName(this.inputs, 'living_province', 'value', null)
  269. // FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'value', null)
  270. }
  271. }
  272. })
  273. }
  274. },
  275. selectedBirthProvince (newValue) {
  276. if (this.isAbroadBirthAddress) {
  277. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'type', 'input')
  278. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'disable', false)
  279. return
  280. }
  281. if (!newValue) {
  282. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'disable', true)
  283. if (this.inputDataLoaded) {
  284. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'value', null)
  285. }
  286. return
  287. }
  288. const filteredCities = getCitiesOfProvince(this.selectedBirthProvince)
  289. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'options', filteredCities)
  290. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'disable', false)
  291. if (this.inputDataLoaded) {
  292. FormBuilderAssist.setAttributeByName(this.inputs, 'birth_city', 'value', null)
  293. }
  294. },
  295. selectedLivingProvince (newValue) {
  296. if (this.isAbroadBirthAddress) {
  297. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'type', 'input')
  298. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'disable', false)
  299. return
  300. }
  301. if (!newValue) {
  302. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'disable', true)
  303. if (this.inputDataLoaded) {
  304. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'value', null)
  305. }
  306. return
  307. }
  308. const filteredCities = getCitiesOfProvince(this.selectedLivingProvince)
  309. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'options', filteredCities)
  310. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'disable', false)
  311. if (this.inputDataLoaded) {
  312. FormBuilderAssist.setAttributeByName(this.inputs, 'living_city', 'value', null)
  313. }
  314. }
  315. },
  316. mounted() {
  317. this.mounted = true
  318. },
  319. methods: {
  320. afterLoadInputData (responseData, setNewInputData) {
  321. if (!responseData.national_code) {
  322. FormBuilderAssist.setAttributeByName(this.inputs, 'national_code_barcode', 'type', 'hidden')
  323. FormBuilderAssist.setAttributeByName(this.inputs, 'barcode_space', 'type', 'hidden')
  324. }
  325. this.updateGender(responseData, setNewInputData)
  326. this.updateMaritalStatus(responseData, setNewInputData)
  327. this.$nextTick(() => {
  328. this.inputDataLoaded = true
  329. })
  330. },
  331. updateGender (responseData, setNewInputData) {
  332. // const gender = this.getInputValue('gender')
  333. const gender = responseData.gender
  334. if (gender !== 'UNKNOWN') {
  335. return
  336. }
  337. this.setInputValue('gender', null)
  338. setNewInputData(this.inputs)
  339. },
  340. updateMaritalStatus (responseData, setNewInputData) {
  341. // const gender = this.getInputValue('gender')
  342. const maritalStatus = responseData.marital_status
  343. if (maritalStatus !== 'UNKNOWN') {
  344. return
  345. }
  346. this.setInputValue('marital_status', null)
  347. setNewInputData(this.inputs)
  348. },
  349. setInputValue (name, value) {
  350. const inputIndex = this.inputs.findIndex(input => input.name === name)
  351. this.inputs[inputIndex].value = value
  352. },
  353. getInputValue (name) {
  354. const inputIndex = this.inputs.findIndex(input => input.name === name)
  355. return this.inputs[inputIndex].value
  356. },
  357. getRoleTitle (roleName) {
  358. const target = Enums.groups.find(item => item.value === roleName)
  359. if (!target) {
  360. return '-'
  361. }
  362. return target.label
  363. },
  364. editEntity () {
  365. this.$refs.entityEdit.editEntity(false)
  366. .then(() => {
  367. this.$q.notify({
  368. message: 'اطلاعات با موفقیت ویرایش شد',
  369. type: 'positive'
  370. })
  371. APIGateway.user.getCurrent()
  372. .then((user) => {
  373. this.$store.commit('Auth/updateUser', new User(user))
  374. })
  375. .catch(() => {
  376. })
  377. })
  378. .catch(() => {
  379. })
  380. }
  381. }
  382. }
  383. </script>