<template>
	<view class="sales-list-wrap">
		<u-dropdown class="search-top-box" id="tjCons">
			<u-dropdown-item v-model="searchForm.billStatus" @change="handleChange('bill')" title="业务状态"
				:options="billStatusOpt"></u-dropdown-item>
			<u-dropdown-item v-model="searchForm.financialStatus" @change="handleChange('financial')" title="财务状态"
				:options="(pageType&&pageType=='onlinePagOrder')?onlinePagStatusOpt:financialStatusOpt"></u-dropdown-item>
		</u-dropdown>
		<!-- 销售单列表 -->
		<view class="list-box">
			<listComponent ref="salesList" :height="listHeight" :params="searchForm" />
		</view>
		<!-- 查询右侧弹框 -->
		<salesSearch ref="searchBox" :openModal="openModal" :defaultParams="searchForm" @refresh="refresh"
			@close="openModal=false" />
	</view>
</template>

<script>
	import ListComponent from './listComponent.vue'
	import SalesSearch from './salesSearch.vue'
	import {
		getLookUpItem
	} from '@/api/data'
	import {
		salesList
	} from '@/api/sales'
	export default {
		components: {
			ListComponent,
			SalesSearch
		},
		data() {
			return {
				listData: [],
				pageNo: 1,
				pageSize: 6,
				totalNum: 0,
				noDataText: '暂无数据',
				billStatusOpt: [],
				financialStatusOpt: [],
				onlinePagStatusOpt:[],
				searchForm: {
					billStatus: null,
					financialStatus: null,
					payOnlineFlag:null//1线上支付订单  0 支付订单
				},
				listHeight: 200,
				openModal: false,
				pageType:null
			}
		},
		onNavigationBarButtonTap(e) { // 标题栏 按钮操作
			this.openModal = true
		},
		onBackPress() {
			if (this.openModal) {
				this.$refs.searchBox.closeBox()
				this.openModal = false
				return true
			}
		},
		onReady() {
			const query = uni.createSelectorQuery().in(this);
			query.select('#tjCons').boundingClientRect(data => {
				this.listHeight = Math.floor(data.height + 5)
			}).exec();
		},
		onLoad(options) {
			const _this = this
			this.getLookUpItem('SALES_BILL_STATUS')
			this.getLookUpItem('FINANCIAL_RECEIVE_STATUS')
			this.getLookUpItem('FINANCIAL_ONLINE_RECEIVE_STATUS')
			this.$nextTick(function() {
				// 监听整改完成后刷新事件
				uni.$on('refreshSalesBL', function(data) {
					_this.$refs.salesList.getList(1)
				})
			})
			this.searchForm.payOnlineFlag=options?(options.pageType&&options.pageType=='onlinePagOrder')?1:0:0
			if (options&&options.pageType&&options.pageType=='onlinePagOrder') {
				this.pageType = options.pageType
				uni.setNavigationBarTitle({
					title: '线上支付订单' // 页面标题为“新的页面标题”
				});
			}
		},
		onUnload() {
			uni.$off('refreshSalesBL')
		},
		methods: {
			// 获取查询参数 刷新列表
			refresh(params) {
				const _this = this
				const data = params ? Object.assign(this.searchForm, params) : {
					billStatus: null,
					financialStatus: null
				}
				data.beginDate = data.beginDate ? (data.beginDate + ' 00:00:00') : ''
				data.endDate = data.endDate ? (data.endDate + ' 23:59:59') : ''
				this.searchForm = data
				this.$nextTick(function() {
					_this.$refs.salesList.refash()
				})
			},
			// 状态  change
			handleChange(type) {
				this.$refs.salesList.refash()
			},
			// 配送方式
			getLookUpItem(type) {
				getLookUpItem({
					lookupCode: type,
					pageNo: 1,
					pageSize: 1000
				}).then(res => {
					if (res.status == 200 && res.data && res.data.list) {
						res.data.list.map(item => {
							item.label = item.dispName
							item.value = item.code
						})
						res.data.list.splice(0, 0, {
							label: '全部',
							value: null
						})
						if (type == 'SALES_BILL_STATUS') {
							if(this.pageType =='onlinePagOrder'){
								this.billStatusOpt = res.data.list.filter(item=>item.code!='WAIT_SUBMIT'&&item.code!='SUPERIOR_CHANGE')
							}else{
								this.billStatusOpt = res.data.list
							}
						} else if (type == 'FINANCIAL_RECEIVE_STATUS') {
							this.financialStatusOpt = res.data.list
						}else if(type=='FINANCIAL_ONLINE_RECEIVE_STATUS'){
							this.onlinePagStatusOpt = res.data.list
						}
					} else {
						if (type == 'SALES_BILL_STATUS') {
							this.billStatusOpt = []
						} else if (type == 'FINANCIAL_RECEIVE_STATUS') {
							this.financialStatusOpt = []
						}else if(type=='FINANCIAL_ONLINE_RECEIVE_STATUS'){
							this.onlinePagStatusOpt = []
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.sales-list-wrap {
		width: 100%;

		.search-top-box {
			background-color: #fff;
		}

		.list-box {
			padding: 0 25upx;
		}
	}
</style>