<template>
	<!-- 规格管理 -->
	<view class="specspage">
		
		<!-- 规格列表 -->
		<view class="specslist">
			<view class="specsItemdata flex ali-c jus-b" v-for="(item,index) in specsList" :key="index">
				<view class="flex1">
					<view class="specsname" v-if="TypeList[item.type_id]">{{TypeList[item.type_id].name}}  {{item.name}}</view>
					<view class="specsname" v-else>  {{item.name}}</view>
					<view class="spectag twoline">{{item.spec_item}}</view>
				</view>
				<view class="issysbtns">
					<view class="btns" @tap="getedti(item)">修改</view>
				</view>
			</view>
		</view>
		
		<view class="addspecs">
			<navigator url="../specsadd/specsadd" class="submitbtn active">添加规格</navigator>
		</view>
		
	</view>
</template>

<script>
	import {specitemList,specTypeList} from  "@/utils/api/api.js";
	export default {
		data() {
			return {
				specsList:[],
				TypeList:[],//关联分类
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.getspecitemList();
			
			this.getspecTypeList();//分类模型
		},
		methods:{
			//获取规格列表
			async getspecitemList(){
				let res = await specitemList({
				});
				if(res.code==0){
					this.specsList = res.data;
				}else{
					this.$api.msg(res.msg);
				}
			},
			async getspecTypeList(){
				let res = await specTypeList({
					
				});
				if(res.code==0){
					let TypeList = res.data;
					let twoobj ={};
					TypeList = TypeList.map((item,index)=>{
						let id = "name";
						id = item.id;
						twoobj[id] = item;
						return {[id]:{...item}};
					})
					this.TypeList = twoobj;
				}else{
					this.$api.msg(res.msg);
				}
			},
			getedti(data){
				uni.setStorageSync("editspecs",data);
				uni.navigateTo({
					url:`/pages/specsadd/specsadd?actiontype=2&id=${data.id}`,
				})
			}
		}
	}
</script>

<style lang="scss">
	@import  "./specs.scss";
</style>
