publish.vue 11.2 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
<template>
	<view class="berCon">
		<view class="berInput">
			<input type="text" placeholder-class="place-holder" value="" placeholder="请输入商品名称" @input="bindInput"
				v-model="inputVlaue" />
		</view>
		<view class="berTextarea">
			<view class="" style="margin-bottom: 20rpx;">
				<textarea class="zd_textarea" value="" placeholder="简要描述物品的型号、新旧程度、转手原因、使用感受吧~" @input="textareaInout"
					v-model="areaValue" />
			</view>
			<view class="" style="margin-left: 32rpx;width: 100%;">
				<view class="photoImgList" v-for="(item,index) in fileList" :key="index"
					style="display:inline-block;width: 29.3%;position: relative;margin-right: 1%;">
					<image :src="item" mode="" style="width:100%;height:176rpx;"></image>
					<view style="position: absolute;top: 0;right: 0;" @click="deleteImg(index)">
						<image src="/static/image/close@2x.png" style="width: 52rpx;height: 52rpx;"></image>
					</view>
				</view>
				<image src="/static/image/tianjia_icon@2x.png" mode="" style="width: 176rpx;height:176rpx;"
					@click="uploadImg"></image>
			</view>
			<view class="berBottom" @click="goMap">
				<image src="../../static/image/Frame_11@2x.png" style="width: 32rpx;height: 32rpx;margin-left: 32rpx;"
					mode=""></image>
				<text class="berAddresxz">{{SelectAddress}}</text>
				<image src="../../static/image/gengduo_icon_5@2x.png" style="width: 48rpx;height: 48rpx;" mode="">
				</image>
			</view>
		</view>
		<view class="" style="margin: 0 32rpx;border-radius: 16rpx;margin-bottom: 160rpx;">
			<view class="" style="position: relative;">
				<view class="">
					<van-cell title="价格" />
				</view>
				<view class="" style="position: absolute;top: 25rpx;left: 195rpx;">
					<input type="number" value="" placeholder-class="sizeColor" placeholder="请输入价格" @input="priceInput"
						v-model="peiceValue" />
				</view>
			</view>
			<view class="">
				<van-cell-group>
					<van-cell title="分类" is-link @click="showPickerSelect = true" />
					<view class="">
						<text class="SelectData" @click="showPickerSelect = true">{{select}}</text>
						<van-popup :show="showPickerSelect" position="bottom">
							<van-picker show-toolbar value-key="h_name" :columns="array" @confirm="bindPickerChange"
								@cancel="showPickerSelect = false" />
						</van-popup>
					</view>
				</van-cell-group>

			</view>
			<view class="" v-if="arrayIndex != null">
				<van-cell-group>
					<van-cell title="分类二" is-link @click="showPickerSelect2 = true" />
					<view class="">
						<text class="SelectData" @click="showPickerSelect2 = true">{{select2}}</text>
						<van-popup :show="showPickerSelect2" position="bottom">
							<van-picker show-toolbar value-key="h_name" :columns="array2" @confirm="bindPickerChange2"
								@cancel="showPickerSelect2 = false" />
						</van-popup>
					</view>
				</van-cell-group>
			</view>
			<view class="">
				<van-cell-group>
					<van-cell title="新旧程度" is-link @click="showPickerSelects = true" />
					<view class="">
						<text class="SelectData" @click="showPickerSelects = true">{{degree}}</text>
						<van-popup :show="showPickerSelects" position="bottom">
							<van-picker show-toolbar value-key="h_name" :columns="degreeArray"
								@confirm="bindPickerDegree" @cancel="showPickerSelects = false" />
						</van-popup>
					</view>
				</van-cell-group>
			</view>
		</view>
		<view class="BtnBackup">
			<view class="BtnBack" @click="publish">
				<text class="BtnBackText">发布</text>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		onLoad() {
			this.getlocation()
		},
		data() {
			return {
				SelectAddress: '位置选择',
				address: '',
				latitude: '',
				longitude: '',
				fileList: [],
				urlImg: [],
				inputVlaue: '',
				degree: '', //新旧程度
				areaValue: '',
				peiceValue: '',
				showPickerSelects: false, //新旧程度
				degreeArray: [],
				degreeArrayIndex: null,
				degreeId: [],
				showPickerSelect: false, //分类
				showPickerSelect2: false, //分类二
				username: "",
				array: [],
				arrayId: [],
				arrayIndex: null,
				select: '请选择分类',
				array2: [],
				arrayId2: [],
				arrayIndex2: null,
				select2: '请选择分类',
				btn: true,
				tempFilePaths: [], //多张上传
				wechat: '', //微信号
				mobile:'',   //手机号
			}
		},
		onShow() {
			this.getUserinfo()
		},
		created() {
			if (uni.getStorageSync('token')) {

			} else {
				uni.redirectTo({
					url: '/pages/index/login'
				})
			}
			this.classifyList()
			this.newOld()

		},
		methods: {
			bindInput(e) {
				this.inputVlaue = e.detail.value
			},
			textareaInout(e) {
				this.areaValue = e.detail.value
			},
			priceInput(e) {
				this.peiceValue = e.detail.value
			},
			uploadImg() {
				let that = this
				that.tempFilePaths = []
				uni.chooseImage({
					count: 6,
					success: (chooseImageRes) => {
						let list = chooseImageRes.tempFilePaths
						list.forEach((item, index) => {
							that.tempFilePaths.push(item);
						})
						let lists = that.tempFilePaths
						lists.forEach(ele => {
							const uploadTask = uni.uploadFile({
								url: 'https://ketao.shequtaoapp.com/api/common/upload',
								filePath: ele,
								fileType: 'image',
								name: 'file',
								formData: {
									'user': 'test'
								},
								header: {
									'token': uni.getStorageSync('token') || ''
								},
								success: (uploadFileRes) => {
									let uploadList = JSON.parse(uploadFileRes.data).data
									that.fileList.push(uploadList.url)
									that.urlImg.push(uploadList.save_path)
								}
							});
						})

					}
				});
			},
			//删除图片
			deleteImg(idx) {
				this.fileList.splice(idx, 1);
				this.urlImg.splice(idx, 1);
				this.tempFilePaths.splice(idx, 1);
			},
			//新旧程度
			newOld() {
				request.get('/api/push/Mo', {}).then(res => {
					let nameList = [];
					let idList = [];
					let list = res.data.info.reverse();
					list.forEach((item, index) => {
						nameList.push(item.name);
						idList.push(item.id)
					})
					this.degreeArray = nameList;
					this.degreeId = idList;
				}).catch(err => {

				})
			},
			//分类
			classifyList() {
				request.get('/api/index/fen', {}).then(res => {
						let nameList = [];
						let idList = [];
						let list = res.data.info;
						list.forEach((item, index) => {
							nameList.push(item.name);
							idList.push(item.id)
						})
						this.array = nameList;
						this.arrayId = idList;
					})
					.catch(err => {

					})
			},
			bindPickerChange(e) {
				this.select = e.target.value
				this.arrayIndex = e.target.index
				this.$forceUpdate()
				this.showPickerSelect = false
				this.classifyList2()
			},
			//二级分类
			classifyList2() {
				request.get('/api/push/fenLei', {
						id: this.arrayId[this.arrayIndex]
					}).then(res => {
						let nameList = [];
						let idList = [];
						let list = res.data.info;
						list.forEach((item, index) => {
							nameList.push(item.name);
							idList.push(item.id)
						})
						this.array2 = nameList;
						this.arrayId2 = idList;
					})
					.catch(err => {

					})
			},
			bindPickerChange2(e) {
				this.select2 = e.target.value
				this.arrayIndex2 = e.target.index
				this.showPickerSelect2 = false
			},
			//新旧程度
			bindPickerDegree(e) {
				this.degree = e.target.value
				this.degreeArrayIndex = e.target.index
				this.showPickerSelects = false
			},
			onFenl() {
				this.showPickerSelect = true
			},
			//跳转地图
			goMap() {
				let that = this;
				uni.chooseLocation({
					success: function(res) {
						that.SelectAddress = res.name
						that.address = res.name
						that.latitude = res.latitude
						that.longitude = res.longitude
					},
				});
			},
			getlocation() {
				let that = this
				uni.getLocation({
					type: 'gcj02',
					altitude: true,
					success(r) {
						// uni.setStorageSync('nowLat', r.latitude)
						// uni.setStorageSync('nowLot', r.longitude)
						that.latitude = r.latitude
						that.longitude = r.longitude
						uni.request({
							url: 'https://apis.map.qq.com/ws/geocoder/v1',
							data: {
								key: 'Y4PBZ-MBQ3Q-XSV5A-GWLXE-HXV4E-JNB3P',
								location: (r.latitude + "," + r.longitude)
							},
							success: res => {
								that.SelectAddress = res.data.result.formatted_addresses.recommend
							}
						})
					},
					fail(err) {}
				})
			},
			//获取信息判断是否设置微信号
			getUserinfo() {
				request.get('/api/personal/chaKan', {}).then(res => {
					this.wechat = res.data.info[0].wechat_id
					this.mobile = res.data.info[0].mobile
					if (this.mobile == '') {
						uni.showModal({
							title: '提示',
							content: '请绑定手机号用于接收卖家/买家短信消息提醒',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/myPackage/pages/me/personal'
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}
				}).catch(err => {

				})
			},
			//发布需求
			publish() {
				if (this.btn) {
					if (this.inputVlaue == '') {
						uni.showToast({
							title: '请输入商品名称',
							icon: 'none'
						})
					} else if (this.areaValue == '') {
						uni.showToast({
							title: '请输入商品描述',
							icon: 'none'
						})
					} else if (this.latitude == '') {
						uni.showToast({
							title: '请选择地址',
							icon: 'none'
						})
					} else if (this.peiceValue == '') {
						uni.showToast({
							title: '请选择商品价格',
							icon: 'none'
						})
					} else if (this.arrayIndex == null) {
						uni.showToast({
							title: '请选择一级分类',
							icon: 'none'
						})
					} else if (this.arrayIndex2 == null) {
						uni.showToast({
							title: '请选择二级分类',
							icon: 'none'
						})
					} else if (this.degree == '') {
						uni.showToast({
							title: '请选择新旧程度',
							icon: 'none'
						})
					} else if (this.wechat == 'null ') {
						uni.showToast({
							title: '请先设置微信号',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/myPackage/pages/me/set-wechat'
							})
						}, 1000)
					} else {
						this.btn = false
						request.get('/api/push/xuQiu', {
							lat: this.latitude,
							lng: this.longitude,
							address: this.SelectAddress,
							need_name: this.inputVlaue,
							images: this.urlImg.toString(),
							content: this.areaValue,
							price: this.peiceValue,
							sort_id: this.arrayId[this.arrayIndex],
							sort2_id: this.arrayId2[this.arrayIndex2],
							damage_id: this.degreeId[this.degreeArrayIndex] || ''
						}).then(res => {
							if (res.code == 1) {
								this.btn = false
								uni.showToast({
									title: '发布成功',
									duration: 2000,
									icon: 'success'
								})
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/index/index'
									})
								}, 1500)
							} else {
								uni.showToast({
									title: res.msg
								})
							}
						}).catch(err => {})
					}


				}

			}
		}
	}
</script>

<style>
	@import url("/common/uni.css");
	@import url("/common/publish.css");

	input {
		width: 98%;
	}
</style>