send.vue 17.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
<template>
	<view class="Send">
		<view class="contail">
			<view class="main">
				<view class="bar">
					<view class="name">
						物品名称:
					</view>
					<view class="nameinput">
						<input v-model="form.name" type="text" placeholder="请输入">
					</view>
				</view>
				<view class="bar">
					<view class="name">
						所属分类:
					</view>
					<view class="barchoose flexA" @click="showCategory = true">
						<text :style="{color:sortName=='请选择'?'grey':'#000'}">{{sortName}}</text>
						<image src="/static/ic-arrow2.png" mode=""></image>
					</view>
				</view>
				<view class="bar">
					<view class="name">
						价格:
					</view>
					<view class="nameinput">
						<input @input="checkNumber" v-model="form.price"  type="text" placeholder="请输入(元)">
					</view>
				</view>
				<view class="newbar">
					<view class="name">
						物品介绍:
					</view>
					<u--textarea :autoHeight="true" maxlength="300" v-model="form.description" border="none" placeholder="请输入"></u--textarea>
				</view>
				<view class="newbar">
					<view class="name">
						物品图片:(最多五张)
					</view>
					<view class="upimg">
						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="5"></u-upload>
					</view>
				</view>
			</view>

			<u-gap height="12" bgColor="#F6F6F6"></u-gap>
			<view class="main">
				<view class="title">
					卖家信息
				</view>
				<view class="bar">
					<view class="name">
						姓名:
					</view>
					<view class="nameinput">
						<input v-model="form.seller_name" type="text" placeholder="选填">
					</view>
				</view>
				<view class="bar">
					<view class="name">
						手机号:
					</view>
					<view class="nameinput">
						<input v-model="form.seller_mobile" type="text" placeholder="选填">
					</view>
				</view>

				<view class="bar">
					<view class="name">
						<text>*</text>发送账户:
					</view>
					<view class="nameinput">
						<input v-model="form.package_add" type="text" placeholder="请输入手机号或钱包地址">
					</view>
				</view>

				<view class="bar">
					<view class="name">
						<text>*</text>微信号:
					</view>
					<view class="nameinput">
						<input v-model="form.wechat_num" type="text" placeholder="请输入">
					</view>
				</view>
				<view class="bar">
					<view class="name">
						<text>*</text>保证金:{{lastInfo.cert_withdraw_price}}
					</view>
					<view class="barlast" v-if="lastInfo.is_cert_withdraw!=1">
						去缴纳<image src="/static/arrowR.png" mode=""></image>
					</view>
					<view class="barlast" v-else style="color: #18D18E;">
						已缴纳
					</view>
				</view>
				<view class="bar" @click="show = true">
					<view class="name">
						<text>*</text>实名认证:
					</view>
					<view class="barlast" v-if="lastInfo.is_cert==0" >
						去认证<image src="/static/arrowR.png" mode=""></image>
					</view>
					<view class="barlast" v-else style="color: #18D18E;">
						已认证
					</view>
				</view>
			</view>
			<view style="height: 200rpx;"></view>
			<view class="btn">
				<view class="paybtn" @click="send">
					提交
				</view>
			</view>
		
			<u-popup :show="showmoney" :closeOnClickOverlay="false" @close="close" @open="open" mode="center" :round="12">
				<view class="popname">
					<view class="title">
						缴纳保证金
					</view>
					<view class="contant">
						为了保证平台用户交易的安全性,您需要缴纳{{lastInfo.cert_withdraw_price}}元保证金后方可在平台中进行发布物品操作。交易完成后,可在余额中心中进行退回。
					</view>
					<view class="btngroup" >
						<view class="concle" @click="back">
							暂不缴纳
						</view>
						<view class="requt"  @click="authorization">
							立即缴纳
						</view>
					</view>
				</view>
			</u-popup>
			<u-popup :show="show" :closeOnClickOverlay="false" @close="close" @open="open" mode="center" :round="12">
				<view class="popname">
					<view class="title">
						实名认证
					</view>
					<view class="contant">
						为了保证平台用户交易的安全性,您需要实名认证后,才能在平台中进行发布物品操作
					</view>
					<view class="btngroup" >
						<view class="concle" @click="back">
							暂不认证
						</view>
						<view class="requt" @click="goRealName">
							立即认证
						</view>
					</view>
				</view>
			</u-popup>
		</view>
		
		<u-picker :show="showCategory" @cancel="showCategory=false" @confirm="selctCategory" :columns="columns"  keyName="name"></u-picker>
		<Botton  :flag="3"></Botton>
	</view>
