IntegralItemMgr_info.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. * 初始化认定条件管理详情对话框
  3. */
  4. var IntegralItemMgrInfo = {
  5. integralItemMgrInfoData: {},
  6. validateFields: {
  7. projectId: {
  8. validators: {
  9. notEmpty: {
  10. message: '请选择所属积分项目'
  11. }
  12. }
  13. },
  14. name: {
  15. validators: {
  16. notEmpty: {
  17. message: '请输入标准名称'
  18. }
  19. }
  20. },
  21. active: {
  22. validators: {
  23. notEmpty: {
  24. message: '请选择启用状态'
  25. }
  26. }
  27. },
  28. plan: {
  29. validators: {
  30. notEmpty: {
  31. message: '请选择积分方案'
  32. }
  33. }
  34. },
  35. unit: {
  36. validators: {
  37. notEmpty: {
  38. message: '请输入计量单位'
  39. }
  40. }
  41. },
  42. fstNeedAmount: {
  43. validators: {
  44. notEmpty: {
  45. message: '请输入首次达成量'
  46. }
  47. }
  48. },
  49. fstGainPoints: {
  50. validators: {
  51. notEmpty: {
  52. message: '请输入首次获得积分'
  53. }
  54. }
  55. },
  56. stepNeedAmount: {
  57. validators: {
  58. notEmpty: {
  59. message: '请输入每新增量'
  60. }
  61. }
  62. },
  63. stepGainPoints: {
  64. validators: {
  65. notEmpty: {
  66. message: '请输入每新增获得积分'
  67. }
  68. }
  69. }
  70. }
  71. };
  72. /**
  73. * 清除数据
  74. */
  75. IntegralItemMgrInfo.clearData = function () {
  76. this.integralItemMgrInfoData = {};
  77. }
  78. /**
  79. * 设置对话框中的数据
  80. *
  81. * @param key 数据的名称
  82. * @param val 数据的具体值
  83. */
  84. IntegralItemMgrInfo.set = function (key, val) {
  85. this.integralItemMgrInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
  86. return this;
  87. }
  88. /**
  89. * 设置对话框中的数据
  90. *
  91. * @param key 数据的名称
  92. * @param val 数据的具体值
  93. */
  94. IntegralItemMgrInfo.get = function (key) {
  95. return $("#" + key).val();
  96. }
  97. /**
  98. * 关闭此对话框
  99. */
  100. IntegralItemMgrInfo.close = function () {
  101. parent.layer.close(window.parent.IntegralItemMgr.layerIndex);
  102. }
  103. /**
  104. * 收集数据
  105. */
  106. IntegralItemMgrInfo.collectData = function () {
  107. this
  108. .set('id')
  109. .set('type')
  110. .set('projectId')
  111. .set('name')
  112. .set('plan')
  113. .set('unit')
  114. .set('fstNeedAmount')
  115. .set('fstGainPoints')
  116. .set('stepNeedAmount')
  117. .set('stepGainPoints')
  118. .set('fileTypeId')
  119. .set('limit')
  120. .set('yearly')
  121. .set('max')
  122. .set('active');
  123. }
  124. IntegralItemMgrInfo.onTypeChange = function () {
  125. var type = $("#type").val();
  126. Feng.addAjaxSelect({
  127. "id": "projectId",
  128. "displayCode": "id",
  129. "displayName": "name",
  130. "type": "GET",
  131. "url": "/admin/integral_mgr/getProjectsByType/type/" + type
  132. });
  133. var projectId = $("#projectId").attr("selectVal");
  134. $("#projectId").val(projectId);
  135. Feng.addAjaxSelect({
  136. "id": "fileTypeId",
  137. "displayCode": "id",
  138. "displayName": "name",
  139. "type": "GET",
  140. "url": "/admin/integral_mgr/getFilesByType/type/" + type
  141. });
  142. $("#fileTypeId").trigger('chosen:updated');
  143. }
  144. //切换积分方案
  145. IntegralItemMgrInfo.onIntegralPlanChange = function () {
  146. var plan = $("#plan").val();
  147. switch (plan) {
  148. case "1":
  149. $(".planb").css("display", "none");
  150. $('#integraMgrInfoForm').bootstrapValidator('removeField', "stepNeedAmount");
  151. $('#integraMgrInfoForm').bootstrapValidator('removeField', "stepGainPoints");
  152. break;
  153. case "2":
  154. $(".planb").css("display", "block");
  155. $('#integraMgrInfoForm').bootstrapValidator('addField', "stepNeedAmount", {validators: {notEmpty: {message: '请填写每新增量'}}});
  156. $('#integraMgrInfoForm').bootstrapValidator('addField', "stepGainPoints", {validators: {notEmpty: {message: '请填写每新增获得积分'}}});
  157. break;
  158. }
  159. }
  160. IntegralItemMgrInfo.onLimitChange = function () {
  161. var limit = $("#limit").val();
  162. switch (limit) {
  163. case "1":
  164. $('#integraMgrInfoForm').bootstrapValidator('addField', "yearly", {validators: {notEmpty: {message: '请选择上限方案'}}});
  165. $('#integraMgrInfoForm').bootstrapValidator('addField', "max", {validators: {notEmpty: {message: '请填写积分上限'}}});
  166. $(".limit-setting").css("display", "block");
  167. break;
  168. default:
  169. $('#integraMgrInfoForm').bootstrapValidator('removeField', "yearly");
  170. $('#integraMgrInfoForm').bootstrapValidator('removeField', "max");
  171. $(".limit-setting").css("display", "none");
  172. }
  173. }
  174. /**
  175. * 提交添加
  176. */
  177. IntegralItemMgrInfo.addSubmit = function () {
  178. this.clearData();
  179. this.collectData();
  180. if (!this.validate()) {
  181. return;
  182. }
  183. var ajax = new $ax("/admin/integral_mgr/addItem", function (data) {
  184. if (data.code == "200") {
  185. Feng.success(data.msg);
  186. window.parent.IntegralItemMgr.table.refresh();
  187. IntegralItemMgrInfo.close();
  188. } else {
  189. Feng.error(data.msg);
  190. }
  191. }, function (data) {
  192. Feng.error("添加失败!" + data.responseJSON.message + "!");
  193. });
  194. ajax.set(this.integralItemMgrInfoData);
  195. ajax.start();
  196. }
  197. /**
  198. * 提交修改
  199. */
  200. IntegralItemMgrInfo.editSubmit = function () {
  201. this.clearData();
  202. this.collectData();
  203. if (!this.validate()) {
  204. return;
  205. }
  206. var ajax = new $ax(Feng.ctxPath + "/admin/integral_mgr/editItem", function (data) {
  207. if (data.code == "200") {
  208. Feng.success(data.msg);
  209. window.parent.IntegralItemMgr.table.refresh();
  210. IntegralItemMgrInfo.close();
  211. } else {
  212. Feng.error(data.msg);
  213. }
  214. }, function (data) {
  215. Feng.error("修改失败!" + data.responseJSON.message + "!");
  216. });
  217. ajax.set(this.integralItemMgrInfoData);
  218. ajax.start();
  219. }
  220. /**
  221. * 验证数据是否为空
  222. */
  223. IntegralItemMgrInfo.validate = function () {
  224. $('#integraMgrInfoForm').data("bootstrapValidator").resetForm();
  225. $('#integraMgrInfoForm').bootstrapValidator('validate');
  226. return $("#integraMgrInfoForm").data('bootstrapValidator').isValid();
  227. }
  228. $(function () {
  229. Feng.initValidator("integraMgrInfoForm", IntegralItemMgrInfo.validateFields);
  230. //下拉框数据回显
  231. $("select").each(function () {
  232. $(this).val($(this).attr("selectVal"));
  233. });
  234. IntegralItemMgrInfo.onTypeChange();
  235. IntegralItemMgrInfo.onIntegralPlanChange();
  236. IntegralItemMgrInfo.onLimitChange();
  237. $("#fileTypeId").chosen({
  238. no_results_text: "没有找到结果!",
  239. width: '100%',
  240. search_contains: true,    //关键字模糊搜索。设置为true,只要选项包含搜索词就会显示;设置为false,则要求从选项开头开始匹配
  241. disable_search: false,
  242. enable_split_word_search: true,
  243. rtl: true
  244. });
  245. var fileTypeIds = $("#fileTypeId").attr("selectVal")
  246. $("#fileTypeId").val(fileTypeIds.split(",")).trigger("chosen:updated");
  247. });