personConfigScheduleEdit.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. var patt = /^(\d{4})-(0[1-9]|1[0-2])$/;
  2. var time;
  3. var hrNumber;
  4. var billId;
  5. var nowTime;
  6. shr.defineClass("shr.customer.PersonConfigScheduleEdit", shr.framework.Edit, {
  7. initalizeDOM : function() {
  8. shr.customer.PersonConfigScheduleEdit.superClass.initalizeDOM.call(this);
  9. this.storeF7Event();
  10. //this.setEditEnable();
  11. this.getBudgetPersonTotal();
  12. nowTime = getNowTime();
  13. },
  14. //监控项目F7值
  15. storeF7Event : function() {
  16. if(this.getOperateState() != "VIEW"){
  17. time = $("#Time").val();
  18. hrNumber = $("#HRNumber").val();
  19. billId = $("#id").val();
  20. $("#Store").shrPromptBox("option", {
  21. onchange : function (e, value) {
  22. if(value.current == null){
  23. return;
  24. }
  25. hrNumber = value.current.number;
  26. $("#HRNumber").val(hrNumber);
  27. if(time && time == nowTime){//还要加上是否为当月判断
  28. var storeId = $("#Store_el").val();
  29. getNumByStoreFrontNumber(storeId,time);
  30. }
  31. }
  32. });
  33. //监控时间
  34. $("#Time").blur(function () {
  35. time = $("#Time").val();
  36. if(!time){
  37. return;
  38. }else if (!patt.test(time)) {
  39. shr.showWarning({
  40. message: "时间格式有误,正确格式为 yyyy-MM",
  41. });
  42. return;
  43. }
  44. if(hrNumber){
  45. var arr = verifyTime(billId,hrNumber,time);
  46. if(arr[0] == '1'){
  47. shr.showWarning({
  48. message: "时间必须在项目筹备期 "+arr[1]+" 至 "+arr[2]+" 内"
  49. });
  50. return;
  51. }else if(arr[0] == '3'){
  52. shr.showWarning({
  53. message: "当前门店在该月份已存在预算维护数据, 请勿重复提交!"
  54. });
  55. return;
  56. }
  57. if(time && time == nowTime){
  58. //还要加上是否为当月判断
  59. var storeId = $("#Store_el").val();
  60. getNumByStoreFrontNumber(storeId,time);
  61. }else if(time && time != nowTime){
  62. $("#ManagerAmnoutPra").val('');
  63. $("#PersonAmountPra").val('');
  64. }
  65. }
  66. });
  67. }
  68. },
  69. //监控一线员工人数和管理员人数 计算计划人数总和
  70. getBudgetPersonTotal: function () {
  71. if (this.getOperateState() != "VIEW") {
  72. var frontLinePerson = $("#FrontLinePerson").val();
  73. var administrator = $("#Administrator").val();
  74. //监控管理人员
  75. $("#Administrator").blur(function () {
  76. administrator = $("#Administrator").val();
  77. if (administrator && frontLinePerson) {
  78. var total = parseInt(administrator) + parseInt(frontLinePerson);
  79. $("#BudgetPersonTotal").val(total);
  80. }
  81. });
  82. //监控一线人员
  83. $("#FrontLinePerson").blur(function () {
  84. frontLinePerson = $("#FrontLinePerson").val();
  85. if (administrator && frontLinePerson) {
  86. var total = parseInt(administrator) + parseInt(frontLinePerson);
  87. $("#BudgetPersonTotal").val(total);
  88. }
  89. });
  90. //计划人数合计已经设置为只读,下面的方法作废
  91. // //计划人数合计失焦
  92. // $("#BudgetPersonTotal").blur(function () {
  93. // frontLinePerson = $("#FrontLinePerson").val();
  94. // administrator = $("#Administrator").val();
  95. // if (administrator && frontLinePerson) {
  96. // var total = parseInt(administrator) + parseInt(frontLinePerson);
  97. // $("#BudgetPersonTotal").val(total);
  98. // }
  99. // });
  100. // //计划人数合计获焦
  101. // $("#BudgetPersonTotal").focus(function () {
  102. // frontLinePerson = $("#FrontLinePerson").val();
  103. // administrator = $("#Administrator").val();
  104. // if (administrator && frontLinePerson) {
  105. // var total = parseInt(administrator) + parseInt(frontLinePerson);
  106. // $("#BudgetPersonTotal").val(total);
  107. // }
  108. // });
  109. }
  110. },
  111. //保存
  112. saveAction : function(){
  113. var time = $("#Time").val();
  114. if(time && !patt.test(time)){
  115. shr.showWarning({
  116. message: "时间格式有误,正确格式为 yyyy-MM",
  117. });
  118. return;
  119. }
  120. var arr;
  121. hrNumber = $("#HRNumber").val();
  122. billId = $("#id").val();
  123. if(time && hrNumber){
  124. arr = verifyTime(billId,hrNumber,time);
  125. }
  126. if(time && hrNumber && arr[0] == '1'){
  127. shr.showWarning({
  128. message: "时间必须在项目筹备期 "+arr[1]+" 至 "+arr[2]+" 内"
  129. });
  130. return;
  131. }else if(time && hrNumber && arr[0] == '3'){
  132. shr.showWarning({
  133. message: "当前门店在该月份已存在预算维护数据, 请勿重复提交!"
  134. });
  135. return;
  136. }
  137. //判断实际人数是否都有值或都为空
  138. var managerAmnoutPra = $("#ManagerAmnoutPra").val();
  139. var personAmountPra = $("#PersonAmountPra").val();
  140. if((managerAmnoutPra && !personAmountPra) || (!managerAmnoutPra && personAmountPra)){
  141. shr.showWarning({
  142. message: "管理人员实际人数 和 一线人员实际人数 要么都有值,要么都为空!"
  143. });
  144. return;
  145. }
  146. shr.customer.PersonConfigScheduleEdit.superClass.saveAction.call(this);
  147. },
  148. //重写assembleModel的原因是,保存时无法获取到PracticalPreparedTime的值
  149. assembleModel: function () {
  150. var model = shr.customer.PersonConfigScheduleEdit.superClass.assembleModel.call(this);
  151. model.BudgetPersonTotal = $("#BudgetPersonTotal").val();
  152. return model;
  153. },
  154. //设置编辑按钮是否可用
  155. // setEditEnable : function(){
  156. // //判断当前月份是否比单据参数时间月份大
  157. // //var billId = $("#id").val();
  158. // var flag = 'false';
  159. // var time = $("#Time").text();
  160. // var split = time.split('-');
  161. // var dateTime = new Date(split[0],split[1]-1,1);
  162. // var date = new Date();
  163. // var year = date.getFullYear();
  164. // var month = date.getMonth();
  165. // date.setTime(new Date(year,month,1));//将日期设为本月一号
  166. // if((dateTime - date) < 0){//历史数据
  167. // //历史数据需要判断操作人是否有更改权限
  168. // var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.PersonConfigScheduleEditHandler&method=setEditEnable";
  169. // shr.ajax({
  170. // async:false,
  171. // type:'post',
  172. // data :{},
  173. // url:url,
  174. // success:function(res){
  175. // flag=res.data;
  176. // }
  177. // });
  178. // if(flag == 'true'){
  179. // $("#edit").hide();
  180. // }
  181. // }
  182. // }
  183. });
  184. //根据门店编码和时间获取实际人数
  185. function getNumByStoreFrontNumber(storeId,time){
  186. var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.PersonConfigScheduleEditHandler&method=getNumByStoreFrontNumber";
  187. shr.ajax({
  188. async: false,
  189. type: 'post',
  190. data: {
  191. storeId: storeId
  192. },
  193. url: url,
  194. success: function (res) {
  195. if(res.data){
  196. $("#ManagerAmnoutPra").val(res.data.managerNum);
  197. $("#PersonAmountPra").val(res.data.personNum);
  198. }
  199. }
  200. });
  201. }
  202. //检查时间是否合法
  203. function verifyTime(billId,hrNumber,time){
  204. var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.PersonConfigScheduleEditHandler&method=verifyTime";
  205. var arr = new Array();
  206. shr.ajax({
  207. async:false,
  208. type:'post',
  209. data :{
  210. billId : billId,
  211. hrNumber : hrNumber,
  212. time : time
  213. },
  214. url:url,
  215. success:function(res){
  216. arr[0] =res.data.num;
  217. arr[1] =res.data.startPreparedMonth;
  218. arr[2] =res.data.openDate;
  219. }
  220. });
  221. return arr;
  222. }
  223. function getNowTime(){
  224. var date = new Date();
  225. var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : '0'+(date.getMonth() + 1);
  226. return date.getFullYear() +"-"+ month;
  227. }