<!-- 站点列表 -->
<!-- :filters="[{text: '2016-05-01', value: '2016-05-01'}, {text: '2016-05-02', value: '2016-05-02'}, {text: '2016-05-03', value: '2016-05-03'}, {text: '2016-05-04', value: '2016-05-04'}]"
 :filter-method="filterHandler" -->
<template>
    <div class="siteList-wrap column">
        <div class="siteList-main ">
            <div class="flex-between site-top">
                <div class="left flex">
                    <h2>站点列表</h2>
                    <GuipButton size="medium" class="addgroupBtn" type="normal"
                        :btnstyle="{ width: '115px', hright: '32px' }" @click="addGroupVisiable = true">
                        <img src="@/assets/site/addIcon.svg" alt="">新增分组
                    </GuipButton>
                   <div style="width: 120px;">
                       <GuipSelectFilter v-model="selectedValue" :options="options" :searchable="true" placeholder="请选择"
                           :filter-method="customFilter" search-placeholder="搜索..." />
                   </div>

                    <!-- <searchable-select :styleObj="{
                        'width': '140px', 'height': '32px'
                    }" v-model="selectedValue1" :options="options1" :searchable="true" placeholder="请选择"
                        search-placeholder="关键词搜索" @change="handleChange" />
                    <el-form>
                        <GuipSelect width="600px" v-model="selectedValue" :options="options" defaultValue="选项1" />
                    </el-form>
                   -->
                    <!-- <GuipSelectFilter2
      v-model="selectedValue"
      :options="options1"
      :searchable="true"
      placeholder="请选择水果"
      search-placeholder="搜索水果名称"
      no-data-text="没有找到匹配的水果"
      @change="handleFruitChange"
    /> -->
                </div>
                <div class="right">
                    <GuipButton size="medium" @click="addSite" :btnstyle="btnstyleObj_add" type="primary">新增站点
                    </GuipButton>
                </div>
            </div>
            <el-form>
                <el-table :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                    style="width: 100%" :key="random()">
                    <!-- 其他列 -->
                    <el-table-column prop="name" label="站点简称" width="210">
                        <template slot-scope="scope">
                            <a class="name_link flex cell_render" :href="scope.row.link" target="_blank">
                                {{ scope.row.name }}
                                <img class="edit_icon" src="@/assets/site/form_link.svg" alt="">
                            </a>
                        </template>
                    </el-table-column>
                    <el-table-column prop="registerDate" label="注册时间"></el-table-column>

                    <!-- 价格列 -->
                    <el-table-column label="站点分组" prop="group">
                        <template slot-scope="scope">
                            <!-- <a class="name_link flex cell_render" :href="scope.row.link" target="_blank">
                                {{ scope.row.name }}
                                <img class="edit_icon" src="@/assets/site/form_link.svg" alt="">
                            </a> -->
                            <!-- <searchable-select slot="reference"  :styleObj="{ 'width': '140px', 'height': '32px','position': 'absolute',
    'z-index': '1119' }" v-model="scope.row.group"
                                :options="options1" :searchable="true" placeholder="请选择" search-placeholder="关键词搜索"
                                @change="handleChange" /> -->
                            <!-- <GuipSelect width="600px" v-model="scope.row.group" prop="card" :options="options"
                                defaultValue="选项1" /> -->
                            <GuipSelectFilter v-model="scope.row.group" :options="options" :searchable="true"
                                placeholder="请选择" :filter-method="customFilter" search-placeholder="搜索..." />
                            <!-- <GuipSelectFilter2
      v-model="scope.row.group"
      :options="options1"
      :searchable="true"
      placeholder="请选择水果"
      search-placeholder="搜索水果名称"
      no-data-text="没有找到匹配的水果"
      @change="handleFruitChange"
    /> -->
                        </template>
                        <!-- <template v-slot="{ row, $index }">
                            <el-popover v-model="row.group_popover" placement="top" trigger="manual"
                                :ref="`popover-${$index}`" @show="popshow">
                                <searchable-select slot="reference"  :styleObj="{ 'width': '140px', 'height': '32px' }" v-model="selectedValue1"
                                :options="options1" :searchable="true" placeholder="请选择" search-placeholder="关键词搜索"
                                @change="handleChange" >
                                <span @click="handlePriceClick(row, $index, 'group')">
                                    <div class="flex cell_render">
                                        <span v-if="row.group" :key="random()">{{ groupList[row.group] }}</span>
                                        <img class="edit_icon" src="@/assets/site/drop_icon.svg" alt="">
                                    </div>
                                </span>
                                </searchable-select>
                            </el-popover>
                        </template> -->
                    </el-table-column>
                    <el-table-column prop="phoneService" label="手机服务" :filters="phoneService"
                        :filter-method="filterHandler">
                    </el-table-column>
                    <!-- <el-table-column prop="department" label="部门">
                        <template #default="{ row, $index }">
                            <template v-if="editingIndex === $index">
                                <searchable-select v-model="row.department" :options="departmentOptions"
                                    @change="handleDepartmentChange(row, $index)" @click.native.stop />
                            </template>
                            <template v-else>
                                <span @click="startEditing($index)">{{ row.department }}</span>
                            </template>
                        </template>
                    </el-table-column> -->
                    <el-table-column prop="status" label="状态" width="195">
                        <template v-slot="{ row, $index }">
                            <el-popover v-model="row.status_popover" placement="top" trigger="manual"
                                :ref="`popover-${$index}`" @show="popshow">
                                <!-- 弹框内容 -->
                                <div class="statusList">
                                    <p class="flex">
                                        <img style="margin-right: 8px;" src="@/assets/site/info_filled.svg"
                                            alt="">自有域名验证未通过
                                    </p>
                                    <p class="flex" style="margin: 12px 0;">
                                        <img style="margin-right: 8px;" src="@/assets/site/info_filled.svg"
                                            alt="">收款方式未配置
                                    </p>
                                    <p class="flex">
                                        <img style="margin-right: 8px;" src="@/assets/site/info_filled.svg"
                                            alt="">支付宝收款账号未配置
                                    </p>
                                </div>
                                <!-- 触发弹框的按钮 -->
                                <span slot="reference" @click="handlePriceClick(row, $index, 'status')">
                                    <div class="flex cell_render">
                                        <span :class="(row.status == '0' ? 'in_services' : 'in_config')">{{
                                            row.status == '0' ? '运行中' : '配置中' }}</span>
                                        <img class="edit_icon" v-if="row.status == '1'"
                                            src="@/assets/site/more_setIcon.png" alt="">
                                    </div>
                                </span>

                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="182">
                        <template slot-scope="scope">
                            <div class="flex">
                                <el-button @click="handleServiceClick(scope.row)" type="text">服务列表</el-button>
                                <el-button @click="handleSetClick(scope.row)" type="text">站点设置</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination background @size-change='handleSizeChange' @current-change='handleCurrentChange'
                    :current-page="currentPage" :page-size=pageSize layout="prev, pager, next,jumper"
                    :total="tableData.length">
                </el-pagination>
            </el-form>
        </div>
        <GuipDialog type="normal" width="396px" :dialogVisible="addGroupVisiable" title="温馨提示" :show-close-button="false"
            :show-cancel-button="true" cancelText="取消" confirmText="确定" @confirm="handleConfirmAddGroup" @cancel="handleCancelAddGroup"
             @dialogVisibleChange="dialogVisibleChange">
                <el-input ref="GuipInput" width="252px" v-model="groupName" label="分组名称" placeholder="请输入名称" />
        </GuipDialog>
        <Footer></Footer>
    </div>
