我有详细的商店列表。我已经存储了日间商店的开放时间和关闭时间。我需要花时间和当前时间检查每个商店的日期和时间(我有开店时间的商店开放日和关闭时间)。如果当前时间与商店开放时间订单按钮匹配应该启用。如果当前日期和时间没有成功我需要禁用button.i新技术请帮助我一些
示例:今天是星期二,如果时间是08.00PM只有一个商店订单按钮应该启用ragu移动服务中心订单按钮演示demo。我试图花一天时间但我无法接受bcoz我是初学者,请帮助我完成这项任务。
angular.module('myApp', [])
.controller("myCntrl", function ($scope,$filter) {
$scope.dealers = [{
S_Email_id: "aditiya@gmail.com",
S_Store: "samsung",
status:"",
Store_Name: "Adtiya Samsung Store",
S_Services: "Regular Service,Software Faults,Hardware Faults",
Store_long_description: "Undertake all kind of samsung mobiles",
Store_short_description: "Undertake all kind of samsung mobiles",
Day: {
"monday": "09:10AM - 06:30PM",
"tuesday": "09:10AM - 06:30PM",
"wednesday": "09:10AM - 06:30PM",
"thursday": "09:10AM - 06:30PM",
"friday": "09:10AM - 06:30PM",
"saturday": "10:15AM - 04:15PM",
"sunday":"10:15AM - 04:15PM"
},
}, {
S_Email_id: "rajs@gmail.com",
S_Store: "nokia",
status:"",
Store_Name: "sri shakthi mobile service",
S_Services: "Settings Faults,Regular Service,Hardware Faults",
Store_long_description: "Undertake all kind of nokia mobiles",
Store_short_description: "Undertake all kind of nokia mobiles",
Day: {
"monday": "09:00AM - 06:00PM",
"tuesday": "09:00AM - 06:00PM",
"wednesday": "09:00AM - 06:00PM",
"thursday": "09:00AM - 06:00PM",
"friday": "09:00AM - 06:00PM",
"saturday": "09:00AM - 06:00PM",
"sunday":"Leave"
},
}, {
S_Email_id: "sprtive23@gmail.com",
S_Store: "nokia,samsung",
status:"",
Store_Name: "sun mobile service center",
S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles",
Day: {
"monday": "08:30AM - 07:30PM",
"tuesday": "08:30AM - 07:30PM",
"wednesday": "08:30AM - 07:30PM",
"thursday": "08:30AM - 07:30PM",
"friday": "08:30AM - 07:30PM",
"saturday": "08:15AM - 02:15PM",
"sunday":"8:15AM - 12:15AM"
},
},
{
S_Email_id: "super@gmail.com",
S_Store: "nokia,samsung",
status:"",
Store_Name: "ragu mobile service center",
S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles",
Day: {
"monday": "10:00AM - 10:00PM",
"tuesday": "10:00AM - 10:00PM",
"wednesday": "10:00AM - 10:00PM",
"thursday": "10:00AM - 10:00PM",
"friday": "10:00AM - 10:00PM",
"saturday": "leave",
"sunday":"leave"
},
}
]
var date = new Date();
$scope.hhmmsstt = $filter('date')(new Date(), 'hh:mm:ss a');
//console.log($scope.hhmmsstt);
}
)
<div ng-app="myApp">
<div ng-controller="myCntrl">
<label>Search on Label</label><br>
<input ng-model="query" type="text" placeholder="Search for name" />
<br><br>
<div ng-repeat="dealer in dealers">
{{dealer.Store_Name}}<br>
{{dealer.S_Email_id}}<br>
{{dealer.Day}}<br>
<input type="button" value="order"/>
<br><br><br>
</div>
</div>
</div>
答案 0 :(得分:0)
您想在ng-disabled
按钮上使用input
,并使用表达式将今天与dealer.Day
内的星期几进行比较,然后您必须将日期值拆分为“ - ”获取开始和结束时间,并检查现在是否在这两次之间。它需要日期转换和解析。
angular.module('myApp', [])
.controller("myCntrl", function($scope, $filter) {
$scope.isOpen = function(dealerSchedule) {
var now = new Date();
// 09:10AM - 06:30PM
var times = dealerSchedule[Object.keys(dealerSchedule)[now.getDay() - 1]].replace(/(\d\d\:\d\d)(AM|PM)/g, '1/1/1900 $1 $2').split(" - ");
var nowTime = new Date('1/1/1900 ' + now.toLocaleTimeString(navigator.language, {
hour: '2-digit',
minute: '2-digit',
hour12: true
}));
return nowTime >= new Date(times[0]) && nowTime <= new Date(times[1]);
};
$scope.dealers = [{
S_Email_id: "aditiya@gmail.com",
S_Store: "samsung",
status: "",
Store_Name: "Adtiya Samsung Store",
S_Services: "Regular Service,Software Faults,Hardware Faults",
Store_long_description: "Undertake all kind of samsung mobiles",
Store_short_description: "Undertake all kind of samsung mobiles",
Day: {
"monday": "09:10AM - 06:30PM",
"tuesday": "09:10AM - 12:00PM",
"wednesday": "09:10AM - 10:30AM",
"thursday": "09:10AM - 06:30PM",
"friday": "09:10AM - 06:30PM",
"saturday": "10:15AM - 04:15PM",
"sunday": "10:15AM - 04:15PM"
},
}, {
S_Email_id: "rajs@gmail.com",
S_Store: "nokia",
status: "",
Store_Name: "sri shakthi mobile service",
S_Services: "Settings Faults,Regular Service,Hardware Faults",
Store_long_description: "Undertake all kind of nokia mobiles",
Store_short_description: "Undertake all kind of nokia mobiles",
Day: {
"monday": "09:00AM - 06:00PM",
"tuesday": "09:00AM - 06:00PM",
"wednesday": "09:00AM - 06:00PM",
"thursday": "09:00AM - 06:00PM",
"friday": "09:00AM - 06:00PM",
"saturday": "09:00AM - 06:00PM",
"sunday": "Leave"
},
}, {
S_Email_id: "sprtive23@gmail.com",
S_Store: "nokia,samsung",
status: "",
Store_Name: "sun mobile service center",
S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles",
Day: {
"monday": "08:30AM - 07:30PM",
"tuesday": "02:30PM - 07:30PM",
"wednesday": "08:30AM - 07:30PM",
"thursday": "08:30AM - 07:30PM",
"friday": "08:30AM - 07:30PM",
"saturday": "08:15AM - 02:15PM",
"sunday": "8:15AM - 12:15AM"
},
}, {
S_Email_id: "super@gmail.com",
S_Store: "nokia,samsung",
status: "",
Store_Name: "ragu mobile service center",
S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles",
Day: {
"monday": "10:00AM - 10:00PM",
"tuesday": "10:00AM - 10:00PM",
"wednesday": "10:00AM - 10:00PM",
"thursday": "10:00AM - 10:00PM",
"friday": "10:00AM - 10:00PM",
"saturday": "leave",
"sunday": "leave"
},
}]
var date = new Date();
$scope.hhmmsstt = $filter('date')(new Date(), 'hh:mm:ss a');
//console.log($scope.hhmmsstt);
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="myCntrl">
<label>Search on Label</label>
<br>
<input ng-model="query" type="text" placeholder="Search for name" />
<br>
<br>
<div ng-repeat="dealer in dealers">
{{dealer.Store_Name}}
<br>{{dealer.S_Email_id}}
<br>{{dealer.Day}}
<br>
<input type="button" value="order" ng-disabled="!isOpen(dealer.Day)" />
<span>{{isOpen(dealer.Day) ? 'Open' : 'Closed'}}</span>
<br>
<br>
<br>
</div>
</div>
</div>