CitySettings.vue 3.95 KB
<template>
    <div>
        <h2 class="mt-12 font-bold text-2xl">Cities</h2>

        <div v-if="cities.length" class="mt-4 flex flex-wrap">
            <select-input v-model="city" class="pr-6">
                <option v-for="city in cities" :value="city.id">
                    {{ city.name }}
                </option>
            </select-input>

            <button class="btn-indigo hover:underline"
                    tabindex="-1"
                    type="button"
                    @click="cityAdd"
            >
                Add
            </button>

        </div>

        <div class="mt-6 bg-white rounded shadow">
            <table class="w-full whitespace-nowrap">
                <tr class="text-left font-bold">
                    <th class="px-6 pt-6 pb-4" colspan="2">Name</th>
                    <th class="px-6 pt-6 pb-4">Обновлять?</th>
                    <th class="px-6 pt-6 pb-4"></th>
                </tr>
                <template v-for="city in token_cities" >
                <tr :key="city.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
                    <td  colspan="2" class="border-t">
                        <span class="px-6 py-4 flex items-center focus:text-indigo-500"> {{ city.name }} </span>
                    </td>
                    <td class="border-t">
                        <input :checked="city.pivot.updated"
                               @change="cityUpdated(city.id, !city.pivot.updated)"
                               type="checkbox"
                        >
                    </td>
                    <td>
                        <button class="px-4 flex items-center"
                                tabindex="-1"
                                @click="cityDelete(city.id)"
                        >
                            <icon name="trash" class="block w-6 h-6 fill-gray-400" />
                        </button>
                    </td>
                </tr>
                    <tr>
                        <th class="px-6 pt-6 pb-4"></th>
                        <th class="px-6 pt-6 pb-4">Кампания</th>
                        <th class="px-6 pt-6 pb-4">Синхронизировать?</th>
                        <th></th>
                    </tr>
                    <tr v-for="campaign in main_token_campaigns">
                        <td class="border-t"></td>
                        <td class="border-t">
                            <span class="px-6 py-4 flex items-center focus:text-indigo-500">
                                {{ campaign.name }}
                            </span>
                        </td>
                        <td class="border-t">
                            <input :checked="false"
                                   @change="campaignUpdated(campaign.id, false)"
                                   type="checkbox"
                            >
                        </td>
                        <td></td>
                    </tr>
                </template>
                <tr v-if="token_cities.length === 0">
                    <td class="border-t px-6 py-4" colspan="4">No City found.</td>
                </tr>
            </table>
        </div>
    </div>
</template>

<script>

import SelectInput from "../../Shared/SelectInput";
import Icon from "../../Shared/Icon";
export default {
    components: {Icon, SelectInput},
    props: {
        cities: Array,
        token_cities: Array,
        main_token_campaigns: Array,
    },
    data() {
        return {
            city: false
        }
    },
    watch: {

    },
    mounted() {

    },
    methods: {
        cityAdd() {
            this.$emit('add', this.city)
        },
        cityDelete(id) {
            this.$emit('delete', id)
        },
        cityUpdated(id, updated) {
            console.log(this.token_cities);
            this.$emit('updated', id, updated)
        },
        campaignUpdated(id, updated) {
            this.$emit('campaignUpdated', id, updated)
        },
    }
}
</script>