storefrontBudgetEdit.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. var patt = /^(\d{4})-(0[1-9]|1[0-2])$/;
  2. var time;
  3. var hrNumber;
  4. var billId;
  5. shr.defineClass("shr.customer.StorefrontBudgetEdit", shr.framework.Edit, {
  6. initalizeDOM: function () {
  7. shr.customer.StorefrontBudgetEdit.superClass.initalizeDOM.call(this);
  8. this.storeF7Event();
  9. },
  10. //监控门店F7值
  11. storeF7Event: function () {
  12. //var self = this;
  13. if (this.getOperateState() != "VIEW") {
  14. time = $("#Time").val();
  15. hrNumber = $("#HRNumber").val();
  16. billId = $("#id").val();
  17. $("#Store").shrPromptBox("option", {
  18. onchange: function (e, value) {
  19. if (value.current == null) {
  20. return;
  21. }
  22. hrNumber = value.current.number;
  23. $("#HRNumber").val(hrNumber);
  24. if(time){
  25. var storeId = $("#Store_el").val();
  26. getNumByStoreFrontNumber(storeId,time);
  27. }
  28. }
  29. });
  30. //监控时间
  31. $("#Time").blur(function () {
  32. time = $("#Time").val();
  33. if(!time){
  34. return;
  35. }else if (!patt.test(time)) {
  36. shr.showWarning({
  37. message: "时间格式有误,正确格式为 yyyy-MM",
  38. });
  39. return;
  40. }if(hrNumber){
  41. var arr = verifyTime(billId,hrNumber,time);
  42. if(arr[0] == '1'){
  43. shr.showWarning({
  44. message: "时间必须在项目筹备期 "+arr[1]+" 至 "+arr[2]+" 内"
  45. });
  46. return;
  47. }else if(arr[0] == '3'){
  48. shr.showWarning({
  49. message: "当前门店在该月份已存在预算维护数据, 请勿重复提交!"
  50. });
  51. return;
  52. }
  53. var storeId = $("#Store_el").val();
  54. getNumByStoreFrontNumber(storeId,time);
  55. }
  56. });
  57. }
  58. },
  59. //保存
  60. saveAction: function () {
  61. time = $("#Time").val();
  62. if (time && !patt.test(time)) {
  63. shr.showWarning({
  64. message: "时间格式有误,正确格式为 yyyy-MM",
  65. });
  66. return;
  67. }
  68. // var num;
  69. // var startPreparedMonth;
  70. // var openDate;
  71. var arr;
  72. hrNumber = $("#HRNumber").val();
  73. billId = $("#id").val();
  74. if(time && hrNumber){
  75. arr = verifyTime(billId,hrNumber,time);
  76. }
  77. if(time && hrNumber && arr[0] == '1'){
  78. shr.showWarning({
  79. message: "时间必须在项目筹备期 "+arr[1]+" 至 "+arr[2]+" 内"
  80. });
  81. return;
  82. }else if(time && hrNumber && arr[0] == '3'){
  83. shr.showWarning({
  84. message: "当前门店在该月份已存在预算维护数据, 请勿重复提交!"
  85. });
  86. return;
  87. }
  88. shr.customer.StorefrontBudgetEdit.superClass.saveAction.call(this);
  89. },
  90. //重写assembleModel的原因是,保存时无法获取到NumberOfPractical的值
  91. assembleModel: function () {
  92. var model = shr.customer.StorefrontBudgetEdit.superClass.assembleModel.call(this);
  93. model.NumberOfPractical = $("#NumberOfPractical").val();
  94. return model;
  95. },
  96. });
  97. //根据门店编码和时间获取实际人数
  98. function getNumByStoreFrontNumber(storeId,time){
  99. var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.StorefrontBudgetEditHandler&method=getNumByStoreFrontNumber";
  100. shr.ajax({
  101. async: false,
  102. type: 'post',
  103. data: {
  104. storeId: storeId,
  105. time: time
  106. },
  107. url: url,
  108. success: function (res) {
  109. if(res.data){
  110. $("#NumberOfPractical").val(res.data);
  111. }else{
  112. $("#NumberOfPractical").val(0);
  113. }
  114. }
  115. });
  116. }
  117. function verifyTime(billId,hrNumber,time){
  118. var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.StorefrontBudgetEditHandler&method=verifyTime";
  119. var arr = new Array();
  120. shr.ajax({
  121. async:false,
  122. type:'post',
  123. data :{
  124. billId : billId,
  125. hrNumber : hrNumber,
  126. time : time
  127. },
  128. url:url,
  129. success:function(res){
  130. arr[0] =res.data.num;
  131. arr[1] =res.data.startPreparedMonth;
  132. arr[2] =res.data.openDate;
  133. }
  134. });
  135. return arr;
  136. }