HTML:
<div class="item row row-wrap row-no-padding" style="height: 50px;border: none;padding-left: 10px;">
<div class="col col-33 col-center">
<p style="font-size: 16px;">服务态度</p>
</div>
<div class="col col-center">
<p>
<a style="float: right;">
<i ng-class="{true: 'icon ion-ios-star energized', false: 'icon ion-ios-star-outline'}[service[0]]"
ng-click="chooseService(0)" style="font-size: 30px;"></i>
<i ng-class="{true: 'icon ion-ios-star energized', false: 'icon ion-ios-star-outline'}[service[1]]"
ng-click="chooseService(1)" style="font-size: 30px;"></i>
<i ng-class="{true: 'icon ion-ios-star energized', false: 'icon ion-ios-star-outline'}[service[2]]"
ng-click="chooseService(2)" style="font-size: 30px;"></i>
<i ng-class="{true: 'icon ion-ios-star energized', false: 'icon ion-ios-star-outline'}[service[3]]"
ng-click="chooseService(3)" style="font-size: 30px;"></i>
<i ng-class="{true: 'icon ion-ios-star energized', false: 'icon ion-ios-star-outline'}[service[4]]"
ng-click="chooseService(4)" style="font-size: 30px;"></i>
</a>
</p>
</div>
</div>
JS:
//星级评价
$scope.service = [false, false, false, false, false];
$scope.satisfaction = [false, false, false, false, false];
//点击一个,看他是否被选中,如果他被选中,他上面也被选中,那么就把上面的全去掉,如果上面的没选中,那就把之前的全去掉
//点击一个,如果他没被选中,那就到他这为止都选中
$scope.chooseService = function (index) {
if (index == 4)//选中最后一个
{
if ($scope.service[index]) {
for (var i = 0; i < 5; i++)
$scope.service[i] = false;
}
else //如果没有选中
{
for (var i = 0; i < 5; i++)
$scope.service[i] = true;
}
}
else {
if ($scope.service[index]) //当前选中
{
if ($scope.service[index + 1]) //如果后面是选中的话
{
for (var i = index + 1; i < 5; i++)
$scope.service[i] = false; //往更高的地方全部不选中
}
else //如果后面没有选中
{
for (var i = 0; i <= index; i++)
$scope.service[i] = false;
}
}
else {
for (var i = 0; i <= index; i++)
$scope.service[i] = true;
}
}
};
$scope.chooseSatisfaction = function (index) {
if (index == 4)//选中最后一个
{
if ($scope.satisfaction[index]) {
for (var i = 0; i < 5; i++)
$scope.satisfaction[i] = false;
}
else //如果没有选中
{
for (var i = 0; i < 5; i++)
$scope.satisfaction[i] = true;
}
}
else {
if ($scope.satisfaction[index]) //当前选中
{
if ($scope.satisfaction[index + 1]) //如果后面是选中的话
{
for (var i = index + 1; i < 5; i++)
$scope.satisfaction[i] = false; //往更高的地方全部不选中
}
else //如果后面没有选中
{
for (var i = 0; i <= index; i++)
$scope.satisfaction[i] = false;
}
}
else {
for (var i = 0; i <= index; i++)
$scope.satisfaction[i] = true;
}
}
};