功能描述:
数据库add_time+5分钟倒计时,是否等于数据库add_time
index页会有很多条数据:
做法:
(以秒计算)一、js拿着name的值循环+60秒,再赋值给name
.二、再拿着赋给name的值去做倒计时操作
三、倒计时的时候,若其中一条已为0,则arr[i]=-1;(表示很多条数据减去时间为0的)
x下面附代码:
html:
input type="text" name="assignments_time" value="{{$item->assignments_time}}"/>
<td style="color:red;"><strong class="RemainM">已超时</strong></td>
JS:
$(function () {
//当前时间
var order_status =$('input[name="order_status"]');
var timetamp4 = Number(new Date());
var timer =$('input[name="assignments_time"]');
var a_id =$('input[name="a_id"]');
var showtime =$('strong[class="RemainM"]');
var arr = [];
$.each(order_status,function (i,b) {
if(b.valueOf().value !=403){//满足条件的才会倒计时
$.each(timer, function (i, v) {
var temp =parseInt(v.valueOf().value) +60 -parseInt(timetamp4 /1000);
if(temp>0){
showtime[i].innerHTML =parseInt(temp/60)+"分"+parseInt(temp%60)+"秒";
arr[i]=temp;
}
})
}
})
//倒计时操作
if(arr.length >1){
window.setInterval(function () {
timing();
}, 1000);
}
// console.log(arr)
function timing() {
$.each(timer, function (i, v) {
var temp = arr[i];
var status=order_status[i];
if(temp>0){
showtime[i].innerHTML =parseInt(temp/60)+"分"+parseInt(temp%60)+"秒";
arr[i]=temp-1;
}else if(temp ==0){
arr[i]=-1;
showtime[i].innerHTML ="已超时";
var aid=a_id[i];
//修改数据库状态
var status=order_status[i];
aid=aid.valueOf().value;
status=status.valueOf().value;
var token = $('meta[name="csrf-token"]').attr('content');
var url = "/dist_edit";
$.ajax({
url: url,
dataType: 'json',
type: 'post',
data: {'id': aid, 'order_status': status, "_token": token},
async: false,
success: function (info) {
if (info.code === 1) {
setTimeout(function () {
location.href = "/dist";
}, 1000);
}
// layer.msg(info.msg);
}, error: function (e) {
//console.log(e.status)
}
});
}
})
}
})
PHP:
public function dist_edit(Request $request){
if(!empty($request->post())){
if($request->post("order_status") == 103){
$res=DB::table('assignments')
->where('id', $request->post("id"))
->update(['order_status' => '404']);//上传超时
}
if($res){
return json_encode(['msg'=>'更改成功','code'=>1]);
}else{
return json_encode(['msg'=>'更改失败','code'=>3]);
}
}else{
return json_encode(['msg'=>'不是post提交','code'=>0]);
}
}