---
title: "party_bid项目 第二张卡总结"
author: "zhangkehbg"
date: "2014-08-09T01:22:29Z"
tags: []
categories: ["Web前端"]
slug: "party-bid"
draft: false
lastmod: "2014-08-09T21:52:33Z"
id: 2101971
url: "https://itzk.iteye.com/blog/2101971"
---

1,开始和结束按钮的变换：ng-switch

```
<div ng-switch="start_button">
            <button  ng-switch-when="true" ng-click="start()">开始</button>
            <button  ng-switch-when="false" ng-click="end()">结束</button>
        </div>
```

 在控制器中通过函数给start\_button 赋值，ng-switch判断start\_button的值是否为true或false，如果为true，则显示开始按钮，反之显示结束按钮。

 

2,在控制台模拟发送短信：

```
notify_message_received({"messages":[{"create_date":"Tue Jan 15 15:28:44 格林尼治标准时间+0800 2013","message":"bm张三","phone":"18733171780"}]})
```

 需要引用一个sms.js文件，js文件内容如下：

 

```
var native_accessor = {
    send_sms: function (phone, message) {
        native_access.send_sms({"receivers":[{"name":'name', "phone":phone}]}, {"message_content":message});
        //console.log(phone, message);
    },
    receive_message: function (json_message) {        
    },
    process_received_message: function (json_message) {
        
};
function notify_message_received(message_json) {
    //console.log(JSON.stringify(message_json));
    //JSON.stringify(message_json);
    //alert(JSON.stringify(message_json.messages));
    native_accessor.receive_message(message_json);
    //phone_number=message_json.messages[0].phone;
}
```

调用 native\_access.send\_sms({"receivers":\[{"name":'name', "phone":phone}]}, {"message\_content":message})函数实现回复短信。

 

3,短信去空格：

```
json_message.messages[0].message.replace(/\s/g, "");   \s代表空格,/g是全局
```

4,判断短信信息是否以bm开头 ：

```
message.search(/bm/i) == 0 //i 表示不区分大小写
```

5,用element和$apply实现页面实时刷新： 

```
 Sign_up_Scope = angular.element("#activity_sign-up").scope();//#activity_sign-up为页面的id
```

```
    if(Sign_up_Scope!=undefined){//判断当前是否在需要刷新的页面上。如果不是就不刷新，避免出错
        Sign_up_Scope.$apply(function () {
            Sign_up_Scope.refresh();
        });
```

 refresh函数写在显示页面的controller里。refresh函数写需要更新的数据。

6,重复报名：通过遍历电话号码，如果有电话号码与当前信息的电话号码相同则不予报名。

7,正在报名的活动底色为黄色：在样式表中添加一个样式，并设置为inportant。

```
.true{
    background: yellow !important;
}
```

在view中设置样式：

```
<li  ng-repeat="list in lists"  class="{{list==started_activity}}"  >
                        <p>{{list}}</p>
                    </li>
```

  用开始的活动started\_activity与当前ng-repeat的list判断，如果相等则为true，显示true样式，如果不想等，则不现实黄色。方法有点巧妙，暂时用到，重构的时候肯定得改掉。

8,点击结束按钮的提示框：

在按钮点击事件函数中添加

```
confirm("是否要结束报名？")
```