Form_wev8.js 47.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
define(['mUtil', "Component", "i18n", "mApi/form"], function (mUtil, Component, i18n) {
	var Form = function (options) {
		var _form = {},
			_edit = {},
			_formMecIDlist = {},
			_formFieldsAttr = {},
			$form;

		Component.super(this, options);
		this.type = "Form";
		this.tpl = this.type + "_html";
		this.css = this.type + "_css";

		var vm = this.viewModel = {
			table: {
				datasource: "$ECOLOGY_SYS_LOCAL_POOLNAME",
				name: "",
				key: ""
			},
			submit: {
				action: "", //提交地址
				validate: function () {
					//表单提交前验证脚本
				}
			},
			relate: {
				formid: -1, //表单id
				modeid: -1, //模块id
				wfid: -1, //流程id
				wftitle: "" //流程标题
			},
			reply: {
			    enable: false,
			    atAll: true,
			    isCheck: false,
			    cubeEnable: false
			},
			detailtable: {
				isA: false //是否明细表
			},
			repeatField: {},
			empowStr: "",
            fieldAuthorize: {}
		};

		this.beforeMount = function () {
			vm.billid = $p("billid",this.pageid);
			vm.layoutType = vm.billid ? 0 : 1; //  0:view,1:add,2:edit
			var action = vm.submit.action,
				actionUrl;

			if (action != "save" && action != "createWf") return;

			if (action == "save") {
				vm.table.datasource = vm.table.datasource || "$ECOLOGY_SYS_LOCAL_POOLNAME";
			}
			vm.submit.action = mUtil.getActionUrl("service.FormComponent", {
				action: action
			});

			if(action == "save") {
				var params = mUtil.getPageParam(this.pageid);
				if (params) {
					var queryStr = "";
					for (var key in params) {
						queryStr += "&" + key + "=" + params[key];
					}
					vm.submit.action += queryStr;
				}
			}
			vm.submit.type = action;
		};

		this.mounted = function () {
			var that = this;

			$form = this.$el.find(".wev-form");

			_form.fillFormData().then(function () {
                mUtil.trigger('dataload', that.pageid, that.id);
				$load(function () {
					_form.initFieldTrigger();
				});
			});

			vm.pageExtend && _form.initPageExpand();

			$load(function () {
				//检查附件目录是否设置
				_form.issetModeDocCategory();
				//获取重复验证
				_form.getRepeatVerifyFields();
			});
			//回复评论初始化
			_form.preInitReply();
			
			require(["formExtHelper"]);
		};
		
		_form.preInitReply = function(cb){
		    if(!vm.reply.enable || !vm.billid) return;
		    (function(){
	            var actionUrl = mUtil.getActionUrl("service.MobileCommon", {
	                action: "checkCubeReply"
	            });
	            var d = $.Deferred();
	            if(vm.reply.isCheck){
	                d.resolve();
	            }else{
	                mUtil.getJSON(actionUrl, function (result) {
	                    vm.reply.isCheck = true;
	                    vm.reply.cubeEnable = result.enable;
	                    d.resolve();
	                });
	            }
	            return d;
	        })().then(function(){
                if(vm.reply.cubeEnable){
                    cb ? cb() : _form.initReply();
                }else{
                    mUtil.console.error("Cube reply is not enabled!");
                }
            });
		};
		
		_form.initReply = function(){
		    var that = this;
		    var $container = that.$container;

            require(["wev-loading", "mService"], function(WevLoading, mService){
                new ReplyList({
                    compid: that.id,
                    $page: $container,
                    $wrapper: $container.find(".page-scroller"),
                    pageid: that.pageid,
                    compType: that.type,
                    atAll: vm.reply.atAll,
                    modeid: vm.relate.modeid,
                    formid: vm.relate.formid,
                    billid: vm.billid
                }, WevLoading, mService).render();
            });
            $load(function(){
                var $abbr = that.$container.find(".page-footer").find("abbr[data-type='FButton']");
                if($abbr.length){
                    mUtil.pluginLoad(that.pageid, $abbr.attr("id"), function(){
                        setTimeout(function(){
                            _form.initReplyBtn();
                        }, 250);
                    });
                }else{
                    _form.initReplyBtn();
                }
            });
		};
		
		_form.initReplyBtn = function(){
		    var that = this;
            var $container = that.$container;
		    var $footer = $container.find(".page-footer"),
                $content = $container.children(".page-content");
            if(!$footer.length){
                $footer = $("<div class=\"page-footer\"></div>");
                $content.after($footer);
            }
            var intiCommentBtn = function(){
                var $comment = $footer.find(".wev-form-comment-btns");
                if(!$comment.length){
                    var commentHtml = '\
                        <div class="wev-form-comment-btns">\
                            <div class="comment">'+i18n.COMMENT+'</div>\
                        </div>\
                    ';
                    $comment = $(commentHtml);
                    $footer.append($comment).show();
                }
                var $fbcomp = $footer.find(".wev-comp-FButton");
                var hasBtn = $fbcomp.find(".wev-btn:not(.wev-btn-hide)").length > 0;
                $comment.toggleClass("independent", !hasBtn);
                if($fbcomp.length){
                    var mr = $comment.width();
                    $fbcomp.css("margin-right", mr);
                }
                if($footer.height()){
                    $footer.attr("footer-height", $footer.height());
                    $content.css("bottom", $footer.height() + "px");
                }else{
                    if($footer.attr("footer-height")){
                        $content.css("bottom", $footer.attr("footer-height") + "px");
                    }else{
                        $content.css("bottom", "0px");
                    }
                }
            };
            intiCommentBtn();
		};
		
		this.resetReplyBtn = function(){
		    _form.preInitReply(function(){
		        _form.initReplyBtn();
		    });
		};
		
		//	属性联动清空选择项,获取表单字段原始属性
		this.getFormFieldsAttr = function () {
			return _formFieldsAttr;
		};
		
		//检查是否设置了文档目录
		_form.issetModeDocCategory = function () {
			var modeid = Number(vm.relate.modeid);
			var checkModeDocCategory = function (isSet) {
				_form.getFormMecIDList().forEach(function (formMecId) {
					var mecInstance = mUtil.getInstance(formMecId);
					if (mecInstance && mUtil.isFunction(mecInstance.checkModeDocCategory)) {
						mecInstance.checkModeDocCategory(isSet);
					}
				});
			};

			if (isNaN(modeid) || modeid === -1) {
				checkModeDocCategory(true);
			} else {
				var actionUrl = mUtil.getActionUrl(this.type, {
					action: "issetModeDocCategory",
					modeid: modeid
				}, this.pageid);
				mUtil.getJSON(actionUrl, function (result) {
					checkModeDocCategory(result.data);
				});
			}
		};

		//获取重复验证
		_form.getRepeatVerifyFields = function () {
			var formid = Number(vm.relate.formid);

			if (isNaN(formid) || formid === -1) {
				vm.repeatField = {};
			} else {
				var actionUrl = mUtil.getActionUrl(this.type, {
					action: "getRepeatVerifyFields",
					formid: formid
				}, this.pageid);
				mUtil.getJSON(actionUrl, function (result) {
					if (result.data) {
						vm.repeatField = result.data;
					}
				});
			}
		};

		_form.fillFormData = function () {
			var d = $.Deferred();
			var that = this;
			
			//主表和明细表默认值不走这里赋值
			if ((!vm.billid && !vm.detailtable.isA) || vm.detailtable.add || vm.isDynamicForm) {

				_form.triggerFieldDataLoad();
				
				d.resolve();
				return d;
			}

			var setFieldsValue = function (datas) {
				var splitChar = "||||";
				var fieldInstances = _form.getFormMecIDList(false);
				var len = fieldInstances.length;
				fieldInstances.forEach(function (formMecId) {
					var fInstance = mUtil.getInstance(formMecId);
					var fname;
					if (mUtil.isFunction(fInstance.getFieldNameOfDB)) {
						fname = fInstance.getFieldNameOfDB();
					} else {
						fname = fInstance.viewModel.field.name;
					}
					var fValueArr = [];
					var fnameArr = fname.split(splitChar);
					fnameArr.forEach(function (fnameTmp) {
						for (var fkey in datas) {
							if (fkey.toLocaleLowerCase() == fnameTmp.toLocaleLowerCase()) {
								fValueArr.push(datas[fkey]);
								break;
							}
						}
					});
					var fValue = fValueArr.join(splitChar);
					if (mUtil.isFunction(fInstance.initComponentData)) {
						fInstance.initComponentData().then(function () {
							fInstance.setValueByDB(fValue);
							if (!--len) {
								d.resolve();
							}
						});
					} else {
						fInstance.setValueByDB(fValue);
						if (!--len) {
							d.resolve();
						}
					}
				});
			};
			if (vm.detailtable.datas) {
				$load(function () {
					setFieldsValue(vm.detailtable.datas);
				});
				return d;
			}
			var actionUrl = mUtil.getActionUrl(that.type, {
				action: "getData",
				datasource: vm.table.datasource,
				tablename: vm.table.name,
				key: vm.table.key,
				billid: vm.billid,
				modelid: vm.relate.modeid
			}, that.pageid);

			mUtil.getJSON(actionUrl, function (result) {
				var fdata = result.data;
				$load(function () {
				    vm.empowStr = fdata._empowStr_ || "";
				    vm.fieldAuthorize = fdata._fieldAuthorize_ || {};
					setFieldsValue(fdata);
				});
			}, function (errMsg) {
				Mobile_NS.alert(errMsg);
				d.resolve();
			});
			return d;
		};

		// 手动触发组件上通过 $pluginload 绑定的事件
		_form.triggerFieldDataLoad = function () {
			var that = this;

			$load(function () {
				var fieldInstances = _form.getFormMecIDList(false);

				fieldInstances.forEach(function (formMecId) {
					var fInstance = mUtil.getInstance(formMecId);
					var statusFin = fInstance.status;

					var Component = require('Component');
					var status = Component.status.DATALOAD;

					if (statusFin !== status) {
						mUtil.trigger('dataload', that.pageid, formMecId);
					}
				});
			})
		}

		_form.initPageExpand = function () {
			var that = this,
				actionUrl = mUtil.getActionUrl(that.type, {
					action: "parsePageExpand",
					appid: mUtil.getAppid() || -1,
					modeid: vm.relate.modeid,
					billid: vm.billid
				}, that.pageid);
			mUtil.getJSON(actionUrl, function (result) {
				var tabs = result.data.tabs || [];
				if (tabs.length) {
					require(["css!commonTab_css"], function () {
						var $page = that.$container,
							$pageTip = that.$container.children(".page-tip"),
							$header = that.$container.children(".page-header"),
							$content = that.$container.children(".page-content"),
							$pagescroller = $content.children(".page-scroller");

						$pagescroller.addClass("tabpanel in").attr("data-form", "show_hide").show().siblings(".tabpanel").remove();

						if (!$header.length) {
							$header = $('<div class="page-header"></div>');
							$content.before($header);
						}
						var $tabtitle = $header.children(".wev-page-extend");
						if (!$tabtitle.length) {
							$tabtitle = $('<div class="wev-page-extend wev-tab-title"></div>');
							$header.prepend($tabtitle);
						}
						$page.children(".page-footer").show(); //防止页面拓展标签切换导致第二次进入页面时footer被隐藏
						var tabtitleHtml = '<li class="wev-tab-nav wev-tab-selected" data-loaded="true" data-href="#' + $pagescroller.attr("id") + '">' + result.data.modename + '</li>';
						var pageAddr = "/mobilemode/appHomepageView.jsp";
						tabs.forEach(function (tab) {
							if (tab.href && ~tab.href.indexOf(pageAddr)) {
								tab.href = tab.href.replace(pageAddr, "/mobilemode/mobile/page.jsp");
								tab.href += (tab.href.indexOf("?") > 0 ? "&" : "?") + "istab=1";
							}
							tabtitleHtml += '<li class="wev-tab-nav" data-url="' + tab.href + '">' + tab.text + '</li>';
						});
						$tabtitle.html('<ul>' + tabtitleHtml + '</ul>');
						$tabtitle[0].scrollLeft = 0;
						
						if($header.height()){
							$header.attr("header-height", $header.height());
							$content.css("top", $header.height() + "px");
						}else{
							if($header.attr("header-height")){
								$content.css("top", $header.attr("header-height") + "px");
							}else{
								$content.css("top", "0px");
							}
						}
						
						var bottom = "";
						$(".wev-tab-nav", $tabtitle).on("click", function () {
							if (!$pageTip.length) {
								$pageTip = $("<div class='page-tip'></div>");
								$page.prepend($pageTip);
							}
							$pageTip.removeClass("page-tip-show page-warn");
							var $nav = $(this);
							var index = $nav.index();

							if ($nav.hasClass("wev-tab-selected")) return;

							$nav.addClass("wev-tab-selected").siblings("li.wev-tab-selected").removeClass("wev-tab-selected");
							$(".wev-tab-panel").addClass("wev-tabpanel-hidden").eq(index).removeClass("wev-tabpanel-hidden");

							bottom = bottom || $content.css("bottom");
							if (index === 0) {
								$page.children(".page-footer").show();
								$content.css("bottom", bottom);
							} else {
								$page.children(".page-footer").hide();
								$content.css("bottom", "0px");
							}

							var taburl = $nav.data("url"),
								href = $nav.data("href");
							var Mobilebone = require("mobilebone");
							if (taburl && !$nav.data("loaded")) {
								if (~taburl.indexOf("/mobilemode/mobile/page.jsp")) {
									if (/(appHomepageId|appid)=\d+/i.test(taburl)) {
										Mobilebone.ajax({
											url: taburl,
											type: 'GET',
											container: $content[0],
											classPage: 'tabpanel',
											form: 'show_hide',
											success: function (data) {
												var tabPageid = $(data).attr("id");
												tabPageid && $nav.data("loaded", true).data("href", "#" + tabPageid);
											}
										});
									} else {
										if (taburl.indexOf("layout=list") != -1) {
											mUtil.getLabel(5463, "查询列表不存在", function (title) {
												$pageTip.addClass("page-tip-show page-warn").attr('data-title', title);
											});
										} else if (taburl.indexOf("layout=add") != -1) {
											mUtil.getLabel(5464, "默认新建布局不存在", function (title) {
												$pageTip.addClass("page-tip-show page-warn").attr('data-title', title);
											});
										} else if (taburl.indexOf("layout=view") != -1) {
											mUtil.getLabel(5465, "默认显示布局不存在", function (title) {
												$pageTip.addClass("page-tip-show page-warn").attr('data-title', title);
											});
										} else {
											mUtil.getLabel(5308, "页面(布局)id不存在", function (title) {
												$pageTip.addClass("page-tip-show page-warn").attr('data-title', title);
											});
										}
									}
								} else {
									var tabid = mUtil.UUID();
									Mobilebone.createPage('<iframe id="frame_' + tabid + '" src="' + taburl + '" class="wev-page-frame tabpanel" frameborder="0" scrolling="auto" data-form="show_hide"></iframe>', {
										container: $content[0],
										classPage: 'tabpanel'
									});
									$content.find("#frame_" + tabid)[0].onload = function () {
										$nav.data("loaded", true).data("href", "#frame_" + tabid);
									};
								}
							} else {
								var pagein = $content.find(href)[0],
									pageout = $content.children(".tabpanel.in")[0];
								Mobilebone.transition(pagein, pageout, false, {
									classPage: "tabpanel",
									history: false,
									reload: false,
									title: false
								});
							}
						});
					});
				}
			});
		};

		_form.initFieldTrigger = function () {
			var that = this,
				modeid = Number(vm.relate.modeid);

			if (isNaN(modeid) || modeid === -1) return;

			require(["fieldTriggerHelper"], function () {
				var actionUrl = mUtil.getActionUrl(that.type, {
					action: "parseFieldTrigger",
					modeid: vm.relate.modeid,
					formid: vm.relate.formid
				}, that.pageid);

				mUtil.getJSON(actionUrl, function (result) {
					var needAttrLinkage = false;
					var fieldMecIds = {};

					_form.getFormMecIDList().forEach(function (formMecId) {
						var mecInstance = mUtil.getInstance(formMecId);
						if (mecInstance) {
							mUtil.isFunction(mecInstance.bindTrigger) && mecInstance.bindTrigger(result.data, vm.detailtable.add);

							if (needAttrLinkage === false && mecInstance.type === "FSelect" || mecInstance.type === "FCheckbox") {
								needAttrLinkage = true;
							}
							if (mecInstance.type === "DetailTable"){
								mecInstance.setTriggers(result.data);
							}
							if (vm.billid && mecInstance.viewModel.readonly !== undefined && mecInstance.viewModel.readonly === false) {
								vm.layoutType = 2; // 表单为edit布局
							}
							mecInstance.viewModel.field && (fieldMecIds[mecInstance.viewModel.field.id] = formMecId);
							
							if (mecInstance.viewModel.readonly) {// 初始字段属性
								_formFieldsAttr[formMecId] = 3;
							} else if (mecInstance.viewModel.required) {
								_formFieldsAttr[formMecId] = 2;
							} else {
								_formFieldsAttr[formMecId] = 1;
							}
						}
					});
					//	在字段联动之后进行有必要的属性联动
					(needAttrLinkage && vm.layoutType > 0) && _form.initFieldAttrLinkage(fieldMecIds);
				});
			});
		};

		_form.initFieldAttrLinkage = function (fieldMecIds) {
			var that = this;
			var pageId = mUtil.getPageIntId(that.pageid);
			var actionUrl = mUtil.getActionUrl(that.type, {
				action: "getFieldAttrLinkage",
				modeid: vm.relate.modeid,
				type: vm.layoutType,
				pageid: pageId
			}, that.pageid);

			mUtil.getJSON(actionUrl, function (result) {
				var attrLinkageFields = new Set();
				var datas = result.data;
				datas && Object.keys(datas).forEach(function (fieldid) {
					var mecId = fieldMecIds[fieldid];
					if (mecId) {
						var mecInstance = mUtil.getInstance(mecId);
						if (mecInstance && mUtil.isFunction(mecInstance.bindAttrLinkage)) {
							var linkages = datas[fieldid];
							Object.keys(linkages).forEach(function (v) {
								linkages[v].forEach(function (attr) {
									attr.changeFields.forEach(function (f, index, arr) {
										var mid = fieldMecIds[f] || -1;
										arr[index] = mid;
										mid !== -1 && attrLinkageFields.add(mid);
									});
								});
							})
							mecInstance.bindAttrLinkage(linkages, vm.layoutType == 2);
						}
					}
				});

				Object.keys(_formFieldsAttr).forEach(function (mecId) {// 保留联动字段的初始属性
					!attrLinkageFields.has(mecId) && delete _formFieldsAttr[mecId];
				})
			});
		};

		//表单提交标记
		_form.submiting = false;
		
		//检查明细表数据是否加载完成
		_form.checkDetailTableDataLoaded = function(){
			var dataloaded = true;
			_form.getFormMecIDList(true).some(function(detailmecid){
				 if(!mUtil.getInstance(detailmecid).dataloaded){
					return !(dataloaded = false);
				 }
			});
			return dataloaded;
		};
		
		//检查字段是否已准备好提交,比如有些异步操作未完成可以借助此方法来保证数据完成性,如需提示信息由方法内部自行完成
		this.checkFieldIsReadyForSubmit = function(){
			var that = this;
			return _form.getFormMecIDList().every(function (formMecId) {
				var mecInstance = mUtil.getInstance(formMecId, that.pageid);
				if (mecInstance && mUtil.isFunction(mecInstance.isReadyForSubmit)) {
					return mecInstance.isReadyForSubmit();
				}else{
					return true;
				}
			});
		};

		this.checkRequired = function () {
			var that = this;
			var checkComponents = function (compoIds) {
				var checkFields = [];
				compoIds.forEach(function (formMecId) {
					var result = mUtil.getInstance(formMecId, that.pageid).checkRequired();
					result && checkFields.push(result);
				});
				return checkFields;
			};
			var mainRequiredFields = checkComponents(_form.getFormMecIDList(false));
			var detailRequiredFields = checkComponents(_form.getFormMecIDList(true));
			var errorMsg = "";
			if (mainRequiredFields.length || detailRequiredFields.length) {
				errorMsg = "<div style=\"text-align:left;\">" + i18n.FIELDS_MUST_FILLED + "</div>";
			}
			if (mainRequiredFields.length) {
				errorMsg += "<div style=\"text-align:left;\">" +
					(detailRequiredFields.length ? i18n.MAIN_FIELD : "") + mainRequiredFields.join(",") + "</div>";
			}
			if (detailRequiredFields.length) {
				errorMsg += "<div style=\"text-align:left;\">" + i18n.DETAIL_FIELD + detailRequiredFields.join(",") + "</div>";
			}
			return errorMsg;
		};

		this.submit = function (callback) {
			if (_form.submiting) return;
			
			if(!_form.checkDetailTableDataLoaded()){ //明细表数据加载成功后才能提交
				return _form.info(i18n.LOADING_DATA);
			}
			
			var that = this;
			
			if(!that.checkFieldIsReadyForSubmit()){
				return;
			}
			
			var opts, isSkipCheck,isDraft = false, errorMsg;
			if (mUtil.isObject(callback)) {
				opts = callback;
				callback = opts.onsuccess || function () {};
				isSkipCheck = opts.isSkipCheck;
				isDraft = true;
			}

			if (!isSkipCheck) {
				errorMsg = this.checkRequired();
			}

			if (errorMsg) return Mobile_NS.msg("" + errorMsg, 3);

			_form.disableFbuttons();
			_form.submiting = true;

			$.when(mUtil.eval(vm.submit.validate, that.pageid))
				.then(function (isValid) {
					if (isValid === false) {
						_form.activeFbuttons();
						_form.submiting = false;

						return;
					}

					if ($.isEmptyObject(vm.repeatField)) {
						_form.send(callback,null,isDraft);
					} else {
						require(["formExtHelper"], function (formExtHelper) {
							formExtHelper.formFieldRepeatVerify(that, function () {
								_form.send(callback,null,isDraft);
							}, function () {
								_form.activeFbuttons();
								_form.submiting = false;
							});
						});
					}
				});
		};

		this.reset = function () {
			$form[0].reset();
			_form.getFormMecIDList().forEach(function (formMecId) {
				mUtil.getInstance(formMecId).reset();
			});
		};

		this.edit = function () {
			if (_edit.url) {
				//执行查看编辑页面扩展
				var modeId = vm.relate.modeid;
				if (modeId != -1){
                    var params = {
                        "billid": vm.billid,
                        "modeid": modeId,
                        "systemFlag": 3
                    };
                    var url = mUtil.getActionUrl("service.FormComponent", {
                        action: "doPageExpand"
                    });
                    mUtil.ajax(url, params);
				}
				$u_r_replace(_edit.url);
			} else {
				Mobile_NS.alert(_edit.errMsg);
			}
		};

		this.preloadEditUrl = function (cb) {
			var url = mUtil.getActionUrl("service.FormComponent", {
				action: "getLayoutUrl"
			});
			var params = {
				billid: vm.billid,
				modelid: vm.relate.modeid,
				appid: mUtil.getAppid() || -1,
				uitype: 2
			};
			var _excuCb = function () {
				mUtil.isFunction(cb) && cb();
			};

			_edit = {};
			mUtil.getJSON(url, params, function (result) {
				_edit.url = result.data;
				_excuCb();
			}, function (result) {
				_edit.errMsg = result;
				_excuCb();
			});
		};

		this.deleteData = function (callback) {
			Mobile_NS.confirm(i18n.CONFIRM_DEL_DATA, function () {
				_form.disableFbuttons();
				_form.submiting = true;
				var url = mUtil.getActionUrl("service.FormComponent", {
						action: "delete"
					}),
					relatekey = "mainid",
					detailTables = [];

				var params = {
					billid: vm.billid,
					modelid: vm.relate.modeid,
					tablename: vm.table.name,
					datasource: vm.table.datasource,
					mainkey: vm.table.key
				};

				_form.getFormMecIDList(true).forEach(function (id) {
					var detailvm = mUtil.getInstance(id).viewModel;
					relatekey = detailvm.relatekey || "mainid";
					detailTables.push(detailvm.tablename);
				});
				params.relatekey = relatekey;
				params.detailTables = detailTables.join(",");

				mUtil.getJSON(url, params, function (data) {
					mUtil.isFunction(callback) && callback();
				}, function (errMsg) {
					_form.activeFbuttons();
					_form.submiting = false;
					_form.info(errMsg);
				});
			});
		};

		this.getRepeatVerifyInfo = function (callback) {
			mUtil.isFunction(callback) && callback(vm.repeatField);
		};

		this.getFormData = function () {
			var formData = {};

			_form.getFormMecIDList().forEach(function (formMecId) {
				var resultData = mUtil.getInstance(formMecId).getData();

				if (mUtil.isObject(resultData)) {
					formData = $.extend(formData, resultData);
				}
			});
			return formData;
		};

		this.getFormShowData = function () {
			var formData = {};
			_form.getFormMecIDList().forEach(function (formMecId) {
				var resultData = mUtil.getInstance(formMecId).getShowData();

				if (mUtil.isObject(resultData)) {
					for (var key in resultData) {
						formData[key.toLowerCase()] = resultData[key];
					}
				}
			});
			return formData;
		};

		this.hasDraftOperation = function(cb){
			if(vm.relate.modeid == -1) return cb && cb(false);
			var  hasDarftStatusUrl= mUtil.getActionUrl("Form", { action: "checkModelHasDraftStatus", modelid: vm.relate.modeid});
			mUtil.getJSON(hasDarftStatusUrl, function (result) { //检查模块是否开启 草稿 功能
				if(result.data == true){
					if(!vm.billid ) return cb && cb(true);
					var checkDataIsDraftStautsUrl = mUtil.getActionUrl("Form", { action: "checkFormDataIsDraftStatus",  billid:vm.billid,  modelid: vm.relate.modeid });
					mUtil.getJSON(checkDataIsDraftStautsUrl, function (result){
						cb && cb(result.data);
					});
				}else{
					cb && cb(false);
				}
			});
		};

		_form.error = function (msg) {
			Mobile_NS.alert(msg);
		};

		_form.info = function (msg) {
			Mobile_NS.msg(msg);
		};

		_form.send = function (callback, successMsg,isDraft) {
			if (mUtil.isString(callback)) {
				successMsg = callback;
			}

			var formData = _form.getFormData();
			if(isDraft)formData.append("isDraftOperation","1");

			var req = mUtil.ajax(vm.submit.action, formData, function (responseText, textStatus) {
				if (!responseText) {
					mUtil.getLabel(5309, "表单提交后服务端返回值为空", function (msg) {
						_form.error(msg);
					});
					return;
				}

				var result = $.parseJSON(responseText);

				var status = result.status,
					data = result.data || {};

				if (mUtil.isFunction(Mobile_NS.formResponse)) { //兼容老的代码会重写formResponse的情况
					return Mobile_NS.formResponse($.extend(true, {
						status: result.status
					}, result.data));
				}

				if (status == "1") {
					var billid = data.id, codeField = data.codefield || "";

					successMsg && _form.info(successMsg);

					if (billid) {
						vm.billid = billid;
						$form.find("input[type='hidden'][name='billid']").val(billid);
					}

					//明细表相关逻辑处理
					_form.getFormMecIDList(true).forEach(function (id) {
						mUtil.getInstance(id, this.pageid).afterSubmit(data.detailidsList || []);
					});

					if (mUtil.isFunction(callback)) {
						try {
							callback(billid, codeField);
						} catch (e) {
							console.error(e);
						}
					}
				} else if (status == "0") {
					mUtil.getMultiLabel({
						5310: "表单保存出现异常:",
						5311: "流程创建异常:"
					}, function (tips) {
						var errMsg = tips['5310'];
						if (vm.submit.type == "createWf") {
							errMsg = tips['5311'];
						}
						errMsg += decodeURIComponent(result.errMsg);
						_form.error(errMsg);
					});
				}
				_form.activeFbuttons();
				_form.submiting = false;
			}, {
				type: "POST",
				processData: false,
				contentType: false,
				error: function () {
					Mobile_NS.alert(i18n.NETWORK_ERROR, function(){
						_form.activeFbuttons();
						_form.submiting = false;
                    });
				}
			});
            //设置15秒的超时时间,超过时限请求未发出则放弃该请求,提示网络状况
            setTimeout(function(){
                if(req.readyState < 2){
                    req.abort();
                }
            }, 15000);
		};

		_form.disableFbuttons = function () {
			$(".wev-comp-FButton[target-form='" + vm.id + "'] .wev-btn-wrapper", this.$container).addClass("disabled");
		};

		_form.activeFbuttons = function () {
			$(".wev-comp-FButton[target-form='" + vm.id + "'] .wev-btn-wrapper", this.$container).removeClass("disabled");
		};
		/*
		 * detailtable 为true 只获取明细表插件id, 为false只获取主表插件id,为undefined获取所有表单插件id
		 * */
		_form.getFormMecIDList = function (detailtable) {
			if (detailtable === true && _formMecIDlist["detailtable"]) {
				return _formMecIDlist["detailtable"];
			} else if (detailtable === false && _formMecIDlist["maintable"]) {
				return _formMecIDlist["maintable"];
			} else if (detailtable === undefined && _formMecIDlist["all"]) {
				return _formMecIDlist["all"];
			} else {
				var formMecIDlist = [],
					expr = detailtable ? ".wev-comp-DetailTable[data-form='" + vm.id + "']" : "[data-form='" + vm.id + "']";

				$(expr, this.$container).forEach(function (element) {
					var formMecId = element.id;
					if (formMecId && ((detailtable === false && !element.classList.contains("wev-comp-DetailTable")) || detailtable === true || detailtable === undefined)) {
						formMecId = formMecId.replace("NMEC_", "");
						formMecIDlist.push(formMecId);
					}
				});
				if (detailtable === true) {
					_formMecIDlist["detailtable"] = formMecIDlist;
				} else if (detailtable === false) {
					_formMecIDlist["maintable"] = formMecIDlist;
				} else {
					_formMecIDlist["all"] = formMecIDlist;
				}
				return formMecIDlist;
			}
		};

		_form.getFormData = function () {
			var that = this;
			var formData = new FormData($form[0]);
			_form.getFormMecIDList().forEach(function (formMecId) {
				var resultData = mUtil.getInstance(formMecId, that.pageid).getData();
				if (mUtil.isObject(resultData)) {
					for (var key in resultData) {
						formData.append(key, resultData[key]);
					}
				}
			});
			return formData;
		};

		for (var key in _form) {
			if (mUtil.isFunction(_form[key])) {
				_form[key] = _form[key].bind(this);
			}
		}
	};
	
	var ReplyList = function(options, WevLoading, mService){
        var _list = {}, replyorNameMap = {}, $scroller, $container, $list, $count, $replyPage;
        
        var config = $.extend({}, options);
        
        this.components = {
            loading: new WevLoading({
                delay: 300,
                animation: 1
            }),
            moreLoading: new WevLoading({
                btn: 1,
                onclick: function (hideLoading) {
                    _list.loadData(hideLoading);
                }
            })
        };
        
        this.render = function(){
            var that = this;
            $replyPage = $(".wev-replybox-page", config.$page);
            if($replyPage.length == 0) {
                $replyPage = $('<div class="wev-replybox-page out"></div>');
                config.$page.append($replyPage);
            }
            $container = config.$wrapper.find(".wev-form-comment");
            Object.keys(that.components).forEach(function (key) {
                var com = that.components[key];
                com.props = com.props || {};
                com.uid = com.props.uid = "_" + mUtil.UUID();
                com.content = juicer(com.tmpl, com.props);
            });
            if(!$container.length){
                $container = config.$wrapper.append('<div class="wev-form-comment"></div>')
                    .find(".wev-form-comment");
            }
            $scroller = $container.closest(".page-content");
            
            var template = '\
                <div class="wev-comment-header">'+i18n.COMMENT+'<span>(0)</span></div>\
                $${loading.content}\
                <div class="wev-comment-list">\
                    <dl></dl>\
                    $${moreLoading.content}\
                </div>\
            ';
            $container.html(mUtil.parseTemplate(template, $.extend({}, that.components)));
            Object.keys(that.components).forEach(function (key) {
                var com = that.components[key];
                com.$el = $container.find("#" + com.uid);
                com.mounted();
            });
            
            $list = $container.find(".wev-comment-list>dl");
            $count = $container.find(".wev-comment-header>span")
            _list.initEvent();
            _list.refreshList();
        };
        
        _list.initEvent = function(){
            require(["mApi/popup", "css!comment_css", "css!swipe_css", "browserHelper"]);
            var that = this, modeid = config.modeid, formid = config.formid, mainid = config.billid, atAll = config.atAll;
            var openServicePage = function(preload, replyParam, reqParam){
                if(mUtil.isObject(preload)){
                    reqParam = replyParam;
                    replyParam = preload;
                    preload = false;
                }
                var cfg = {
                    preload: preload,
                    compid: config.compid,
                    target: replyParam,
                    closeCallback : function(){
                        $replyPage.removeClass("in").addClass("out");
                    },
                    onSubmit: function(formData, callback){
                        Object.keys(reqParam).forEach(function(key) {
                            formData.append(key, reqParam[key]);
                        });
                        _list.submitReply.call(that, replyParam.rootid, formData, callback);
                    }
                };

                !preload && $replyPage.removeClass("out").addClass("in").empty();

                mService.load('replybox', function (html, service) {
                    $replyPage.html(mUtil.replaceI18n(html));
                    service.mounted($replyPage, cfg);
                });
            };
            //预加载页面,解决ios第一次加载页面输入法无法弹出问题
            openServicePage(true);
            var replyParam = {
                scroller: $scroller,
                mainid: mainid,
                modeid: modeid,
                atAll: atAll
            }, reqParam = {
                mainid: mainid,
                modeid: modeid,
                formid: formid
            };
            //评论
            config.$page.off("click.comment").on("click.comment", ".wev-form-comment-btns>.comment", function(){
                openServicePage($.extend({
                    position: $container.find(".wev-comment-header"),
                    tip: i18n.COMMENT
                }, replyParam), reqParam);
            });
            
            $list.on("click.comment", ".wev-comment-relate-target, .wev-comment-item", function (e) {
                var $this = $(this),
                    $target = $(e.target);
                if($target.hasClass("wev-file")) return;
                if($this.hasClass("wev-comment-relate-target")){
                    //点击相关文档、流程等事件
                    require(["browserHelper"], function (browserHelper) {
                        var type = $this.data("type"), typeid;
                        switch(type){
                        case 'doc':
                            typeid = '9';
                            break;
                        case 'workflow':
                            typeid = '16';
                            break;
                        case 'crm':
                            typeid = '7';
                            break;
                        case 'project':
                            typeid = '8';
                            break;
                        }
                        if(type == 'attach'){
                            mUtil.previewFile($this.data("id"), decodeURIComponent($this.data("name")), $this.data("authorize")||"");
                        }else{
                            browserHelper.openBrowserLink($this.data("id"), $this.text(), typeid);
                        }
                    });
                    return;
                }
                
                if($this.hasClass("wev-comment-item")){
                    var replyor = $this.data("replyor"), replyid = $this.data("id"), rootid = $this.data("rootid");
                    if(replyor == 'self'){
                        var deadline = Number($this.data("deadline")),
                            now = new Date().getTime();
                        if(!isNaN(deadline) && now > deadline) return;
                        Mobile_NS.footerMenu({
                            iconPosition: "right",
                            items: [{
                                icon: "/mobilemode/mobile/images/plugin/delete-red.png",
                                text: "<div class=\"wev-comment-popmenu\">"+i18n.DELETE+"</div>", callback: function () {
                                    Mobile_NS.confirm(i18n.CONFIRM_DEL_DATA, function(){
                                        var actionUrl = mUtil.getActionUrl(config.compType, {
                                            action: "deleteReply",
                                            modeid: modeid,
                                            mainid: mainid,
                                            billid: replyid
                                        }, config.pageid);
                                        mUtil.getJSON(actionUrl, function (result) {
                                            if(replyid === rootid){//删除评论
                                                _list.refreshList();
                                            }else{//删除回复
                                                $this.css({transition:"opacity 300ms", opacity:"0"});
                                                setTimeout(function(){
                                                    $this.remove();
                                                }, 300);
                                            }
                                        }, function(errMsg){
                                            Mobile_NS.alert(errMsg);
                                        });
                                    });
                                }
                            }]
                        });
                    }else{//回复
                        openServicePage($.extend({
                            position: $this,
                            replyid: replyid,
                            rootid: rootid,
                            tip: i18n.REPLY + replyorNameMap[replyid] + ":"//回复XXX
                        }, replyParam), $.extend({
                            replyid: replyid
                        }, reqParam));
                    }
                }
                e.stopPropagation();
            });
        };
        
        _list.submitReply = function(rootid, requestFormData, callback){
            var that = this;
            var actionUrl = mUtil.getActionUrl(config.compType, {
                action: "submitReply",
                mec_id: that.id
            }, config.pageid);
            
            Mobile_NS.showLoader();
            mUtil.ajax(actionUrl, requestFormData, function (result) {
                Mobile_NS.hideLoader();
                var status = result.status,
                    result = result.data;

                if (status == "1") {
                    if(rootid){
                        var $comment = $list.find("[data-rootid='"+rootid+"']").eq(-1);
                        var $target = $(_list.renderHtml(result.data));
                        $comment.after($target);
                        setTimeout(function(){
                            $target[0].scrollIntoView({behavior: "smooth", block: "end"});
                        }, 100);
                    }else{
                        _list.refreshList(function(){
                            var scrollTop = $scroller.scrollTop() + $container.offset().top;
                            $scroller.scrollTop(scrollTop);
                        });
                    }
                } else if (status == "0") {
                    Mobile_NS.alert(result.errMsg);
                }
                callback && callback();
            }, {
                type: "POST",
                dataType: "json",
                processData: false,
                contentType: false,
                error: function (responseText) {
                    Mobile_NS.hideLoader();
                    mUtil.getLabel(5360, "网络请求失败,请稍后重试!", function (msg) {
                        Mobile_NS.alert(msg);
                    });
                    callback && callback();
                }
            });
        };
        
        _list.state = {
            timestamp: 0,
            pageNo: 0
        };
        
        _list.refreshList = function(cb){
            var that = this;
            var coms = this.components;
            var loading = coms.loading,
                moreLoading = coms.moreLoading;
            
            var state = _list.state;
            state.pageNo = 0;
            
            loading.setRefs($container, "wev-refreshing");
            loading.show();
            
            _list.loadData(function(hasMore, noData){
                loading.hide();
                moreLoading.hide(hasMore, noData);
                
                // 支持上拉刷新功能
                if(hasMore) {
                    require(['pullToRefreshHelper'], function (PullToRefresh) {
                        var $pageContent = $container.closest('.page-content');

                        new PullToRefresh({
                            el: $list,
                            container: $pageContent.get(0),
                            loadData: _list.loadData,
                            loading: that.components.moreLoading
                        });
                    });
                }
                cb && cb();
            });
        };
        
        _list.loadData = function(cb){
            var that = this,
                state = _list.state,
                timestamp = new Date().valueOf();
    
            state.timestamp = timestamp;
            state.pageNo++;
            
            var pageSize = 10, pageNo = state.pageNo;
            var actionUrl = mUtil.getActionUrl(config.compType, {
                action: "getReplyData",
                modeid: config.modeid
            }, config.pageid);
            mUtil.getJSON(actionUrl, {pageNo: pageNo, pageSize: pageSize}, function (result) {
                result = result.data;
                if (timestamp != state.timestamp) return;
                var datas = result.datas,
                    totalSize = result.totalSize;
                
                $list[pageNo == 1 ? "html" : "append"](_list.renderHtml(datas));
                $count.html('('+totalSize+')');
                
                var totalPageCount = totalSize % pageSize === 0 ? totalSize / pageSize : parseInt(totalSize / pageSize) + 1;
                var hasMore = pageNo < totalPageCount;
                var noData = totalSize <= 0;
                cb && cb(hasMore, noData);
            });
        };
        
        _list.renderHtml = function(datas){
            if(mUtil.isObject(datas)){
                datas = [datas];
            }
            datas.forEach(function(data) {
                replyorNameMap[data.billid] = data.replyorName;
            });
            var template = '\
                {@each datas as d}\
                <dd class="wev-comment-item" data-id="${d.billid}" data-rootid="${d.rootid}" data-replyor="${d.replyorId}" data-deadline="${d.deleteDeadline}">\
                    <div class="wev-comment-item-avatar">$${d.avatar}</div>\
                    <div class="wev-comment-item-header">\
                        <div class="left">$${d.replyorName}</div>\
                        <div class="right">{@if d.floorNum}#$${d.floorNum}{@/if}<span>$${d.replyDate}&nbsp;$${d.replyTime}</span>\
                        </div>\
                    </div>\
                    <div class="wev-comment-item-content">\
                        {@if d.parentid && nameMap[d.parentid]}\
                        <span class="at">'+i18n.REPLY+'</span>\
                        <span class="username">\$${nameMap[d.parentid]}</span>\
                        <span class="split">:</span>\
                        {@/if}\
                        <span class="content">$${d.content}</span>\
                    </div>\
                </dd>\
                {@/each}';
            var html = mUtil.parseTemplate(template, { datas: datas, nameMap: replyorNameMap});
            return html;
        };
        
        for(var key in _list){
            if(mUtil.isFunction(_list[key])){
                _list[key] = _list[key].bind(this);
            }
        }
    };

    Form.utils = {
        defSqlPrefix: "__SQL__",
        containsSQL: function(value){
            return value && value.indexOf && value.indexOf(this.defSqlPrefix) == 0;
        },
        getUIType: function(pageid) {
            var $page = $('#' + pageid);
            var uitype = $page.data('uitype');

            if(uitype){
                return uitype;
            }

            var p = $page.data('pageoptions') || '';
            p = p.split(':');
            uitype = p[1] || '';
            $page.data('uitype', uitype);

            return uitype;
        },
		setDefaultValue: function(pageid, vm, expectedVal) {
        	var uitype = this.getUIType(pageid);
            var isShowLayout = uitype == '1';  //是否显示布局
            var isDetailTableData = vm.detailtable.isA;  //是否明细表中数据
			var isDetailTableAdd = vm.detailtable.add;  //是否明细表添加数据
			var allowDefaultValue = !isShowLayout && !isDetailTableData || isDetailTableAdd;

            //插件期望的空值,滑块和Check框插件空值状态不为'',而是'0'
            expectedVal = expectedVal || "";

            if(allowDefaultValue && vm.field.value == expectedVal && vm.field.defaultValue != ""){
                var defVal = vm.field.defaultValue, parseSql = this.containsSQL(defVal);
                vm.field.value = parseSql ? expectedVal : defVal;
                vm.field.needParseSqlValue = parseSql;
            }
		},
		parseDefaultSqlValue: function(defVal, pageid, cb){
		    if(this.containsSQL(defVal)){
		        defVal = defVal.replace(this.defSqlPrefix, "");
                var actionUrl = mUtil.getActionUrl("Form", {
                    action: "parseDefaultValue",
                    content: defVal
                }, pageid);
                
                return mUtil.getJSON(actionUrl, function (result) {
                    cb && cb(result.data);
                });
            }
		}
	}

	function factory(methodName) {
		return function () {
			var args = [].slice.call(arguments), // 调用时的传参
				callArgs = args.slice(1),
				instance = mUtil.getInstance(args[0]);
			return instance[methodName].apply(null, callArgs);
		};
	}

	Mobile_NS.checkRequired = factory("checkRequired");

	Mobile_NS.checkFieldIsReadyForSubmit = factory("checkFieldIsReadyForSubmit");

	Mobile_NS.formReset = factory("reset");

	Mobile_NS.formEdit = factory("edit");

	Mobile_NS.getFormData = factory("getFormData");

	Mobile_NS.getFormShowData = factory("getFormShowData");

	Mobile_NS.dateDiff = function (startDate, endDate) {
		var dates = 0;
		if (startDate != 0 && endDate != 0) {
			var startTime = new Date(Date.parse(startDate.replace(/-/g, "/"))).getTime();
			var endTime = new Date(Date.parse(endDate.replace(/-/g, "/"))).getTime();
			dates = (endTime - startTime) / (1000 * 60 * 60 * 24) || 0;
		}
		return dates;
	};

	return Component.init(Form);
});