<template>
	<view class="">
		<navigation :showBack="false">
			Search
		</navigation>
      <view class="sea_con">
      		<u-form-item  :border-bottom="false" class="sea_item">
				<image  src="../../../static/home/icon_search@3x.png" mode="aspectFit" class="img" ></image>
				<u-input v-model="name" :placeholder="'Search'"  :border="false" :height="80" class="item_input" @input="search()"/></u-form-item>
      </view>

	<view class="goods_list_con">
		<view class="good_item" v-for="item,index in goods_list" :key="item.index" @click="goGoodsDetail(item.id)">
			<image :src="$constant.APP+item.goodsImgThumbUrl" mode="aspectFit"></image>
			<view class="text">
				{{item.goodsName}}
			</view>
			<view class="price">
				{{currencySymbol}} {{item.goodsPrice}}
			</view>
		</view>
	</view>


	
	
	</view>
</template>

<script>
	import api from '@/utils/api'
	import utils from '@/utils'
	import md5 from 'js-md5'
	import store from '@/store'
	export default {
		data() {
			return {
			name:"",
			goods_list:[],
			currencySymbol:'',
			}
		},

		onLoad() {
		  this.goodList();
			this.openGame()
			this.currencySymbol=uni.getStorageSync('siteInfo').currencySymbol;
   
		},
		
			onReady() {
			
			},
		methods: {
			goodList(){
				const post2 = api.goodsList({})
				.then(res =>{
					this.goods_list=res.data;
				   for(var i=0;i<this.goods_list.length;i++){
					this.goods_list[i].goodsPrice=parseFloat(this.goods_list[i].goodsPrice).toFixed(2)
				   }
				}).catch(err =>{
					console.log(err)
				}) 
			},
			openGame() {
				const post = api.info()
				post.then(d => {
						// uni.setStorage({
						// 	key: 'Gamestatus',
						// 	data: d.data.gameMenuStatus,
						// });
					
						if (d.data.gameMenuStatus == 'close') {
							uni.setTabBarItem({
								index: 2,
								text: 'Order',
								pagePath:'/pages/menu/order/index',
								iconPath: '/static/tabbar/dorder.png',
								selectedIconPath: '/static/tabbar/dorderS.png'
							})
						}else if (d.data.gameMenuStatus == 'open'){
							uni.setTabBarItem({
								index: 2,
								text: 'Game',
								pagePath: "/pages/menu/color/index",
								iconPath: "/static/tabbar/meun_icon_game_nor@2x.png",
								selectedIconPath: "/static/tabbar/meun_icon_game_sel@2x.png"
							})
						}
					})
					.catch((e) => {
						console.log(e)
					})
			},
	
			goGoodsDetail(i){
				uni.navigateTo({
					url:'../goods/goodsDetail/index?id='+i
				})
			},
		   search(){
				   const post = api.goodsList({
				   	"name": this.name,
				   })
				   post.then(res => {
				   	var that = this;
				  
				   	this.goods_list=res.data;
					for(var i=0;i<this.goods_list.length;i++){
					this.goods_list[i].goodsPrice=parseFloat(this.goods_list[i].goodsPrice).toFixed(2)
					    }
				   	
				   	})
				   	.catch(e => {
				   	uni.showToast({
				   		title: e,
				   		icon: 'none',
				   		duration: 2500
				   	})
				   	})
			   if(this.name==''){
				   this.goodList();
			   }
		   }
			},
	
		}
	
</script>

<style>
	@import './index.css';
</style>
