Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
allCampaign
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
allCampaign
Commits
fc6ff67b
Commit
fc6ff67b
authored
May 20, 2019
by
Sweet Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
暂时提交
parent
a48001b9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
212 additions
and
89 deletions
+212
-89
questionnaire/src/app/age/age.component.html
+4
-7
questionnaire/src/app/age/age.component.ts
+55
-17
questionnaire/src/app/app-routing.module.ts
+1
-1
questionnaire/src/app/common.service.ts
+94
-32
questionnaire/src/app/family/family.component.html
+6
-10
questionnaire/src/app/family/family.component.ts
+38
-11
questionnaire/src/app/job/job.component.ts
+9
-9
questionnaire/src/app/transit/transit.component.ts
+5
-2
No files found.
questionnaire/src/app/age/age.component.html
View file @
fc6ff67b
...
@@ -12,14 +12,14 @@
...
@@ -12,14 +12,14 @@
</li>
</li>
</ul>
</ul>
</div>
</div>
<div
class=
"addChild"
<div
class=
"addChild"
(
click
)="
addChild
()"
>
(
click
)="
addChild
()"
>
<div
class=
"icon"
>
+
</div>
<div
class=
"icon"
>
+
</div>
<div
data-toggle=
"modal"
>
增加孩子年龄
</div>
<div
data-toggle=
"modal"
>
增加孩子年龄
</div>
</div>
</div>
<div
class=
"content_footer"
>
<div
class=
"content_footer"
>
<div
style=
"color: #8a8a8a;"
>
<
</div>
<div
style=
"color: #8a8a8a;"
>
<
</div>
<div
[
ngStyle
]="{
color:
nextBtn =
=
false
?
'#
8a8a8a
'
:
'#
ec2d37
'
}"
>
下一步
</div>
<div
[
ngStyle
]="{
color:
nextBtn =
=
false
?
'#
8a8a8a
'
:
'#
ec2d37
'
}"
(
click
)="
next
()"
>
下一步
</div>
</div>
</div>
<div
class=
"toastWrapper toast"
*
ngIf=
"isShow"
(
click
)="
closeToast
()"
>
<div
class=
"toastWrapper toast"
*
ngIf=
"isShow"
(
click
)="
closeToast
()"
>
...
@@ -30,10 +30,7 @@
...
@@ -30,10 +30,7 @@
<li
<li
[
ngClass
]="{
selected:
this
.
curQuestionSelecte =
==
options
.
optionName
}"
[
ngClass
]="{
selected:
this
.
curQuestionSelecte =
==
options
.
optionName
}"
*
ngFor=
"let options of curQues.options"
*
ngFor=
"let options of curQues.options"
(
click
)="
(
click
)="
selectedAge
(
curQues
,
options
);"
>
closeToast
();
"
>
{{ options.optionName }}
{{ options.optionName }}
</li>
</li>
</ul>
</ul>
...
...
questionnaire/src/app/age/age.component.ts
View file @
fc6ff67b
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
CommonService
}
from
'../common.service'
;
import
{
CommonService
}
from
'../common.service'
;
import
{
ActivatedRoute
,
Router
}
from
"@angular/router"
;
@
Component
({
@
Component
({
selector
:
'app-age'
,
selector
:
'app-age'
,
...
@@ -7,34 +8,71 @@ import {CommonService} from '../common.service';
...
@@ -7,34 +8,71 @@ import {CommonService} from '../common.service';
styleUrls
:
[
'./age.component.css'
]
styleUrls
:
[
'./age.component.css'
]
})
})
export
class
AgeComponent
implements
OnInit
{
export
class
AgeComponent
implements
OnInit
{
curPageData
:
Array
<
any
>
;
// 家庭结构
type
:
any
;
curPageData
:
Array
<
any
>
;
isShow
:
boolean
;
isShow
:
boolean
;
curQues
:
Object
;
curQues
:
any
;
curQuesIndex
:
number
;
curQuesIndex
:
number
;
curQuestionSelecte
:
string
;
curQuestionSelecte
:
string
;
constructor
(
private
commonService
:
CommonService
)
{
}
pageAnswers
:
any
;
ngOnInit
()
{
constructor
(
private
commonService
:
CommonService
,
private
router
:
Router
,
private
route
:
ActivatedRoute
)
{
this
.
surveyInfo
()
/**
* 1:单身贵族
* 2:二人世界
* 3:独立带娃
* 4:多口之家
* @type {any}
*/
this
.
type
=
this
.
route
.
snapshot
.
queryParams
[
'type'
];
console
.
log
(
this
.
type
);
this
.
pageAnswers
=
{
pageId
:
''
,
questions
:
[],
};
}
}
surveyInfo
()
{
ngOnInit
()
{
this
.
commonService
.
surveyInfo
().
then
(
res
=>
{
this
.
commonService
.
surveyInfo
().
then
(
res
=>
{
if
(
res
[
'success'
])
{
this
.
curPageData
=
res
[
'data'
][
'survey'
][
'pages'
].
filter
(
item
=>
item
.
pageId
===
3
).
pop
();
this
.
curPageData
=
res
[
'data'
][
'survey'
].
pages
[
'2'
]
this
.
pageAnswers
.
pageId
=
this
.
curPageData
[
'pageId'
];
console
.
log
(
this
.
curPageData
)
});
}
// 选择年龄
selectedAge
(
curQues
,
options
)
{
const
question
=
{
questionId
:
curQues
.
questionId
,
questionName
:
curQues
.
questionName
,
options
:
[
options
]
};
for
(
let
i
=
0
;
i
<
this
.
pageAnswers
.
questions
.
length
;
i
++
)
{
if
(
this
.
pageAnswers
.
questions
[
i
].
questionId
==
curQues
.
questionId
)
{
const
index
=
this
.
pageAnswers
.
questions
.
indexOf
(
this
.
pageAnswers
.
questions
[
i
]);
this
.
pageAnswers
.
questions
.
splice
(
index
,
1
);
}
}
})
}
this
.
pageAnswers
.
questions
.
push
(
question
);
this
.
commonService
.
addAnswer
(
this
.
pageAnswers
);
console
.
log
(
this
.
commonService
.
todos
)
this
.
closeToast
();
}
}
showToast
(
question
,
idx
)
{
showToast
(
question
,
idx
)
{
this
.
isShow
=
true
this
.
isShow
=
true
;
this
.
curQues
=
question
this
.
curQues
=
question
;
this
.
curQuesIndex
=
idx
this
.
curQuesIndex
=
idx
;
this
.
curQuestionSelecte
=
question
.
name
this
.
curQuestionSelecte
=
question
.
name
;
}
}
closeToast
()
{
closeToast
()
{
this
.
isShow
=
false
this
.
isShow
=
false
;
}
// 下一步
next
()
{
this
.
router
.
navigate
([
'/job'
]);
}
}
}
}
questionnaire/src/app/app-routing.module.ts
View file @
fc6ff67b
...
@@ -16,7 +16,7 @@ import {Transit1Component} from './transit1/transit1.component';
...
@@ -16,7 +16,7 @@ import {Transit1Component} from './transit1/transit1.component';
import
{
Transit2Component
}
from
'./transit2/transit2.component'
;
import
{
Transit2Component
}
from
'./transit2/transit2.component'
;
import
{
Transit3Component
}
from
'./transit3/transit3.component'
;
import
{
Transit3Component
}
from
'./transit3/transit3.component'
;
import
{
CommonModule
}
from
'@angular/common'
import
{
CommonModule
}
from
'@angular/common'
;
const
routes
:
Routes
=
[
const
routes
:
Routes
=
[
{
{
...
...
questionnaire/src/app/common.service.ts
View file @
fc6ff67b
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
environment
}
from
'./../environments/environment'
;
import
{
environment
}
from
'./../environments/environment'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
// import {LocalStorage} from './local.storage'
;
import
{
Subject
}
from
"rxjs/index"
;
@
Injectable
({
@
Injectable
({
providedIn
:
'root'
providedIn
:
'root'
})
})
export
class
CommonService
{
export
class
CommonService
{
// Observable string sources
private
todosSource
=
new
Subject
<
any
>
();
// Observable string streams
todos$
=
this
.
todosSource
.
asObservable
();
todos
:
Array
<
any
>
=
[];
// 任务列表
private
USER_API_URL
=
''
;
private
USER_API_URL
=
''
;
private
httpOptions
;
private
httpOptions
;
constructor
(
private
http
:
HttpClient
,
// private ls: LocalStorage
constructor
(
private
http
:
HttpClient
)
{
)
{
this
.
USER_API_URL
=
environment
.
apiUrl
;
this
.
USER_API_URL
=
environment
.
apiUrl
;
this
.
httpOptions
=
{
this
.
httpOptions
=
{
headers
:
new
HttpHeaders
({
headers
:
new
HttpHeaders
({
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
'X-Authorization'
:
''
'X-Authorization'
:
''
})
})
};
};
}
}
/**
* 获取问卷所有问题
* @returns {Promise<TResult2|TResult1>}
*/
async
surveyInfo
()
{
async
surveyInfo
()
{
const
url
=
this
.
USER_API_URL
+
'/survey/surveyInfo'
;
const
url
=
this
.
USER_API_URL
+
'/survey/surveyInfo'
;
const
res
=
await
this
.
obtainToken
();
const
res
=
await
this
.
obtainToken
();
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
return
this
.
http
return
this
.
http
.
post
(
url
,
JSON
.
stringify
({}),
this
.
httpOptions
).
toPromise
().
then
(
response
=>
{
.
post
(
url
,
JSON
.
stringify
({}),
this
.
httpOptions
).
toPromise
().
then
(
response
=>
{
return
response
;
return
response
;
});
});
}
}
async
saveCustomerAnwers
(
objParam
){
/**
* 保存答案
* @param objParam
* @returns {Promise<TResult2|TResult1>}
*/
async
saveCustomerAnwers
(
objParam
)
{
const
url
=
this
.
USER_API_URL
+
'/survey/saveCustomerAnwers'
;
const
url
=
this
.
USER_API_URL
+
'/survey/saveCustomerAnwers'
;
const
res
=
await
this
.
obtainToken
();
const
res
=
await
this
.
obtainToken
();
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
return
this
.
http
return
this
.
http
.
post
(
url
,
JSON
.
stringify
(
objParam
),
this
.
httpOptions
).
toPromise
().
then
(
response
=>
{
.
post
(
url
,
JSON
.
stringify
(
objParam
),
this
.
httpOptions
).
toPromise
().
then
(
response
=>
{
return
response
;
return
response
;
});
});
}
}
...
@@ -51,26 +65,41 @@ export class CommonService {
...
@@ -51,26 +65,41 @@ export class CommonService {
return
this
.
http
.
post
(
url
,
JSON
.
stringify
(
ticketObj
),
this
.
httpOptions
).
toPromise
();
return
this
.
http
.
post
(
url
,
JSON
.
stringify
(
ticketObj
),
this
.
httpOptions
).
toPromise
();
}
}
async
provinceqry
(
objParam
){
/**
* 获取省份
* @param objParam
* @returns {Promise<TResult2|TResult1>}
*/
async
provinceqry
(
objParam
)
{
const
url
=
this
.
USER_API_URL
+
'/partner/provinceqry'
;
const
url
=
this
.
USER_API_URL
+
'/partner/provinceqry'
;
const
res
=
await
this
.
obtainToken
();
const
res
=
await
this
.
obtainToken
();
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
return
this
.
http
.
post
(
url
,
JSON
.
stringify
(
objParam
),
this
.
httpOptions
).
toPromise
().
then
(
res
=>
{
return
this
.
http
.
post
(
url
,
JSON
.
stringify
(
objParam
),
this
.
httpOptions
).
toPromise
().
then
(
res
=>
{
return
res
;
return
res
;
})
})
}
}
async
getCityqry
(
objParam
){
/**
* 获取城市
* @param objParam
* @returns {Promise<TResult2|TResult1>}
*/
async
getCityqry
(
objParam
)
{
const
url
=
this
.
USER_API_URL
+
'/partner/cityqry'
;
const
url
=
this
.
USER_API_URL
+
'/partner/cityqry'
;
const
res
=
await
this
.
obtainToken
();
const
res
=
await
this
.
obtainToken
();
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
this
.
httpOptions
.
headers
=
this
.
httpOptions
.
headers
.
set
(
'X-Authorization'
,
res
[
'data'
][
'token'
]);
return
this
.
http
return
this
.
http
.
post
(
url
,
JSON
.
stringify
(
objParam
),
this
.
httpOptions
)
.
post
(
url
,
JSON
.
stringify
(
objParam
),
this
.
httpOptions
)
.
toPromise
().
then
(
res
=>
{
.
toPromise
().
then
(
res
=>
{
return
res
;
return
res
;
})
})
}
}
/**
* 获取URL参数
* @param name
* @returns {any}
*/
getQueryString
(
name
)
{
getQueryString
(
name
)
{
const
after
=
window
.
location
.
hash
.
split
(
'?'
)[
1
];
const
after
=
window
.
location
.
hash
.
split
(
'?'
)[
1
];
if
(
after
)
{
if
(
after
)
{
...
@@ -83,4 +112,37 @@ export class CommonService {
...
@@ -83,4 +112,37 @@ export class CommonService {
}
}
}
}
}
}
/**
* 添加一个答案
*/
addAnswer
(
todo
)
{
for
(
let
i
=
0
;
i
<
this
.
todos
.
length
;
i
++
)
{
if
(
this
.
todos
[
i
].
pageId
==
todo
.
pageId
)
{
const
index
=
this
.
todos
.
indexOf
(
this
.
todos
[
i
]);
this
.
todos
.
splice
(
index
,
1
);
break
;
}
}
this
.
todos
.
push
(
todo
);
this
.
todosSource
.
next
(
this
.
todos
);
return
this
;
}
// 更新一个答案
updateTodoById
(
pageId
:
number
,
values
:
Object
=
{})
{
const
todo
=
this
.
todos
.
filter
(
todo
=>
todo
.
pageId
==
pageId
).
pop
();
if
(
!
todo
)
{
return
null
;
}
Object
.
assign
(
todo
,
values
);
// 将更新的values对象的属性值赋给todo对象
this
.
todosSource
.
next
(
this
.
todos
);
return
todo
;
}
// 获取所有答案
getTodos
()
{
return
this
.
todos
;
}
}
}
questionnaire/src/app/family/family.component.html
View file @
fc6ff67b
<div
class=
"layout"
>
<div
class=
"layout"
>
<div
class=
"content"
>
<div
class=
"content"
>
<div
class=
"questionTitle"
>
{{
this.
curPageData?.pageName }}
</div>
<div
class=
"questionTitle"
>
{{ curPageData?.pageName }}
</div>
<ul
class=
"option_item"
style=
"margin-top: 20%;"
>
<ul
class=
"option_item"
style=
"margin-top: 20%;"
>
<li
<li
*
ngFor=
"let options of curPageData?.questions[0]['options']"
(
click
)="
selectedFamily
(
options
)"
>
*
ngFor=
"let options of curPageData?.questions[0]['options']"
<img
[
ngClass
]="{
selected:
selectedOptionId =
=
options
.
optionId
}"
>
src=
"assets/images/icon{{ options.optionId }}.png"
<img
alt=
"{{ options.optionName }}"
/>
[
ngClass
]="{
selected:
options
['
selected
']
==
true
}"
src=
"assets/images/icon{{ options.optionId }}.png"
alt=
"{{ options.optionName }}"
/>
<span>
{{ options.optionName }}
</span>
<span>
{{ options.optionName }}
</span>
</li>
</li>
</ul>
</ul>
...
@@ -17,5 +13,5 @@
...
@@ -17,5 +13,5 @@
</div>
</div>
<div
class=
"content_footer"
>
<div
class=
"content_footer"
>
<div
style=
"color: #8a8a8a;"
>
<
</div>
<div
style=
"color: #8a8a8a;"
>
<
</div>
<div
[
ngStyle
]="{
color:
nextBtn =
=
false
?
'#
8a8a8a
'
:
'#
ec2d37
'
}"
>
下一步
</div>
<div
[
ngStyle
]="{
color:
nextBtn =
=
false
?
'#
8a8a8a
'
:
'#
ec2d37
'
}"
(
click
)="
next
()"
>
下一步
</div>
</div>
</div>
questionnaire/src/app/family/family.component.ts
View file @
fc6ff67b
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
CommonService
}
from
'../common.service'
;
import
{
CommonService
}
from
'../common.service'
;
import
{
Router
}
from
"@angular/router"
;
@
Component
({
@
Component
({
selector
:
'app-family'
,
selector
:
'app-family'
,
templateUrl
:
'./family.component.html'
,
templateUrl
:
'./family.component.html'
,
styleUrls
:
[
'./family.component.css'
]
styleUrls
:
[
'./family.component.css'
]
})
})
export
class
FamilyComponent
implements
OnInit
{
export
class
FamilyComponent
implements
OnInit
{
curPageData
:
Array
<
any
>
;
curPageData
:
Array
<
any
>
;
constructor
(
private
commonService
:
CommonService
)
{
}
pageAnswers
:
any
;
selectedOptionId
:
any
;
ngOnInit
()
{
constructor
(
private
commonService
:
CommonService
,
private
router
:
Router
)
{
this
.
surveyInfo
()
this
.
pageAnswers
=
{
pageId
:
''
,
questions
:
[{
questionId
:
''
,
questionName
:
''
,
options
:
[{
optionId
:
''
,
optionName
:
''
,
optionOrder
:
''
,
selected
:
''
}]
}],
};
}
}
surveyInfo
()
{
ngOnInit
()
{
this
.
commonService
.
surveyInfo
().
then
(
res
=>
{
this
.
commonService
.
surveyInfo
().
then
(
res
=>
{
if
(
res
[
'success'
])
{
this
.
curPageData
=
res
[
'data'
][
'survey'
][
'pages'
].
filter
(
item
=>
item
.
pageId
===
2
).
pop
();
this
.
curPageData
=
res
[
'data'
][
'survey'
].
pages
[
'1'
]
console
.
log
(
this
.
curPageData
)
console
.
log
(
this
.
curPageData
)
});
}
}
})
// 选择家庭结构
selectedFamily
(
option
)
{
this
.
selectedOptionId
=
option
.
optionId
;
option
.
selected
=
true
;
this
.
pageAnswers
=
{
pageId
:
this
.
curPageData
[
'pageId'
],
questions
:
[{
questionId
:
this
.
curPageData
[
'questions'
][
'0'
][
'questionId'
],
questionName
:
this
.
curPageData
[
'questions'
][
'0'
][
'questionName'
],
options
:
[
option
]
}],
};
this
.
commonService
.
addAnswer
(
this
.
pageAnswers
);
}
// 下一步
next
()
{
this
.
router
.
navigate
([
'/age'
],
{
queryParams
:
{
type
:
this
.
selectedOptionId
}});
}
}
}
}
questionnaire/src/app/job/job.component.ts
View file @
fc6ff67b
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
CommonService
}
from
'../common.service'
;
import
{
CommonService
}
from
'../common.service'
;
@
Component
({
@
Component
({
selector
:
'app-job'
,
selector
:
'app-job'
,
...
@@ -6,21 +6,21 @@ import {CommonService} from '../common.service';
...
@@ -6,21 +6,21 @@ import {CommonService} from '../common.service';
styleUrls
:
[
'./job.component.css'
]
styleUrls
:
[
'./job.component.css'
]
})
})
export
class
JobComponent
implements
OnInit
{
export
class
JobComponent
implements
OnInit
{
curPageData
:
Array
<
any
>
;
curPageData
:
Array
<
any
>
;
constructor
(
private
commonService
:
CommonService
constructor
(
private
commonService
:
CommonService
)
{
)
{
}
}
ngOnInit
()
{
ngOnInit
()
{
this
.
surveyInfo
()
// this.surveyInfo();
}
}
surveyInfo
()
{
surveyInfo
()
{
this
.
commonService
.
surveyInfo
().
then
(
res
=>
{
this
.
commonService
.
surveyInfo
().
then
(
res
=>
{
if
(
res
[
'success'
])
{
if
(
res
[
'success'
])
{
this
.
curPageData
=
res
[
'data'
]
[
'survey'
].
pages
[
'3'
]
this
.
curPageData
=
res
[
'data'
]
.
survey
.
pages
[
'3'
];
console
.
log
(
this
.
curPageData
)
console
.
log
(
this
.
curPageData
)
;
}
}
})
})
;
}
}
}
}
questionnaire/src/app/transit/transit.component.ts
View file @
fc6ff67b
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
CommonService
}
from
"../common.service"
;
@
Component
({
@
Component
({
selector
:
'app-transit'
,
selector
:
'app-transit'
,
...
@@ -7,9 +8,11 @@ import { Component, OnInit } from '@angular/core';
...
@@ -7,9 +8,11 @@ import { Component, OnInit } from '@angular/core';
})
})
export
class
TransitComponent
implements
OnInit
{
export
class
TransitComponent
implements
OnInit
{
constructor
()
{
}
constructor
(
private
commonService
:
CommonService
)
{
}
ngOnInit
()
{
ngOnInit
()
{
this
.
commonService
.
surveyInfo
().
then
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment