<template>
	<view class="page">
		<customHead mode='searchNav' :title='headtitle'></customHead>
		<view class="coupon-tab">
			<view class="list" :class="{'action':TabShow===index}" v-for="(item,index) in TypeData"
				@click="onCouponTab(index,item)">
				<text>{{item.name}}</text>
				<text class="line"></text>
			</view>

		</view>
		<view class="goods-list">
			<view class="list">
				<view class="cart-box"  v-for="item in ComData">
					<view class="cart-box-top">
						<view class="cart-box-img">
							<image :src="item.image[0]==null?'../../static/img/head.jpg':(BASE_URL+item.image[0].url)"></image>
						</view>
						<view class="cart-box-text">
							<view class="one-omit my-qymc">{{item.name}}</view>
							<view><text class="my-one-omit">{{item.synopsis}}</text></view>
						</view>
						<view>
							<view class="cart-box-btn" @click="freeTell(item.phone)">
								<image src="../../static/kefu.png"></image>联系客服
							</view>
						</view>
					</view>
					<view class="cart-box-list" v-for="Info in item.goods" @click="OrderDetails(Info.id,item.phone)">
						<view class="cart-box-img">
							<image :src="Info.cover[0]==null?'../../static/img/head.jpg':(BASE_URL+Info.cover[0].url)"></image>
						</view>
						<view class="cart-box-text">
							<view class="one-omit my-qymc">{{Info.name}}</view>
						</view>
						<view>
							<view class="cart-box-btn">￥{{Info.price}}</view>
						</view>
					</view>

				</view>

			</view>
		</view>
		<!-- tabbar -->
		<!-- tabbar -->
		<TabBar :tabBarShow="2"></TabBar>
	</view>
</template>

<script>
		import BASE_URL from '@/common/config.js'
	import TabBar from '../../components/TabBar/TabBar.vue';
	// 引入mescroll-mixins.js
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import customHead from "@/components/xy-customhead/xy-customhead.vue";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			TabBar,
			customHead,
		},
		data() {
			return {
				BASE_URL,
				headtitle: '铭钛招聘',
				TabShow: 0,
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					use: false,
					toTop: {
						src: '',
					}
				},
				isEdit: false,
				query: {
					currentPage: 1,
					pageSize: 10
				},
				comQuery: {
					type: "",
					currentPage: 1,
					pageSize: 10
				},
				TypeData: [],
				ComData: [],
			};
		},
		onReady() {
			uni.hideTabBar()
		},
		onLoad(e) {
			this.Gettbgoodstype();
		},
		methods: {
			freeTell(phone) {
				wx.makePhoneCall({
					phoneNumber: phone, //仅为示例，并非真实的电话号码
					success: function() {
						console.log("拨打电话成功！")
					},
					fail: function() {
						console.log("拨打电话失败！")
					}
				})
			},
			Gettbgoodstype() {
				this.API.Gettbgoodstype(this.query).then(res => {
					this.TypeData = res.data.list;
					this.comQuery.type = this.TypeData[0].id;
					this.GettGetListCom();
				});
			},
			GettGetListCom() {
				this.API.GettGetListCom(this.comQuery).then(res => {
					this.ComData = res.data;
					console.log(this.ComData)
				});
			},

			onCouponTab(index, item) {
				this.TabShow = index;
				this.comQuery.type = item.id;
				this.GettGetListCom();
			},
			/*下拉刷新的回调, 有三种处理方式:*/
			downCallback() {
				this.mescroll.endSuccess();
			},
			/*上拉加载的回调*/
			upCallback(page) {
				setTimeout(() => {
					this.mescroll.endByPage(10, 20);
				}, 2000)
			},
			OrderDetails(id,phone) {
				uni.navigateTo({
					url: '/pages/OrderDetails/OrderDetails?id='+id+'&phone='+phone,
				})
			},
			/**
			 * 跳转点击
			 * @param {String} type 跳转类型
			 */
			onSkip(type) {
				switch (type) {
					case 'classify':
						uni.navigateTo({
							url: '/pages/SearchGoodsList/SearchGoodsList',
						})
						break;
					case 'goods':
						uni.navigateTo({
							url: '/pages/GoodsDetails/GoodsDetails',
							animationType: 'zoom-fade-out',
							animationDuration: 200
						})
						break;
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'cart.scss';
</style>
