<template>
	<view class="flex-row relative page">
	  <view class="flex-row justify-between items-center section_2 pos_9">
	    <text class="text">商品</text>
	    <view class="flex-row items-center section_3">
	      <image
	        class="image"
	        src="https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=28ba6eb522ea75763e30176e00a6dc3a.png"
	      />
	      <text class="font text_2 ml-30">“梅花簪子”</text>
	    </view>
	  </view>
	  <image
	    class="image_2 pos_1"
	    src="https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=b76714d3da7f86025735dfadff342eb6.png"
	  />
	  <view class="flex-col section_4 pos_8">
	    <view class="flex-col items-center self-stretch relative group" v-for="(item, index) in items" :key="index">
	      <image
	        class="image_3"
	        src="https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=46b84eacccfe4ba701e720a92c26f90d.png"
	      />
	      <view class="section_5 pos"></view>
	      <text class="relative font text_5">发簪</text>
	    </view>
	  </view>
	  <view class="flex-row section_6 pos_2">
	    <text class="font_2 text_3">发</text>
	    <text class="font_2 ml-12">簪</text>
	  </view>
	  <view class="flex-col pos_6">
	    <view class="flex-row list-item mt-9" v-for="(item, index) in items_1" :key="index">
	      <image
	        class="self-center image_4"
	        src="https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=c7ccccbe00e8f4c6f0fb90cc641168c7.png"
	      />
	      <view class="flex-col items-start self-center group_6">
	        <text class="font text_14">琉璃发体验包</text>
	        <text class="font_3 mt-10">非遗材料包，匠心独运</text>
	        <text class="font_4 text_6 mt-10">￥750</text>
	      </view>
	      <image
	        class="self-start image_5"
	        src="https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=e20444f9a975445c969b636750776aa5.png"
	      />
	    </view>
	  </view>
	</view>
</template>

<script setup>
import { ref,onMounted, toRaw } from 'vue';
import { baseUrl, testUrl , suiUrl} from '@/api/request';
const currentColor = ref(0);
const sort =ref([{}]) //商品类别对象数组
const headerList = ref([{}]) //类别标题和介绍
const productList = ref([{}]) //类别下对应的商品
const cookie = wx.getStorageSync("cookie")
const product_type = [{
	type: "材料包",
	detail: "提供材料自行DIY"
}]
const items = [null,null,null,null]
const items_1 = [null,null,null]
onMounted( async () => {
	console.log('cookie--->',cookie);
  await Getsort() //获取商品类别
  await changeTypes( sort.value[0] , 0 ) //首先获取最开始的类别
})
//获取商品分类
const Getsort = async ()=>{
	const res = await uni.request({
		url: baseUrl + '/category/list',
		method:'POST',
		header: {
			cookie,
		}
	})
	if(res.data.code === 1){
		for(let key in res.data.data) {
			sort.value[key] = {//类别列表
				name : res.data.data[key].typeName,
				imgurl : res.data.data[key].typeUrl,
				id : res.data.data[key].id
			}//标题列表
			headerList.value[key] = {
				name : res.data.data[key].typeName,
				typeIntro : res.data.data[key].typeIntro
			}
		}
	} else {
		uni.showToast({ //提示请求错误
			title: '请求商品分类错误',
			icon: 'none',
			duration: 2000
		})
	}
	console.log('获取商品分类==>',res.data);
}
//更改类别
const changeTypes = async (item , index) =>{
	currentColor.value = index  
	const res = await uni.request({
		url: baseUrl + '/category/list/type',
		method: 'POST',
		data: {
			id : item.id
		},
		header:{
			cookie,
		}
	})
	if(res.data.code === 1) {
		productList.value = res.data.data[item.id]
	} else {
		uni.showToast({ //商品请求错误
			title: '更改类别错误',
			icon: 'none',
			duration: 2000
		})
	}
}
//更改box颜色
const getBoxStyle = (index) => ({
    backgroundColor: currentColor.value === index ? 'brown' : '#fffef8'  
});


