options_view.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Created by Zhong on 2017/9/28.
  3. */
  4. let optionsOprObj = {
  5. options: null,
  6. optionsTypes: {GENERALOPTS: 'GENERALOPTS', COLOROPTS: 'COLOROPTS'},
  7. rationQuanACToBillsQuan: $('#generalOpts1'),
  8. rationQuanACToRationUnit: $('#generalOpts2'),
  9. getOptions: function () {
  10. let me = this;
  11. CommonAjax.post('/options/getOptions', [], function (rstData) {
  12. me.options = rstData;
  13. let gOpts = me.options[me.optionsTypes.GENERALOPTS];
  14. if(isDef(gOpts)){
  15. for(let attr in gOpts){
  16. me[attr].prop('checked', gOpts[attr]);
  17. }
  18. }
  19. });
  20. },
  21. saveOptions: function (type, opts) {
  22. let optSettingType = 'options.' + type;
  23. let postData = Object.create(null);
  24. postData[optSettingType] = opts;
  25. CommonAjax.post('/options/saveOptions', {optSetting: postData});
  26. },
  27. //更新optionsOprObj对象options数据
  28. updateOptions: function (options, updateObj) {
  29. if(isDef(options[updateObj.type])){
  30. options[updateObj.type][updateObj.opt] = updateObj.value;
  31. }
  32. },
  33. getOptsByType: function (options, type) {
  34. return isDef(options[type]) ? options[type] : null;
  35. },
  36. getOption: function (type, optionName) {
  37. if(!isDef(optionName)){
  38. return isDef(this.options[type]) ? this.options[type] : null;
  39. }
  40. else {
  41. return isDef(this.options[type][optionName])
  42. ? this.options[type][optionName]
  43. : optionName === this.optionsTypes.GENERALOPTS
  44. ? true
  45. : null;
  46. }
  47. },
  48. needToSaveGeneralOpts: function () {
  49. let v1 = this.rationQuanACToBillsQuan.prop('checked');
  50. let v2 = this.rationQuanACToRationUnit.prop('checked');
  51. let orgV1 = this.getOption(this.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  52. let orgV2 = this.getOption(this.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit');
  53. return v1 !== orgV1 || v2 !== orgV2;
  54. }
  55. };
  56. $('#poj-set').on('shown.bs.modal', function () {
  57. let orgV1 = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  58. let orgV2 = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit');
  59. optionsOprObj.rationQuanACToBillsQuan.prop('checked', orgV1);
  60. optionsOprObj.rationQuanACToRationUnit.prop('checked', orgV2);
  61. });
  62. //选项移到了项目属性的系统选项中
  63. /*optionsOprObj.rationQuanACToBillsQuan.click(function () {
  64. let value = optionsOprObj.rationQuanACToBillsQuan.checked;
  65. optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: value});
  66. optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
  67. });
  68. optionsOprObj.rationQuanACToRationUnit.click(function () {
  69. let value = optionsOprObj.rationQuanACToRationUnit.checked;
  70. optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: value});
  71. optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
  72. });*/