</template>

<script>
	var that 
	var wx = require('jweixin-module')
	import {baseURL} from '@/utils/request.js'
	import Botton from "@/components/Botton.vue"
	import {sortList,product_detail} from '@/api/index'
	import {toa} from '@/utils/toast.js'
	import { getCategory,sendProduct,getLastInfo,payGuarantee,authorization ,getOpenid,userCertWithdraw} from '@/api/send'
	export default {
		name:'send',
		components: {
			Botton
		},
		data() {
			return {
				fileList1: [],
				show: false,
				showmoney: false,
				showCategory:false,
				content:'',
				columns: [],
				lastInfo:{},
				sortName:'请选择',
				form:{
					product_id:'', //	string	否	物品id
					name:'', //	string	是	物品名称
					sort_id:'', //	integer	是	所属分类
					price:'', //	string	是	价格
					description:'', //	string	是	物品介绍
					images:'', //	string	是	物品图片
					seller_name:'', //	string	否	卖家姓名
					seller_mobile:'', //	string	否	手机号
					package_add:'', //	string	是	钱包地址
					wechat_num:'', //	string	是	微信号
				},
				code:''
			}
		},
		onLoad(e) {
			that = this
			if(e.id){
				this.form.product_id = e.id
				this.getDetail()
			}
			this.code = e.code || ''
			this.getLastInfo()
			this.sortList()
			if(this.code){
				this.getOpenid()
			}
		
		},
		onShow() {
		},
		methods: {
			back(){
				uni.navigateBack({})
				this.showmoney=false
			},
			// 获取openid
			async getOpenid(){
			  try {
			    const res = await getOpenid(this.code)
			    console.log('getOpenid', res)
				uni.setStorageSync('openId',res.openid)
				this.userCertWithdraw()
			    // 保存数据
			  } catch (err) {
			 	setTimeout(()=>{
					uni.showToast({ title:err,icon:'none' })
				},300)
				uni.redirectTo({
					url:'/pages/index/index'
				})
			    console.log('getOpenid', err)
			  }
			},
			// 缴纳保证金
			async userCertWithdraw(){
			  try {
				const openId =  uni.getStorageSync('openId')
			    const res = await userCertWithdraw(openId)
				 console.log(res.pay_data);
			    console.log('userCertWithdraw', res)
				 wx.config({
				              debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
				              appId: res.pay_data.appId, // 必填,公众号的唯一标识
				              timestamp: res.pay_data.timeStamp, // 必填,生成签名的时间戳
				              nonceStr: res.pay_data.nonceStr, // 必填,生成签名的随机串
				              signature: res.pay_data.paySign, // 必填,签名
				              jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
				            })
				            wx.ready(function () {
				              wx.chooseWXPay({
				                timestamp: res.pay_data.timeStamp, // 时间戳
				                nonceStr: res.pay_data.nonceStr, // 随机数
				                package: res.pay_data.package, //
				                signType: res.pay_data.signType,
				                paySign: res.pay_data.paySign, // 签名
				                success: function () {
									that.lastInfo.is_cert_withdraw = 1
									that.showmoney = false
									that.getLastInfo()
									toa.success('支付成功')
				                },
				                cancel: function () {
									setTimeout(()=>{
										toa.toast('取消失败')
									},200)
									uni.navigateBack({})
				                },
				                fail: function () {
									setTimeout(()=>{
										toa.toast('支付失败')
									},200)
									uni.navigateBack({})
				                }
				              })
				            })
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('userCertWithdraw', err)
			  }
			},
			// 获取详情
			async getDetail(){
			  try {
			    const res = await product_detail(this.form.product_id)
				// this.form = res.detail
				this.form.sort_id = res.detail.sort.id
				this.sortName = res.detail.sort.name
				this.form.product_id = res.detail.id
				this.form.name = res.detail.name
				this.form.price = res.detail.price
				this.form.description = res.detail.description
				res.detail.fileList.forEach(it=>{
					it.shortUrl = it.url
					it.url = it.fullUrl
				})
				this.fileList1 = res.detail.fileList
				console.log(this.fileList1,'图片');
			    console.log('getDetail', res)
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('getDetail', err)
			  }
			},
			checkNumber(e) {
				let val = e.target.value.replace(/(^\s*)|(\s*$)/g, "")
				var reg = /[^\d.]/g
							
				// 只能是数字和小数点,不能是其他输入
				val = val.replace(reg, "")
				// // 保证第一位只能是数字,不能是点
				val = val.replace(/^\./g, "");
				// // 小数只能出现1位
				val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				// // 小数点后面保留2位
				val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
				// console.log(val);
				this.$nextTick(() => {
					this.form.price = val;
				})
			},
			async sortList(){
			  try {
			    const res = await sortList(2)
				this.columns = [res.list]
			    console.log('sortList', res)
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('sortList', err)
			  }
			},
			async getLastInfo(){
			  try {
			    const res = await getLastInfo()
				this.lastInfo = res.detail
				console.log(1);
				if(res.detail.is_cert==0){ return	this.show = true}
				if(res.detail.is_cert_withdraw!=1 && !this.code){ 	this.showmoney = true}
				console.log(2);
				console.log(res.detail.is_cert_withdraw!=1,!this.code);
				this.form.seller_mobile = res.detail.seller_mobile
				this.form.seller_name = res.detail.seller_name
				this.form.package_add = res.detail.package_add
				this.form.wechat_num = res.detail.wechat_num
			    console.log('getLastInfo', res)
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('getLastInfo', err)
			  }
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				this.showmoney = false
				// console.log('close');
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					console.log(result,'获取的结构');
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result.fullurl,
						shortUrl:result.url
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: baseURL + 'common/upload', // 仅为示例,非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							token:uni.getStorageSync('token') || ''
						},
						success: (res) => {
							setTimeout(() => {
								resolve(JSON.parse(res.data).data)
							}, 1000)
						}
					});
				})
			},
			selctCategory(e){
				this.sortName = e.value[0].name
				this.form.sort_id = e.value[0].id
				this.showCategory = false
				console.log(e);
			},
			// 发布
			send(){
				console.log(this.lastInfo);
				if(this.lastInfo.is_cert_withdraw!=1 ) return this.showmoney = true
				if(this.lastInfo.is_cert==0) return this.show = true
				if(this.fileList1.length){
					this.form.images = this.fileList1.map(it=>it.shortUrl).join(',')
				}
				console.log(this.form);
				this.sendProduct()
			},
			async sendProduct(){
			  try {
			    const res = await sendProduct(this.form)
			    console.log('sendProduct', res)
				setTimeout(()=>{
					toa.success(this.form.product_id?'修改成功':'发布成功')
				},400)
				uni.redirectTo({
					url:'/pages/mine/myRelease'
				})
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('sendProduct', err)
			  }
			},
			goRealName(){
				uni.navigateTo({
					url:'/pages/index/realName'
				})
			
			},
			// 拿code
			async authorization(){
			  try {
				const openId =  uni.getStorageSync('openId')
				if(openId) return this.userCertWithdraw()
			    const res = await authorization(window.location.href)
			    console.log('authorization', res)
				window.location.href = res.url
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('authorization', err)
			  }
			},
		
		}
	}
