<template>
    <el-dialog title="分享" :visible.sync="openDeviceList" width="700px" append-to-body>
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
            <el-form-item label="设备名称" prop="deviceName">
                <el-input v-model="queryParams.deviceName" :placeholder="$t('device.device-edit.148398-2')" clearable
                    size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search')
                    }}</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
            </el-form-item>
        </el-form>

        <el-table ref="multipleTable" v-loading="loading" :data="deviceList" :border="false" row-key="serialNumber"
            size="mini" :header-cell-style="{ backgroundColor: '#F2F6FC' }">
            <el-table-column :label="$t('device.device-edit.148398-1')" align="center" prop="deviceName" />

            <el-table-column label="操作" align="center" prop="opation">
                <template slot-scope="scope">
                    <el-button size="mini" plain @click="share(scope.row)" style="color: cornflowerblue">分享</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList(null)" />

        <el-dialog title="分享" :visible.sync="shareopen" width="700px" append-to-body>
            <div v-show="isShare">
                <div>
                    <el-row>
                        <el-col :span="20">
                            <div>
                                <p>链接</p>
                            </div>
                        </el-col>
                        <el-col :span="4">
                            <div>
                                <el-button type="text" icon="el-icon-link" @click="closeshare">关闭分享</el-button>
                            </div>
                        </el-col>
                    </el-row>
                    <div>
                        <el-row :gutter="10">
                            <el-col :span="18">
                                <el-input v-model="link" :disabled="true"></el-input>
                            </el-col>
                            <el-col :span="5">
                                <el-button type="primary" style="width: 115px">复制链接</el-button>
                            </el-col>
                        </el-row>
                        <el-checkbox style="margin-top: 10px; margin-bottom: 20px"
                            v-model="checked">访问需要密码</el-checkbox>
                    </div>
                </div>
                <div>
                    <div style="margin-bottom: 30px">
                        <p>二维码</p>
                    </div>
                    <el-row>
                        <el-col :span="8">
                            <div style="border: 1px solid #ccc; width: 200px; height: 200px; margin-top: -15px">
                                <div style="padding-bottom: 10px"></div>
                            </div>
                        </el-col>
                        <el-col :span="14">
                            <div>
                                <p>将二维码分享给他人</p>
                                <p>对方通过微信扫一扫即可查看</p>
                            </div>
                            <div>
                                <el-button icon="el-icon-download">下载二维码</el-button>
                            </div>
                        </el-col>
                    </el-row>
                    <el-button style="margin-top: 20px" type="text" icon="el-icon-back"
                        @click="shareopen = false">返回继续分享</el-button>
                </div>
            </div>
            <div v-show="!isShare" style="text-align: center; height: 100%">
                <div style="display: inline-block; vertical-align: middle">
                    <img class="closeShare" style="width: 400px; height: 400px; margin: auto"
                        src="@/assets/images/send.png" />
                </div>
                <div>
                    <el-button type="primary" style="width: 400px; margin-top: 20px; margin-bottom: 40px"
                        @click="openShare">开启分享</el-button>
                </div>
            </div>
        </el-dialog>
    </el-dialog>
</template>

<script>
import { listDeviceShort } from '@/api/iot/device';
export default {
    name: 'device-list',
    dicts: ['iot_device_status', 'iot_location_way'],
    data() {
        return {
            link: 'http',
            qrText: 'fastbee',
            // 遮罩层
            loading: true,
            // 选中设备
            selectDeviceNums: [],
            productId: 0,
            productName: '',
            // 是否显示设备列表
            openDeviceList: false,
            // 总条数
            total: 0,
            shareopen: false,
            isShare: false,
            checked: false,
            deviceId: '',
            // 设备表格数据
            deviceList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                deviceName: null,
                productId: null,
                productName: null,
                serialNumber: null,
                status: null,
            },
        };
    },
    created() { },
    methods: {
        // 获取设备列表
        getList() {
            this.deviceList = [];
            this.loading = true;
            this.queryParams.productId = this.queryParams.productId == 0 ? null : this.queryParams.productId;
            listDeviceShort(this.queryParams).then((response) => {
                this.deviceList = response.rows;
                this.total = response.total;
                this.loading = false;
                this.deviceList.forEach((item) => {
                    item.isShare = true;
                });

                console.log(this.deviceList);
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList(null);
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm');
            this.handleQuery();
        },
        //组态设备分享
        share(row) {
            console.log(row);
            this.deviceId = row.deviceId;
            if (row.isShare == true) {
                this.shareopen = true;
                this.isShare = true;
            } else {
                this.shareopen = true;
            }
        },
        closeshare() {
            this.isShare = false;
            console.log(this.deviceId);
            this.deviceList.forEach((item) => {
                if (item.deviceId == this.deviceId) {
                    item.isShare = false;
                    this.isShare = false;
                }
            });
        },
        openShare() {
            this.isShare = true;
            this.deviceList.forEach((item) => {
                if (item.deviceId == this.deviceId) {
                    item.isShare = true;
                    this.isShare = true;
                }
            });
        },
    },
};
</script>

<style lang="scss" scoped>
/***隐藏全选，避免选中不同产品的设备**/
::v-deep .el-table__header-wrapper .el-checkbox {
    display: none;
}
</style>
