<template>
	<view class="boxcon">
		<view class="container">
			<view class="titleall">
				<text class="pl">供应商</text>
				<text class="pr">{{form.name}}</text>
			</view>
			<view class="titleall">
				<text class="pl">统一社会信用代码</text>
				<text class="pr">{{form.socialCode}}</text>
			</view>
			<view class="titleall">
				<text class="pl">法人姓名</text>
				<text class="pr">{{form.socialCode}}</text>
			</view>
			<view class="titleall">
				<text class="pl">联系人</text>
				<text class="pr">{{form.contacts}}</text>
			</view>
			<view class="titleall">
				<text class="pl">联系电话</text>
				<text class="pr">{{form.contactsMobile}}</text>
			</view>
			<view class="titleall">
				<text class="pl">账号</text>
				<text class="pr">{{form.account}}</text>
			</view>
			<view class="titleall">
				<text class="pl">密码</text>
				<view style="display: flex;justify-content: center;align-items: center;" @click="show=true">
					<text class="pr">重置</text>
					<u-icon name="arrow-right" color="" size="15" bold="true"></u-icon>
				</view>

			</view>
			<view class="titleall ">
				<text class="pl psa ">认证照片</text>
				<text class="pr" v-if="!form.identifyPicList">暂无</text>
				<view class="fanuppic" v-if="form.identifyPicList.length>0">
					<view class="picbox" v-for="item in form.identifyPicList">
						<image :src="item" mode="aspectFill" @click="prviewPic(item)"></image>
					</view>
				</view>
			</view>
			<view class="titleall ">
				<text class="pl psa ">授权委托书</text>
				<text class="pr" v-if="!form.proxyFileList">暂无</text>
				<view class="fanuppic" v-if="form.proxyFileList.length>0">
					<view class="picbox" v-for="item in form.proxyFileList">
						<image :src="item" mode="aspectFill" @click="prviewPic(item)"></image>
					</view>
				</view>
			</view>
			<view class="titleall">
				<text class="pl">认证状态</text>
				<text class="pr">{{form.statusText}}</text>
			</view>
		</view>
		<view style="width: 100%;height: 80rpx;"></view>

		<view class="newbill flex1" v-if="form.isDeleted==0&&form.statusText=='未认证'">
			<view class="choosebtn">
				<view class="delbtn flex1" @click="examineFail">认证失败</view>
				<view class="succbtn flex1" @click="examineSuccess">认证成功</view>
			</view>

		</view>
		<view class="newbill flex1" v-if="form.isDeleted==0&&form.statusText=='已认证'" @click="forbidden">
			<view class="newbillbtn">
				<text>禁用</text>
			</view>

		</view>
		<view class="newbill flex1" @click="resert()" v-if="form.isDeleted==1">
			<view class="newbillbtn">
				<text>复原</text>
			</view>

		</view>
		<!-- 弹出层 -->
		<u-popup :show="show" @close="close" @open="open" mode="center">
			<view class="forgetbox">
				<!-- <view class="ciclebg">
					<image src="../../static/img/forpwdbg.png" mode="aspectFill"></image>
				</view> -->
				<!-- <view class="keybox">
					<image src="../../static/img/foricon.png" mode="aspectFill"></image>
				</view> -->
				<text class="keytitle">重置密码</text>
				<u--form labelPosition="left" :model="model1"  ref="form1" labelWidth="50">
				<!-- 	<u-form-item label="旧密码" prop="pwd.oldPassword" borderBottom ref="item1">
						<u--input v-model="pwd.oldPassword" border="none" password></u--input>
					</u-form-item> -->
					<u-form-item label="新密码" prop="pwd.newPassword" borderBottom ref="item1">
						<u--input v-model="pwd.password" border="none" password></u--input>
					</u-form-item>
				</u--form>
				<!-- <text class="remindtitle">请电联系管理员，进行密码确定</text> -->
				<view class="surebtn" @click="makeSurePwd()">确认</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	let that
	export default {
		data() {
			return {
				form: {

				},
				pwd: {
					password: '',
				},
				show: false,
				// rules: {
				// 	'pwd.oldPassword': {
				// 		type: 'string',
				// 		required: true,
				// 		message: '请填写旧密码',
				// 		trigger: ['blur', 'change']
				// 	},
				// 	'pwd.newPassword': {
				// 		type: 'string',
				// 		required: true,
				// 		message: '请填写新密码',
				// 		trigger: ['blur', 'change']
				// 	},
				// },

			}
		},
		onLoad(o) {
			that = this
			if (o.id) {
				this.id = o.id
			}
			this.init()
		},
		methods: {
			close() {
				this.show = false
			},
			open() {
				this.show = true
			},
			tryAgain() {

			},
			init() {
				uni.showLoading()
				uni.$u.http.get(`/api/Supplier/${this.id}`, {
					custom: {
						auth: true
					}
				}).then((res) => {
					uni.hideLoading()
					this.form = res

				}).catch((err) => {
					uni.hideLoading()
					console.log(err)
				})
			},
			prviewPic(item) {
				let pics=[]
				pics.push(item)
				uni.previewImage({
					urls: pics,
				});
			},
			makeSurePwd() {
				uni.showLoading()
				let pwd={
					password:this.pwd.password,
					supplierId:this.form.id
				}
				uni.$u.http.post('/api/Account/password/resetSupplier', pwd, {
					custom: {
						auth: true
					}
				}).then((res) => {
					uni.hideLoading()
					this.$toast("重置成功")
					this.show = false
				}).catch((err) => {
					console.log(err)
					uni.hideLoading()
					this.$toast(err.msg)
				})
			},
			resert() {
				let ids = []
				ids.push(this.id)
				uni.showModal({
					title: '提示',
					content: "是否认复原？",
					success: function(res) {
						if (res.confirm) {

							uni.showLoading()
							uni.$u.http.post('/api/Supplier/manage', {
								ids: ids,
								operateType: 2
							}, {
								custom: {
									auth: true
								}
							}).then((res) => {
								uni.hideLoading()
								that.$toast("操作成功")
								setTimeout(() => {
									that.init()
								}, 500)

							}).catch((err) => {
								uni.hideLoading()
								that.$toast(err.msg)
							})

						} else if (res.cancel) {

						}
					}
				})
			},
			forbidden() {
				let ids = []
				ids.push(this.id)
				uni.showModal({
					title: '提示',
					content: "是否认禁用？",
					success: function(res) {
						if (res.confirm) {

							uni.showLoading()
							uni.$u.http.post('/api/Supplier/manage', {
								ids: ids,
								operateType: 1
							}, {
								custom: {
									auth: true
								}
							}).then((res) => {
								uni.hideLoading()

								that.$toast("操作成功")
								setTimeout(() => {
									that.init()
								}, 500)

							}).catch((err) => {
								uni.hideLoading()
								that.$toast(err.msg)
							})

						} else if (res.cancel) {

						}
					}
				})
			},
			examineSuccess() {
				let ids = []
				ids.push(this.id)
				uni.showModal({
					title: '提示',
					content: "是否认证成功？",
					success: function(res) {
						if (res.confirm) {

							uni.showLoading()
							uni.$u.http.post('/api/Supplier/manage', {
								ids: ids,
								operateType: 3
							}, {
								custom: {
									auth: true
								}
							}).then((res) => {
								uni.hideLoading()

								that.$toast("操作成功")
								setTimeout(() => {
									that.init()
								}, 500)

							}).catch((err) => {
								uni.hideLoading()
								that.$toast(err.msg)
							})

						} else if (res.cancel) {

						}
					}
				})

			},
			examineFail() {
				let ids = []
				ids.push(this.id)
				uni.showModal({
					title: '提示',
					content: "是否认证失败？",
					success: function(res) {
						if (res.confirm) {

							uni.showLoading()
							uni.$u.http.post('/api/Supplier/manage', {
								ids: ids,
								operateType: 4
							}, {
								custom: {
									auth: true
								}
							}).then((res) => {
								uni.hideLoading()

								that.$toast("操作成功")
								setTimeout(() => {
									that.init()
								}, 500)

							}).catch((err) => {
								uni.hideLoading()
								that.$toast(err.msg)
							})

						} else if (res.cancel) {

						}
					}
				})

			}

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6 !important;
	}

	.boxcon {
		margin: 20rpx 20rpx;
		padding: 50rpx 20rpx;
		border-radius: 20rpx;
		background: #fff;

		.titlename {
			font-size: 36rpx;
			font-weight: 600;
			padding-bottom: 30rpx;
			display: block;
			margin-bottom: 30rpx;
			border-bottom: 1rpx solid #E8E8E8;
		}

		.container {
			.bod {
				border-bottom: 1rpx solid #E8E8E8;
				box-sizing: border-box;
			}

			.ptin {
				padding-top: 50rpx;
			}

			.plas {
				padding-left: 65rpx;
				word-wrap: wrap;
				box-sizing: border-box;
			}

			.ds {
				padding-top: 30rpx;
			}

			.psa {
				padding-right: 30rpx;
			}

			.cls {
				color: #68625B;
			}

			.titleall {
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;
				padding-bottom: 30rpx;

				.pl {
					// width: 180rpx;
					color: #BEBDBB;
					flex-shrink: 0;
					// margin-right: 30rpx;
				}

				.pr {
					word-wrap: wrap;
					display: block;
					display: -webkit-box;
				}

				.uppic {
					display: flex;
					flex-wrap: wrap;
					justify-content: flex-end;


				}

				.picbox {
					width: 150rpx;
					height: 150rpx;
					margin-left: 20rpx;
					border-radius: 20rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.fanuppic {
					display: flex;
					flex-wrap: wrap;
				}
			}

		}
	}

	.forgetbox {
		width: 600rpx;
		height: 500rpx;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		background-image: url("@/static/img/forpwdbg.png");
		background-repeat: no-repeat;
		background-position: right 0 top 0;
		background-size: 367rpx 225rpx;

		.ciclebg {
			position: relative;
			right: 0;
			top: 0;
			width: 367rpx;
			height: 225rpx;

		}

		.keybox {
			margin-top: 84rpx;
			width: 196rpx;
			height: 161rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.keytitle {
			color: #1F242A;
			padding-top: 70rpx;
			padding-bottom: 70rpx;
			font-size: 36rpx;
			font-weight: 600;
		}

		.remindtitle {
			color: #68625B;
			font-size: 28rpx;
			padding-top: 30rpx;
		}

		.surebtn {
			width: 314rpx;
			height: 84rpx;
			line-height: 84rpx;
			border-radius: 43rpx;
			background: linear-gradient(to right, #FFE1AD, #D8AB5A);
			color: #412900;
			margin-top: 86rpx;
			text-align: center;
		}
	}
</style>
