<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding: 20px;">
      <el-form :inline="true" :model="filters">
        <div>
          <el-form-item>
            <el-button>Order ID</el-button>
          </el-form-item>
          <el-form-item>
            <el-input v-model="filters.orderid" placeholder="订单号" :disabled="lock_order"></el-input>
          </el-form-item>
          <el-button @click="send_query" v-if="!lock_order" :loading="loading_getorder">确认</el-button>
		  <el-button @click="send_log" style="float:right;">下载日志</el-button>
		  <el-button @click="reset_info" v-if="lock_order" type="danger" style="float:right;">重 置 User Settings</el-button>
        </div>

        <div v-if="display_step">
          <el-form-item>
            <el-button>&nbsp;&nbsp;Step&nbsp;&nbsp;&nbsp;&nbsp;</el-button>
          </el-form-item>
          <el-form-item>
            <el-input v-model="filters.step" placeholder="Step" :disabled="lock_step"  @input="set_step"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button>Min. Tolerance</el-button>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="filters.tolerance"
              placeholder="Min. Tolerance"
              :disabled="lock_step"
            ></el-input>
          </el-form-item>
          <el-button @click="send_step" v-if="!lock_step">确认</el-button>
        </div>

        <div v-if="display_user">
          <el-form-item>
            <el-button>&nbsp;Groups</el-button>
          </el-form-item>
          <el-form-item>
            <el-input v-model="filters.group" placeholder="组" type="textarea" :row="3"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="info" plain>&nbsp;Users&nbsp;&nbsp;</el-button>
          </el-form-item>
          <el-form-item>
            <el-input v-model="filters.username" placeholder="用户名" type="textarea" :row="4"></el-input>
          </el-form-item>
          <br>
        </div>

        <div v-if="display_user">
          <el-row style="text-align:center;">
            <el-button type="primary" @click="Preview" >预览</el-button>
            <!-- <el-button type="info"    @click="roolback_query">成功订单&nbsp;刷新</el-button>
            <el-button type="warning" @click="retry_query">失败订单&nbsp;刷新</el-button> -->
          </el-row>
        </div>
      </el-form>
    </el-col>
    



    <!-- 查询订单的信息表 -->
    <el-table  :data="order_data"   v-loading="orderloading"  border style="width:100%;" v-if="lock_order" align="center" >
        <el-table-column  label="订单信息表" align="center">
			<el-table-column type="expand" align="center">
				<template slot-scope="props" >
					<el-form label-position="left" inline class="demo-table-expand">
					<el-form-item label="开始时间：">
						<span>{{ props.row.OPEN_TIME }}</span>
					</el-form-item>
					<el-form-item label="开仓价格：">
						<span>{{ props.row.OPEN_PRICE }}</span>
					</el-form-item>
					<el-form-item label="关闭时间：">
						<span>{{ props.row.CLOSE_TIME }}</span>
					</el-form-item>
					<el-form-item label="关闭价格：">
						<span>{{ props.row.CLOSE_PRICE }}</span>
					</el-form-item>
					<el-form-item label="佣金：">
						<span>{{ props.row.COMMISSION}}</span>
					</el-form-item>
					<el-form-item label="注释：">
						<span>{{ props.row.COMMENT ? props.row.COMMENT : "无"}}</span>
					</el-form-item>
					<el-form-item label="仓储费：">
						<span>{{ props.row.SWAPS }}</span>
					</el-form-item>
					</el-form>
				</template>
			</el-table-column>
			
			<el-table-column prop="LOGIN" label="用户号" width="167" align="center" ></el-table-column>
			<el-table-column prop="TICKET" label="订单号" width="165" align="center" ></el-table-column>
			<el-table-column prop="SYMBOL" label="品种"  align="center" ></el-table-column>
			<el-table-column prop="VOLUME" label="手数" width="165" align="center" ></el-table-column>
			<el-table-column prop="TP" label="止盈" width="165" align="center" ></el-table-column>
			<el-table-column prop="SL" label="止损" width="165" align="center" ></el-table-column>
			<el-table-column prop="PROFIT" label="利润" width="166" align="center" ></el-table-column>
		</el-table-column>
    </el-table>
	<br/>
	<br/>

<!--用户筛选列表--------- userdata 开始的位置-->
    <el-table  :data="userdata"  highlight-current-row   v-loading="listLoading"  @selection-change="selsChange"  :max-height="700" style="width: 100%;" border v-if="display_table">
		<el-table-column   label="用户信息表" align="center">
			<el-table-column type="selection" width="55"  align="center"></el-table-column>
			<el-table-column type="index" width="80"  align="center"></el-table-column>
			<el-table-column prop="NAME" label="姓名" width="120" sortable  align="center"></el-table-column>
			<el-table-column prop="GROUP" label="分组" width="100" sortable  align="center"></el-table-column>
			<el-table-column prop="LOGIN" label="用户名" width="120" sortable  align="center"></el-table-column>
			<el-table-column prop="BALANCE" label="用户余额" width="120" sortable  align="center"></el-table-column>
			<el-table-column label="Step"  sortable  align="center">{{this.filters.step}}</el-table-column>
			<el-table-column  prop="handsnum" label="手数"  sortable  align="center"></el-table-column>
			<el-table-column prop ="state" label="状态说明" width="180"  align="center">
				<template scope="scope">
				        <el-button type="success" size="small" v-show="scope.row.state==100">成功</el-button>
						<el-button type="danger"  size="small" v-show="scope.row.state!=100 && scope.row.state!=0">{{scope.row.state}}</el-button>
						<el-button  size="small" v-show="scope.row.state==0">暂无</el-button>
				</template>
			</el-table-column>
		</el-table-column>
    </el-table>

    <!--底部工具条-->
    <el-col :span="24" class="toolbar" v-if="display_table">
      <el-button type="danger" @click="Insert" :disabled="this.sels.length===0" :loading="loading_insert">Insert</el-button>
	  <el-button type="warning" @click="Preview" >刷新</el-button>
	  <el-button type="primary" @click="Insert_all" :loading="loading_insert">Insert全部</el-button>
      <el-pagination layout="total,sizes,prev, pager, next,jumper"   @size-change="handleSizeChange"  @current-change="handleCurrentChange" :page-sizes="[100, 200, 300, 500,1000,2000,total]"  :page-size="page_size" :total="total"  style="float:right;"></el-pagination>
    </el-col>

