You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
7.0 KiB

2 years ago
  1. <template>
  2. <v-card class="border-radius-20" flat min-width="900px" max-width="900px">
  3. <v-spacer class="px-7 pt-7">
  4. <v-spacer class="d-flex align-center mb-7">
  5. <div class="circle-decoration me-2"></div>
  6. <div class="circle-decoration me-2"></div>
  7. <span class="font-weight-bold text-size-20 ms-7 text-height-26">{{ $t("userProfile.companyInfo") }}</span>
  8. </v-spacer>
  9. <v-data-table
  10. class="pb-7"
  11. hide-default-footer
  12. :headers="companyTableColumns"
  13. :items="userCompanyList"
  14. >
  15. <template slot="no-data">
  16. <div class="d-flex justify-center data-table-no-content">
  17. <div class="mb-7">
  18. <v-img width="150px" aspect-ratio="1" :src="emptyImage"></v-img>
  19. </div>
  20. </div>
  21. <div>
  22. <span class="empty-font-style">
  23. {{ $t("userProfile.noCompany") }}
  24. </span>
  25. </div>
  26. </template>
  27. <template v-slot:[`item.company_name`]="{item}">
  28. {{ item.company_name }}
  29. </template>
  30. <template v-slot:[`item.company_tax_no`]="{item}">
  31. {{ item.company_tax_no }}
  32. </template>
  33. <template v-slot:[`item.company_country`]="{item}">
  34. {{ countrySortOptions[item.company_country] }}
  35. </template>
  36. <template v-slot:[`item.company_city`]="{item}">
  37. {{ item.company_city }}
  38. </template>
  39. <template v-slot:[`item.company_address`]="{item}">
  40. <span v-if="item.company_address1">{{ item.company_address1 }}</span>
  41. <span v-if="item.company_address2 && !item.company_address1">{{ item.company_address2 }}</span>
  42. </template>
  43. <template v-slot:[`item.action`]="{item}">
  44. <div class="d-flex align-center">
  45. <v-btn @click="activeEditCompanyInfoDialog(item)" class="d-flex justify-center" icon>
  46. <unicon name="pen" height="20px" fill="neutrals-darken5"/>
  47. </v-btn>
  48. <v-btn @click="deleteUserCompany(item)" icon>
  49. <unicon name="trash-alt" height="20px" fill="neutrals-darken5"/>
  50. </v-btn>
  51. </div>
  52. </template>
  53. </v-data-table>
  54. <v-spacer class="d-flex justify-center pb-7">
  55. <v-btn @click="activeAddNewCompanyInfoDialog" class="border-radius-12 text-capitalize" color="primary">
  56. <v-icon class="me-2">mdi-plus</v-icon>
  57. {{ $t("userProfile.addNewCompany") }}
  58. </v-btn>
  59. </v-spacer>
  60. </v-spacer>
  61. <CompanyEditInfoDialog
  62. :companyEditInfoDialogActive="companyEditDialogActive"
  63. :userCompany="propUserCompany"
  64. :countryOptions="countryOptions"
  65. :user_uuid="user_uuid"
  66. @refetch-company="getCompanyList"
  67. @refetch-user="fetchUserData"
  68. @close-edit-dialog="companyEditDialogActive = !companyEditDialogActive"
  69. ></CompanyEditInfoDialog>
  70. <CompanyAddNewDialog
  71. :companyAddNewDialogActive="companyAddNewDialogActive"
  72. :countryOptions="countryOptions"
  73. :addNewCompanyList="userAddNewCompanyList"
  74. :user_uuid="user_uuid"
  75. @refetch-company="getCompanyList"
  76. @refetch-user="fetchUserData"
  77. @close-add-new-dialog="companyAddNewDialogActive = !companyAddNewDialogActive"
  78. ></CompanyAddNewDialog>
  79. <CompanyDeleteDialog
  80. :deleteCompanyInfoDialogAcitve="companyDeleteDialogAcitve"
  81. :companyData="propUserCompany"
  82. @refetch-company="getCompanyList"
  83. @refetch-user="fetchUserData"
  84. @closeCompanyDeleteDialog="companyDeleteDialogAcitve = !companyDeleteDialogAcitve"
  85. ></CompanyDeleteDialog>
  86. </v-card>
  87. </template>
  88. <script>
  89. import CompanyDeleteDialog from '../../components/user/companyDeleteDialog.vue'
  90. import CompanyEditInfoDialog from '../../components/user/companyEditInfoDialog.vue'
  91. import CompanyAddNewDialog from '../../components/user/companyAddNewDialog.vue'
  92. import jwt_decode from 'jwt-decode'
  93. export default {
  94. name: "CompanyInfo",
  95. props: {
  96. userCompanyId: {
  97. type: Array,
  98. required: true,
  99. default: () => []
  100. },
  101. countrySortOptions: {
  102. type: Array,
  103. required: true,
  104. default: () => []
  105. }
  106. },
  107. components: {
  108. CompanyEditInfoDialog,CompanyAddNewDialog,CompanyDeleteDialog
  109. },
  110. data() {
  111. return {
  112. companyEditDialogActive: false,
  113. companyAddNewDialogActive: false,
  114. companyDeleteDialogAcitve: false,
  115. propUserCompany:{},
  116. countryOptions:[],
  117. user_uuid: '',
  118. emptyImage: require('~/assets/img/companyEmpty.png'),
  119. userCompanyList:[],
  120. userAddNewCompanyList:[],
  121. companyTableColumns: [
  122. {
  123. text: this.$t('userProfile.companyName'),
  124. value: 'company_name',
  125. sortable:false,
  126. width:'16%'
  127. },
  128. {
  129. text: this.$t('userProfile.taxNumber'),
  130. value: 'company_tax_no',
  131. sortable:false,
  132. width:'16%'
  133. },
  134. {
  135. text: this.$t('userProfile.companyCountry'),
  136. value: 'company_country',
  137. sortable:false,
  138. width:'10%'
  139. },
  140. {
  141. text: this.$t('userProfile.companyCity'),
  142. value: 'company_city',
  143. sortable:false,
  144. width:'12%'
  145. },
  146. {
  147. text: this.$t('userProfile.companyAddress'),
  148. value: 'company_address',
  149. sortable:false,
  150. width:'39%'
  151. },
  152. {
  153. text: '',
  154. value: 'action',
  155. sortable:false,
  156. width:'7%'
  157. },
  158. ]
  159. }
  160. },
  161. created() {
  162. this.getCompanyList()
  163. this.fetchCountry()
  164. if (this.$auth.$storage.getUniversal('jwt')) {
  165. const jsonPayload = jwt_decode(this.$auth.$storage.getUniversal('jwt').token)
  166. this.user_uuid = JSON.parse(jsonPayload.ueid)
  167. }
  168. },
  169. methods: {
  170. activeEditCompanyInfoDialog(item) {
  171. this.companyEditDialogActive = !this.companyEditDialogActive
  172. this.propUserCompany = {...item}
  173. },
  174. activeAddNewCompanyInfoDialog() {
  175. this.companyAddNewDialogActive = !this.companyAddNewDialogActive
  176. },
  177. deleteUserCompany(item) {
  178. this.companyDeleteDialogAcitve = !this.companyDeleteDialogAcitve
  179. this.propUserCompany = {...item}
  180. },
  181. getCompanyList() {
  182. this.$axios.post( `/member/company/list?jwt=${this.$auth.$storage.getUniversal('jwt').token || ''}`,this.userCompanyId)
  183. .then((res) => {
  184. this.userCompanyList = res.data.company_list
  185. this.userAddNewCompanyList = res.data.add_new_company_list
  186. })
  187. .catch((err) => { console.log(err);})
  188. },
  189. fetchCountry() {
  190. this.$axios.get(`/users/countries?lang=${this.$i18n.locale.replace('-','')}`)
  191. .then((res) => {
  192. this.countryOptions = res.data.result
  193. })
  194. .catch((err) => { console.log(err);})
  195. },
  196. fetchUserData() {
  197. this.getCompanyList()
  198. this.$emit('refetch-user')
  199. },
  200. },
  201. watch: {
  202. userCompanyId: {
  203. handler:function() {
  204. this.getCompanyList()
  205. },
  206. deep:true
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .data-table-no-content {
  213. margin-top: 100px;
  214. }
  215. .empty-font-style {
  216. font-size: 20px;
  217. font-weight: 400;
  218. line-height: 26px;
  219. letter-spacing: 0.02em;
  220. }
  221. </style>