<template>
	<view>
		<!-- 选择业务类型 -->
		<u-action-sheet :list="billTypeList" :tips="{text: '请选择业务类型',color: '#2979ff',fontSize: 36}" v-model="opengShow" :mask-close-able="false" :cancel-btn="false" @click="actionSheet"/>

		<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"/>
		<!-- 时间选择组件 -->
		<u-calendar v-model="show" max-date="2050" mode="range" :closeable="false" :mask-close-able="false" @change="changeTwo" />
		<!-- 状态选择组件 -->
		<u-action-sheet :list="listData" v-model="showTwo" :mask-close-able="false" @click="click" @close="close" />
		<view v-for="(item,index) in dataList" :key="index" style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 10rpx;"></span>
			<h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">
				{{item.audit}}
			</h4>
			<view style="width: 90%;margin: 0 auto;">
				<view style="display: flex;justify-content: space-between;height: 60rpx;line-height: 60rpx;border-bottom: 1rpx solid #eff4ff;">
					<h4>{{item.type == '仓库'? '提单号：'+item.fmblno :'系统编号：'+item.refno3}}</h4>
				</view>
				<view v-if="item.type == '仓库'">
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">项目名称</view>
						<view style="float: right;">{{item.actName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">贸易方式</view>
						<view style="float: right;">{{item.ftrademodeid}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">商品名称</view>
						<view style="float: right;">{{item.goodsName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">仓库名称</view>
						<view style="float: right;">{{item.warehouseName}}</view>
					</view>
				</view>
				<view v-else>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">供应商</view>
						<view style="float: right;">{{item.refno1}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">提货日期</view>
						<view style="float: right;">{{item.fBsdate}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">项目名称</view>
						<view style="float: right;">{{item.projectName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">申请人</view>
						<view style="float: right;">{{item.nickName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">申请日期</view>
						<view style="float: right;">
							{{item.sendTime ? item.sendTime.slice(0,10) : item.sendTime}}
						</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">审核人</view>
						<view style="float: right;">{{item.nickName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">审核日期</view>
						<view style="float: right;">
							{{item.auditOpTime ? item.auditOpTime.slice(0,10) : item.auditOpTime}}
						</view>
					</view>
				</view>
				<view
					style="width: 100%;margin: 0 auto;height: 80rpx;margin: 0 auto;line-height: 80rpx;border-top: 1rpx solid #eff4ff;"
					@click="expenseDetails(item)">
					<view style="float: left;">
						<h3>立即审核业务</h3>
					</view>
					<view style="float: right;">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				opengShow: true,
				status: 'loadmore',
				iconType: 'flower',
				total: 0,
				billTypeList: [{
					text: '入库',
					value: 'SJRK'
				}, {
					text: '出库',
					value: 'SJCK'
				}, {
					text: '调拨',
					value: 'CKDB'
				}, {
					text: '货转',
					value: 'HQZY'
				}],
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				dataList: [],
				listData: [{
					text: '全部',
					value: null
				}, {
					text: '提交',
					value: '0'
				}, {
					text: '待审',
					value: 'S'
				}, {
					text: '审核退回',
					value: 'B'
				}, {
					text: '审核通过',
					value: 'A'
				}],
				showTwo: false,
				show: false,
				billType: '',
				list: [{
					name: '待审核'
				}, {
					name: this.type = '仓库' ? '申请时间' : '提货时间'
				}, {
					name: '状态'
				}, {
					name: '业务类型'
				}],
				current: 0,
				form: {
					//安品默认传
					// refno2: 'SQ',
					auditStatus: 'S',
					pageNum: 1,
					pageSize: 10
				},
				type: '',
			}
		},
		onShow() {
			this.form = {
				//安品默认传
				// refno2: 'SQ',
				auditStatus: 'S',
				pageNum: 1,
				pageSize: 10
			}
			this.dataList = []
			this.queryAudit()
		},
		onReachBottom() {
			this.status = 'loading'
			if (this.dataList.length < this.total) {
				this.form.pageNum++
				this.queryAudit()
			} else {
				this.status = 'nomore'
			}
		},
		methods: {
			actionSheet(index) {
				this.current = null
				this.billType = this.billTypeList[index].value
				this.dataList = []
				this.queryAudit()
			},
			change(index) {
				this.current = index
				console.log(index)
				if (index == 1) {
					this.show = true
				} else if (index == 2) {
					this.showTwo = true
				} else if (index == 3) {
					this.opengShow = true
				} else {
					this.form = {
						// 安品默认传
						// refno2: 'SQ',
						auditStatus: 'S',
						pageNum: 1,
						pageSize: 10
					}
					this.dataList = []
					this.queryAudit(false)
				}
			},
			changeTwo(e) {
				// console.log(e);
				this.current = null
				let data = [e.startDate, e.endDate]
				if (this.type = '仓库') {
					this.form = {
						pageNum: 1,
						pageSize: 10,
						sendTimeInterval: data
					}
				} else {
					this.form = {
						refno2: 'SQ',
						pageNum: 1,
						pageSize: 10,
						sendTimeList: data
					}
				}
				this.dataList = []
				this.queryAudit()
			},
			click(index) {
				this.form = {
					// refno2: 'SQ',
					pageNum: 1,
					pageSize: 10,
					auditStatus: this.listData[index].value
				}
				this.dataList = []
				this.queryAudit()
				this.current = null
			},
			close() {
				this.current = null
			},
			queryAudit(e) {
				// if(e == false) this.current = null
				// console.log(this.form)
				if (this.billType) this.form.billType = this.billType
				this.$u.get('/warehouse/paths/selectOrderAuditItems', this.form).then(res => {
					this.total = res.total
					if (res.rows) {
						this.dataList = this.dataList.concat(res.rows)
						this.type = '仓库'
					} else {
						res.data.map((e) => {
							if (e.sendTime) {
								e.sendTime = e.sendTime.slice(0, 10);
							}
							if (e.refno2) {
								switch (e.refno2) {
									case "SJRK": {
										e.refno2 = "入库"
										break;
									}
									case "SJCK": {
										e.refno2 = "出库"
										break;
									}
									case "HQZY": {
										e.refno2 = "货转"
										break;
									}
									case "CKDB": {
										e.refno2 = "调拨"
										break;
									}
									case "HWTG": {
										e.refno2 = "货物通关"
										break;
									}
									case "JSCCF": {
										e.refno2 = "计算仓储费"
										break;
									}
									case "CCF": {
										e.refno2 = "仓储费"
										break;
									}
									case "ZYF": {
										e.refno2 = "作业费"
										break;
									}
									case "SF": {
										e.refno2 = "收费"
										break;
									}
									case "DZ": {
										e.refno2 = "对账"
										break;
									}
									case "FF": {
										e.refno2 = "付费"
										break;
									}
									case "SE": {
										e.refno2 = "下单配船"
										break;
									}
									case "ApplyFP": {
										e.refno2 = "凯合开票申请"
										break;
									}
									case "KHDZ": {
										e.refno2 = "凯合对账"
										break;
									}
									case "KHSF": {
										e.refno2 = "凯合收费"
										break;
									}
									case "KHFF": {
										e.refno2 = "凯合付费"
										break;
									}
									case "KHDD": {
										e.refno2 = "凯合订单"
										break;
									}
									case "XS": {
										e.refno2 = "销售出库"
										break;
									}
									case "SQ": {
										e.refno2 = "采购申请"
										break;
									}
									case "XMGL": {
										e.refno2 = "项目管理"
										break;
									}
									default: {
										return uni.showToast({
											icon: 'none',
											title: '未知错误，无状态',
											position: "center"
										})
									}
								}
							}
						})
						this.dataList = res.data
					}
				})
			},
			expenseDetails(item) {
				console.log(item)
				switch (item.refno4) {
					case 'SQ':
						this.$u.route('/pages/home/procurementApplicationApproval/detailsOrUpdates', {
							form: JSON.stringify(item),
							toExamine: JSON.stringify(true)
						});
						break
					case 'SJRK':
						this.$u.route('/pages/home/allReview/index', {
							form: JSON.stringify(item)
						});
						break
					case 'SJCK':
						this.$u.route('/pages/home/allReview/index', {
							form: JSON.stringify(item)
						});
						break
					case 'HQZY':
						this.$u.route('/pages/home/allReview/index', {
							form: JSON.stringify(item)
						});
						break
					case 'CKDB':
						this.$u.route('/pages/home/allReview/index', {
							form: JSON.stringify(item)
						});
						break
					default:
						return uni.showToast({
							icon: 'none',
							title: '该单据暂不能在APP上审核',
							position: "center"
						})
						break
				}
			}
		}
	}
</script>

<style scoped lang="scss">
</style>