<!--用户筛选列表--------- userdata 结束的位置-->


<!-- 用户做过次订单的rollback 开始的位置-->
    <div  style="float:left;width:50%;" >
		<el-table  :data="rollbackdata_list"  highlight-current-row   v-loading="rollbackloading" :max-height="700" style="width:99%;"  border  v-if="lock_order" align="center" @selection-change="rollselsChange">
			<el-table-column  label="成功的订单" align="center">
				<el-table-column type="selection" width="55"  align="center"></el-table-column>
                <el-table-column type="index" width="70"  align="center"></el-table-column>
				<el-table-column prop="orig_order" label="操盘手订单" width="105"  align="center"></el-table-column>
				<el-table-column prop="orig_login" label="操盘手账号" width="105"  align="center"></el-table-column>
				<el-table-column prop="dest_order" label="客户订单" width="110"  align="center"></el-table-column>
				<el-table-column prop="dest_login" label="客户账号" width="110"  align="center"></el-table-column>
				<el-table-column prop="percentage" label="梯度"  align="center"></el-table-column>
				<el-table-column prop="state" label="状态" width="80" align="center">
					<template  scope="scope">
						<el-button type="success" size="small" v-show="scope.row.state==100">成功</el-button>
						<el-button type="danger"  size="small" v-show="scope.row.state!=100 && scope.row.state!=0">{{scope.row.state}}</el-button>
						<el-button  size="small" v-show="scope.row.state==0">暂无</el-button>
					</template>
				</el-table-column>
			</el-table-column>
		</el-table>

		<!--底部工具条-->
		<el-col  class="toolbar" v-if="lock_order" style="width:99%;" >
			<el-button type="danger" @click="Rollback" :disabled="this.rollback_sels.length===0"  :loading="loading_rollback">Rollback</el-button>
			 <el-button type="warning"  @click="roolback_query">刷新</el-button>
			 <el-button type="primary" @click="Rollback_all" :loading="loading_rollback">Rollback全部</el-button>
			<el-pagination layout="total,sizes,prev, pager, next,jumper" @current-change="rollbackCurrentChange"  @size-change="rollbackSizeChange"  :page-sizes="[100, 200, 300, 500,1000,2000,rollback_total]"     :page-size="rollback_page_size" :total="rollback_total" style="float:right;"></el-pagination>
		</el-col>
    </div>
<!-- 用户做过次订单的rollback 结束的位置-->


<!-- 用户做失败的订单  retry 开始的位置-->
    <div style="float:left;width:50%;">
		<el-table  :data="retrydata_list"  highlight-current-row   v-loading="retryloading" :max-height="700"  style="width:100%;"  border  v-if="lock_order" align="center" @selection-change="retryselsChange">
				<el-table-column  label="失败的订单" align="center">
					<el-table-column type="selection" width="55"  align="center"></el-table-column>
					<el-table-column prop="orig_order" label="操盘手订单" width="110"  align="center" ></el-table-column>
					<el-table-column prop="orig_login" label="操盘手账号" width="110"  align="center" ></el-table-column>
					<el-table-column prop="dest_order" label="客户订单" width="110"  align="center" ></el-table-column>
					<el-table-column prop="dest_login" label="客户账号" width="110"  align="center" ></el-table-column>
					<el-table-column prop="percentage" label="梯度" align="center" ></el-table-column>
					<el-table-column prop="state" label="状态" width="80">
						<template scope="scope">
							<el-button type="success" size="small" v-show="scope.row.state==100">成功</el-button>
							<el-button type="danger"  size="small" v-show="scope.row.state!=100 && scope.row.state!=0">{{scope.row.state}}</el-button>
							<el-button  size="small" v-show="scope.row.state==0">暂无</el-button>
						</template>
					</el-table-column>
				</el-table-column>
		</el-table>
		<!--底部工具条-->
		<el-col :span="10" class="toolbar" v-if="lock_order" style="width:100%;">
			<el-button type="danger"  @click="ErrorInsert"              :disabled="this.retry_sels.length===0"  :loading="loading_retry" >Retry</el-button>
			<el-button type="danger"  @click="ErrorInsert_all"                                                  :loading="loading_retry" >Retry执行全部</el-button>
			<el-button type="warning" @click="retry_query">刷新</el-button>
			<el-pagination layout="total,sizes,prev, pager, next,jumper" @current-change="retryCurrentChange"  @size-change="retrySizeChange"   :page-sizes="[100, 200, 300, 500,1000,2000,retry_total]"  :page-size="retry_page_size" :total="retry_total" style="float:right;"></el-pagination>
		</el-col>
	</div>
    

