<template>
	<view class="index">
		<view class="title_text">
			创建分类
		</view>
		<view class="onecontent">
			<view class="onecontent_item flex-between">
				<view class="onecontent_itemleft">
					项目分类
				</view>
				<view class="onecontent_itemright flex-start">
					<input class="onecontent_itemright_text" v-model="name" maxlength="8" type="text"
						placeholder="请输入项目分类">
				</view>
			</view>
		</view>
		<view class="thereconse thereconses" @click="servicecreateitemclass">
			确定
		</view>
		<view class="title_text">
			管理分类
		</view>
		<view class="onecontent">
			<view class="onecontent_item flex-between" v-for="(item,index) in list" :key="index"
				@click="contentfixedclick(item)">
				<view class="onecontent_itemleft">
					{{item.name}}
				</view>
				<u-icon name="arrow-right" color="#333" size="20"></u-icon>
			</view>
		</view>
		<view v-if="list.length==0 && is_end == true" style="margin-top: 100rpx;width: 100%;" class="flex-colum">
			<image src="https://ointmentweapp.oss-cn-beijing.aliyuncs.com/image/my/order/nothave.png" mode="">
			</image>
		</view>
		<u-loadmore :status="form.status" />
	</view>
</template>
<script>
	export default {
		data() {
			return {
				name: '',
				list: [],
				is_end: false,
				form: {
					page: 1,
					status: 'loadmore',
				},
			}
		},
		onShow() {
			this.init_fn()
		},
		methods: {
			init_fn() {
				this.list = []
				this.is_end = false
				this.form.page = 1
				this.form.status = 'loadmore'
				this.shoppinggooodstype()
			},
			async shoppinggooodstype() {
				let res = await this.api.serviceitemclass({
					page:1
				});
				if (res.code == 1) {
					if (res.data.length == 0) {
						this.is_end = true
						this.form.status = 'nomore'
						return false;
					} else {
						this.form.status = 'loading';
						this.form.page = ++this.form.page;
						setTimeout(() => {
							this.list = [...this.list, ...res.data];
							if (res.data.length == 10) {
								this.form.status = 'loading';
							} else {
								this.is_end = true;
								this.form.status = 'nomore';
							}
						}, 500)
					}
				}
			},
			contentfixedclick(e) {
				uni.navigateTo({
				  url: '/pages/project/createcapinfo?name=' + e.name +'&goods_type_id='+ e.id
				});
			},
			async servicecreateitemclass() {
				let res = await this.api.servicecreateitemclass({
					name: this.name,
					type:1
				});
				if (res.code == 1) {
					uni.showToast({
						title: '创建成功',
						icon: 'none'
					});
					setTimeout(() => {
						uni.navigateBack();
					}, 1000);
				}
			},

		}
	}
</script>

<style lang="scss">
	page {
		background: #F6F6F6;
	}

	.index {
		.title_text {
			padding: 12rpx 40rpx;
			font-size: 28rpx;
			font-family: SourceHanSansCN-Regular, SourceHanSansCN;
			font-weight: 400;
			color: #666666;
		}

		#editor {
			width: 100%;
			height: 456rpx;
			padding: 12rpx 40rpx;
			background: #FFFFFF;
		}

		.onecontent {
			background: #ffffff;

			.onecontent_item {
				width: 100%;
				padding: 16rpx 46rpx;
				border-bottom: 2rpx solid #E5E5E5;

				.onecontent_itemleft {
					flex: 1;
					font-size: 28rpx;
					font-family: SourceHanSansCN-Regular, SourceHanSansCN;
					font-weight: 400;
					color: #666666;
				}

				.onecontent_itemright {
					flex: 3;

					.onecontent_itemrighttext {
						font-size: 24rpx;
						font-family: SourceHanSansCN-Regular, SourceHanSansCN;
						font-weight: 400;
						color: #999999;
					}

					.onecontent_itemrightimges {
						width: 112rpx;
						height: 112rpx;
						background: #F5F5F5;
						border-radius: 10rpx;
						font-size: 40rpx;
						color: #878787;
					}

					.onecontent_itemright_text {
						width: 100%;
						font-size: 24rpx;
						font-family: SourceHanSansCN-Regular, SourceHanSansCN;
						font-weight: 400;
						color: #999999;
					}
				}
			}
		}

		.thereconse {
			width: 630rpx;
			height: 80rpx;
			background: #999999;
			border-radius: 40rpx;
			font-size: 36rpx;
			text-align: center;
			margin: 84rpx auto;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 80rpx;
		}

		.thereconses {
			background: linear-gradient(115deg, #7E81A5 0%, #4D4E64 100%);
		}
	}
</style>