<#include "/incloud/header.ftl"/>
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html>
    <@header></@header>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <@top></@top>
    <@left></@left>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                异常订单管理
                <small>Optional description</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
                <li class="active">Here</li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="content container-fluid" id="app">
            <div class="box-body">
                <!--查询区域-->
                <div class="query">
                    <el-form :inline="true" :model="con" class="demo-form-inline">
                    	 <el-form-item label="发布时间" :label-width="queryLabelWidth">
		                    <el-date-picker
						      v-model="con.times"
						      type="datetimerange"
						      range-separator="至"
						      start-placeholder="开始日期"
						      end-placeholder="结束日期">
						    </el-date-picker>
					    </el-form-item>
                        <el-form-item label="异常订单" :label-width="queryLabelWidth">
                            <el-input v-model="con.orderNo" placeholder="异常订单号"></el-input>
                        </el-form-item> 
                       <el-form-item label="异常类型" :label-width="queryLabelWidth">
		                    <el-select v-model="con.type" placeholder="请选择">
		                    	<el-option :key="0" :label="'全部'" :value="0"></el-option>
		                    	<el-option :key="1" :label="'退款异常'" :value="1"></el-option>
							    <el-option :key="2" :label="'出票异常'" :value="2"></el-option>
							 </el-select>
						</el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="loadTable1()">查询</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <!--表格区-->
                <el-table border
                          :data="tableData"
                          style="width: 100%">
                    <el-table-column min-width="150px"
                                     label="流水号"
                                     prop="orderNo">
                    </el-table-column>
                    <el-table-column min-width="150px"
                                     label="操作人"
                                     prop="managerName">
                    </el-table-column>
                    <el-table-column min-width="150px"
                                     label="订单号"
                                     prop="orderNum">
                    </el-table-column>
                    <el-table-column min-width="150px"
                                     label="类型">
                           <template slot-scope="scope">
                            {{scope.row.type == 1 ? '退款异常' : '出票异常'}}
                        </template>
                    </el-table-column>
                    <el-table-column min-width="150px"
                                     label="描述"
                                     prop="description">
                    </el-table-column>
                    <el-table-column min-width="150px"
                                     label="记录时间"
                                     prop="time">
                    </el-table-column>
                    <el-table-column label="操作" min-width="300px">
                        <template slot-scope="scope">
                            <el-button
                                    size="mini"
                                    type="danger"
                                    @click="refund(scope.$index, scope.row)">退款
                            </el-button>
                            <el-button
                                    size="mini"
                                    type="primary"
                                    @click="outTicket(scope.$index, scope.row)">出票
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!--分页-->
                <div class="block">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="con.currentPage"
                            :page-sizes="[1,10, 50, 200, 500]"
                            :page-size="con.pageSize"
                            layout="total, sizes, prev, pager, next, jumper, slot"
                            :total="con.total">
                    </el-pagination>
                </div>

                <!--对话框2 编辑-->
                <el-dialog title="编辑" :visible.sync="dialog2Visible" :custom-class="'ele-dialog'" :center="true">
                    <el-form :model="editData" status-icon :rules="rules2" ref="dialog2">
                        <el-form-item label="姓名" :label-width="formLabelWidth" prop="name">
                            <el-input v-model="editData.name" placeholder="请输入姓名"></el-input>
                        </el-form-item>
                        <el-form-item label="电话" :label-width="formLabelWidth" prop="phone">
                            <el-input v-model="editData.phone" placeholder="请输入电话"></el-input>
                        </el-form-item>
                        <el-form-item label="账号" :label-width="formLabelWidth" prop="account">
                            <el-input v-model="editData.account" placeholder="请输入账号"></el-input>
                        </el-form-item>
                        <el-form-item label="密码" :label-width="formLabelWidth" prop="password">
                            <el-input type="password" v-model="editData.password" placeholder="请输入密码"></el-input>
                        </el-form-item>
                        <el-form-item label="确认密码" :label-width="formLabelWidth" prop="password2">
                            <el-input type="password" v-model="editData.password2" placeholder="请再次输入密码"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="dialog2Sub('dialog2')">提 交</el-button>
                        <el-button @click="dialog2Visible = false">取 消</el-button>
                    </div>
                </el-dialog>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- Main Footer -->
    <!--<@footer></@footer>-->
    <@footer></@footer>
