order.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 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
<template>
	<view class="container">
		<Navbar title="订单" />
		<u-sticky bgColor="#fff">
			<u-tabs :current="current" :list="statusList" :is-scroll="false" lineColor="#EA5707"
				:activeStyle="activeStyle" :itemStyle="itemStyle" @change="tabChange"></u-tabs>
		</u-sticky>
		<view v-for="(item,index) in orderCardList" :key="item.id">
			<view class="orderCard" @click="goOrderDetaPage(item)">
				<view class="flex justify-between align-center">
					<view class="flex align-center w80" @click.stop="goStorePage(item)">
						<!--            <u-icon name="/static/images/home/shopTitle.png" size="20"></u-icon>-->
						<view
							:style="{ backgroundImage: 'url(/static/images/home/shopTitle.png)', backgroundSize:'100% 100%',width:'20px',height:'20px', backgroundRepeat: 'no-repeat'}">
						</view>
						<view class="margin-left-xs overflow-one-lines">
							{{ item.fCzmc }}
						</view>
					</view>
					<view class="themeColor">
						{{ ddDdzt.get(item.fDdzt) }}
					</view>
				</view>
				<u-divider></u-divider>
				<!--        ${$assignKeys(index)}-->
				<view v-for="(ddxpItem,index) of item.ddxqList" :key="`${$assignKeys(ddxpItem.id)}`"
					class="flex justify-between margin-top">
					<view class="" style="min-width: 80px;min-height: 80px">
						<u-image width="80px" height="80px"
							:src="ddxpItem.fTp?ddxpItem.fTp:'/static/images/gas-icon/gasicon.png'"></u-image>
					</view>
					<view class="w60 flex flex-direction  justify-between margin-left-sm">
						<view class="overflow-one-lines">
							{{ ddxpItem.fSpmc }}
						</view>
						<view class="text-sm text-gray overflow-one-lines">
							规格8:{{ ddxpItem.fMs }}
						</view>
						<view class="text-lg text-bold overflow-one-lines">
							¥{{ ddxpItem.fDj }}
						</view>
					</view>
					<view class="flex flex-wrap justify-end">
						<view v-if="item.fPsfs" :class="[item.fPsfs=='1'?'ztSty':'psSty','psfsSty']">
							{{ ddPsfs.get(item.fPsfs) }}
						</view>
						<view class="flex align-end">X{{ ddxpItem.fSl }}</view>
					</view>
				</view>
				<u-divider></u-divider>
				<view class="flex margin-top-lg">
					<view class="text-gray overflow-one-lines">
						订单编号:{{ item.fDddh }}
					</view>
				</view>
				<view class="flex margin-top-sm">
					<view class="text-gray">
						备注信息:{{ item.fMjly }}
					</view>
				</view>
				<view class="flex margin-top-lg margin-bottom-lg justify-end  ">
					<view class="text-gray">
						<!-- 共{{pageForm.ddxqList.length}}件商品 -->
						合计:
					</view>
					<view class="themeColor  overflow-one-lines">
						¥{{ item.fDdje }}
					</view>
				</view>
				<view class="flex justify-end">
					<view class="margin-left-sm" v-if="item.fDdzt =='201' || item.fDdzt =='202' || item.fDdzt =='203' "
						@click.stop="goGasCancel(item)">
						<u-button shape="circle" color="">取消订单</u-button>
					</view>
				</view>
			</view>
			<!--			<orderCard  :orderitem="item"  @orderCancel="cancelOrderLoad"></orderCard>-->
		</view>
		<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"
			v-if="!orderCardList.length &&!loading "></u-empty>
		<u-loadmore :status="status" marginTop="20" height="10" marginBottom="10"
			v-if="orderCardList.length>0 && !loading" />
		<u-loading-icon text="加载中" style="display: flex;align-items: center; margin-top: 100px;"
			:show="loading"></u-loading-icon>

		<!-- app不支持$route -->
		<!-- <TabBar :currentPagePath="this.$route.meta.pagePath"></TabBar> -->
		<TabBar :currentPagePath="'pages/order/order'"></TabBar>
	</view>
</template>

