<template>
	<view class="sales-list-wrap">
		<!-- 标题 -->
		<u-navbar title="销售单" :safeAreaInsetTop="false" :border-bottom="true">
			<view class="u-nav-slot" slot="right" style="padding-right: 20rpx;">
				<u-icon name="search" color="#999" size="28" @click="openModal=true"></u-icon>查询
			</view>
		</u-navbar>
		<u-dropdown class="search-top-box">
			<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="financialStatusOpt"></u-dropdown-item>
		</u-dropdown>
		<!-- 销售单列表 -->
		<view class="list-box">
			<listComponent ref="salesList" height="80" :params="searchParams" />
		</view>
		<!-- 查询右侧弹框 -->
		<salesSearch :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: [],
				searchForm: {
					billStatus: null,
					financialStatus: null
				},
				searchParams: {},
				openModal: false
			}
		},
		onLoad() {
			this.getLookUpItem('SALES_BILL_STATUS')
			this.getLookUpItem('FINANCIAL_RECEIVE_STATUS')
		},
		methods: {
			// 获取查询参数 刷新列表
			refresh(params){
				const _this = this
				this.searchParams = Object.assign(params, this.searchForm)
				this.$nextTick(function(){
					_this.$refs.salesList.getList(1)
				})
			},
			// 状态  change
			handleChange(type){
				if(type == 'bill'){
					this.searchParams.billStatus = this.searchForm.billStatus
				}else if(type == 'financial'){
					this.searchParams.financialStatus = this.searchForm.financialStatus
				}
				this.$refs.salesList.getList(1)
			},
			// 配送方式
			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'){
							this.billStatusOpt = res.data.list
						}else if(type == 'FINANCIAL_RECEIVE_STATUS'){
							this.financialStatusOpt = res.data.list
						}
					} else {
						if(type == 'SALES_BILL_STATUS'){
							this.billStatusOpt = []
						}else if(type == 'FINANCIAL_RECEIVE_STATUS'){
							this.financialStatusOpt = []
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.sales-list-wrap{
		width: 100%;
		.search-top-box{
			background-color: #fff;
		}
		.list-box{
			padding: 20upx 20upx;
		}
	}
</style>
