<template>
    <div class="my_material_modal">
        <!-- <a-modal class="my_material_modal" 
            v-model:visible="myMaterialModalShow" 
            :footer="null" 
            width="80%"
            :maskClosable="false"
            :centered="true"
        > -->
            <div class="my_material_header">
                <div class="my_material_header_right">
                    <div class="content_search_block">
                        <input class="search_input" placeholder="Please input" v-model="searchPictureName"  @keydown.enter="getLibraryList()">
                        <div class="search_icon_block" @click.stop="getLibraryList()"><span class="icon iconfont icon-sousuo"></span></div>
                    </div>
                </div>
            </div>

            <div class="my_material_content">
             
                <div class="material_content_body scroll_style">
					<div v-for="item,index in imgList" :key="item" class="content_img_item" :class="[ item?.checked ? 'active':''  , selectCode == 'Moodboard' ? 'moodb':''  ]" >
						<img :src="item.imgUrl" @click.stop="selectImgItem(item)">
						<div v-if="selectCode == 'Sketchboard'" class="operate_file_block">
                            <div class="select_img_type">
                                <div
                                    class="select_category"
                                    @click.stop="showFileCategory(item)"
                                >
                                    {{ getSketchLabel(item.category) }}
                                    <div
                                        :class="[
                                            'icon',
                                            'iconfont',
                                            'icon-xiala',
                                            item.categoryShow
                                                ? 'icon_rotate'
                                                : '',
                                        ]"
                                    ></div>
                                </div>
                                <div
                                    class="category_list"
                                    v-show="item.categoryShow"
                                >
                                    <div
                                        :class="[
                                            'category_item',
                                            item.category == cate.value
                                                ? 'select_category_item'
                                                : '',
                                        ]"
                                        v-for="(
                                            cate, index
                                        ) in disignTypeList"
                                        :key="index"
                                        @click.stop="selectFileCategory(item, cate)"
                                    >
                                        {{ cate.label }}
                                    </div>
                                </div>
                            </div>
                        </div>
						<div v-if="selectCode == 'Sketchboard' || selectCode == 'Printboard'" class="pin_block">
							<a-checkbox v-model:checked="item.pin">PIN</a-checkbox>
						</div>
					</div>

                </div>
                <div class="no_data_block loading_block" v-show="isShowLoading">
                    <a-spin size="large"></a-spin>
                </div>
             
            </div>
        <!-- </a-modal> -->
    </div>
    
</template>
<script lang="ts">
import { defineComponent, ref} from 'vue'
import { Https } from "@/tool/https";
import { message } from 'ant-design-vue';
import { useStore } from "vuex";
import GO from '@/tool/GO';

