<!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>
</head>
<body>
<div class="vue-box" style="display: none;" :style="'display: block;'">
    <div class="c-panel">
        <el-form ref="form" :model='p' @submit.native.prevent>
            <sa-item type="text" name="车牌号" v-model="p.carNo"></sa-item>
            <div class="c-item">
                <label class="c-label">入场时间:</label>
                <el-date-picker :clearable="false" v-model="inTime" type="datetimerange" range-separator="至"
                                start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
            </div>
            <el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
            <el-button size="mini" type="info" @click="sa.f5()">重置</el-button>
            <el-button size="mini" type="primary" @click="confirmSelectFn">确定</el-button>
        </el-form>
        <!-- ------------- 数据列表 ------------- -->
        <el-table class="data-table" ref="data-table" :data="dataList">
            <sa-td type="selection"></sa-td>
            <sa-td name="车牌号" prop="carNo" width=120></sa-td>
            <el-table-column label="车牌颜色">
                <template slot-scope="s">
                    <label v-if="!s.row.color">-</label>
                    <label v-else>{{s.row.color}}</label>
                </template>
            </el-table-column>
            <sa-td name="入场通道" prop="inChannel"></sa-td>
            <sa-td name="入场时间" prop="realInTime"></sa-td>
            <sa-td name="离场时间" prop="realOutTime"></sa-td>
            <el-table-column label="停车费">
                <template slot-scope="s">
                    <label v-if="s.row.money">{{s.row.money}}</label>
                    <label v-else>-</label>
                </template>
            </el-table-column>
            <sa-td name="支付状态" prop="payType"></sa-td>
            <!-- <el-table-column label="操作"  fixed="right">
                <template slot-scope="s">
                    <el-button class="c-btn" type="primary" @click="sureFn(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>
</div>
<script>
    var app = new Vue({
        components: {
            "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
            "sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue'),
        },
        el: '.vue-box',
        data: {
            leveTime: [],
            inTime: [],
            businessId: sa.p('id', '-1'),
            businessCarIds: sa.p('businessCarIds', ''),
            carNo: sa.p('carNo', ''),
            p: { // 查询参数
                carNo: decodeURIComponent(sa.p('carNo', '')), //
                inStart: '',
                inEnd: '',
                limitDay: 1,
                pageNo: 1, // 当前页
                pageSize: 10, // 页大小
                sortType: 10,// 排序方式
            },
            dataCount: 0,
            dataList: [], // 数据集合
            colorList: []
        },
        methods: {
            sureFn(data) {
                let id = data.id;
                let businessCarId = this.businessCarId;
                let content = '是否将[' + data.carNo + ']绑定到此业务';
                if (businessCarId && id != businessCarId) {
                    content = '此业务已绑定车辆【' + decodeURIComponent(this.carNo) + '】,是否覆盖?';
                }
                if (id === businessCarId) {
                    sa.error('该车已绑定此业务,无需绑定');
                    return;
                }
                let obj = {
                    id: this.businessId,
                    businessCarId: id
                };
                sa.confirm(content, function () {
                    sa.ajax('/TbBusiness/bindCar', obj, function (resp) {
                        sa.alert('绑定成功');
                        setTimeout(() => {
                            sa.closeCurrIframe(); // 关闭本页
                            parent.app.f5(); // 刷新父页面列表
                        }, 1000)
                    }.bind(this))
                }.bind(this));

            },

            confirmSelectFn() {
                let selection = this.$refs['data-table'].selection;
                if (selection.length == 0) {
                    return sa.msg('至少选择一条记录')
                }
                let ids = sa.getArrayField(selection, 'id');
                let obj = {
                    businessId: this.businessId,
                    businessCarIds: ids.join(',')
                }
                sa.confirm('是否确认绑定选中车辆?', function () {
                    sa.ajax('/TbBusiness/bindOtherBusinessCar', obj, function (resp) {
                        sa.alert('绑定成功');
                        setTimeout(() => {
                            sa.closeCurrIframe(); // 关闭本页
                            parent.app.f5(); // 刷新父页面列表
                        }, 1000)
                    }.bind(this))
                }.bind(this));
            },
            // 刷新
            f5: function () {
                if (this.inTime && this.inTime.length > 0) {
                    this.p.inStart = sa.forDatetime(this.inTime[0]);
                    this.p.inEnd = sa.forDatetime(this.inTime[1]);
                } else {
                    this.p.inStart = '';
                    this.p.inEnd = '';
                }
                sa.ajax('/TbBusinessCar/getList', sa.removeNull(this.p), function (res) {
                    let list = res.data;
                    this.dataList = list; // 数据
                    this.dataCount = res.dataCount; // 数据总数
                    let businessCarIdList = this.businessCarIds.split(',');
                    list.forEach(row => {
                        if (businessCarIdList.indexOf(row.id) !== -1) {
                            this.$nextTick(() => {
                                this.$refs['data-table'].toggleRowSelection(row,
                                    true)
                            })
                        }
                    })
                    sa.f5TableHeight(); // 刷新表格高度
                }.bind(this));
            },
            // 查看
            get: function (data) {
                sa.showIframe('数据详情', 'tb-business-car-info.html?id=' + data.id + '&businessId=' + this.p
                    .businessId, '800px', '80%');
            },
            // 修改
            update: function (data) {
                sa.showIframe('修改数据', 'tb-business-car-add.html?id=' + data.id + '&businessId=' + this.p
                    .businessId, '500px', '80%');
            },
            // 新增
            add: function (data) {
                sa.showIframe('新增数据', 'tb-business-car-add.html?id=-1' + '&businessId=' + this.p.businessId,
                    '550px', '80%');
            },
        },
        created: function () {
            this.f5();
            sa.onInputEnter();
        }
    })
</script>
</body>
</html>