<template>
	<view class="Box">
		<view class="Box_box_O">
			<view class="Box_box flex-between" @click="showpopupclick">
				<view>*项目名称</view>
				<view class=""
					style="width: 60%;  overflow:hidden; font-size:32rpx;color:grey;text-overflow: ellipsis;white-space: nowrap; "
					v-model="form.article">{{ form.article || '选择项目名称' }}
				</view>
			</view>
			<view class="Box_box flex-between" @click="showpicker = true">
				<view class="Box_boxlang Box_box_bouttme_item_O">*发票类型</view>
				<view class="Box_box_bouttme_item_T">
					<text type="text" v-model="form.type">{{ form.type || '请输入发票类型' }}</text>
				</view>
			</view>
			<view class="Box_box flex-between">
				<view>备注：</view>
				<u--textarea v-model="form.notes" placeholder="请输入内容"></u--textarea>
			</view>
		</view>
		<view class="preservation flex-colum">
			<view class="preservation_box" @tap="$u.throttle(saveMerchantBaseInfoV2, 1000)">提交</view>
		</view>
		<u-popup :show="showpopup" @close="showpopup = false" @open="openpopup">
			<view class="popupshow">
				<view class="popupshowone">请选择项目名称</view>
				<view class="popupshowone_item" style="	border-bottom: 1rpx solid #E5E5E5;" v-if="keyword">
					<view class="popupshowone_itemone" @click="popupshowone_itemone">
						{{keyword}}
					</view>
				</view>
				<view class="popupshowonebotton" @click="businesscategory">搜索其他项目名称</view>
			</view>
		</u-popup>
		<u-picker :show="showpicker" @confirm="showpickerconfirm" :columns="columns"
			@cancel="showpicker = false"></u-picker>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				keyword: uni.getStorageSync('keyword'),
				showpopup: false,
				showpicker: false,
				columns: [],
				Uploadurlnumber: '',
				namelang: '',
				merchantAuditStatus: '',
				form: {
					store_id: uni.getStorageSync('userId'),
					article: '',
					type: '',
					se_amount: '',
					notes: ''
				}
			};
		},
		onNavigationBarButtonTap() {
			uni.pro.navigateTo('index/order');
		},
		onLoad(e) {
			// #ifdef APP-PLUS
			let webView = this.$mp.page.$getAppWebview();
			webView.setTitleNViewButtonStyle(0, {
				width: '70px'
			});
			// #endif
			uni.request({
				url: uni.conf.baseUrl + 'store/digitalinvoice',

				method: 'POST', //请求方式，必须为大写
				success: res => {
					console.log(res.data.data)
					this.columns = res.data.data
				}
			});

		},
		onShow() {
			uni.$on('businesscategorys', res => {
				console.log(res);
				this.form.mcc = res.code;
				this.form.article = res.name;
				this.keyword = uni.cache.get('keyword')
				// this.form.contactLine = res.unionpayCode
				// this.form.branchName = res.branchName
			});
		},
		methods: {
			showpopupclick() {
				this.keyword = uni.getStorageSync('keyword')
				this.showpopup = true
			},
			popupshowone_itemone() {
				this.showpopup = false
				this.form.article = this.keyword
			},
			handleInputChange() {
				if (this.form.type == null || this.form.type == '') {
					return false;
				}
				uni.$u.debounce(this.showpickerconfirm(), 1000)

			},
			async showpickerconfirm(e) {
				try {
					if (e.value) {
						if (e.value[1] == "1%") {
							this.form.se_amount = 1
						} else {
							this.form.se_amount = 3
						}
						this.form.type = e.value.toString();
					}
					this.showpicker = false
				} catch (e) {
					//TODO handle the exception
				}
			},
			businesscategory() {
				this.showpopup = false
				uni.pro.navigateTo('index/businesscategory');
			},
			async saveMerchantBaseInfoV2() {
				this.form.store_id = uni.getStorageSync('userId')
				console.log(this.form)
				if (this.form.article == null || this.form.article == '') {
					uni.showToast({
						title: '选择项目名称',
						icon: 'none'
					});
					return false;
				}
				if (this.form.type == null || this.form.type == '') {
					uni.showToast({
						title: '请选择类型',
						icon: 'none'
					});
					return false;
				}
				let res = await this.api.storemerchantfixedinvoicinglink(this.form)
				// console.log(res)
				setTimeout(() => {
					uni.pro.navigateTo('index/wxinvoicing',{
						url:res.data.url,
						// url:'0',
						tope:0
					})
				}, 1000)
				// uni.request({
				// 	url: uni.conf.baseUrl + 'store/subinvoicing',
				// 	data: this.form,
				// 	method: 'POST', //请求方式，必须为大写
				// 	success: res => {
				// 		console.log(res)
				// 		this.form = {
				// 			store_id: uni.getStorageSync('userId'),
				// 			article: '',
				// 			type: '',
				// 			notes: '',
				// 			se_amount: ''
				// 		}
				// 		uni.showToast({
				// 			title: res.data.message || res.data.msg,
				// 			icon: "none",
				// 		})
				// 		setTimeout(datalange => {
				// 			uni.pro.navigateTo('index/wxinvoicing', res.data.data.invoice_records)
				// 		}, 2000)

				// 	}

				// });
			}
		}
	};
</script>

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

	.Box {
		.Box_box_O {
			padding: 0 28rpx;

			.Box_box {
				text-align: right;
				padding: 24rpx;
				border-bottom: 1px solid #e5e5e5;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #333333;
			}

			.Box_box_bouttme_item_T {
				padding-left: 30rpx;
				flex: 1;
				text-align: right;

				text {
					color: #808080;
				}
			}
		}

		.Box_box_T {
			padding: 0 28rpx;
			border-top: 16rpx solid #e5e5e5;

			.Box_box_T_o {
				margin-top: 16rpx;
			}

			.flex-colum {
				image {
					width: 396rpx;
					height: 240rpx;
				}

				padding-bottom: 16rpx;
				border-bottom: 1px solid #e5e5e5;

				.Box_box_Ts {
					width: 396rpx;
					height: 240rpx;
					background: #ffffff;
					border-radius: 8rpx;
					border: 2rpx dashed #707070;
					background: url(@/static/my2.png) no-repeat;
					background-position: 50% 50%;
					background-size: 50%;
				}
			}
		}

		.preservation {
			margin-top: 50rpx;
			width: 100%;

			.preservation_box {
				width: 70%;
				height: 72rpx;
				background: #288efb;
				text-align: center;
				line-height: 72rpx;
				border-radius: 50rpx;
				font-size: 36rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #ffffff;
			}
		}

		.popupshow {
			width: 100%;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 0rpx 0rpx;
			padding-bottom: 50rpx;

			.popupshowone {
				margin-top: 22rpx;
				text-align: center;
				width: 100%;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 400;
				font-size: 32rpx;
				color: #333333;
			}

			.popupshowone_item {
				padding: 26rpx 52rpx;

				.popupshowone_itemone {
					text-align: center;
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 500;
					font-size: 36rpx;
					color: #333333;
				}

			}

			.popupshowonebotton {
				margin: 100rpx auto 0 auto;
				width: 558rpx;
				height: 84rpx;
				background: #288EFB;
				border-radius: 50rpx 50rpxmy2 50rpx 50rpx;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 400;
				font-size: 36rpx;
				color: #FFFFFF;
				line-height: 84rpx;
				text-align: center;
				padding-bottom: 32rpx;
			}
		}
	}
</style>