</template>
<script>
import Footer from '@/components/Footer.vue';
// import GuipInput from '@/components/GuipInput.vue';
import GuipButton from '@/components/GuipButton.vue';
// import GuipSelect from '@/components/GuipSelect.vue';
import GuipSelectFilter from '@/components/GuipSelectFilter.vue';
import GuipDialog from '@/components/GuipDialog.vue';
// import SearchableSelect from '@/components/GuipSelectFilter1.vue';
// import GuipSelectFilter2 from '@/components/GuipSelectFilter2.vue';
// import SearchableSelect from '@/components/GuipSelectFilter2.vue'
export default {
    name: 'sitelist',
    components: {
        // HelloWorld
        // GuipInput,
        GuipDialog,
        GuipSelectFilter,
        // SearchableSelect,
        // GuipSelectFilter2,
        // SearchableSelect,
        // GuipSelect,
        Footer,
        GuipButton
    },
    data() {
        return {
            searchText: '',
            filteredOptions: this.options,
            editingIndex: -1,
            groupName: '',//分组名称
            addGroupVisiable: false,
            selectedValue: '',
            fruitOptions: [
                { label: '苹果', value: 'apple' },
                { label: '香蕉', value: 'banana' },
                { label: '橙子', value: 'orange' },
                { label: '葡萄', value: 'grape' },
                { label: '西瓜', value: 'watermelon' },
                { label: '菠萝', value: 'pineapple' }
            ],
            options: [
                { label: '选项1', value: '1' },
                { label: '选项2', value: '2' },
                { label: '选项3', value: '3' },
                // 更多选项...
            ],
            selectedValue1: '',
            options1: [
                { label: '苹果', value: '1' },
                { label: '香蕉', value: '2' },
                { label: '橙子', value: '22' },
                { label: '葡萄', value: '13' },
                { label: '西瓜', value: '31' },
                { label: '菠萝', value: '32' },
                { label: '菠萝1', value: '14' },
                { label: '菠萝2', value: '15' },
                { label: '菠萝21', value: '156' },
                { label: '菠萝22', value: '24' },
            ],
            btnstyleObj_add: {
                width: '90px',
                height: '30px'
            },
            tableData: [
                {
                    name: '哈哈哈',
                    link: 'http://www.chachongz.com',
                    registerDate: '2025.02.18',
                    group: '1',
                    phoneService: '撒大事',
                    status: '1',//配置中中
                },
                {
                    name: '知网学诚教育',
                    link: 'http://new.checkcopy.com',
                    registerDate: '2025.02.18',
                    group: '2',
                    phoneService: '设计部',
                    status: '0',//运行中
                },
            ],
            groupList: {
                1: '内部测试',
                2: '查重站点'
            },
            phoneServicelist:
            {
                0: '不限',
                1: ' H5',
                2: '小程序',
                3: '无手机服务'

            },
            currentPage: 1,    //当前页
            pageSize: 2,   //每页的容量
            total: 0,   //列表总数
            phoneService: [
                {
                    text: '不限',
                    value: '0'
                },
                {
                    text: 'H5',
                    value: '1'
                },
                {
                    text: '小程序',
                    value: '2'
                },
                {
                    text: 'H5以及小程序',
                    value: '3'
                },
            ]
        }
    },
    mounted() {
        const list = ['group', 'status']
        list.forEach(item => {
            this.tableData = this.tableData.map(item1 => {
                item1[item + '_popover'] = false
                return {
                    ...item1,
                }
            })
        })
        console.log(this.tableData, '000--');

    },
    methods: {
         // 处理搜索输入
         handleSearch(keyword) {
            console.log(keyword,'keyword---');
            if (this.filterMethod && typeof this.filterMethod === 'function') {
                // 使用自定义筛选方法
                this.filteredOptions = this.filterMethod(keyword, this.options)
            } else {
                // 默认筛选方法
                if (!keyword) {
                    this.filteredOptions = this.options
                } else {
                    const lowerKeyword = keyword.toLowerCase()
                    this.filteredOptions = this.options.filter(item => {
                        const label = item[this.labelKey] || ''
                        return label.toString().toLowerCase().includes(lowerKeyword)
                    })
                }
            }
        },
        startEditing(index) {
            this.editingIndex = index
            // 保存原始数据以便取消编辑时恢复
            this.originalData = JSON.parse(JSON.stringify(this.tableData[index]))
        },

        saveEditing() {
            this.editingIndex = -1
            this.originalData = null
            this.$message.success('保存成功')
        },

        cancelEditing() {
            if (this.originalData) {
                this.$set(this.tableData, this.editingIndex, this.originalData)
            }
            this.editingIndex = -1
            this.originalData = null
        },

        handleDepartmentChange(row, index) {
            console.log('部门已修改:', index, row.department)
            // 可以在这里添加部门变更后的逻辑
        },
        // 确认按钮事件
        handleConfirmAddGroup() {
            this.$message.success('点击了确认按钮');
            this.addGroupVisiable = false;
        },
        // 取消按钮事件
        handleCancelAddGroup() {
            this.$message.warning('点击了取消按钮');
            this.addGroupVisiable = false;
        },
        dialogVisibleChange(data) {
            console.log(data, 'data098908090');
        },
        handleChange(value) {
            console.log('选中值变化:', value)
        },
        popshow() {
            var ariaEls = document.querySelectorAll('.el-popover')
            ariaEls.forEach((item) => {
                item.removeAttribute('aria-hidden')
            })

            ariaEls = document.querySelectorAll('.el-radio__original')
            ariaEls.forEach((item) => {
                item.removeAttribute('aria-hidden')
            })
        },
        random() {
            var randomNumber = Math.random();
            return randomNumber
        },
        handleSizeChange(val) {
            this.pageSize = val
        },
        handleCurrentChange(val) {
            this.currentPage = val
        },
        // 列筛选
        filterHandler(value, row, column) {
            const property = column['property'];
            return row[property] === value;
        },
        handleSetClick(row) {
            console.log(row);
        },
        handleServiceClick(row) {
            console.log(row);
        },
        addGroup() {
            // 新增分组
        },
        addSite() {
            // 新增站点
        },
        // 自定义搜索筛选
        customFilter(keyword, options) {
            if (!keyword) return options
            return options.filter(item => {
                // 自定义筛选逻辑
                return item.label.includes(keyword) || item.value.includes(keyword)
            })
        },
        customFilter1(keyword, options) {
            if (!keyword) return options
            // 自定义筛选逻辑，比如同时匹配 label 和 value
            return options.filter(item => {
                return (
                    item.label.includes(keyword) ||
                    item.value.toString().includes(keyword)
                )
            })
        },
        handleFruitChange(value) {
            console.log('水果选择变化:', value)
        },
        // 气泡弹出框
        handlePriceClick(row, index, type) {
            // 关闭其他行的弹框
            this.tableData.forEach((item, i) => {
                if (i !== index) {
                    item[type + '_popover'] = false;
                }
            });
            // 打开当前行的弹框
            row[type + '_popover'] = true;
            row['edit_' + type] = row[type]
            // row.edit_price = row.price; // 初始化输入框的值
        },

    }
}
</script>
<style lang="scss" scoped>
::v-deep .el-popover {
    padding: 24px 32px !important;
}

.siteList-wrap {
    padding: 12px 12px 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;

    .in_services {
        color: #0DAF49;
    }

    .in_config {
        color: #FF4D4F;
    }

    .addgroupBtn {
        margin: 0 12px;

        img {
            margin-right: 4px;
        }
    }

    .siteList-main {
        flex: 1;
        padding: 32px 36px;
        border-radius: 4px;
        box-sizing: border-box;
        width: 100%;
        background: #FFFFFF;

        .site-top {
            margin-bottom: 32px;

            .left {

                h2 {
                    margin: 0;
                }
            }
        }

        .statusList {
            padding: 24px 32px;

            img {
                margin-right: 8px;
            }

            p {
                display: flex;
                align-items: center;
            }

            letter-spacing: 0.08em;
            color: #1E2226;
        }

        .edit_icon {
            width: 16px;
            height: 16px;
            display: none;
            transition: all .3s;
            margin-left: 8px;
        }

        .name_link {
            text-decoration: none;
            color: #1E2226;
        }

        .el-table__row:hover {
            .edit_icon {
                display: block;
                transition: all .3s;
            }
        }
    }

}
</style>