<template>
    <Wraper :hidden="hidden" :refresh="refresh" :onOk="submit">
        <Table
            url="/ranger/inspection/api/v1/place/page"
            rowKey="placeId"
            :selected.sync="selected"
            :otherQuery="otherQuery"
            :width="552"
        >
            <template #search="{ query }">
                <MoreItem label="地点名称">
                    <a-input v-model="query.inputValue" placeholder="请输入" />
                </MoreItem>
            </template>

            <a-table-column title="地点名称" data-index="placeName" />
            <a-table-column title="二维码" data-index="qrCode" />
            <a-table-column title="电子标签" data-index="electronicTag" />

            <!-- <a-table-column v-if="rowKey === 'unitId'" title="单元名称" data-index="unitName" />
            <a-table-column v-if="rowKey === 'unitId'" title="设备编号" data-index="equipmentCode" />

            <a-table-column v-if="rowKey === 'itemId'" title="项目名称" data-index="itemName" />
            <a-table-column v-if="rowKey === 'itemId'" title="数据类型" data-index="dataType" />
            <a-table-column v-if="rowKey === 'itemId'" title="项目描述" data-index="equipmentCode" /> -->
        </Table>
    </Wraper>
</template>

<script>
import Table from '@/components/table/table.vue';
import MoreItem from '@/components/table/more_item.vue';
import Wraper from '@/components/table/wraper.vue';
import { addRouteAssemblesListApi } from '@/api';

export default {
    components: { Table, MoreItem, Wraper },
    props: {
        data: Object,
        row: Object,
        hidden: Function,
        refresh: Function,
    },
    watch: {
        row: {
            handler(val) {
                if (val) {
                    const { regionId, routeId } = val;
                    this.otherQuery = { regionId };
                    this.submitData = {
                        assembleObjectType: 'PLACE',
                        parentAssembleObjectType: 'REGION',
                        parentAssembleObjectId: regionId,
                        routeId,
                    };
                }
            },
            deep: true,
            immediate: true,
        },
    },
    data() {
        return {
            selected: {
                keys: [],
            },
            otherQuery: {},
            submitData: {},
        };
    },
    methods: {
        async submit() {
            if (this.selected?.keys?.length !== 0) {
                return await addRouteAssemblesListApi({
                    ...this.submitData,
                    assembleObjectIdList: this.selected.keys,
                });
            }
            this.$message.warning('请选择');
            throw new Error('请选择');
        },
    },
};
</script>
