Ionic3 demo TallyBook 实例2
1.添加插件


2.相关页面

消费页面:
<ion-header>
<ion-navbar>
<ion-title>
消费记录
</ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="openModal()">
<ion-icon name="add"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content>
<datepick (onDaySelect) ="onClick($event)"></datepick>
<div padding> <h4>{{data.date}} <span class="price">¥{{data.amount}}</span></h4> </div>
<ion-list>
<ion-item-sliding *ngFor="let consum of consums; let i=index">
<ion-item nopadding>
<h3>{{consum.name}}</h3>
<p>
<span>{{consum.type}}</span><br>
{{consum.description}}
</p>
<h3 item-end class="price">
¥{{consum.amount}}
</h3>
</ion-item>
<ion-item-options side="right">
<button ion-button color="primary" >
<ion-icon name="paper"></ion-icon>
</button>
<button ion-button color="danger" >
<ion-icon name="trash"></ion-icon>
</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
</ion-content>
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,ModalController } from 'ionic-angular';
import {SQLiteService} from '../../app/sqlite.service'
import { Toast } from '@ionic-native/toast';
@IonicPage()
@Component({
selector: 'page-consum',
templateUrl: 'consum.html'
})
export class ConSumPage {
consums: any = [];
data = {date:"", amount:0 };
constructor(public navCtrl: NavController,
public modalCtrl: ModalController,
private sqlite: SQLiteService,
private toast :Toast
) {
}
onClick(e){
//console.log(e);
let m=parseInt(e.month+1)<10?"0"+parseInt(e.month+1):parseInt(e.month+1).toString();
let d=parseInt(e.date)<10?"0"+parseInt(e.date):parseInt(e.date).toString();
let date=e.year+"-"+m+"-"+d;
this.data.date=date;
this.sqlite.database.executeSql("select consum.*,consumtype.name typename From consum left outer join consumtype on consum.type=consumtype.id where consum.date=? ORDER BY consum.id DESC",[date]).then(res=>{
this.consums = [];
let amount=0;
for(var i=0; i<res.rows.length; i++) {
this.consums.push({id:res.rows.item(i).id,
name:res.rows.item(i).name,
date:res.rows.item(i).date,
type:res.rows.item(i).typename,
description:res.rows.item(i).description,
amount:res.rows.item(i).amount});
amount=amount+parseFloat(res.rows.item(i).amount);
}
this.data.amount=amount;
}).catch(e=>{
this.toast.show(e, '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
});
}
openModal(){
this.navCtrl.push("AddconsumPage");
}
}
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ConSumPage } from './consum';
import { ComponentsModule } from '../../components/components.module'
@NgModule({
declarations: [
ConSumPage,
],
imports: [
IonicPageModule.forChild(ConSumPage),
ComponentsModule
],
})
export class ConSumPageModule {}
添加消费页面:
<ion-header>
<ion-navbar>
<ion-title>添加消费</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<form (ngSubmit)="saveData()">
<ion-item>
<ion-label floating >物品名称</ion-label>
<ion-input type="text" [(ngModel)]="data.name" name="name" required="" ></ion-input>
</ion-item>
<ion-item>
<ion-label floating >日期</ion-label>
<ion-datetime displayFormat="YYYY-MM-DD" [(ngModel)]="data.date" name="date" required=""></ion-datetime>
</ion-item>
<ion-item>
<ion-label floating >类型</ion-label>
<ion-select [(ngModel)]="data.type" name="type" required="" cancelText="取消" okText="确定" >
<ion-option *ngFor="let tp of consumtype" value="{{tp.id}}">{{tp.name}}</ion-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label floating >描述</ion-label>
<ion-textarea [(ngModel)]="data.description" name="description" maxlength="100" required="" ></ion-textarea>
</ion-item>
<ion-item>
<ion-label floating >金额</ion-label>
<ion-input type="number" [(ngModel)]="data.amount" name="amount" required="" ></ion-input>
</ion-item>
<button ion-button type="submit" block>保存消费</button>
</form>
</ion-content>
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Toast } from '@ionic-native/toast';
import {SQLiteService} from '../../app/sqlite.service'
@IonicPage()
@Component({
selector: 'page-addconsum',
templateUrl: 'addconsum.html',
})
export class AddconsumPage {
data = {name:"", date:"", type:"", description:"", amount:0 };
consumtype : any = [];
constructor(public navCtrl: NavController,
public navParams: NavParams,
private sqlite: SQLiteService,
private toast: Toast) {
this.sqlite.database.executeSql("SELECT * FROM consumType ",{}).then(res=>{
this.consumtype = [];
for(var i=0; i<res.rows.length; i++) {
this.consumtype.push({id:res.rows.item(i).id,name:res.rows.item(i).name})
}
}).catch(e=>{
this.toast.show(e, '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
});
}
saveData() {
this.sqlite.database.executeSql('INSERT INTO consum VALUES(NULL,?,?,?,?,?)',
[ this.data.name,this.data.date,this.data.type,this.data.description,this.data.amount])
.then(res => {
this.toast.show('保存成功', '5000', 'center').subscribe(
toast => {
this.navCtrl.pop();
}
);
})
.catch(e => {
this.toast.show(e, '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad AddconsumPage');
}
}
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { AddconsumPage } from './addconsum';
@NgModule({
declarations: [
AddconsumPage,
],
imports: [
IonicPageModule.forChild(AddconsumPage),
],
})
export class AddconsumPageModule {}
sqlite
import { Platform } from 'ionic-angular';
import { Injectable} from '@angular/core'
import { SQLite,SQLiteObject} from '@ionic-native/sqlite'
@Injectable()
export class SQLiteService{
public database:SQLiteObject;
private consumtypedata=[
{id:1,name:"衣着消费支出",description:"包括服装,做衣材料,鞋,袜,帽,及其它零星穿着用品。"}
,{id:2,name:"食品消费支出",description:"包括蔬菜,粮油及其制品,在外用餐,肉,禽,蛋及其制品.鲜奶及奶制品,水产品,调味品,豆制品,烟,酒,茶,糖,干鲜瓜果,饮料,糕点等。"}
,{id:3,name:"医疗保健服务费支出",description:"包括药品,及各类健身工具。"}
,{id:4,name:"交通和通信支出",description:"包括交通费,交通工具购买费,燃料,维修及零部件,通信工具购买费,通信服务费。"}
,{id:5,name:"文化和教育费用支出",description:"包括报名费,学杂费,赞助费,租书费,教材,教育软件,家教费,培训班费等。"}
,{id:6,name:"非商品及服务性支出",description:"房租,水费,电费,煤气费,物业管理费中介费,旅游支出等。"}
,{id:7,name:"日杂消费支出",description:"日常用的东西。"}
,{id:8,name:"其它支出",description:"包括理发,洗澡,美容等"}
];
constructor(private platform: Platform,private sqlite: SQLite){
this.platform.ready().then(() => {
this.sqlite.create({
name: 'tally.db',
location: 'default'
}).then((db: SQLiteObject) => {
this.database = db;
this.createTables();
});
});
}
createTables(){
this.database.executeSql("CREATE TABLE IF NOT EXISTS consumType (id INTEGER PRIMARY KEY , name TEXT,description TEXT)",{})
.then(res=>console.log("consumType success"))
.catch(e=>console.log(e));
this.database.executeSql('CREATE TABLE IF NOT EXISTS consum(id INTEGER PRIMARY KEY ,name TEXT, date TEXT, type INTEGER, description TEXT, amount REAL)', {})
.then(res => {console.log('consum success');})
.catch(e => {console.log(e);});
this.consumtypedata.forEach(element => {
this.database.executeSql("insert into consumType (id , name, description) values(?,?,?)",[element.id,element.name,element.description])
.then(res=>console.log("consumType success"))
.catch(e=>console.log(e));
});
}
}
import { NgModule } from '@angular/core'
import { SQLite} from '@ionic-native/sqlite'
import {SQLiteService} from './sqlite.service'
@NgModule({
imports:[],
exports:[],
declarations:[] ,
providers:[
SQLite,
SQLiteService]
})
export class ServicesModule{}
app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { SQLiteService} from './sqlite.service'
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = 'TabsPage';
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,sqliteSerice:SQLiteService) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
}
app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Toast } from '@ionic-native/toast';
import {ServicesModule} from './service.module';
import { ComponentsModule} from '../components/components.module'
@NgModule({
declarations: [
MyApp
],
imports: [
BrowserModule,
ServicesModule,
ComponentsModule,
IonicModule.forRoot(MyApp,{
tabsHideOnSubPages: 'true', //隐藏全部子页面 tabs
})
],
bootstrap: [IonicApp],
entryComponents: [
MyApp
],
providers: [
StatusBar,
SplashScreen,
Toast,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
3.展示页面



Ionic3 demo TallyBook 实例2的更多相关文章
- Ionic3 demo TallyBook 实例1
1.创建项目 ionic start TallyBook blank 创建一个空的项目 ionic cordova platform add android 添加andorid平台 io ...
- Ionic3 demo TallyBook 实例3
1.准备应用相关组件 echarts--直接 npm install 安装即可 2.home.ts import { Component,ViewChild,ElementRef } from '@a ...
- appium跑demo简单实例讲解
安装appium,设置 demo.pyfrom appium import webdriver #要装webdriver,方法查看http://www.cnblogs.com/sincoolvip/p ...
- react介绍、环境搭建、demo运行实例
React官网:https://reactjs.org/docs/create-a-new-react-app.html cnpm网址:http://npm.taobao.org/ 1.react介绍 ...
- Ionic3 Demo
本文为原创文章,转载请标明出处 最近又开源了一个小 Demo,基于 Ionic 3.9.2.注册登录功能使用的是 WildDog 野狗通信云,大家可以放心的注册登录玩.电影相关数据来源自"某 ...
- js实现『加载更多』功能实例
DEMO : 滚动加载示例 关于如何实现『加载更多』功能,网上有插件可用,例如比较著名的使用iscroll.js实现的上拉加载更多.下拉刷新功能. 但实际用起来却是很麻烦.由于是第三方插件,要按照对方 ...
- nodejs入门demo
demo的实例引用自:http://www.runoob.com/nodejs/nodejs-event.html, 官方文档:https://nodejs.org/dist/latest-v6.x/ ...
- DWR入门实例(二)
DWR(Direct Web Remoting) DWR is a Java library that enables Java on the server and JavaScript in a b ...
- JDBC连接SqlServer数据库(非默认实例)方法
一般我们在连接数据库的时候都是用的默认实例名,今天遇到了用非默认是实例名:连接代码如下(Java): URL=jdbc:microsoft:sqlserver://192.168.1.85//DEMO ...
随机推荐
- postman中如何传数组
方法一: postman的传参: java接收: package com.nps.base.xue.xd.groovyEngine import com.google.gson.Gson import ...
- 『BASH』——Learn BashScript from Daniel Robbins——[003]
ABSTRACT: Daniel Robbins is best known as the creator of Gentoo Linux and author of many IBM develop ...
- 1-电脑C盘(系统盘)清理
推荐,亲测有效! 转自: https://baijiahao.baidu.com/s?id=1612762644229315967&wfr=spider&for=pc
- 榨取kkksc03
题目描述 洛谷的运营组决定,如果一名oier向他的教练推荐洛谷,并能够成功的使用(成功使用的定义是:该团队有20个或以上的成员,上传10道以上的私有题目,布置过一次作业并成功举办过一次公开比赛),那么 ...
- springboot项目中使用设计模式一策略模式
策略模式: 使用常用,支付,之前做了微信支付,支付宝支付,然后另外一个同事写了一个银联支付,那么如果代码方法一起就会导致代码不是很好操作所以,采用策略模式进行,同事只需要写一个实现类,就可以了, 在协 ...
- C 二维数组与指针
http://c.biancheng.net/view/2022.html 1. 区分指针数组和数组指针 指针数组:存放指针的数组,如 int *pstr[5] = NULL; 数组中每个元素存放的是 ...
- VS2017打包
转载:https://blog.csdn.net/Houheshuai/article/details/78518097 在要打包项目的解决方案 右键→添加→ 新建项目 后出现如下选择 如果没 ...
- 深度探索C++对象模型之第一章:关于对象之关键词所引起的差异
————如果不是为了努力维护与C之间的兼容性,C++远比现在简单的多. 如果一个程序员渴望学习C++,但是他却发现书中没有熟悉的struct,一定会苦恼,将这个主题包含到C++里,可以提供语言转移时的 ...
- RAKsmart新出香港服务器的优势
RAKsmart为了更好地服务用户,所以最近RAKsmart新推出得香港服务器又带给了用户更多的选择,那这次RAKsmart新推出香港服务器有哪些优势呢? 1.带宽更大可升至10Mpbs 香港服务器的 ...
- axios调用接口
axios调用接口 1. 按照axiosnpm install --save-dev axios2.在main.js 引入axios, 设置全局属性$http 指向axios main.js impo ...