</div>
</body>
<script src="/js/util/dyAjax.js"></script>
<script>
    $(function () {
        var option = {
            mixins: [dyMixin],
            data() {
                return {
                    con: {currentPage: 1, pageSize: 10, total: 0},//查询条件
                    tableData: [],
                    editData: {},//编辑数据
                    dialog2Visible: false,//编辑弹框隐藏
                    rules2: {
                        name: [
                            {required: true, message: '请输入姓名', trigger: 'change'}
                        ],
                        phone: [
                            {required: true, message: '请输入联系方式', trigger: 'change'}
                        ],
                        account: [
                            {required: true, message: '请输入账号', trigger: 'change'}
                        ],
                        password: [
                            {
                                required: true, validator: (rule, value, callback) => {
                                if (value === '') {
                                    callback(new Error('请输入密码'));
                                } else {
                                    if (this.editData.password !== '') {
                                        this.$refs.dialog2.validateField('pwd2');
                                    }
                                    callback();
                                }
                            }, trigger: 'blur'
                            }
                        ],
                        password2: [
                            {
                                required: true, validator: (rule, value, callback) => {
                                if (value === '') {
                                    callback(new Error('请再次输入密码'));
                                } else if (value !== this.editData.password) {
                                    callback(new Error('两次输入密码不一致!'));
                                } else {
                                    callback();
                                }
                            }, trigger: 'blur'
                            }
                        ],
                    },//对话框2验证规则
                }
            },
            mounted: function () {
                this.loadTable1();
            },
            methods: {
              //退款
                refund: function (index, row) {
                    let _this = this;
                    console.log(row);
                    this.$confirm('确认同意退款, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        $.dyAjax('/good/refundByOrderNo', {orderNo: row.orderNo}, function (data) {
                            _this.loadTable1(function () {
                                _this.$message({
                                    type: 'success',
                                    message: '申请退款成功!'
                                });
                            });
                        },'get');
                    }).catch(() => {
                    });
                },
                //出票
                outTicket: function (index, row) {
                    let _this = this;
                    console.log(row);
                    this.$confirm('确认重新出票, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        $.dyAjax('/good/outTicket', {id: row.id}, function (data) {
                            _this.loadTable1(function () {
                                _this.$message({
                                    type: 'success',
                                    message: '出票成功!'
                                });
                            });
                        },'get');
                    }).catch(() => {
                    });
                },
                //翻页大小改变事件
                handleSizeChange(val) {
                    var _this = this;
                    _this.con.pageSize = val;
                    _this.loadTable1();
                },
                //翻页翻页事件
                handleCurrentChange(val) {
                    var _this = this;
                    _this.con.currentPage = val;
                    _this.loadTable1();
                },
                //加载表数据
                loadTable1: function (callback) {
                    var _this = this;
                    if(this.con.times != null){
                    	var date1 = new Date(this.con.times[0]); 
                    	var date2 = new Date(this.con.times[1]); 
                    	
                    	this.con.startTime = date1.getFullYear() + '-' + (date1.getMonth() + 1) + '-' + date1.getDate() + ' ' + date1.getHours() + ':' + date1.getMinutes() + ':' + date1.getSeconds();
                    	this.con.endTime = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate() + ' ' + date2.getHours() + ':' + date2.getMinutes() + ':' + date2.getSeconds();
                    }else{
                    	this.con.startTime = "";
                    	this.con.endTime = "";
                    }
                    if(this.con.type == 0){
						this.con.type = ""                    	
                    }
                    $.dyAjax('/errorOrders/selectPage', this.con, function (data) {
                        callback && callback(data);
                        console.log(data)
                        _this.tableData = data.list;
                        _this.con.total = data.total;
                        _this.con.currentPage = data.pageNum;
                        _this.con.pageSize = data.pageSize;
                    });
                },
                //对话框2 编辑提交事件
                dialog2Sub: function (formName) {
                    var _this = this;
                    console.log(this.editData);
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            console.log(_this.editData);
                            $.dyAjax('/errorOrders/update', _this.editData, function (data) {
                                _this.loadTable1(function () {
                                    _this.$message({
                                        message: '成功',
                                        type: 'success'
                                    });
                                    _this.dialog2Visible = false;
                                    _this.jsonClear(_this.editData);
                                });
                            });
                        } else {
                            return false;
                        }
                    });
                },
            }
        };
        var app = Vue.extend(option);
        new app().$mount('#app');
    });
</script>
</html>