<!-- 用户做失败的订单  retry 结束的位置-->


<!-- 遮罩框的显示 -->
    <el-dialog  title="进度提示"   width="30%" :visible.sync="dialogVisible"  :before-close="handleClose" :show-close='false' >
		
		 <el-progress type="line" :percentage="child_num" ></el-progress>
		 
  </el-dialog>
	
<!-- 遮罩框的显示 -->	


  </section>
   
</template>

<script>
	import util from '../../common/js/util';
	import debugout from "../../common/js/debugout.js";
	//import NProgress from 'nprogress'
    
	export default {
		data() {
			return {
				filters: {
					group:'',                   //组的选择(数组的)
					username:'',                //用户名(用户的选择)
					step:'1000',                    //步长（step）
					tolerance:'1000',               //最小公差(tolerance)
					orderid:'',                 //订单号码 (设置的跟单)
					type:'',                    //信息的类型 (发起请求的类型)
					volume:'',                  //存储跟踪订单的volume信息
					send:''
				},

				users: [],                      //请求的所有用户
				userdata:[],                    //对用户数据进行（分割）
				total: 0,                       //用户总数
				page: 1,                        //用户的分页
                page_size:100,                   //用户分页的数目
				listLoading: false,             //用户表的loading效果
				sels: [],                       //用户表 列表选中列



                dialogVisible:false,            //控制是否显示锁屏
                child_num:0,                    //控制进度条的进度
                

				rollbackdata:[],                //rollback表的信息
                rollbackdata_list:[],           //rollback表中的数据分割
                rollback_page:1,                //rollback信息表中的分页
				rollback_total:0,               //rollback信息表中的用户总数
				rollback_page_size:100,         //rollback用户分页的数目
				rollbackloading:false,          //rollback信息表的loading效果
                rollback_sels:[],               //rollback信息表选中的列



				retrydata:[],                   //retry表的信息
                retrydata_list:[],              //retry信息表中的数据分割
				retryloading:false,             //retry信息表的loading效果
				retry_sels:[],                  //retry信息表选中的列
				retry_page:1,                   //retry信息表中的分页
                retry_total:0,                  //retry信息表中的用户总数
                retry_page_size:100,            //retry用户分页的数目


				lock_order:false,
				lock_step:false,
				display_step:false,
				display_user:false,
				display_table:false,
				socket: null,                   //socket对象的存储



                reConnect:null,                 //重新连接函数定时器存储
				order_data:[],                  //订单数据的存储
				orderloading:false,             //订单信息表的loading效果 


				rollback_index:0,               //rollback计数器
				insert_index:0,                 //insert计数器
				retry_index:0,                  //retry计数器
				loading_insert:false,
				loading_rollback:false,
                loading_retry:false,
				loading_getorder:false,
				bugout:null,
			}
		},
		mounted() {
			 this.connect();                     //一开始就开启连接	
			 this.bugout = new debugout();
			//监听键盘按键事件
			let self = this;
			this.$nextTick(function () {
				document.addEventListener('keyup', function (e) {
					//此处填写你的业务逻辑即可(此处我为ESC按键)
					if (e.keyCode == 27) {
						self.closeScreenFull();
					}
				})
			})
		},

		methods: {

			// 使用ESC按键取消弹出框
            closeScreenFull(){ 
				 this.dialogVisible =false;
				 this.child_num =0;
			},
			// 重置函数
			reset_info(){

				var _this = this;
				this.$confirm('确定重置信息', '提示', {
					//type: 'warning'
				}).then(() => {
					this.lock_order = false;
					this.lock_step = false;
					this.display_step = false;
					this.display_user = false;
					this.display_table = false;
					this.order_data =[];
					this.users=[];
					this.userdata=[];
					this.sels=[];

					this.filters.group='';
					this.filters.username='';
					this.filters.step='1000';
					this.filters.type='';
                    this.filters.orderid='';
					this.filters.tolerance='1000';

                    this.dialogVisible = false;
					this.page_size = 100;
					this.rollback_page_size= 100;
					this.retry_page_size = 100;
					
				}).catch(() => {
                    return false;
				});
            },

            handleClose(done) {
                return false;
			},
			//下载日志
			send_log(){
				console.log('下载日志');
				this.bugout.downloadLog();    //下载 
				//this.bugout.clear(); //清理日志
			},
			// 查询订单函数
			send_query(){
                //this.bugout.downloadLog();    下载
			   if(this.filters.orderid){
				  
                   this.orderloading = true;
                   this.loading_getorder = true;
				   //发起socket请求  
				   this.filters.type = 'vue_set_current_position'; 
                  
                    let para = {
						orderid: this.filters.orderid,                    //订单的信息
				    };
				    //向后端请求order信息
				    this.$api.post('/api/index/index/getorder',para,response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code ,data} = response.data;
								if(code=="00"){
									this.lock_order = true;         //锁定查询
									this.display_step = true;       //展示步长
									this.orderloading = false;
									this.filters.volume = data.VOLUME;
                   data.VOLUME = (data.VOLUME)/10000;   //前端显示的时候需要进行部分的计算
                                    this.order_data.push(data);
									this.loading_getorder = false;
									this.filters.send = data.send;
									this.socket.send(JSON.stringify(this.filters));   //socket请求发送
									this.roolback_query();
									this.retry_query();

								}else{
                                    this.orderloading = false;
                                    this.loading_getorder = false;
									this.$message.error(msg);
								}
							} else {

                                this.orderloading = false;
                                this.loading_getorder = false;
								console.log(response.message);

							}
					});
					   
			    }else{

				   this.$message.error("订单号码不能为空");

			   }
			},
			
			//步长和最小公差
            send_step(){

				if(this.filters.step && this.filters.tolerance){
					
					this.lock_step = true;
					this.display_user = true;

				}else{

					this.$message.error("请填写完整信息");
				}
			},

			//监听键盘输入事件
			set_step(){
               this.filters.tolerance = this.filters.step;
			},
			// insert表中选择的数据
			selsChange: function (sels) {
				this.sels = sels;
			},
			// rollback表中选择的数据
			rollselsChange:function(sels){
                this.rollback_sels = sels;
			},

			// retry表中选择的数据
			retryselsChange:function(sels){
                this.retry_sels = sels;
			},
            //预览函数( 目前筛选的是用户 ) 
			Preview: function() {
                
                let para = {
					group: this.filters.group,                    //组的 条件
					user: this.filters.username,                  //用户 条件
					order:this.filters.orderid                    //当前准备跟踪的订单
                };
                this.loading_insert = false;
				this.listLoading = true;
				var __that__ = this; 
				this.$api.post('/api/index/index/getuser',para,response => {
					if (response.status == 200 && response.status < 300) {
						let { msg, code ,user} = response.data;
						if(code=="00"){

							this.total = user.length;
							//对用户中的数据进行了计算
                            user.forEach(element => {
								if(element.BALANCE<__that__.filters.step){
									if( element.BALANCE>=__that__.filters.tolerance){
										element.handsnum = 0.01;   
										element.ladder =1;
									}else{
										element.handsnum =  __that__.toDecimal2(0);
										element.ladder =0;
									}
									
								}else if(element.BALANCE<=0){
									element.handsnum = __that__.toDecimal2(0);
									element.ladder = 0;
								}else{
									element.handsnum = __that__.toDecimal2(Math.floor((element.BALANCE/__that__.filters.step))*(__that__.filters.volume/1000000));    //对数据进行格式化(保留两位小数)
									element.ladder = parseInt(element.BALANCE/__that__.filters.step);
								}
								element.state =0;     //初始状态均为0 即是暂无
							});
							this.users = user;
							this.page_size = 100;
							this.userdata = this.users.slice((this.page-1)*this.page_size,this.page*this.page_size);
							this.listLoading = false;
							this.display_table = true;
						}else{

							// 失败就清除所有的用户信息
							this.$message.error(msg);
							this.listLoading = false;
							this.users=[];
							this.userdata=[];

						}
					} else {

						this.listLoading = false;
						console.log(response.message);

					}
				});
			},

			//用户信息表的分页
			handleCurrentChange(val) {
				this.page = val;
				this.userdata = this.users.slice((this.page-1)*this.page_size,this.page*this.page_size);
			},
			handleSizeChange(val) {
			    this.page_size = val;
			    this.page = 1;
                this.userdata = this.users.slice((this.page-1)*this.page_size,this.page*this.page_size);
            },
            //rollback中数据和分页的对应 
			rollbackCurrentChange(val){
				this.rollback_page = val;
				this.rollbackdata_list = this.rollbackdata.slice((this.rollback_page-1)*this.rollback_page_size,this.rollback_page*this.rollback_page_size);
			},
			rollbackSizeChange(val){
                this.rollback_page_size = val;
			    this.rollback_page = 1;
                this.rollbackdata_list = this.rollbackdata.slice((this.rollback_page-1)*this.rollback_page_size,this.rollback_page*this.rollback_page_size);
			},
			//retry中分页和数据的对应 
			retryCurrentChange(val){
			   this.retry_page = val;
			   this.retrydata_list = this.retrydata.slice((this.retry_page-1)*this.retry_page_size,this.retry_page*this.retry_page_size);
			},

			retrySizeChange(val){
                this.retry_page_size = val;
			    this.retry_page = 1;
                this.retrydata_list = this.retrydata.slice((this.retry_page-1)*this.retry_page_size,this.retry_page*this.retry_page_size);
			},

            //插入函数
			Insert:function() {
				var _this = this;
				this.$confirm('确认操作吗?', '提示', {
					//type: 'warning'
				}).then(() => {

                    // 二次确认密码
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
					}).then(({ value }) => {
						console.log(value);
						var loginParams = { password: value,nickname:JSON.parse(sessionStorage.getItem('user'))};  //传递过去用户名和密码
						// 向后台请求密码的正确性
						_this.$api.post('/api/index/index/querypassword',loginParams, response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code } = response.data;
								if(code=="00"){
                                   console.log('插入函数');
								    for (let index = 0; index < _this.sels.length; index++) {
										const element = _this.sels[index];
										if(element.state !=0){
											_this.$message.error("含有做过的单");
											return false;
										}else{
											if(element.BALANCE<_this.filters.tolerance){
												
												_this.sels.splice(index,1);        //删除手数为0的元素
												index = index-1;                   //因为数组会改变,所以长度也会变化
												continue;                          //结束本次循环
											}
										    element.step = _this.filters.step;  //加入步长的计算	
										}
									}
									if(_this.sels.length==0){
										_this.$message.error("没有任何选择");
										return false;
									}
									_this.insert_index = 0;
									_this.loading_insert = true;
									_this.dialogVisible = true;
									let data_insert={};
									data_insert.type = 'vue_insert';
									data_insert.orderid = _this.filters.orderid;
									data_insert.data = _this.sels;      //数组的格式(多个数据发送过去)
								
									//发送socket
									_this.socket.send(JSON.stringify(data_insert));

								}else{
									this.logining = false;
									this.$message.error(msg);
								}
							} else {
								this.logining = false;
								console.log(response.message);
							}
						});
						
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});       
					});
				}).catch(() => {
                   console.log('取消了');
				});
				
			},
			//插入全部函数
			Insert_all(){
               //将所有的数据传递给sels    
			   this.sels = this.users;
			   this.Insert();             //发送数据

			},

			ErrorInsert_all(){
				 this.retry_sels = this.retrydata;
				 this.ErrorInsert();
			},
			//失败订单insert
			ErrorInsert:function() {
				
				/*var _this = this;
				this.$confirm('确认操作吗?', '提示', {
					//type: 'warning'
				}).then(() => {
					
					console.log('ErrorInsert函数');
                    // 二次确认密码
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
					}).then(({ value }) => {
						var loginParams = { password: value,nickname:JSON.parse(sessionStorage.getItem('user'))};
						// 向后台请求密码的正确性
						_this.$api.post('/api/index/index/querypassword',loginParams, response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code } = response.data;
								if(code=="00"){
								    console.log('ErrorInsert');
									// 验证成功开始执行rollback操作    retry_sels
								
									if(_this.retry_sels.length==0){
										_this.$message.error("没有任何选择");
										return false;
									}
									_this.retry_index =0;
									_this.loading_retry = true;
									_this.dialogVisible = true;
								
									let data_insert={};
									data_insert.type = 'vue_insert'; 
									
									data_insert.message = 'ErrorInsert';
									for( var i in _this.retry_sels){
										
										_this.retry_sels[i].LOGIN = parseInt(_this.retry_sels[i].dest_login);
										_this.retry_sels[i].ladder = parseInt(_this.retry_sels[i].percentage);
									}
									data_insert.orderid = _this.filters.orderid;
									data_insert.data = _this.retry_sels;
									console.log(data_insert);		return false;						
									// 发送socket
									_this.socket.send(JSON.stringify(data_insert));

								}else{
									this.logining = false;
									this.$message.error(msg);
								}
							} else {
								this.logining = false;
								console.log(response.message);
							}
						});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});       
					});

				}).catch(() => {

                    console.log("取消了");
				});*/
			

			//-----------------------------------------

				var _this = this;
				this.$confirm('确认Retry操作吗?', '提示', {
					//type: 'warning'
				}).then(() => {
					console.log('retry函数');
                    this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
					}).then(({ value }) => {
                        if(!(_this.filters.step)){
							this.$message.error("请填写Step信息");
							return false;
						}
						if(!(_this.filters.tolerance)){
							this.$message.error("请填写Tolerance信息");
							return false;
						}	
						var loginParams = { password: value,nickname:JSON.parse(sessionStorage.getItem('user'))};
						// 向后台请求密码的正确性
						_this.$api.post('/api/index/index/querypassword',loginParams, response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code } = response.data;
								if(code=="00"){
                                    console.log(_this.retry_sels);
									var retry_obj =[]; //空数组
                                    _this.retry_sels.forEach(element => {
										retry_obj.push(element.dest_login);      //获取到数组的login数据
									});

									// 重新更新retry中数据的  percentage  的数据
                                    _this.$api.post('/api/index/index/update_percentage',retry_obj, response => {
										if (response.status == 200 && response.status < 300) {
											 let { msg, code , data} = response.data;

											//对请求的数量进行格式的梳理
											if(code=="00"){
												var data_arr = []
												for (let i in data) {
													let o = {};
													o[i] = data[i];
													data_arr.push(o);
												}


											    //获取到数据   
												data_arr.forEach((element,index) => {
														_this.retry_sels.forEach(element1 => {
															
															// 对所有的数据重新进行更新梯度操作
															if(element[element1.dest_login]){
																let balance = element[element1.dest_login]; //获取到的余额  percentage
																_this.$set(element1,'LOGIN',element1.dest_login);
																if(balance<_this.filters.step){
																		if( balance >= _this.filters.tolerance){
																			_this.$set(element1,'ladder',1);
																		}else{
																			_this.$set(element1,'ladder',0);
																		}
																		
																}else{
																		
																		_this.$set(element1,'ladder',parseInt(balance/_this.filters.step));
																	}
															
															}
														});
												});

											    if(_this.retry_sels.length==0){
													_this.$message.error("没有任何选择");
													return false;
												}

											   //对改变完成的数据进行发送
												_this.retry_index =0;
											
												_this.loading_retry = true;
												_this.dialogVisible = true;
												let data_insert={};
												data_insert.type = 'vue_insert'; 
												data_insert.message = 'ErrorInsert';
												data_insert.orderid = _this.filters.orderid;
												data_insert.data = _this.retry_sels;
												
												// 发送socket
												_this.socket.send(JSON.stringify(data_insert));

											}else{
											   console.log(response.msg);
											}
										} else {
											console.log(response.message);
										}
									});
									
								}else{
									this.logining = false;
									this.$message.error(msg);
								}
							} else {
								this.logining = false;
								console.log(response.message);
							}
						});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});       
					});
				}).catch(() => {
                    console.log("取消了");
				});

			},
            //rollback函数
			Rollback:function() {
				var _this = this;
				this.$confirm('确认操作吗?', '提示', {
					//type: 'warning'
				}).then(() => {
					console.log('rollback函数');
                    // 二次确认密码
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
					}).then(({ value }) => {
						var loginParams = { password: value,nickname:JSON.parse(sessionStorage.getItem('user'))};
						// 向后台请求密码的正确性
						_this.$api.post('/api/index/index/querypassword',loginParams, response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code } = response.data;
								if(code=="00"){
								    console.log('插入函数');
								    // 验证成功开始执行rollback操作    
									if(_this.rollback_sels.length==0){
										_this.$message.error("没有任何选择");
										return false;
									}
									_this.rollback_index = 0;
									_this.loading_rollback = true;
									_this.dialogVisible = true;
									let data_insert={};
									data_insert.type = 'vue_rollback'; 
									data_insert.data = _this.rollback_sels;
									// 发送socket
									_this.socket.send(JSON.stringify(data_insert));

								}else{
									this.logining = false;
									this.$message.error(msg);
								}
							} else {
								this.logining = false;
								console.log(response.message);
							}
						});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});       
					});

				}).catch(() => {

                    console.log("取消了");
				});
				
			},
			Rollback_all(){
				//将所有的数据传递给rollback_sels
				this.rollback_sels = this.rollbackdata;
				this.Rollback();            //发送数据
			},
			
			// retry表中的数据进行  rollback
			Rollback_retry(){
				var _this = this;
				this.$confirm('确认rollback吗?', '提示', {
					//type: 'warning'
				}).then(() => {

                    this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
					}).then(({ value }) => {
						var loginParams = { password: value,nickname:JSON.parse(sessionStorage.getItem('user'))};
						// 向后台请求密码的正确性
						_this.$api.post('/api/index/index/querypassword',loginParams, response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code } = response.data;
								if(code=="00"){
									console.log('retry表中rollback');

									// 验证成功开始执行retry表中的rollback操作    
									if(_this.retry_sels.length==0){
										_this.$message.error("没有任何选择");
										return false;
									}

									_this.retry_index =0;
									_this.loading_retry = true;
									_this.dialogVisible = true;
									let data_insert={};
									data_insert.type = 'vue_except_rollback';
									data_insert.data = _this.retry_sels;
									// 发送socket
									_this.socket.send(JSON.stringify(data_insert));
									
								}else{
									this.logining = false;
									this.$message.error(msg);
								}
							} else {
								this.logining = false;
								console.log(response.message);
							}
						});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});       
					});
				}).catch(() => {
                   console.log("取消了");
				});
			   
			}, 

			// retry表中的数据进行     rollback全部
            Rollback_retry_all(){
			   this.retry_sels = this.retrydata;    //将所有的数据传递给retry_sels
               this.Rollback_retry();             //执行Rollback_retry函数
			},


			//retry 函数
			Retry:function(params) {
                var _this = this;
				this.$confirm('确认Retry操作吗?', '提示', {
					//type: 'warning'
				}).then(() => {
					console.log('retry函数');
                    this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
					}).then(({ value }) => {
                        if(!(_this.filters.step)){
							this.$message.error("请填写Step信息");
							return false;
						}
						if(!(_this.filters.tolerance)){
							this.$message.error("请填写Tolerance信息");
							return false;
						}	
						var loginParams = { password: value,nickname:JSON.parse(sessionStorage.getItem('user'))};
						// 向后台请求密码的正确性
						_this.$api.post('/api/index/index/querypassword',loginParams, response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code } = response.data;
								if(code=="00"){
                                    console.log(_this.retry_sels);
									var retry_obj =[]; //空数组
                                    _this.retry_sels.forEach(element => {
										retry_obj.push(element.dest_login);      //获取到数组的login数据
									});

									// 重新更新retry中数据的  percentage  的数据
                                    _this.$api.post('/api/index/index/update_percentage',retry_obj, response => {
										if (response.status == 200 && response.status < 300) {
											 let { msg, code , data} = response.data;

											//对请求的数量进行格式的梳理
											if(code=="00"){
												var data_arr = []
												for (let i in data) {
													let o = {};
													o[i] = data[i];
													data_arr.push(o);
												}


											    //获取到数据   
												data_arr.forEach((element,index) => {
														_this.retry_sels.forEach(element1 => {
															
															// 对所有的数据重新进行更新梯度操作
															if(element[element1.dest_login]){
																let balance = element[element1.dest_login]; //获取到的余额  percentage
																if(balance<_this.filters.step  && balance>_this.filters.tolerance){
																	_this.$set(element1,'percentage',1);	
																}else{
																	_this.$set(element1,'percentage',parseInt(balance/_this.filters.step));
																}
															}
														});
												});

											    if(_this.retry_sels.length==0){
													_this.$message.error("没有任何选择");
													return false;
												}

											   //对改变完成的数据进行发送
												_this.retry_index =0;
												_this.loading_retry = true;
												_this.dialogVisible = true;
												let data_insert={};
												data_insert.type = 'vue_retry';
												data_insert.data = _this.retry_sels;
												// 发送socket
												_this.socket.send(JSON.stringify(data_insert));

											}else{
											   console.log(response.msg);
											}
										} else {
											console.log(response.message);
										}
									});
									
								}else{
									this.logining = false;
									this.$message.error(msg);
								}
							} else {
								this.logining = false;
								console.log(response.message);
							}
						});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});       
					});
				}).catch(() => {
                    console.log("取消了");
				});
				
			},

			//retry表中  retry执行全部
			Retry_all(){
				this.retry_sels = this.retrydata;  //将所有的数据传递给retry_sels
                this.Retry();                      //执行Retry函数
			},
		
            // socket连接函数
			connect: function () {
				    var _that_ = this;
					//this.socket = new WebSocket('ws://47.106.182.13:12380');
					//this.socket = new WebSocket('ws://154.218.25.112:12381');
					this.socket = new WebSocket('ws://127.0.0.1:12381');
					//连接成功后的回调函数
                    this.socket.onopen = function () {
                        clearInterval(this.reConnect);
                        _that_.heartbeatStart();
					};

					//指定收到服务器数据后的回调函数
                    this.socket.onmessage = function (e) {
						var msg = JSON.parse(e.data);        //对返回的信息进行处理
                        if (msg) {
						   
                            switch (msg['type']) {
								case "heartbeat":                          //心跳检测
									break; 
								case "get_order_record":                   //查询当前跟单订单									
									break;
								case "set_current_order":                  //设置当前跟单订单信息							
									break;
                                case "insert":                             //插入发送内容
                                    var insert_data = msg['dest'];         //将数组数据传递过去  
									_that_.insert_index+=insert_data.length;
									console.log("insert执行了");
									var arraylog=[_that_.insert_index,_that_.sels.length];
									_that_.bugout.log(arraylog);
									
									_that_.child_num = (Math.round(_that_.insert_index / _that_.sels.length * 10000) / 100.00);
									console.log(_that_.child_num);
                                    if(_that_.sels.length == _that_.insert_index){
										// 全部执行完成后，对所有不是失败的数据，进行成功操作
										_that_.sels.forEach((element1,index) => {
											if(element1.state == 0){
												_that_.$set(element1,'state',100);         //成功的订单
                                            }
										});
                                        _that_.loading_insert = false;
										_that_.insert_index = 0;
										_that_.dialogVisible = false;
										_that_.child_num = 0;
                                    }
                                    insert_data.forEach(element => {      
                                        if(element['error_code']!=0){
                                            _that_.sels.forEach((element1,index) => {
                                                if(element1.LOGIN==element['dest_login']){
                                                   _that_.$set(element1,'state',element['error_code']); //失败的订单(显示为错误码)
                                                }
                                            });
                                        }
									});
									break;
								case "rollback":                           //Rollback请求
                                    var rollback_data = msg['desc'];         //将数组数据传递过去
                                    _that_.rollback_index += rollback_data.length;
									console.log('rollback执行了');
									var arraylog=[_that_.rollback_index,_that_.rollback_sels.length];
									_that_.bugout.log(arraylog);
									_that_.child_num = (Math.round(_that_.rollback_index / _that_.rollback_sels.length * 10000) / 100.00);
                                    if(_that_.rollback_sels.length == _that_.rollback_index){
										//对所有不是失败的订单，变为成功的状态
                                        _that_.rollback_sels.forEach((element1,index) => { 
											if(element1.state == 0){
												_that_.$set(element1,'state',100);
                                            }
                                        });
                                        _that_.loading_rollback = false;
										_that_.rollback_index = 0;
										_that_.dialogVisible = false;
										_that_.child_num = 0;
                                    }
                                    rollback_data.forEach(element => {
										if(element['error_code']!=0){
											//rollback不成功了 将状态更新为失败
                                            _that_.rollback_sels.forEach((element1,index) => { 
												if(element1.dest_login==element['dest_login']){
													_that_.$set(element1,'state',element['error_code']);
                                                }
                                            });
                                        }
									});
									break;
								case "except_rollback":                    //Rollback请求
									console.log('except_rollback');
									var except_rollback_data = msg['desc'];
									_that_.retry_index+=except_rollback_data.length;
									var arraylog=[_that_.retry_index,_that_.retry_sels.length];
									_that_.bugout.log(arraylog);
									_that_.child_num = (Math.round(_that_.retry_index / _that_.retry_sels.length * 10000) / 100.00);

									if(_that_.retry_sels.length == _that_.retry_index){
										_that_.loading_retry = false;
										_that_.retry_index = 0;
										_that_.dialogVisible= false;
										_that_.child_num = 0;
                                    }
                                    except_rollback_data.forEach(element => {
										if(element['error_code']!=0){
											//rollback不成功了 将状态更新为失败
                                            _that_.retry_sels.forEach((element1,index) => { 
												if(element1.dest_login==element['dest_login']){
													_that_.$set(element1,'state',element['error_code']);
                                                }
                                            });
                                        }else{
											//对所有不是失败的订单，变为成功的状态
											_that_.retry_sels.forEach((element2,index) => { 
												if(element2.dest_login==element['dest_login']){
													_that_.$set(element2,'state',100);
                                                }
                                            });
										}
									});
									break;
								case "ErrorInsert":
									var retry_datas = msg['dest'];
									console.log("ErrorInsert");
								
									_that_.retry_index += retry_datas.length; 
							
									var arraylog = [_that_.retry_index,_that_.retry_sels.length];
									
									_that_.bugout.log(arraylog);
									_that_.child_num = (Math.round(_that_.retry_index / _that_.retry_sels.length * 10000) / 100.00);  //进度条变化

									if(_that_.retry_sels.length == _that_.retry_index){
										_that_.loading_retry = false;
										_that_.retry_index = 0;
										_that_.dialogVisible= false;
										_that_.child_num = 0;
                                    }
                                    retry_datas.forEach(element => {
										if(element['error_code']!=0){
											//retry不成功了 将状态更新为失败
                                            _that_.retry_sels.forEach((element1,index) => { 
												if(element1.dest_login==element['dest_login']){
													_that_.$set(element1,'state',element['error_code']);
                                                }
                                            });
                                        }else{
											//对所有不是失败的订单，变为成功的状态
											_that_.retry_sels.forEach((element2,index) => { 
												if(element2.dest_login==element['dest_login']){
													_that_.$set(element2,'state',100);
                                                }
                                            });
										}
									});
									break;
								case "retry":                              //Retry请求
									console.log('retry');
									var retry_data = msg['desc'];
									_that_.retry_index+=retry_data.length;    //retry_index的长度变化
									var arraylog=[_that_.retry_index,_that_.retry_sels.length];
									_that_.bugout.log(arraylog);
									_that_.child_num = (Math.round(_that_.retry_index / _that_.retry_sels.length * 10000) / 100.00);  //进度条变化

									if(_that_.retry_sels.length == _that_.retry_index){
										_that_.loading_retry = false;
										_that_.retry_index = 0;
										_that_.dialogVisible= false;
										_that_.child_num = 0;
                                    }
                                    retry_data.forEach(element => {
										if(element['error_code']!=0){
											//retry不成功了 将状态更新为失败
                                            _that_.retry_sels.forEach((element1,index) => { 
												if(element1.dest_login==element['dest_login']){
													_that_.$set(element1,'state',element['error_code']);
                                                }
                                            });
                                        }else{
											//对所有不是失败的订单，变为成功的状态
											_that_.retry_sels.forEach((element2,index) => { 
												if(element2.dest_login==element['dest_login']){
													_that_.$set(element2,'state',100);
                                                }
                                            });
										}
									});
									break;   
								default:
								    console.log('未知接口');
									break;
						    }
                        }
					};

                    //用于指定连接关闭后的回调函数 
                    this.socket.onclose = function () {
                        clearInterval(_that_.heartbeat);   //清除 心跳检测函数  
						console.log("closed");              
                        _that_.reConnectStart();           //重新连接
					};	
			},


			//重新连接 开始
			reConnectStart: function () {
				var _that_ = this;
				clearInterval(this.reConnect);
				_that_.reConnect = setInterval(function () {
					console.log("reConnect");
					_that_.connect();
				}, 5000);      
			},
	
			//心跳函数检测
			heartbeatStart: function () {
				var _that_ = this;
				this.heartbeat = setInterval(function () {
                    _that_.socket.send(JSON.stringify({
                        type: "heartbeat"
					}));
                }, 30000);
			},



			//查询roolback信息(数据库中获取)
            roolback_query(){
			        let para = {
					    orderid: this.filters.orderid,                              //订单的信息
					};
                    this.rollbackloading = true;
                    this.loading_rollback =false;
                    this.rollback_index = 0;
				    //向后端请求order信息
				    this.$api.post('/api/index/index/rollback_order',para,response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code ,data} = response.data;
								if(code=="00"){

									data.forEach(element => {
										element.state = element.error_code;          //获取状态码的状态(此时一定为0)
									});
									this.rollback_total = data.length;               //获取数据的总数量
									this.rollbackloading =false;
									this.rollbackdata = data;
									this.rollback_page_size = 100;
									this.rollbackdata_list = this.rollbackdata.slice((this.rollback_page-1)*this.rollback_page_size,this.rollback_page*this.rollback_page_size);
								}else{
									this.rollbackloading = false;
									this.rollback_total=0;
									this.rollbackdata =[];
									this.rollbackdata_list = [];	
								}
							} else {

								this.rollbackloading = false;
								console.log(response.message);

							}
					});
			},

			//查询retry表的信息(数据库获取过来)
            retry_query(){
                let para = {
					orderid: this.filters.orderid,                    //订单的信息
				};
                this.retryloading = true;
                this.loading_retry = false;
			    //向后端请求order信息
				this.$api.post('/api/index/index/retry_order',para,response => {
							if (response.status == 200 && response.status < 300) {
								let { msg, code ,data} = response.data;
								if(code=="00"){
									data.forEach(element => {
								        element.state = element.error_code;
							        });
									this.retry_total = data.length;              //获取数据的总数量
									this.retryloading = false;
									this.retrydata = data;
									this.retry_page_size = 100;
									this.retrydata_list = this.retrydata.slice((this.retry_page-1)*this.retry_page_size,this.retry_page*this.retry_page_size);
								}else{
									this.retryloading = false;
									this.retry_total=0;
									this.retrydata=[];
									this.retrydata_list=[];
								}
							} else {
								this.retryloading = false;
								console.log(response.message);
							}
				});
			},
            //保留两位小数的函数 
			toDecimal2(x) {
				var f = parseFloat(x);
				if (isNaN(f)) {
					return false;
				}
				var f = Math.round(x * 100) / 100;
				var s = f.toString();
				var rs = s.indexOf('.');
				if (rs < 0) {
					rs = s.length;
					s += '.';
				}
				while (s.length <= rs + 2) {
					s += '0';
				}
				return s;
			},

        },
	}
</script>

<style>
.demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
   .el-dialog .el-dialog__header{
        text-align: center;
   }
  .el-dialog .el-dialog__body{
    text-align: center !important;
  }
  .el-dialog--small{
     top: 30% !important;
	 width: 30%;
  }
</style>