All files / views/investment Index.vue

81.57% Statements 124/152
100% Branches 2/2
14.28% Functions 1/7
81.57% Lines 124/152

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 1531x 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 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x     2x 2x                     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x       2x           2x             2x 2x 1x 1x 1x 1x 1x 1x  
<template>
  <div class="q-pa-md">
    <!-- Title -->
    <HeaderTitleWithBackButton :btn="false" title="Mutual Fund"/>
    <!-- Table Header Action -->
    <TableHeader v-model:show="show" v-model:filter="filter" label="Add New Data" to="investment-add" roles="mutualFund:create"/>
 
    <q-table
        class="brx-shadow-sm"
        transition-show="fade"
        transition-hide="fade"
        :rows="rows"
        :columns="columns"
        :filter="filter"
        :filter-method="customFilter"
        no-data-label="I didn't find anything for you"
        no-results-label="The filter didn't uncover any results"
        row-key="name"
        :grid ="$q.screen.xs"
        hide-bottom
    >
      <template v-slot:body="props">
        <q-tr :props="props">
          <q-td key="name" :props="props">
            <div class="row">
              <div class="box-image cursor-pointer" v-if="!props.row?.logo?.url.includes('briix.com')" @click="popupImages(true,props.row?.logo?.url)" :style="`background-image: url(${mediaServer}${props.row?.logo?.url})`"></div>
              <div class="box-image cursor-pointer" v-else @click="popupImages(true,props.row?.logo?.url)" :style="`background-image: url(${props.row?.logo?.url})`"></div>
              <div class="col q-ml-md">
                <div class="text-bold overflow-text">{{ props.row.name }}</div>
                <div class="overflow-text">
                  IDR{{ props.row.amount.toLocaleString() }}
                </div>
              </div>
            </div>
          </q-td>
          <q-td key="type" :props="props">
            {{props.row.type}}
          </q-td>
          <q-td key="tenor" :props="props">
            {{props.row.tenor}} Months
          </q-td>
          <q-td key="range" :props="props">
            IDR{{props.row.min.toLocaleString()}} - Rp {{props.row.max.toLocaleString()}}
          </q-td> 
          <q-td key="status" :props="props">
            <q-chip 
              size="11px" 
              flat 
              class="text-weight-bold" 
              :class="statusFlag(props.row.status).class" 
              :label="statusFlag(props.row.status).label" 
            />
          </q-td>
          <q-td key="action" :props="props" >
            <q-icon name="img:edit_square.svg" size="18px" @click="redirect(props.row?.code)" />
          </q-td>
        </q-tr>
      </template>
 
    </q-table>
  </div>
</template>
 
<script lang="ts">
import {onMounted, ref} from 'vue'
import {Product} from '@/common/models'
import {status, statusInvestment} from '@/common/enums'
import {getProducts} from '@/common/api/api'
import router from "@/router";
import {readOnly} from '@/common/session/user'
import HeaderTitleWithBackButton from '@/components/HeaderTitleWithBackButton.vue';
import TableHeader from '@/components/TableHeader.vue';
 
const columns = [
  {name: 'name', label: 'Name', align: 'left', field: 'name', sortable: true},
  {name: 'type', align: 'left', label: 'Type', field: 'titleKind', sortable: true},
  {name: 'tenor', label: 'Tenor', field: 'tenor',align: 'left', sortable: true},
  {name: 'range', label: 'Range',align: 'left', field: 'min', sortable: true},
  {name: 'status', label: 'Status',align: 'left', field: 'status', sortable: true},
  {name: 'action', label: 'Action',align: 'left'},
]
 
export default {
    setup() {
        const popup = ref({
            flag: false,
            image: "",
        });
        const rows = ref([] as Product[]);
        const filter = ref<string>("");
        const mediaServer = import.meta.env.VITE_BASE_MEDIA_SERVER;
        const filterOptions = ref(["Daily", "Weekly", "Monthly", "Annualy"]);
        const showOptions = ref([5, 10, 20, 50]);
        const show = ref(5);
        const read = ref(readOnly());
        onMounted(() => {
            getProducts().then(response => {
                rows.value = response.data;
                rows.value.sort((a, b) => b.id - a.id);
            }).catch(err => {
                console.log(err);
            });
        });
        function statusFlag(status: number): {
            class: string;
            label: string;
        } {
            switch (status) {
                case 0: return { class: "bg-orange-1 text-orange-9", label: "Draft" };
                case 200: return { class: "bg-green-1 text-green-9", label: "Active" };
                case 400: return { class: "bg-red-1 text-red-9", label: "Deactive" };
                default: return { class: "bg-orange-1 text-orange-9", label: "Draft" };
            }
        }
        return {
            show,
            showOptions,
            filterOptions,
            mediaServer,
            columns,
            rows,
            popup,
            status,
            statusInvestment,
            read,
            filter,
            statusFlag,
            popupImages(flag: boolean, image: string) {
                popup.value.flag = true;
                popup.value.image = image;
            },
            redirect(code: string) {
                router.push({
                    name: "investment-update",
                    params: { code },
                });
            },
            customFilter(rows:any, terms:any){
              return rows.filter((row:any)=>{
                return row.name.toLowerCase().includes(terms.toLowerCase())||
                row.type.toLowerCase().includes(terms.toLowerCase())||
                (row.tenor+'').includes(terms)
              })
            }
        };
    },
    components: { HeaderTitleWithBackButton, TableHeader }
}
</script>
<style scoped lang="sass">
 
</style>