addOrg.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. (function (vc) {
  2. vc.extends({
  3. propTypes: {
  4. callBackListener: vc.propTypes.string, //父组件名称
  5. callBackFunction: vc.propTypes.string //父组件监听方法
  6. },
  7. data: {
  8. addOrgInfo: {
  9. orgId: '',
  10. orgName: '',
  11. orgLevel: '',
  12. parentOrgId: '',
  13. description: '',
  14. belongCommunityId: '',
  15. communityId: '',
  16. parentOrg:[],
  17. belongCommunitys:[]
  18. }
  19. },
  20. watch: {
  21. "addOrgInfo.orgLevel":
  22. {//深度监听,可监听到对象、数组的变化
  23. handler(val, oldVal) {
  24. vc.component._addOrgListParentOrgInfo();
  25. }
  26. ,
  27. deep: true
  28. }
  29. }
  30. ,
  31. _initMethod: function () {
  32. //查询入驻的小区
  33. vc.component._loadAddEnterCommunitys();
  34. }
  35. ,
  36. _initEvent: function () {
  37. vc.on('addOrg', 'openAddOrgModal', function (_param) {
  38. if (_param.hasOwnProperty('parentOrgId')) {
  39. vc.component.addOrgInfo.parentOrgId = _param.parentOrgId;
  40. vc.component.addOrgInfo.orgLevel = _param.orgLevel;
  41. if(_param.parentOrgId == 3){ // 部门是不能改小区的,是依赖分公司的小区信息
  42. vc.component.addOrgInfo.communityId = _param.belongCommunityId;
  43. }
  44. }
  45. $('#addOrgModel').modal('show');
  46. });
  47. }
  48. ,
  49. methods: {
  50. addOrgValidate() {
  51. return vc.validate.validate({
  52. addOrgInfo: vc.component.addOrgInfo
  53. }, {
  54. 'addOrgInfo.orgName': [
  55. {
  56. limit: "required",
  57. param: "",
  58. errInfo: "组织名称不能为空"
  59. },
  60. {
  61. limit: "maxin",
  62. param: "2,50",
  63. errInfo: "组织名称长度为2至50"
  64. },
  65. ],
  66. 'addOrgInfo.orgLevel': [
  67. {
  68. limit: "required",
  69. param: "",
  70. errInfo: "组织级别不能为空"
  71. },
  72. {
  73. limit: "num",
  74. param: "",
  75. errInfo: "组织级别错误"
  76. },
  77. ],
  78. 'addOrgInfo.parentOrgId': [
  79. {
  80. limit: "required",
  81. param: "",
  82. errInfo: "上级ID不能为空"
  83. },
  84. {
  85. limit: "num",
  86. param: "",
  87. errInfo: "上级ID不正确"
  88. },
  89. ],
  90. 'addOrgInfo.belongCommunityId': [
  91. {
  92. limit: "required",
  93. param: "",
  94. errInfo: "隶属小区不能为空"
  95. },
  96. {
  97. limit: "num",
  98. param: "",
  99. errInfo: "隶属小区不正确"
  100. },
  101. ],
  102. 'addOrgInfo.description': [
  103. {
  104. limit: "maxLength",
  105. param: "200",
  106. errInfo: "描述不能为空"
  107. },
  108. ],
  109. });
  110. }
  111. ,
  112. saveOrgInfo: function () {
  113. vc.component.addOrgInfo.belongCommunityId = vc.component.addOrgInfo.communityId;
  114. if (!vc.component.addOrgValidate()) {
  115. vc.message(vc.validate.errInfo);
  116. return;
  117. }
  118. vc.component.addOrgInfo.communityId = vc.getCurrentCommunity().communityId;
  119. //不提交数据将数据 回调给侦听处理
  120. if (vc.notNull($props.callBackListener)) {
  121. vc.emit($props.callBackListener, $props.callBackFunction, vc.component.addOrgInfo);
  122. $('#addOrgModel').modal('hide');
  123. return;
  124. }
  125. vc.http.post(
  126. 'addOrg',
  127. 'save',
  128. JSON.stringify(vc.component.addOrgInfo),
  129. {
  130. emulateJSON: true
  131. },
  132. function (json, res) {
  133. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  134. if (res.status == 200) {
  135. //关闭model
  136. $('#addOrgModel').modal('hide');
  137. vc.component.clearAddOrgInfo();
  138. vc.emit('orgManage', 'listOrg', {});
  139. return;
  140. }
  141. vc.message(json);
  142. },
  143. function (errInfo, error) {
  144. console.log('请求失败处理');
  145. vc.message(errInfo);
  146. });
  147. }
  148. ,
  149. clearAddOrgInfo: function () {
  150. vc.component.addOrgInfo = {
  151. orgName: '',
  152. orgLevel: '',
  153. parentOrgId: '',
  154. description: '',
  155. parentOrg: [],
  156. belongCommunityId: '',
  157. communityId: '',
  158. };
  159. }
  160. ,
  161. _addOrgListParentOrgInfo: function () {
  162. var _tmpOrgLevel = vc.component.addOrgInfo.orgLevel;
  163. if (_tmpOrgLevel > 1) {
  164. _tmpOrgLevel = _tmpOrgLevel - 1;
  165. }
  166. var param = {
  167. params: {
  168. orgLevel: _tmpOrgLevel,
  169. page: 1,
  170. row: 30,
  171. }
  172. };
  173. //发送get请求
  174. vc.http.get('addOrg',
  175. 'list',
  176. param,
  177. function (json, res) {
  178. var _orgManageInfo = JSON.parse(json);
  179. vc.component.addOrgInfo.parentOrg = _orgManageInfo.orgs;
  180. }, function (errInfo, error) {
  181. console.log('请求失败处理');
  182. }
  183. );
  184. },
  185. _loadAddEnterCommunitys:function () {
  186. //belongCommunitys
  187. var param = {
  188. params:{
  189. _uid:'mmmllnnjhhjjh'
  190. }
  191. }
  192. //发送get请求
  193. vc.http.get('addOrg',
  194. 'listEnterCommunitys',
  195. param,
  196. function (json, res) {
  197. var _enterCommunitys = JSON.parse(json);
  198. vc.component.addOrgInfo.belongCommunitys = _enterCommunitys;
  199. }, function (errInfo, error) {
  200. console.log('请求失败处理');
  201. }
  202. );
  203. }
  204. }
  205. })
  206. ;
  207. })(window.vc);