<script>
	import login from '../../api/login';
	import orderCard from './components/orderCard.vue'
	import {
		dd_zflx,
		dd_fkfs,
		dd_psfs,
		dd_zffs,
		dd_ddly,
		sys_sf,
		dd_ddzt
	} from "@/utils/enums";

	export default {
		components: {
			orderCard
		},
		props: {},
		data() {
			return {
				ddDdzt: new Map(Object.values(dd_ddzt).map(item => [item.code, item.info])),
				ddPsfs: new Map(Object.values(dd_psfs).map(item => [item.code, item.info])),
				loading: false,
				activeStyle: {
					'color': '#EA5707',
					'fontSize': '16px',
					'fontWeight': 'bold'
				},
				itemStyle: {
					'width': '75px',
					'height': '60px',
				},
				orderCardList: [],
				pageParams: {
					currentPage: 1,
					size: 10,
					currentZt: ''
				},
				status: "loadmore",
				current: 0,
				// current:'全部',
				statusList: [{
					name: '全部',
					id: '全部'
				}, {
					name: '待付款',
					id: 1
				}, {
					name: '待配送',
					id: 2
				}, {
					name: '配送中',
					id: 3
				}, {
					name: '已完成',
					id: 4
				}, ],
				total: null,
			}
		},
		computed: {},
		onPullDownRefresh() {
			this.orderCardList = [];
			this.pageParams.currentPage = 1;
			//调用获取数据方法
			this.getOrderList()
			setTimeout(() => {
				//结束下拉刷新
				uni.stopPullDownRefresh();
			}, 500);
		},
		onReachBottom() {
			let allTotal = this.pageParams.currentPage * this.pageParams.size
			if (allTotal < this.total) {
				//当前条数小于总条数 则增加请求页数
				this.pageParams.currentPage++;
				this.status = 'loading';
				setTimeout(() => {
					this.getOrderList()
				}, 500)
			} else {
				this.status = 'nomore'
				// console.log('已加载全部数据')
			}
		},
		mounted() {
			this.getDictOrder();
			// this.getOrderList();
		},
		async onLoad(options) {
			console.log('options=====', options)
			await this.getOrderList();

			uni.$on('onload', status => {
				console.log("onload刷新", status);
				if (status) {
					this.getOrderList()
				}
			});

		},
		async onShow() {
			const orderCardType = uni.getStorageSync('orderCardType');
			console.log("当前", this.pageParams.currentZt);
			let isChange = this.pageParams.currentZt === orderCardType; //记录状态是否发生改变
			if (orderCardType) {
				// this.pageParams.currentZt = orderCardType;
				switch (orderCardType) {
					case '全部':
						this.current = 0;
						this.pageParams.currentZt = null;
						break;
					case '待配送':
						this.current = 1;
						this.pageParams.currentZt = '202';
						break;
					case '配送中':
						this.current = 2;
						this.pageParams.currentZt = '203';
						break;
					case '已完成':
						this.pageParams.currentZt = '204';
						break;
					case '已取消':
						this.pageParams.currentZt = '207';
						break;
				}
				console.log('打印orderCardType', orderCardType);
			} else {
				this.current = 0;
				this.pageParams.currentZt = '';
			}
			this.pageParams.currentPage = 1;
			if (!isChange) { //如果状态发生改变后刷新
				await this.getOrderList();
			}
		},
		methods: {
			//用户取消订单
			async goGasCancel(val) {
				let paramsData = {
					ddid: val.id
				};
				this.$modal.confirm('确认取消订单?', '提示').then(async () => {
					let cancelOrderResult = await this.$api.orderApi.cancelOrder(paramsData);
					if (cancelOrderResult.code == 200) {
						this.$modal.msgSuccess('订单取消成功!');
						this.getOrderList();
					} else {
						this.$modal.msgError('会员信息修改失败!');
					}
				}).catch(() => {
					console.log("取消");
				});

			},
			goStorePage(val) {
				let czid = val.fCzid;
				console.log('打印czid', czid)
				uni.navigateTo({
					url: "/pages/home/storeDetails?czid=" + czid
				})
			},
			goGasDetailPage() {
				uni.navigateTo({
					url: "/pages/home/gasDetail"
				})
			},
			goOrderDetaPage(val) {
				// console.log('打印this.pageForm.id', this.pageForm);
				uni.navigateTo({
					url: `/pages/order/orderDetail?id=${val.id}`
				})
			},
			cancelOrderLoad() {
				this.getOrderList();
			},
			async getDictOrder() {
				let query = [{
					key: 'NAME_',
					value: '订单状态'
				}]
				console.log(query);
				let queryJson = JSON.stringify(query);
				console.log(queryJson);
				const result = await this.$api.dictApi.getDict(queryJson, 'ztyd');
				let {
					rows
				} = result;
				let statusArray = [];
				statusArray = rows.length > 0 ? rows.map((item) => {
					return {
						name: item.NAME_,
						id: item.NAME_
					}
				}) : [];
				statusArray.unshift({
					name: '全部',
					id: '全部'
				});
				this.statusList = statusArray;
				console.log('大于this.statusList', this.statusList);

			},
			async getOrderList() {
				this.loading = true;
				let params = {
					current: this.pageParams.currentPage,
					size: 10,
				}
				switch (this.pageParams.currentZt) {
					case '全部':
						params.zt = null;
						break;
					case '待支付':
						params.zt = '201';
						break;	
					case '待配送':
						params.zt = '202';
						break;
					case '配送中':
						params.zt = '203';
						break;
					case '已完成':
						params.zt = '204';
						break;
					case '取消中':
						params.zt = '205';
						break;
					case '退款中':
						params.zt = '206';
						break;
					case '已取消':
						params.zt = '207';
						break;
				}
				// setTimeout(async()=>{
				let result = await this.$api.orderApi.getOrderList(params);
				let {
					code,
					value
				} = result;
				// let { current, records,size,total} = value;
				// this.orderCardList = records;
				if (code == 200) {
					let {
						current,
						records,
						size,
						total
					} = value;
					let allTotal = this.pageParams.currentPage * this.pageParams.size
					this.total = total;
					const newlist = records;
					if (this.pageParams.currentPage === 1) {
						this.orderCardList = newlist;
					} else {
						this.orderCardList.push(...newlist)
					}
					if (this.orderCardList.length < allTotal) {
						this.status = 'nomore'
					}
					this.orderCardList.map(async (item) => {
						item.ddxqList.map(async (vitem) => {
							let JsonParse = JSON.parse(vitem.fTp);
							let images = await this.$getPhotoUrl(JsonParse[0].response.fileId);
							vitem.fTp = images;
							this.$forceUpdate();
						});
						this.$forceUpdate();
					});
					this.loading = false;
					// this.orderCardList =JSON.parse(JSON.stringify(this.orderCardList));
					console.log('打印this.orderCardList', this.orderCardList)
				}

				// },2000)
				// let queryJson = JSON.stringify(params);

			},
			tabChange(e) {
				console.log("tabChange e", e);
				this.current = e.index;
				this.pageParams.currentZt = e.name;
				this.pageParams.currentPage = 1;
				this.orderCardList = [];
				this.getOrderList();
			},
			openScan() {
				this.$refs.scanCode.open();
			},
			close() {
				this.$refs.scanCode.close();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding-bottom: 60px;

		// background-color: #f1f1f1 !important;
		::v-deep.u-tabbar__placeholder {
			display: none;

		}
	}

	.tabCss {
		// font-weight: ;
	}
</style>
<style lang="scss" scoped>
	.orderCard {
		margin: 10px;
		padding: 10px;
		background: #fff;
		border-radius: 15px;

		.psfsSty {
			width: 70px;
			height: 23px;
			border-radius: 5px;
			text-align: center;
			line-height: 23px;
			font-size: 12px;
		}

		.ztSty {
			font-family: "苹方 中等", 苹方, sans-serif;
			font-weight: 400;
			font-style: normal;
			color: rgb(0, 174, 170);
			background-color: #e6f7f7;
		}

		.psSty {
			font-family: "苹方 中等", 苹方, sans-serif;
			font-weight: 400;
			font-style: normal;
			color: rgb(255, 165, 0);
			background-color: #fff6e6;
		}
	}
</style>