<template>
    <div class="main">
        <Common />
        <div class="breadcrumb">
            <el-breadcrumb :separator-icon="ArrowRight">
                <el-breadcrumb-item>供应链协同</el-breadcrumb-item>
                <el-breadcrumb-item>生产协作</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <scmSearch
            typeName="协作类型"
            typeListUrl="/mall/webPortal/dictItem/getParkBuyTypeList"
            @handleSearch="handleSearch"
            @handleSort="handleSort"
        >
        </scmSearch>
        <div class="content">
            <div class="left">
                <div class="item" v-for="item in list">
                    <div class="itemLeft">
                        <div class="itemTitle">{{ item.goodsVo.title }}</div>
                        <div class="itemTags">
                            <span class="tag" v-for="tag in item.tags">{{ tag }}</span>
                        </div>
                        <div class="itemInfo">
                            <span>发布企业: {{ item.goodsVo.enterpriseName }}</span>
                            <span>所在地区: {{ item.goodsVo.enterpriseArea }}</span>
                            <span>有效时间: {{ item.goodsVo.timeType == 1 ? '长期有效' : item.goodsVo.indate }}</span>
                        </div>
                    </div>
                    <div class="itemRight">
                        <div class="btn" @click="goToInfo(item)">查看详情</div>
                    </div>
                </div>
            </div>
            <!-- <div class="right">
                <div class="rightTop"></div>
            </div> -->
        </div>
        <div class="pagination">
            <el-pagination background layout="prev, pager, next"  
                @current-change="changePage" 
                :current-page="params.pageNum" 
                :page-size="params.pageSize" 
                :total="total" 
            />
        </div>
        <Footer />

    </div>
</template>
    
<script setup lang='ts'>
import Common from '../../components/common/common.vue';
import Footer from '../../components/common/footer.vue';
import scmSearch from '../../components/common/scmSearch.vue';
import { ArrowRight, ChatLineRound, Search } from '@element-plus/icons-vue';
import { ref, reactive, inject, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
export interface listItem {
    priceType: number | string,
    price: number | string,
    tags: [],
    goodsVo: {
        title: string,
        buyTypeName: string,
        enterpriseName: string,
        enterpriseArea: string,
        timeType: number,
        indate: string,
    }
}
const $http:any = inject("$http");
const router = useRouter();

    const list = ref<listItem[]>([]);
    let params = reactive({
        pageNum: 1,
        pageSize: 10,
        state: 3,
    });
    const total = ref(0);
    function getList(query: object) {
        $http({
            url: '/mall/webPortal/industrialCooperation/queryPageByCondition',
            params: query
        })
        .then((res:any) => {
            // 手动转换 tags
            const data = res.rows.filter((item: any) => {
                if(item.goodsVo.keyWord) {
                    item.tags = item.goodsVo.keyWord.split(",");
                }
                return item;
            })
            list.value = data;
            total.value = res.total;
        })
    }

    function handleSearch(data: any) {
        params = Object.assign(params, data);
        params.pageNum = 1;
        getList(params);
    }
    function handleSort(data: any) {
        params = Object.assign(params, data);
        getList(params)
    }

    function changePage(val:number) {
        params.pageNum = val;
        getList(params);
    }

    onMounted(() => {
        getList(params);
    });

    function goToInfo(param: any) {
        console.log(param)
        router.push({
            name: 'produceDetails',
            query: {
                id: param.id
            }
        })
    }
</script>
    
<style scoped lang="less">
.main {
    width: 100%;
    background-color: #f5f5f5;
    user-select: none;
}

.breadcrumb {
    margin: 0 auto;
    padding: 25px 0;
    width: 1200px;
    display: flex;
}

.content {
    margin: 0 auto;
    padding: 25px 0;
    width: 1200px;
    display: flex;
    .left {
        margin-right: 20px;
        width: 1200px;
        display: flex;
        flex-wrap: wrap;
        .item {
            margin-bottom: 16px;
            width: 1200px;
            height: 150px;
            background-color: #fff;
            font-size: 14px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 28px;
            box-sizing: border-box;
            .itemLeft {
                width: 750px;
                color: #666;
                display: flex;
                flex-wrap: wrap;
                box-sizing: border-box;
                font-size: 14px;
                .itemTitle {
                    width: 100%;
                    color: #101010;
                }
                .itemTags {
                    margin-top: 14px;
                    width: 100%;
                    display: flex;
                    flex-wrap: wrap;
                    .tag {
                        margin-right: 16px;
                        box-sizing: border-box;
                        height: 28px;
                        line-height: 28px;
                        color: #101010;
                        padding: 0 15px;
                        background-color: #f2f2f2;
                    }
                }
                .itemInfo {
                    margin-top: 14px;
                    width: 100%;
                    display: flex;
                    // justify-content: space-between;
                    align-items: center;
                    span {
                        margin-right: 30px;
                    }
                }
            }
            .itemRight {
                width: 180px;
                display: flex;
                justify-content: right;
                .btn {
                    width: 120px;
                    height: 42px;
                    line-height: 42px;
                    box-sizing: border-box;
                    border: 1px solid @baseColor;
                    color: @baseColor;
                    font-size: 14px;
                    border-radius: 5px;
                    text-align: center;
                    cursor: pointer;
                }
                .btn:hover {
                    background-color: @baseColor;
                    color: #fff;
                }
            }
        }
    }
    .right {
        width: 250px;
        .rightTop {
            width: 100%;
            height: 280px;
            background: url('../../assets/image/scm/需求.jpg') no-repeat ;
            background-size: contain;
            cursor: pointer;
        }
        .rightBottom {
            margin-top: 30px;
            width: 100%;
            padding: 24px;
            box-sizing: border-box;
            background-color: #fff;
            .bottomTitle {
                width: 100%;
                text-align: center;
                font-size: 16px;
            }
            .bottomItem {
                width: 100%;
                padding: 20px 0;
                box-sizing: border-box;
                border-bottom: 1px solid #EEEEEE;
                display: flex;
                cursor: pointer;
                .itemImg {
                    width: 53px;
                    height: 53px;
                }
                .bottomItemTitle {
                    margin-left: 8px;
                    color: #666;
                    font-size: 14px;
                    line-height: 20px;
                }
            }

        }
    }
}

.pagination {
    margin: 0 auto;
    padding: 25px 0;
    width: 1200px;
    display: flex;
    :deep(.el-pager li) {
        background-color: #fff;
    }
    :deep(.btn-prev) {
        background-color: #fff;
    }
    :deep(.btn-prev:disabled) {
        background-color: #fff;
    }
    :deep(.btn-next) {
        background-color: #fff;
    }
    :deep(.btn-next:disabled) {
        background-color: #fff;
    }
}

</style>