storefrontInfoEdit.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. var beforeOpenDate; //存放初始的开业时间
  2. var thirtyDay = 1000 * 60 * 60 * 24 * 30;
  3. var method;
  4. var currentPlanPreparedTime;
  5. var beforeJielouDate;
  6. var beforeBudgetTotal;
  7. shr.defineClass("shr.customer.StorefrontInfoEdit", shr.framework.Edit, {
  8. initalizeDOM: function () {
  9. shr.customer.StorefrontInfoEdit.superClass.initalizeDOM.call(this);
  10. this.storeF7Event();
  11. this.getStartPreparedMonth();
  12. method = this.getQueryVariable("method");
  13. beforeOpenDate = $('#OpenDate').val(); //存放初始的开业时间
  14. beforeJielouDate = $('#JielouDate').val(); //存放初始的接楼时间
  15. beforeBudgetTotal = $('#budgetTotal').val(); //存放筹备期预算总额
  16. },
  17. //监控项目F7值
  18. storeF7Event: function () {
  19. if (this.getOperateState() != "VIEW") {
  20. $("#projectName").shrPromptBox("option", {
  21. onchange: function (e, value) {
  22. if (value.current == null) {
  23. return;
  24. }
  25. $("#departmentNumber").val(value.current.number);
  26. var departmentId = value.current.id;
  27. var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.StoreFrontInfoEditHandler&method=getOrgInfoById";
  28. shr.ajax({
  29. async: false,
  30. type: 'post',
  31. data: {
  32. departmentId: departmentId
  33. },
  34. url: url,
  35. success: function (res) {
  36. var city = {
  37. id: res.data.cityID,
  38. name: res.data.cityName
  39. };
  40. $("#city").shrPromptBox("setValue", city);
  41. var businessFormat = {
  42. id: res.data.hrIndustryID,
  43. name: res.data.industryName
  44. };
  45. $("#businessFormat").shrPromptBox("setValue", businessFormat);
  46. }
  47. });
  48. }
  49. });
  50. }
  51. },
  52. //监控开业时间和计划筹备期
  53. getStartPreparedMonth: function () {
  54. if (this.getOperateState() != "VIEW") {
  55. var planPreparedTime = $('#PlanPreparedTime').val(); //计划筹备期
  56. var openDate = $('#OpenDate').val(); //开业时间
  57. //监控文本框
  58. // $("#PlanPreparedTime").bind("input propertychange", function () {
  59. // planPreparedTime = $(this).val();
  60. // if (planPreparedTime && openDate) {
  61. // calculateDate(openDate, planPreparedTime); //计算实际筹备期 和 开始筹备月份
  62. // }
  63. // });
  64. // //监控文本框失焦事件
  65. // $("#PlanPreparedTime").focus(function(){
  66. // currentPlanPreparedTime = $("#PlanPreparedTime").val();
  67. // });
  68. //监控文本框失焦事件
  69. $("#PlanPreparedTime").blur(function () {
  70. planPreparedTime = $("#PlanPreparedTime").val();
  71. if (!planPreparedTime) {
  72. // if(currentPlanPreparedTime){
  73. // planPreparedTime = currentPlanPreparedTime;
  74. // }else{
  75. return;
  76. }
  77. if (isNaN(planPreparedTime)) {
  78. $("#PlanPreparedTime").val('');
  79. return;
  80. }
  81. planPreparedTime = parseFloat(planPreparedTime).toFixed(1);
  82. $("#PlanPreparedTime").val(planPreparedTime);
  83. if (planPreparedTime && openDate) {
  84. calculateDate(openDate, planPreparedTime); //计算实际筹备期 和 开始筹备月份
  85. }
  86. });
  87. //监控日期控件
  88. $('#OpenDate').change(function () { //监听日期的改变
  89. openDate = $('#OpenDate').val();
  90. if (planPreparedTime && openDate) {
  91. calculateDate(openDate, planPreparedTime); //计算实际筹备期 和 开始筹备月份
  92. }
  93. });
  94. }
  95. },
  96. //保存
  97. saveAction: function () {
  98. // var area = $("#area").val();
  99. // if (area && area < 0) {
  100. // shr.showWarning({
  101. // message: "面积不得小于 0 !",
  102. // });
  103. // return;
  104. // }
  105. // var expectedNumberOfPerson = $("#ExpectedNumberOfPerson").val();
  106. // if (expectedNumberOfPerson && expectedNumberOfPerson < 0) {
  107. // shr.showWarning({
  108. // message: "投资预计人工不得小于 0 !",
  109. // });
  110. // return;
  111. // }
  112. // var planPreparedTime = $("#PlanPreparedTime").val();
  113. // if (planPreparedTime && planPreparedTime < 0) {
  114. // shr.showWarning({
  115. // message: "计划筹备期不得小于 0 !",
  116. // });
  117. // return;
  118. // }
  119. if (this.getOperateState() != "ADDNEW") {
  120. var openDate = $('#OpenDate').val(); //开业时间
  121. var jielouDate = $('#JielouDate').val(); //接楼时间
  122. var budgetTotal = $('#budgetTotal').val(); //筹备期预算总额
  123. var storeId = $("#projectName_el").val();
  124. var open;
  125. var jielou;
  126. var budget;
  127. var flag = false;
  128. if (openDate && openDate !== beforeOpenDate) {
  129. flag = true;
  130. open = beforeOpenDate;
  131. }
  132. if (jielouDate && jielouDate !== beforeJielouDate) {
  133. flag = true;
  134. jielou = beforeJielouDate;
  135. }
  136. if (budgetTotal && budgetTotal !== beforeBudgetTotal) {
  137. flag = true;
  138. budget = beforeBudgetTotal;
  139. }
  140. if(flag){
  141. insertStoreAdjustHistory(storeId, open, jielou, budget);
  142. }
  143. }
  144. shr.customer.StorefrontInfoEdit.superClass.saveAction.call(this);
  145. },
  146. // /**
  147. // * 设置按钮可见性
  148. // */
  149. // setButtonVisible: function () {
  150. // var tenthAdjustBusinessTime = $("#TenthAdjustBusinessTime").val(); //开业时间(第十次调整)
  151. // if (tenthAdjustBusinessTime == '') {
  152. // $("#edit").show();
  153. // } else {
  154. // $("#edit").hide();
  155. // }
  156. // },
  157. //重写assembleModel的原因是,保存时无法获取到PracticalPreparedTime的值
  158. assembleModel: function () {
  159. var model = shr.customer.StorefrontInfoEdit.superClass.assembleModel.call(this);
  160. model.PracticalPreparedTime = $("#PracticalPreparedTime").val();
  161. return model;
  162. },
  163. //从父url中获取参数
  164. getQueryVariable: function (variable) {
  165. var query = parent.window.location.search.substring(1);
  166. var vars = query.split("&");
  167. for (var i = 0; i < vars.length; i++) {
  168. var pair = vars[i].split("=");
  169. if (pair[0] == variable) {
  170. return pair[1];
  171. }
  172. }
  173. return (false);
  174. },
  175. });
  176. //计算实际筹备期 和 开始筹备月份
  177. function calculateDate(openDate, planPreparedTime) {
  178. //8.2数值文本框设置保留一位小数无效
  179. // if (planPreparedTime % 0.1 !== 0) {
  180. // $("#PlanPreparedTime").val(parseFloat(planPreparedTime).toFixed(1));
  181. // }
  182. var date = new Date(openDate); //开业时间
  183. date.setDate(date.getDate() - planPreparedTime * 30);
  184. //创建时更新开始筹备月份
  185. if (method == 'addNew') {
  186. var year = date.getFullYear();
  187. var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
  188. $("#StartPreparedMonth").val(year + "-" + month); //更新开始筹备月份
  189. }
  190. //计算实际筹备期
  191. var openBusinessTime = $("#OpenBusinessTime").val();
  192. date = new Date(openDate);
  193. var openBusinessDate;
  194. if (!openBusinessTime) { //开业时间(首次)为空,需要判断第一次调整时是否同时更改开业时间和计划筹备期
  195. if (beforeOpenDate && openDate !== beforeOpenDate) {
  196. var openBusinessDate = new Date(beforeOpenDate);
  197. } else { //新增或者没有修改开业时间
  198. $("#PracticalPreparedTime").val(parseFloat(planPreparedTime).toFixed(1));
  199. return;
  200. }
  201. } else {
  202. var openBusinessDate = new Date(openBusinessTime);
  203. // var monthAmount = ((date - openBusinessDate) / thirtyDay).toFixed(1); //计算开业时间和首次开业时间之间的月份数,四舍五入
  204. // var practicalPreparedMonth = (parseFloat(monthAmount) + parseFloat(planPreparedTime));
  205. // var months = Number.isInteger(practicalPreparedMonth) ? practicalPreparedMonth + ".0" : practicalPreparedMonth
  206. // $("#PracticalPreparedTime").val(months);
  207. }
  208. var monthAmount = ((date - openBusinessDate) / thirtyDay).toFixed(1);
  209. var practicalPreparedMonth = (parseFloat(monthAmount) + parseFloat(planPreparedTime)).toFixed(1);
  210. //var months = Number.isInteger(practicalPreparedMonth) ? practicalPreparedMonth + ".0" : practicalPreparedMonth;
  211. $("#PracticalPreparedTime").val(practicalPreparedMonth);
  212. };
  213. //写入调整记录表
  214. function insertStoreAdjustHistory(billId,open,jielou,budget) {
  215. var url = shr.getContextPath() + "/dynamic.do?handler=com.kingdee.eas.custom.newpreparation.web.customer.StoreFrontInfoEditHandler&method=insertStoreAdjustHistory";
  216. shr.ajax({
  217. async: false,
  218. type: 'post',
  219. data: {
  220. billId:billId,
  221. openDate:open,
  222. jielouDate:jielou,
  223. budgetTotal:budget
  224. },
  225. url: url,
  226. success: function (res) {
  227. flag = res.data;
  228. }
  229. });
  230. }