const goToProduct = (item) => {
	uni.navigateTo({
		url: '../../../pages/store-home/ProductDetails/ProductDetails?info=' + JSON.stringify(item)
	})
}
</script>

<style lang="scss" scoped>
.mt-9 {
  margin-top: 16.88rpx;
}
.page {
  background-color: #ffffff;
  background-image: url('https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=31fcc3e3780867994362dce95afbe89a.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}
.section_2 {
  padding: 30rpx 45.41rpx 33.75rpx;
  background-color: #ebe7e4;
}
.pos_9 {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}
.text {
  color: #000000;
  font-size: 45rpx;
  font-family: FZSongKeBenXiuKaiS-R-GB;
  line-height: 41.66rpx;
}
.section_3 {
  margin-right: 38.96rpx;
  padding: 5.49rpx 12.99rpx 5.76rpx;
  background-color: #f2eeeb;
  border-radius: 28.13rpx;
  width: 468.75rpx;
  height: 90rpx;
  border: solid 1.88rpx #fffef8;
}
.image {
  width: 95.63rpx;
  height: 75rpx;
}
.font {
  font-size: 28.13rpx;
  font-family: FZSongKeBenXiuKaiS-R-GB;
  line-height: 27.24rpx;
  color: #000000;
}
.text_2 {
  color: #bf654f;
  letter-spacing: 11.25rpx;
}
.image_2 {
  width: 100vw;
  height: 55vw;
}
.pos_1 {
  position: absolute;
  left: 0;
  right: 0;
  top: 153.75rpx;
}
.section_4 {
  padding: 3.75rpx 0 62.01rpx;
  background-color: #f0ece8;
  width: 182.01rpx;
}
.pos_8 {
  position: absolute;
  left: 0;
  top: 570rpx;
}
.group {
  padding-top: 22.5rpx;
}
.image_3 {
  width: 101.25rpx;
  height: 105rpx;
}
.section_5 {
  background-color: #fa7e8233;
  border-radius: 9.38rpx;
  width: 180rpx;
  height: 133.13rpx;
}
.pos {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}
.text_5 {
  margin-top: 15.64rpx;
}
.section_6 {
  padding: 33.39rpx 0 20.16rpx;
  background-image: url('https://ide.code.fun/api/image?token=675e8b75797f850011f292da&name=7c35c1d42a85635085a71398166d6c05.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  width: 245.63rpx;
}
.pos_2 {
  position: absolute;
  left: 178.13rpx;
  top: 575.63rpx;
}
.font_2 {
  font-size: 33.75rpx;
  font-family: FZSongKeBenXiuKaiS-R-GB;
  line-height: 30.06rpx;
  color: #c35c5d;
}
.text_3 {
  margin-left: 74.57rpx;
}
.pos_6 {
  position: absolute;
  right: 10.99rpx;
  top: 671.25rpx;
}
.list-item {
  padding: 17.53rpx 14.19rpx 18.23rpx;
  background-color: #ffffff;
  border-radius: 9.38rpx;
}
.list-item:first-child {
  margin-top: 0;
}
.image_4 {
  border-radius: 9.38rpx;
  width: 123.75rpx;
  height: 112.5rpx;
}
.group_6 {
  margin-left: 22.84rpx;
}
.text_14 {
  font-size: 30rpx;
  line-height: 28.95rpx;
}
.font_3 {
  font-size: 22.5rpx;
  font-family: FZSongKeBenXiuKaiS-R-GB;
  line-height: 21.88rpx;
  color: #727272;
}
.font_4 {
  font-size: 28.13rpx;
  font-family: STFangsong;
  line-height: 18rpx;
  color: #ff0000;
}
.text_6 {
  font-size: 26.25rpx;
  -webkit-text-stroke: 1.88rpx #ff000040;
}
.image_5 {
  margin: 63.77rpx 6.02rpx 0 90.64rpx;
  border-radius: 9.38rpx;
  width: 52.5rpx;
  height: 48.75rpx;
}
@import url(../../../common/css/global.css);
</style>