export default defineComponent({
    props: ["msg"],
    setup(prop) {
        let myMaterialModalShow = ref(false)
        let imgList = ref([
		{
                imgUrl: "https://illlustrations.co/static/32913fde3ee589609d98f16c51fcffa6/ee604/day8-printer.png",
                id_: 1,
            },
            {
                imgUrl: "https://illlustrations.co/static/3edf742257c1d1460eb2e2f998a1df96/ee604/day4-polariod.png",
                id_: 2,
            },
            {
                imgUrl: "https://illlustrations.co/static/475732e63175f7dc3bf93c84af8b3d11/ee604/day6-open-vault.png",
                id_: 3,
            },
            {
                imgUrl: "https://illlustrations.co/static/ca430674ef56f1a3a91f705670fd8512/ee604/day17-walkie-talkie.png",
                id_: 4,
            },
		])
		let store = useStore()
        let isShowLoading:any = ref(false)
        let selectCode:any = ref('')
        let currentPage:any = ref(1)
        let searchPictureName = ref('')
        let pageSize = ref(20)
        let total = ref(0)
        let searcMaterialhName:any = ref('') //搜索名字
        let designType:any = ref(null)
        let disignTypeList = [
                {
                    value: "Outwear",
                    label: "Outwear",
                },
                {
                    value: "Blouse",
                    label: "Blouse",
                },
                {
                    value: "Dress",
                    label: "Dress",
                },
                {
                    value: "Trousers",
                    label: "Trousers",
                },
                {
                    value: "Skirt",
                    label: "Skirt",
                },
            ]
        return{
            myMaterialModalShow,
            imgList,
			store,
            isShowLoading,
            selectCode,
            currentPage,
            searchPictureName,
            pageSize,
            total,
            searcMaterialhName,
            designType,
            disignTypeList,
        }
    },
	data (prop) {
		return {
			type_ : {
				type1:'material',
				type2:prop.msg
			}
		}
	},
	computed: {
        getSketchLabel(value:any) {
            return (value: any) => {
                let lable = "";
                for (let item of this.disignTypeList) {
                    if (item.value === value) {
                        lable = item.label;
                        break;
                    }
                }
                return lable;
            };
        },
		
    },
    methods:{

        init(code:any){
            this.selectCode = code
            // this.myMaterialModalShow = true
			if(this.imgList.length == 0){
				this.getLibraryList()
			}
        },
        
        selectImgItem(imgData:any){
            // this.selectImgListIds =  this.selectImgList.map((v:any)=>v.id)
            // if(this.selectImgListIds.indexOf(imgData.id) === -1){
            //     this.selectImgList.push(imgData)
            //     this.selectImgListIds.push(imgData.id)
            // }else{
            //     let index = this.selectImgListIds.indexOf(imgData.id)
            //     this.selectImgList.splice(index,1)
            //     this.selectImgListIds.splice(index,1)
            // }
			imgData.type_ = this.type_

			imgData.resData = JSON.parse(JSON.stringify(imgData))
			this.store.commit("addGenerateMaterialFils", imgData);
        },

        //改变页码
        changePage(current: number, pageSize: number){
            this.currentPage = current
            this.pageSize = pageSize
            this.getLibraryList()
        },

        handleChange(){
            this.getLibraryList()
        },

        //选择所有的图片
       

        getLibraryList(){
            let data = {
                level1Type:this.selectCode,
                // level2Type:this.designType,
                page:this.currentPage,
                pictureName:this.searchPictureName,
                size:this.pageSize,
            }
            this.isShowLoading = true
            Https.axiosPost(Https.httpUrls.queryLibraryPage,data).then(
                (rv: any) => {
					let aa:any = []
					this.imgList = rv.content					
					rv.content.forEach((item:any) => {
						if(this.type_.type2 == 'Sketchboard'){
							item.category = "Outwear";
							item.categoryShow = false;
						}
						if(!item.id_){
							item.id_ = GO.id++
							aa.push(item)
						}else{
							aa.push(item)
						}
					});
					this.imgList = aa
                    this.total = rv.total
                    this.isShowLoading = false
                }
            ).catch((res)=>{
                this.isShowLoading = false
            });
        },

       
        closeModal(){
            this.myMaterialModalShow = false
            this.searchPictureName = ''
            this.designType = null
            this.imgList = []
            this.currentPage = 1
            this.pageSize = 10
            this.total = 0
        },
		showFileCategory(file: any) {
            file.categoryShow = true;
            document.addEventListener("click", this.hiddenFileCategory);
        },
		 selectFileCategory(file: any, cate: any) {
            file.category = cate.value;
			 for (let item of (this.imgList as any)) {
                item.categoryShow = false;
            }
        },
		hiddenFileCategory() {
            for (let item of (this.imgList as any)) {
                item.categoryShow = false;
            }
            document.removeEventListener("click", this.hiddenFileCategory);
        },
    }
})
</script>
<style lang="less">
.my_material_modal{
	height: 30rem;
    overflow-x: hidden;
	border-right: 1px solid #e5e5e5;
	flex: 1;
	border-radius: 0;
	&.my_material_modal::-webkit-scrollbar{display: none;}
    .ant-modal-close{
        width: 3.6rem;
        height: 3.6rem;
        position: absolute;
        top: -1.8rem;
        right: -1.8rem;
    }

    .ant-modal-header{
        display: none;
    }

    .ant-modal-body{
        background: #F2F3FB;
        height: 80vh;
        min-height: 72rem;
        overflow-y: hidden;
        padding: 0;
    }

    .my_material_header{
		display: flex;
		justify-content: flex-end;
        align-items: center;
        width: 100%;
		height: auto;
		padding: 0;
		padding-top: 2.5rem;
		padding-bottom: 2rem;
		background-color: #fff;
		position: sticky;
		top: 0;
		z-index: 2;
        .my_material_header_right{
            display: flex;
            justify-content: space-between;
            align-items: center;

            .content_search_block{
                margin-right: 5rem;
                display: flex;

                .search_input{
                    width: 15rem;
                    padding-left: 1.5rem;
                    // height: 4rem;
                    // line-height: 3.8rem;
                    // background: #FFFFFF;
                    border: 0.1rem solid #F1F1F1;
                    // font-size: 1.6rem;
					font-size: 1.2rem;
                    font-weight: 400;
					height: 3rem;

                    &::placeholder {
                        color: #C2C2C2;
                    }
                }

                .search_icon_block{
                    width: 5rem;
                    height: 3rem;
                    line-height: 3rem;
                    text-align: center;
                    background: #343579;
                    cursor: pointer;

                    .icon-sousuo{
                        font-size: 2rem;
                        color: #FFFFFF;
                    }
                }
            }

            .icon_close{
                color: rgba(174, 178, 183, 1);
                font-size: 2.4rem;
                cursor: pointer;
            }
        }

        
    }

    .my_material_content{
        // padding: 0 3rem 3.5rem 3rem;
		padding: 0;
        // height: calc(100% - 6.6rem);
		height: auto;
        position: relative;

        .material_content_top{
            padding: 1.3rem 0 2.1rem;
            height: 7rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-sizing: border-box;

            .material_content_top_title{
                font-size: 20px;
                color: #030303;
            }

            .material_content_top_right{
                display: flex;
                align-items: center;

                .select_block{
                    background: #FFFFFF;
                    color: #1A1A1A !important;
                    margin-right: 2.3rem;

                    .icon-xiala{
                        color: #1A1A1A !important;
                    }
                }

                .check_all_block{
                    display: flex;
                    align-items: center;
                    font-size: 1.6rem;
                    color: #64686D;
                    cursor: pointer;

                    &.check_all{
                        color: #1A1A1A;
                    }

                    .check_block{
                        width: 2.4rem;
                        height: 2.4rem;
                        background: #EBECF4;
                        border: 0.1rem solid #64686D;
                        padding: 0.3rem;
                        margin-right: 0.7rem;

                        .check_block_body{
                            width: 100%;
                            height: 100%;
                            background: #343579;
                        }
                    }
                }
            }

        }

        .material_content_body{
            width: 100%;
            // height: calc(100% - 19rem);
			height: 100%;
            overflow-y: auto;
            position: relative;
			&.generate::-webkit-scrollbar{display: none;}

            .content_img_item{
				margin: 0 2rem 5rem 0;
				display: inline-block;
				width: 10rem;
				height: 10rem;
				border: 1px solid #f5f5f5;
				position: relative;
				cursor: pointer;
				padding: 0;
				img{
					object-fit: cover;
					width: 100%;
					height: 100%;
				}
				&.moodb{
					margin: 0 2rem 2rem 0;
				}
				&.active{
					opacity: 0.5;
				// border: 2px solid;
					border-radius: 1rem;
					transform: scale(0.9);
					img {
					}
					.pin_block{
						pointer-events:none;
					}
					.operate_file_block{
						pointer-events:none;
					}
				}
                .content_img_name{
                    width: 16.5rem;
                    height: 3.5rem;
                    line-height: 3.5rem;
                    white-space: nowrap;
                    text-align: center;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    font-size: 1.4rem;
                    color: #030303;
                }
            }

            
        }

        .no_data_block{
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 99;

            &.loading_block{
                background: rgba(0,0,0,0.2);
            }
        }

        .material_confirm{
            width: 9.8rem;
            height: 3.6rem;
            line-height: 3.6rem;
            font-size: 1.4rem;
            text-align: center;
            margin: 0 auto;
            color: #FFFFFF;
            background: #343579;
            cursor: pointer;
            margin-top: 2rem;
        }

        .table_pagination{
            position: absolute;
            bottom: 3.5rem;
            left: 0;
            width: 100%;
            text-align: center;
            margin-top: 5rem;
        }
    }
}
</style>
