<!DOCTYPE html>
<html>
	<head>
		<title>入境登记-列表</title>
		<meta charset="utf-8">
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css & js 资源 -->
		<link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css">
		<script src="../../static/kj/vue.min.js"></script>
		<script src="../../static/kj/element-ui/index.js"></script>
		<script src="../../static/kj/httpVueLoader.js"></script>
		<script src="../../static/kj/jquery.min.js"></script>
		<script src="../../static/kj/layer/layer.js"></script>
		<script src="../../static/sa.js"></script>
		<script src="../../static/kj/upload-util.js"></script>
	</head>
	<style>
		.complete-modal .c-label,
		.confirm-in .c-label,
		.confirm-info .c-label {
			width: 140px;
		}
	</style>
	<body>
		<div class="vue-box" style="display: none;" :style="'display: block;'">
			<div class="c-panel">
				<div style="float: right;right: 20px;margin-top: 10px;">
					<label>刷新频率：</label>
					<el-select v-model="fresh.value" placeholder="请选择" @change="restartTimmer">
						<el-option label="10s" :value="10"></el-option>
						<el-option label="20s" :value="20"></el-option>
						<el-option label="30s" :value="30"></el-option>
						<el-option label="50s" :value="50"></el-option>
						<el-option label="60s" :value="60"></el-option>
					</el-select>
				</div>
				<!-- ------------- 检索参数 ------------- -->
				<div class="c-title">检索参数</div>
				<el-form ref="form" :model='p' @submit.native.prevent>
					<sa-item type="text" name="客户名称" placeholder="客户名称" v-model="p.customerName"></sa-item>
					<sa-item type="text" name="车牌号" placeholder="越南车牌" v-model="p.cardNo"></sa-item>
					<sa-item type="text" name="司机名称" placeholder="越南司机" v-model="p.driverName"></sa-item>
					<el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
					<br />
				</el-form>
				<!-- ------------- 快捷按钮 ------------- -->
				<div class="fast-btn">
					<el-button v-if="sa.isAuth('tb-business-add')" size="mini" type="primary" @click="add()">
						新增</el-button>
					<el-button size="mini" type="success" @click="getBySelect()">查看</el-button>
					<el-button size="mini" type="info" @click="sa.f5()">重置</el-button>
				</div>
				<!-- ------------- 数据列表 ------------- -->
				<el-table class="data-table" ref="data-table" :data="dataList">
					<sa-td type="selection"></sa-td>
					<sa-td name="客户名称" width="150" prop="customerName"></sa-td>
					<sa-td name="业务单号" prop="no" width="160"></sa-td>
					<sa-td name="境外车牌号" width="130" prop="cardNo"></sa-td>
					<sa-td name="中国车牌号" width="130" prop="chinaCarNo"></sa-td>
					<sa-td name="载重(kg)" prop="netWeight"></sa-td>
					<sa-td name="确认" prop="adminConfirmInput" type="enum" :jv="{1: '已确认', 0: '未确认'}"></sa-td>
					<sa-td name="总用费(元)" prop="totalMoney"></sa-td>
					<sa-td name="已支付(元)" prop="payMoney" width="140"></sa-td>
					<sa-td width="160" name="录入时间" prop="createTime"></sa-td>
					</sa-td>
					<el-table-column label="操作" width="240px" fixed="right">
						<template slot-scope="s">
							<el-button class="c-btn" type="primary" v-if="s.row.adminConfirmInput==0
								&&s.row.payStatus==1
								&&sa.isAuth('tb-business-confirm')
								&&currentCustomerId=='1'" @click="confirmFn(s.row)">确认账单</el-button>
							
							<el-button class="c-btn" type="primary" @click="itemFn(s.row)"
								v-if="currentCustomerId=='1'">业务项</el-button>
							<el-button v-if="sa.isAuth('tb-business-add')" class="c-btn" type="primary"
								@click="carFn(s.row)">车辆管理
							</el-button>
							<el-button class="c-btn" type="success" @click="get(s.row)">查看</el-button>
							<el-button class="c-btn" type="primary"
								v-if="s.row.adminConfirmInput==0&&sa.isAuth('tb-business-edit')" @click="update(s.row)">
								修改</el-button>
							<el-button class="c-btn" type="danger"
								v-if="s.row.payStatus==1&&sa.isAuth('tb-business-del')&&s.row.adminConfirmInput==0"
								@click="del(s.row)">删除
							</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- ------------- 分页 ------------- -->
				<sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()">
				</sa-item>
			</div>
			<el-dialog title="支付业务" :visible.sync="modal.visible" width="400px">
				<sa-info name="业务单号" br>{{modal.form.no}}</sa-info>
				<sa-info name="总计费用" br>{{modal.form.totalMoney}}元</sa-info>
				<sa-item type="img-list" name="支付凭据" v-model="modal.form.payTicket" br></sa-item>
				<span slot="footer" class="dialog-footer">
					<el-button @click="modal.visible=false">取 消</el-button>
					<el-button type="primary" @click="surePayFn">确 定</el-button>
				</span>
			</el-dialog>
			<el-dialog title="确认账单" :visible.sync="confirm.visible" width="650px">
				<div class="confirm-info">
					<el-row>
						<el-col span="12">
							<sa-info name="订单号" br>{{confirm.form.no}}</sa-info>
							<sa-info name="客户" br>{{confirm.form.customerName}}</sa-info>
							<sa-info :name="item.itemTypeName" br v-for="item in confirm.form.items">
								{{item.itemPrice}}x{{item.num}}={{item.total}}元
							</sa-info>
							<sa-info name="业务费用" br>{{confirm.form.itemPrice}}（元）</sa-info>
						</el-col>
						<el-col span="12">
							<sa-info name="中国车停车费" br>{{confirm.form.chinaPartMoney}}（元）</sa-info>
							<sa-info name="停车费合计" br>{{confirm.form.partMoney+confirm.form.chinaPartMoney}}（元）</sa-info>
							<sa-info name="合计费用" br>{{confirm.form.totalMoney}}（元）</sa-info>
						</el-col>
					</el-row>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="confirm.visible = false">取 消</el-button>
					<el-button type="primary" @click="sureConfirmFn">确 认</el-button>
				</span>
			</el-dialog>
			<el-dialog title="生成账单" :visible.sync="complete.visible" width="600px">
				<div class="complete-modal">
					<sa-info name="客户名称" br>{{complete.form.customerName}}</sa-info>
					<sa-info name="业务单号" br>{{complete.form.no}}</sa-info>
					<sa-info name="业务费用（元）" br>{{complete.form.itemPrice}}</sa-info>
					<sa-info name="境外车入场时间" br>{{complete.form.realInTime}}</sa-info>
					<sa-item type="datetime" @input="jwCaroTimeChange" name="境外车预计离场" v-model="complete.form.outDayTime"
						br></sa-item>
					<sa-info name="停车费用（元）" br>{{complete.form.partMoney}}</sa-info>
					<sa-info name="中国车入场时间" br>{{complete.form.realInTime}}</sa-info>
					<sa-item type="datetime" @input="chinaCaroTimeChange" name="中国车预计离场"
						v-model="complete.form.chinaCarOutTime" br></sa-item>
					<sa-info name="停车费用（元）" br>{{complete.form.chinaPartMoney}}</sa-info>
					<sa-info name="总计费用" br>{{complete.form.totalMoney}}元</sa-info>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="complete.visible = false">取 消</el-button>
					<el-button type="primary" @click="sureCompleteFn">确 认</el-button>
				</span>
			</el-dialog>
			<el-dialog title="支付确认" :visible.sync="pay.visible" width="400px">
				<sa-info name="业务单号" br>{{pay.form.no}}</sa-info>
				<sa-info name="总计费用" br>{{pay.form.totalMoney}}元</sa-info>
				<sa-item type="img-list" name="支付凭据" v-model="pay.form.payTicket" br></sa-item>
				<span slot="footer" class="dialog-footer">
					<el-button @click="pay.visible = false">取 消</el-button>
					<el-button type="primary" @click="surePayirmFn">确 认</el-button>
				</span>
			</el-dialog>
			<el-dialog title="确认入场" :visible.sync="rc.visible" width="600px">
				<el-form label-position="left">
					<div class="confirm-in">
						<sa-item type="datetime" name="境外车入场时间" v-model="rc.form.realInTime" br></sa-item>
						<sa-item type="datetime" name="中国车入场时间" v-model="rc.form.chinaCarInTime" br></sa-item>
					</div>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="rc.visible = false">取 消</el-button>
					<el-button type="primary" @click="sureRcFn">确 认</el-button>
				</span>
			</el-dialog>
			<el-dialog title="确认离场" :visible.sync="out.visible" width="600px">
				<el-form label-position="left">
					<div class="confirm-in">
						<sa-item type="datetime" name="境外车离场" v-model="out.form.outDayTime" br></sa-item>
						<sa-item type="datetime" name="中国车离场" v-model="out.form.chinaCarOutTime" br></sa-item>
					</div>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="out.visible = false">取 消</el-button>
					<el-button type="primary" @click="sureOutFn">确 认</el-button>
				</span>
			</el-dialog>
		</div>
		<script>
			var app = new Vue({
				components: {
					"sa-info": httpVueLoader('../../sa-frame/com/sa-info.vue'),
					"sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
					"sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue'),
				},
				el: '.vue-box',
				data: {
					value: '',
					currentCustomerId: '1',
					confirm: {
						visible: false,
						form: {
							ids: ''
						}
					},
					pay: {
						visible: false,
						form: {
							ids: ''
						}
					},
					modal: {
						visible: false,
						form: {
							id: '',
							payTicket: ''
						}
					},
					p: { // 查询参数  
						id: '', // 主键 
						customerId: '', // 客户id 
						customerName: '', // 客户名称 
						no: '', // 编号 
						isCar: 0,
						cardNo: '', // 车牌号 
						cardSize: '', // 车规格 
						netWeight: '', // 载重(kg) 
						goodsName: '', // 商品 
						goodsCode: '', // 商品编号 
						driverName: '', // 司机名称 
						driverId: '', // 司机id 
						driverPhone: '', // 司机联系号码 
						driverIdCard: '', // 司机身份证 
						expectInDay: '', // 预计进边境日期 
						realInDay: '', // 实际进边境日期 
						realInTime: '', // 实际进境时间 
						payStatus: '', // 支付状态(1=未支付,2=已支付) 
						payTime: '', // 支付时间 
						payType: '', // 支付方式(1=线下支付,2现金支付,3=第三方支付) 
						outDayTime: '', // 离境时间 
						partMoney: '', // 停车费用 
						partTime: '', // 停车时常(分) 
						pageNo: 1, // 当前页 
						pageSize: 10, // 页大小 
						sortType: 0 // 排序方式 
					},
					dataCount: 0,
					dataList: [], // 数据集合 
					perCode: [],
					adminId: '0',
					rc: {
						visible: false,
						form: {
							inChannel: '',
							realInTime: '',
							carType: '境外车'
						}
					},
					out: {
						visible: false,
						form: {
							outChannel: '',
							realInTime: '',
							carType: '境外车'
						}
					},
					complete: {
						visible: false,
						form: {
							id: '',
							no: ''
						}
					},
					timmer: null,
					fresh: {
						value: 60
					}
				},
				methods: {
					itemFn(data) {
						sa.showIframe('业务项', 'tb-business-item-list.html?businessId=' + data.id, '1050px', '95%');
					},
					carFn(data) {
						sa.showIframe('车辆管理', '../car/tb-business-car-list.html?id=' + data.id + '&payStatus=' + data
							.payStatus + '&confirm=' + data.adminConfirmInput, '1050px', '95%');
					},
					blurFn() {
						console.log(123)
					},
					stopTimmer() {
						if (this.timmer != null) {
							clearInterval(this.timmer);
						}
					},
					restartTimmer() {
						this.stopTimmer();
						let val = this.fresh.value;
						this.timmer = setInterval(() => {
							this.f5();
						}, val * 1000)
					},
					jwCaroTimeChange(oTime) {
						if (oTime) {
							let o = Object.assign(this.complete.form);
							o.items = [];
							sa.ajaxNoLoading('/TbBusiness/calJwPartMoney', sa.removeNull(o), function(resp) {
								this.complete.form = resp.data;
							}.bind(this))
						}
					},
					chinaCaroTimeChange(oTime) {
						if (oTime) {
							let o = Object.assign(this.complete.form);
							o.items = [];
							sa.ajaxNoLoading('/TbBusiness/calChinaPartMoney', sa.removeNull(o), function(resp) {
								this.complete.form = resp.data;
							}.bind(this))
						}
					},
					completeFn(data) {
						Object.assign(this.complete, {
							visible: true,
							form: data
						})
						this.stopTimmer();
					},
					sureCompleteFn() {
						this.complete.form.items = null;
						sa.ajax('/TbBusiness/complete', sa.removeNull(this.complete.form), function(resp) {
							this.complete.visible = false;
							this.f5();
							this.restartTimmer();
						}.bind(this))
					},
					inFn(data) {
						Object.assign(this.rc, {
							visible: true,
							form: {
								id: data.id,
								realInTime: data.realInTime,
								chinaCarInTime: data.chinaCarInTime
							}
						})
						this.stopTimmer()
					},
					sureRcFn() {
						if (!this.rc.form.realInTime) {
							sa.error('请选择境外车入场时间')
							return;
						}
						if (!this.rc.form.chinaCarInTime) {
							sa.error('请选择中国车入场时间')
							return;
						}
						sa.ajax('/TbBusiness/adminSetIn', sa.removeNull(this.rc.form), function(resp) {
							this.f5();
							this.rc.visible = false;
							this.restartTimmer();
						}.bind(this))
					},
					outFn(data) {
						Object.assign(this.out, {
							visible: true,
							form: {
								id: data.id,
								outDayTime: '',
								chinaCarOutTime: ''
							}
						})
						this.stopTimmer()
					},
					sureOutFn() {
						if (!this.out.form.outDayTime) {
							sa.error('选择境外车离场时间')
							return;
						}
						if (!this.out.form.chinaCarOutTime) {
							sa.error('选择中国车离场时间')
							return;
						}
						sa.ajax('/TbBusiness/adminOut', this.out.form, function(resp) {
							this.f5();
							this.out.visible = false;
							this.restartTimmer();
						}.bind(this))
					},
					getCurrendCustomer() {
						sa.ajax('/TbCostomer/getCurrentCustomerId', function(resp) {
							this.currentCustomerId = resp.data;
						}.bind(this));
					},
					adminSurePayFn(data) {
						Object.assign(this.pay, {
							visible: true,
							form: data
						})
						this.pay.form.ids = data.id;
						this.stopTimmer()
					},
					surePayirmFn() {
						sa.ajax('/TbBusiness/adminConfirmPay', this.pay.form, function(resp) {
							this.pay.visible = false;
							this.f5();
							this.restartTimmer();
						}.bind(this))
					},
					confirmBatch() {
						// 获取选中元素的id列表
						let selection = this.$refs['data-table'].selection;
						selection = selection.filter(obj => obj.confirmInput == 0)
						let ids = sa.getArrayField(selection, 'id');
						if (selection.length == 0) {
							return sa.msg('至少选择一条未确认数据')
						}
					},
					getPcodeByCurrRid() {
						sa.ajax('/SpRolePermission/getPcodeByCurrRid', function(resp) {
							this.perCode = resp.data;
						}.bind(this))
					},
					confirmFn(data) {
						sa.ajax('/TbBusinessItem/getList', {
							businessId: data.id
						}, function(resp) {
							data.items = resp.data;
							Object.assign(this.confirm, {
								visible: true,
								form: data,
							})
							this.confirm.form.ids = data.id;
							this.stopTimmer();
						}.bind(this));
					},
					sureConfirmFn() {
						sa.ajax('/TbBusiness/confirm', {
							ids: this.confirm.form.ids
						}, function(resp) {
							this.confirm.visible = false;
							this.f5();
							this.restartTimmer();
						}.bind(this))
					},
					payFn(data) {
						Object.assign(this.modal, {
							visible: true,
							form: data
						})
						this.stopTimmer();
					},
					surePayFn() {
						sa.ajax('/TbBusiness/pay', this.modal.form, function(resp) {
							this.f5();
							this.modal.visible = false;
							this.restartTimmer();
						}.bind(this))
					},
					// 刷新
					f5: function() {
						sa.ajaxNoLoading('/TbBusiness/getList', sa.removeNull(this.p), function(res) {
							this.dataList = res.data; // 数据
							this.dataCount = res.dataCount; // 数据总数 
							sa.f5TableHeight(); // 刷新表格高度 
							this.restartTimmer();
						}.bind(this));
					},
					// 查看
					get: function(data) {
						sa.showIframe('数据详情', 'tb-business-info.html?id=' + data.id, '1050px', '90%');
					},
					// 查看 - 根据选中的
					getBySelect: function(data) {
						var selection = this.$refs['data-table'].selection;
						if (selection.length == 0) {
							return sa.msg('请选择一条数据')
						}
						this.get(selection[0]);
					},
					// 修改
					update: function(data) {
						this.stopTimmer();
						sa.showIframe('修改数据', 'tb-business-edit.html?id=' + data.id, '1000px', '90%');
					},
					// 新增
					add: function(data) {
						this.stopTimmer();
						sa.showIframe('新增数据', 'tb-business-add.html?id=-1', '1080px', '90%');
					},
					// 删除
					del: function(data) {
						sa.confirm('是否删除，此操作不可撤销', function() {
							sa.ajax('/TbBusiness/delete?id=' + data.id, function(res) {
								sa.arrayDelete(this.dataList, data);
								sa.ok('删除成功');
								sa.f5TableHeight(); // 刷新表格高度 
							}.bind(this))
						}.bind(this));
					},
				},
				created: function() {
					sa.onInputEnter();
					this.getCurrendCustomer();
					this.getPcodeByCurrRid();
				},
				mounted() {
					this.f5();
				},
				beforeDestroy() {
					this.stopTimmer();
				}
			})
		</script>
	</body>
</html>
