· 5 years ago · Sep 27, 2020, 02:56 PM
1// manggil
2this.getDataCenter(this.activeDataCenter, {
3 attribute: {
4 status: this.StatusFilterSelected,
5 },
6 })
7
8// method
9/**
10 * Get each data center
11 * @param key
12 * @param params{}
13 */
14 getDataCenter: function(key, param = {}) {
15 /** define ANY API prequisite */
16 var params = {
17 klaster_slug: key,
18 simple: true,
19 page: this.page,
20 limit: this.limit,
21 }
22 /** loop param then push to params */
23 if (Object.keys(param).length > 0) {
24 Object.keys(param).forEach((each) => {
25 // attribute[tanggal_ditetapkan][]
26 params[each] = param[each]
27 })
28 }
29 /** params need to encoded from object to url params */
30 var attr = ''
31 params = Object.keys(params)
32 .map(function(key) {
33 if (key === 'attribute' && Object.keys(param[key]).length > 0) {
34 Object.keys(param[key]).forEach((each) => {
35 attr = ''
36 attr = `attribute[${each}][]=${param[key][each]}`
37 })
38 return attr
39 }
40 return key + '=' + params[key]
41 })
42 .join('&')
43
44 /** token required for getting data from backend */
45 const getOptions = {
46 headers: {
47 Authorization: appConfig.default_token,
48 'Access-Control-Allow-Origin': '*',
49 },
50 }
51 /** define endpoint */
52 var endpoint = `${appConfig.endpoint}/klaster-by-member-relation?${params}`
53 console.log(endpoint)
54 /**
55 * Do API Request
56 */
57 Axios.get(endpoint, getOptions).then((response) => {
58 const data = response.data.data
59 this.DataCenter = data
60 this.activeDataCenter = key
61 /** Pagination */
62 this.pageLength = response.data.page_total
63
64 /** Reset filter data */
65 // this.LPFilterOptions = []
66 // this.TPFilterOptions = []
67 // this.StatusFilterOptions = []
68 /**
69 * Loop the data for filtering
70 */
71 data.forEach((element) => {
72 /** Lembaga Pengadilan Filter */
73 if (element.atribut.lembaga_pengadilan) {
74 const options = {
75 text: element.atribut.lembaga_pengadilan.data[0].content,
76 value: element.atribut.lembaga_pengadilan.data[0].content,
77 }
78 this.LPFilterOptions.push(options)
79 }
80 /** Status Filter */
81 if (element.atribut.status) {
82 const options = {
83 text: element.atribut.status.data[0].content,
84 value: element.atribut.status.data[0].content,
85 }
86 this.StatusFilterOptions.push(options)
87 }
88 })
89 })
90 }