</script>

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

	.Send {
		.contail {
			padding-bottom: 160rpx;

			.title {
				padding: 32rpx;
				box-sizing: border-box;
				color: rgba(0, 0, 0, 1);
				font-size: 28rpx;
				font-weight: 600;
				font-family: "PingFang SC";
			}

			.main {
				padding: 0 32rpx;

				.bar {
					display: flex;
					align-items: center;
					justify-content: space-between;
					box-sizing: border-box;
					padding: 32rpx 0;
					border-bottom: 1px solid #F0f0f0;

					.name {
						color: rgba(0, 0, 0, 1);
						font-size: 28rpx;
						font-weight: 400;
						font-family: "PingFang SC";

						text {
							color: rgba(252, 67, 56, 1);
							font-size: 28rpx;
							font-weight: 400;
							font-family: "PingFang SC";
						}
					}

					.barchoose {
						
						color: rgba(0, 0, 0, 0.4);
						font-size: 28rpx;
						font-weight: 400;
						font-family: "PingFang SC";
						image{
							width: 24rpx;
							height: 16rpx;
						}
					}

					.barlast {
						display: flex;
						align-items: center;
						color: rgba(33, 83, 212, 1);
						font-size: 28rpx;
						font-weight: 400;
						font-family: "PingFang SC";

						image {
							margin-left: 12rpx;
							width: 16rpx;
							height: 32rpx;
						}
					}

					input {
						text-align: right;
					}
				}

				.newbar {
					padding: 32rpx 0;
					box-sizing: border-box;
					border-bottom: 1px solid #F0f0f0;

					.name {
						color: rgba(0, 0, 0, 1);
						font-size: 28rpx;
						font-weight: 400;
						font-family: "PingFang SC";
					}

					textarea {
						margin-top: 32rpx;
						padding: 24rpx;
						width: 100%;
						height: 200rpx;
						box-sizing: border-box;
						background-color: #F6F6F6;
					}

					.upimg {
						margin-top: 32rpx;
					}
				}

			}

			.popname {
				padding: 32rpx;
				box-sizing: border-box;
				width: 622rpx;
				text-align: center;

				.title {
					color: rgba(0, 0, 0, 0.9);
					font-size: 32rpx;
					font-weight: 600;
					font-family: "PingFang SC";
					text-align: center;
				}

				.contant {
					color: rgba(179, 179, 179, 1);
					font-size: 28rpx;
					font-weight: 400;
					font-family: "PingFang SC";
					text-align: center;
				}

				.btngroup {
					margin-top: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.concle {
						width: 264rpx;
						height: 76rpx;
						border-radius: 16rpx;
						opacity: 1;
						line-height: 76rpx;
						color: rgba(0, 0, 0, 0.9);
						font-size: 28rpx;
						font-weight: 500;
						font-family: "PingFang SC";
						text-align: center;
						background: rgba(246, 246, 246, 1);
					}

					.requt {
						width: 264rpx;
						height: 76rpx;
						color: rgba(0, 0, 0, 0.9);
						font-size: 28rpx;
						font-weight: 500;
						font-family: "PingFang SC";
						text-align: center;
						line-height: 76rpx;
						border-radius: 16rpx;
						opacity: 1;
						background: rgba(254, 208, 0, 1);
					}
				}

			}

			.btn {
				position: fixed;
				bottom: 50rpx;
				left: 0;
				width: 100%;
				// height: 128rpx;
				padding: 16rpx 32rpx;
				padding-bottom: 100rpx;
				box-sizing: border-box;
				opacity: 1;
				background: rgba(255, 255, 255, 1);

				.paybtn {
					width: 100%;
					height: 96rpx;
					line-height: 96rpx;
					text-align: center;
					border-radius: 28rpx;
					opacity: 1;
					color: rgba(0, 0, 0, 0.9);
					font-size: 32rpx;
					font-weight: 600;
					font-family: "PingFang SC";
					background: linear-gradient(134.8deg, rgba(255, 232, 100, 1) 0%, rgba(255, 216, 0, 1) 100%);
				}
			}

		}
	}
	
	.u-textarea {
		margin-top: 32rpx;
		min-height: 200rpx;
		background: #f4f5f7;
	}
	/deep/ .uni-textarea-wrapper {
		height: 100% !important;
	}
</style>