1- var Vue = require ( 'lib/vue ' ) ;
1+ var CommonCrud = require ( 'common/crud ' ) ;
22
3- var validator = require ( 'common/validator' ) ;
4- var Msg = require ( '/modules/widget/msg/main' ) ;
5-
6- module . exports = Vue . extend ( {
3+ module . exports = CommonCrud . extend ( {
74 template : __inline ( 'main.html' ) ,
8- data : function ( ) {
9- return {
10- jqForm : undefined
11- } ;
5+ data : {
6+ name : undefined ,
7+ ownerId : undefined ,
8+ buydate : undefined ,
9+ state : undefined ,
1210 } ,
1311 methods : {
14- showModal : function ( ) {
15- this . _reset ( ) ;
16- this . $refs . user . init ( ) ;
17-
18- this . $children [ 0 ] . show ( ) ;
19- } ,
20- hideModal : function ( ) {
21- this . $children [ 0 ] . hide ( ) ;
22- } ,
23- reportSuccess : function ( data ) {
24- this . $dispatch ( 'savesuccess' , data ) ;
25- } ,
26- saveSubmit : function ( msg ) {
27- // 提交表单
28- this . jqForm . submit ( ) ;
29- } ,
30- checkOwnerId : function ( name ) {
31- this . jqForm . valid ( ) ;
12+ beforeShowModal : function ( ) {
13+ this . name = '' ;
14+ this . ownerId = undefined ;
15+ this . buydate = '2016-02-25' ; // TODO today
16+ this . state = '1' ;
17+
18+ this . $refs . user . init ( ) ;
3219 } ,
33- _reset : function ( ) {
34- // TODO select2 的初始化
35- $ ( '[name="name"]' , this . jqForm ) . val ( '' ) ;
36- }
37- } ,
38- ready : function ( ) {
39- // 缓存该值,避免重复获取
40- this . $set ( 'jqForm' , $ ( 'form' , $ ( this . $el ) ) ) ;
41-
42- _init ( this ) ;
43- }
44- } ) ;
45-
46- function _init ( vm ) {
47- $ ( function ( ) {
48- handleValidator ( vm ) ;
49- } ) ;
50- }
51-
52-
53- function handleValidator ( vm ) {
54- validator . check ( vm . jqForm , {
55- name : {
56- required : {
57- rule : true ,
58- message : '汽车名字不能为空!'
59- }
60- } ,
61- ownerId : {
62- required : {
63- rule : true ,
64- message : '车主人不能为空!'
65- }
66- }
67- } , {
68- submitHandler : function ( form ) {
69- $ ( form ) . ajaxSubmit ( {
70- success : function ( responseText , statusText ) {
71- if ( statusText !== 'success' || responseText . errno !== 0 ) {
72- // 提示失败
73- Msg . error ( '保存' + JSON . stringify ( responseText . data ) + '出错!' ) ;
74- } else {
75- // 提示成功
76- Msg . success ( '保存' + JSON . stringify ( responseText . data ) + '成功!' ) ;
77-
78- // 关闭对话框
79- vm . hideModal ( ) ;
80-
81- // 刷新列表
82- vm . reportSuccess ( responseText . data ) ;
20+ getValidatorConfig : function ( ) {
21+ var config = {
22+ name : {
23+ required : {
24+ rule : true ,
25+ message : '汽车名字不能为空!'
26+ }
27+ } ,
28+ ownerId : {
29+ required : {
30+ rule : true ,
31+ message : '车主人不能为空!'
32+ }
33+ } ,
34+ buydate : {
35+ required : {
36+ rule : true ,
37+ message : '生日不能为空!'
8338 }
8439 }
85- } ) ;
40+ } ;
41+
42+ return config ;
8643 }
87- } ) ;
88- }
44+ }
45+ } ) ;
0 commit comments