<template>
	<view class="navTab">
		<!-- <img class="logobg" src="http://image.bjkeyware.com/static/banner/tools_banner.png" alt="" /> -->
		<u-tabs-swiper ref="tabs" name="dictLabel" :list="tooltypelist1" :is-scroll="true" @change="tabsChange"
			:current="current" bg-color='transparent' active-color="#1578ED" inactive-color='#666666'>
		</u-tabs-swiper>
		<view>
			<view class="recommend">
				<!-- :class="item.toolTypeName.indexOf('单元')>-1 || item.toolTypeName.indexOf('接口')>-1 || item.toolTypeName.indexOf('安全')>-1?'imgsone':'imgone' " -->
				<view class="currekei" v-for="(item,key) of currenttoolist" :key="key">
					<view class="imgone" @click="details('tool',item.toolId)">
						<view style="width: 120rpx;height: 120rpx;">
							<img :src="item.img" alt="">
							<!-- <img v-if="item.name=='代码静态分析工具'" :src="item.imgs"  alt="">
							<img v-if="item.name=='源代码安全检测工具'" :src="item.imgs" style="width:158rpx"  alt="">
							<img v-if="item.name=='C/C++单元测试工具'" :src="item.imgs" style="width:150rpx"  alt="">
							<img v-if="item.name=='接口测试工具'" :src="item.imgs" style="width:140rpx" alt="">
							<img v-if="item.name=='JAVA单元测试工具'" :src="item.imgs" style="width:152rpx" alt="">
							<img v-if="item.name=='功能测试工具AutoFun'" :src="item.imgs" style="width:145rpx" alt="">
							<img v-if="item.name=='代码组成分析平台'" :src="item.imgs" style="width:145rpx"  alt="">
							<img v-if="item.name=='性能测试工具'" :src="item.imgs"  alt="">
							<img v-if="item.name=='自鉴-交互式应用安全测试系统IAST'" :src="item.imgs" style="width:145rpx" alt="">
							<img v-if="item.name=='Web应用安全测试工具'" :src="item.imgs" style="width:155rpx" alt="">
							<img v-if="item.name=='资产识别及漏洞管理工具'" :src="item.imgs" style="width:200rpx" alt="">
							<img v-if="item.name=='性能测试工具AutoLoad'" :src="item.imgs"  alt="">
							<img v-if="item.name=='性能测试工具KeyTurbo'" src="http://image.bjkeyware.com/static/index/xn.png"  alt=""> -->
						</view>

						<!-- <img  :src=" base + '/profile/upload/2024/04/23/dec9c149-5406-4c52-ac8a-ac624661643f.png'"  alt=""> -->
					</view>
					<text class="leop">{{item.name}}</text>
					<view style='display:flex;margin:30rpx 0'>
						<view v-if='item.toolTypeName' class="tabone">{{item.toolTypeName}}</view>
						<view class="tabone" style="color: #FF8A00;border: 1px solid #FF8A00;margin-left: 10px;">
							{{item.deliverType}}</view>
					</view>
					<view style='display:flex;justify-content:space-between;margin:15rpx 0;width:100%'>
						<!-- <p>¥ {{item.price}}</p> -->
						<p style="font-size: 24rpx;" v-if="item.price == 0">限时免费</p>
						<p style="font-size: 34rpx;" v-else>¥ {{item.price}}</p>
						<!-- <img class="imgtwo" src="http://image.bjkeyware.com/static/index/add.png" alt="" @click="addcart(item.toolId)"> -->
					</view>
				</view>

			</view>
		</view>

		<!-- 	<view v-if="currenttoolist.length==0 &&current!=0" style="font-size:46rpx;
			font-weight: bold;
			color: #9D9D9D; text-align:center;margin-top:100px">暂无工具</view> -->
		<view style="height:10px;"></view>
		<u-toast ref="uToast" />
		<u-modal title='温馨提示' v-model="tokenshow" content="您还没有登录" confirm-text='现在就去' cancel-text='稍等一下'
			show-cancel-button='true' cancel-color='#1578ED' confirm-color='#1578ED' @confirm="confirm"
			@cancel='tokenshow=false'></u-modal>
	</view>
</template>

<script>
	import tool from '@/utils/mixin/tootype.js'
	export default {
		mixins: [tool],
		data() {
			return {
				tokenshow: false,
				current: '0',
				// toolslist: [{name: '全部'}, {name: '静态测试'}, {name: '单元测试'}, {name: '功能测试'}, {name: '性能测试'}],
				toolslist: [{
					name: '静态测试'
				}, {
					name: '单元测试'
				}, {
					name: '功能测试'
				}, {
					name: '性能测试'
				}, {
					name: '静态测试'
				}, {
					name: '单元测试'
				}, {
					name: '功能测试'
				}, {
					name: '性能测试'
				}],
				toollist: [],
				currenttoolist: [],
				base: this.http.baseUrl
			}
		},
		computed: {
			tooltypelist1() {
				return [{
					dictLabel: '全部'
				}, ...this.tooltypelist]
			}
		},
		filters: {
			tiilnamechange(value) {
				if (!value) return ''
				if (value.length > 9) {
					return value.slice(0, 7) + '...'
				}
				return value
			}
		},
		onLoad() {
			this.http.quickGet('/business/tool/listAnon?status=1').then(res => {
				// console.log('---',res.data.rows)
				this.toollist = res.data.rows;
				// this.toollist.forEach(item=>{
				// 	if(item.name=='代码静态分析工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/11.png'
				// 	}else if(item.name=='源代码安全检测工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/5.png'
				// 	}else if(item.name=='C/C++单元测试工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/2.png'
				// 	}else if(item.name=='接口测试工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/12.png'
				// 	}else if(item.name=='JAVA单元测试工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/tool/1.png'
				// 	}else if(item.name=='功能测试工具AutoFun'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/3.png'
				// 	}else if(item.name=='代码组成分析平台'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/tool/4.png'
				// 	}else if(item.name=='性能测试工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/6.png'
				// 	}else if(item.name=='自鉴-交互式应用安全测试系统IAST'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/tool/3.png'
				// 	}else if(item.name=='Web应用安全测试工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/tool/2.png'
				// 	}else if(item.name=='资产识别及漏洞管理工具'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/zc.png'
				// 	}else if(item.name=='性能测试工具AutoLoad'){
				// 		item.imgs='http://image.bjkeyware.com/static/index/xn.png'
				// 	}else{
				// 		item.imgs='http://image.bjkeyware.com/static/index/xn.png'
				// 	}
				// 	item.typel=item.toolTypeName.slice(0,2)
				// })
				this.currenttoolist = this.toollist
				// this.toollist=res.data.rows.splice(0,6)toolType
				// console.log('---',this.toollist)
			})
		},
		methods: {
			confirm() {
				uni.navigateTo({
					url: '/pages/personal/login'
				})
			},
			tabsChange(index, i) {
				if (index == 0) {
					this.currenttoolist = this.toollist
				} else {
					const name = this.tooltypelist1[index].dictLabel
					this.currenttoolist = this.toollist.filter(item => item.toolTypeName == name);
				}

				this.current = index
			},
			details(type, id) {
				if (type == 'tool') {
					// uni.showToast({ title: '该功能开发中', icon: 'none', duration: 1000 });
					uni.navigateTo({
						url: `./tooldetails?id=${id}`
					})
				} else {
					uni.navigateTo({
						url: './crowdsourcingdetails'
					})
				}
			},
			// 加入购物车
			addcart(id) {
				uni.showToast({
					title: '该功能开发中',
					icon: 'none',
					duration: 1000
				});
				return;
				let accessToken = uni.getStorageSync('accessToken');
				if (!accessToken) {
					this.tokenshow = true
				} else {
					// 
					this.http.quickGet(`/my/addShoppingCart/${id}/1`, true).then(response => {
						console.log('response', response)
						if (response.data.code == 200) {
							console.log('111')
							this.$refs.uToast.show({
								title: '添加购物车成功',
								type: 'success',
								duration: 1000,
								isTab: true,
								url: '/pages/shoppingtrolley/shoppingtrolley'
							})
						}
					})
				}
			}

		}
	}
</script>

<style>
	.navTab {
		padding: 0 13px 13px 13px;
	}

	.logobg {
		width: 100%;
		height: 32vw;
		margin-bottom: 5px;
	}

	.recommend {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		margin-top: 10px;
	}

	.currekei {
		width: 48%;
		/* height: 360rpx; */
		background: #FFFFFF;
		border-radius: 10px;
		padding: 10px;
		margin-bottom: 20rpx
	}

	.leop {
		width: 100%;
		font-size: 30rpx;
		/* height:40px ; */
		font-weight: bold;
		color: #1A1A1A;
		/* margin: 13rpx 0; */
		display: flex;
		align-items: center;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		/*! autoprefixer: off */
		-webkit-box-orient: vertical;
	}

	.tabone {
		padding: 2rpx 5rpx;
		border: 1px solid #2B80FC;
		border-radius: 4rpx;
		font-size: 20rpx;
		font-weight: 500;
		color: #2387EE;
		text-align: center;
		box-sizing: border-box;
	}

	.currekei :nth-child(4) {
		color: #FD461A;
		font-weight: 800;
		font-size: 34rpx;
	}

	.imgone {
		width: 180rpx;
		margin: 10px auto;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.imgone img {
		width: 100%;
		height: 100%;
	}

	.imgsone {
		width: 150rpx;
		margin: 20px auto;
	}

	.imgsone img {
		width: 150rpx;
		height: 123rpx;
	}

	.imgtwo {
		width: 32rpx;
		height: 32rpx;
	}
</style>