state.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. layui.config({
  2. base: '../../lib/layui/lay/mymodules/'
  3. ,version: '101100'
  4. }).use('eleTree');
  5. layui.extend({
  6. admin: '{/}../../static/js/admin'
  7. });
  8. layui.use(['jquery','eleTree','table','laypage','admin'], function(){
  9. var $= layui.jquery,
  10. eleTree = layui.eleTree,
  11. laypage = layui.laypage,
  12. table = layui.table;
  13. var addStateHtml = '../../pages/admin/addstate.html';
  14. var updateHtml = '../../pages/admin/updateState.html';
  15. // 部门
  16. var belpID = 'root';
  17. delpFun();
  18. function delpFun(){
  19. $.ajax({
  20. url:'http://apptest.jieweizhineng.com/api/section/getlist',
  21. method:'get',
  22. dataType: 'json',
  23. data: {
  24. },
  25. success:function (res) {
  26. if(res.code === 0){
  27. var data = [res.data];
  28. eleTree.render({
  29. elem: '.ele1',
  30. data:data ,
  31. defaultExpandAll:true,
  32. // showCheckbox: true,
  33. });
  34. eleTree.on("nodeClick(data)",function(d) {
  35. belpID = d.data.currentData.id;
  36. $('.stetaName').val("");
  37. var info={
  38. statusContent: '',
  39. departmentId: d.data.currentData.id,
  40. deleteStatus: 'false',
  41. pageNumber: '1',
  42. pageSize: '1',
  43. };
  44. getStateList(info);
  45. })
  46. }else{
  47. layer.msg('请检查网路', {icon: 2});
  48. }
  49. },
  50. error:function (err) {
  51. layer.msg('请检查网路', {icon: 2});
  52. }
  53. })
  54. }
  55. var info={
  56. statusContent: $('.stetaName').val(),
  57. departmentId: belpID,
  58. deleteStatus: 'false',
  59. pageNumber: '1',
  60. pageSize: '1',
  61. };
  62. getStateList(info);
  63. function getStateList(res) {
  64. $.ajax({
  65. url: 'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/getStatusList',
  66. method: 'get',
  67. dataType: 'json',
  68. data: res,
  69. success: function (data) {
  70. laypage.render({
  71. elem: 'pageItem',
  72. count: data.count,
  73. limit: 10,
  74. layout: ['count', 'prev', 'page', 'next', 'skip'],
  75. jump: function(obj, first) {
  76. var index = layer.load(2);
  77. table.render({
  78. elem: '#stateRemind',
  79. url: 'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/getStatusList',
  80. id: 'idstetaTable',
  81. method: 'get',
  82. loading: true,
  83. cols: [[
  84. {field: 'statusContent', title: '状态名称', align: 'center'}
  85. , {field: 'createDate', title: '创建日期', align: 'center'}
  86. , {title: ' 操作', align: 'center', toolbar: '#barDemo'}
  87. ]],
  88. where: {
  89. statusContent: res.statusContent,
  90. departmentId: res.departmentId,
  91. deleteStatus: res.deleteStatus,
  92. pageNumber: obj.curr,
  93. pageSize: obj.limit,
  94. },
  95. response: {
  96. statusName: 'code'
  97. , statusCode: 200,
  98. countName: 'count',
  99. dataName: 'data'
  100. },
  101. done: function (res, curr, count) {
  102. layer.close(index);
  103. if (res.code === '200') {
  104. $('.fr').html('共有数据:'+res.count+' 条')
  105. }
  106. }
  107. });
  108. }
  109. })
  110. }
  111. });
  112. }
  113. // 查询
  114. $(".seachSteta").click(function () {
  115. var checkbox = $("#checkboxT").prop('checked'),
  116. root='',
  117. info;
  118. if(checkbox == true){
  119. root = '';
  120. info={
  121. statusContent: $('.stetaName').val(),
  122. departmentId: root,
  123. deleteStatus: 'false',
  124. pageNumber: '1',
  125. pageSize: '1',
  126. };
  127. }else {
  128. info={
  129. statusContent: $('.stetaName').val(),
  130. departmentId: belpID,
  131. deleteStatus: 'false',
  132. pageNumber: '1',
  133. pageSize: '1',
  134. };
  135. }
  136. getStateList(info)
  137. });
  138. // 监听状态table
  139. table.on('tool(stateItme)', function(obj) {
  140. if( obj.event === "move"){
  141. } else if (obj.event === "copy"){
  142. var content ={
  143. _method:'put'
  144. };
  145. layer.alert('确认要复制记录模板吗?',{icon: 8}, function(index){
  146. $.ajax({
  147. url: 'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/copyStatus/'+obj.data.id,
  148. method: 'post',
  149. dataType: 'json',
  150. data: content,
  151. success: function (res) {
  152. if (res.code === '200'){
  153. layer.msg('复制成功', {icon: 1});
  154. table.reload('idstetaTable');
  155. } else{
  156. layer.msg('复制失败', {icon: 2});
  157. table.reload('idstetaTable');
  158. }
  159. layer.close(index);
  160. },
  161. error:function () {
  162. layer.msg('请检查网络', {icon: 2});
  163. layer.close(index);
  164. }
  165. });
  166. });
  167. } else if (obj.event === "edit"){
  168. var objID =obj.data;
  169. var delobj=[];
  170. layer.open({
  171. type: 2,
  172. id: 'updateState',
  173. title:'修改状态和提醒设置',
  174. shadeClose: true,
  175. scrollbar:true,
  176. shade: 0.3,
  177. maxmin: true,
  178. skin: 'oaBtn',
  179. btn: ['确认', '取消'],
  180. area: ['500px', '500px'],
  181. content: updateHtml,
  182. success: function (layero, index) {
  183. var body = layer.getChildFrame('body', index);
  184. body.find('#stetaName').val(obj.data.statusContent);
  185. $.ajax({
  186. url: 'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/getStatusItemList/'+obj.data.id,
  187. method: 'get',
  188. dataType: 'json',
  189. success: function (res) {
  190. for (var i=0;i<res.data.length;i++){
  191. var str =`
  192. <div class="a_itme" id-data="${res.data[i].id}" delete-flay="true">
  193. <div class="a_colour">
  194. <span color_data="${res.data[i].statusColor}" style="background: ${res.data[i].statusColor}"></span>
  195. </div>
  196. <div class="a_modle">
  197. <i class="pointedSpan"></i>
  198. <b class="a_continue">继续</b>
  199. <b class="a_complete">完成</b>
  200. <span></span>
  201. <span></span>
  202. </div>
  203. <div class="a_delete">
  204. <i class="layui-icon layui-icon-delete"></i>
  205. </div>
  206. <input type="text" value="${res.data[i].statusContent}" placeholder="请输入状态名称" name="username" required="" lay-verify="required" autocomplete="off" class="layui-input a_steta">
  207. </div>`;
  208. body.find(".a_itmes").append(str)
  209. }
  210. },
  211. error:function () {
  212. layer.msg('请检查网络', {icon: 2});
  213. }
  214. });
  215. body.delegate('.a_delete','click',function () {
  216. if (body.find(".a_itmes .a_itme").length === 1) {
  217. return;
  218. }else {
  219. var id = $(this).parent().attr("id-data"),
  220. deleteFlay = $(this).parent().attr("delete-flay");
  221. var sonterm = {deleteFlag:deleteFlay,id:id,statusColor:'',statusContent:'',zIndex:''};
  222. delobj.push(sonterm)
  223. }
  224. })
  225. },
  226. yes: function (index, layero) {
  227. var body = layer.getChildFrame('body', index);
  228. var item = body.find('.a_itmes .a_itme');
  229. var a_colour = body.find('.a_colour');
  230. var arr = [];
  231. var ID = [];
  232. var json =[];
  233. var color =[];
  234. var obj = {deleteFlag:'false',id:'',statusColor:'',statusContent:'',zIndex:''};
  235. a_colour.each(function () {
  236. var value = $(this).find('span').attr("color_data");
  237. color.push(value);
  238. });
  239. item.each(function () {
  240. var value = $(this).find('input').val();
  241. var ids = $(this).attr("id-data");
  242. arr.push(value);
  243. ID.push(ids)
  244. });
  245. for (var i = 0; i < arr.length; i++) {
  246. obj = {};
  247. obj.deleteFlag = false;
  248. obj.id = ID[i];
  249. obj.statusColor = color[i];
  250. obj.statusContent = arr[i];
  251. obj.zIndex = i+1;
  252. delobj.push(obj)
  253. }
  254. var updateStetaInfo = {
  255. id:objID.id,
  256. statusContent:body.find('#stetaName').val(),
  257. statusItems:delobj,
  258. _method:'put'
  259. };
  260. $.ajax({
  261. url:'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/updateStatus',
  262. method:'POST',
  263. dataType: 'json',
  264. data: updateStetaInfo,
  265. success:function (res) {
  266. if(res.code === '200'){
  267. layer.msg('修改成功', {icon: 1});
  268. table.reload('idstetaTable');
  269. layer.close(index);
  270. }else{
  271. layer.msg('修改失败', {icon: 2});
  272. table.reload('idstetaTable');
  273. layer.close(index);
  274. }
  275. },
  276. error:function (err) {
  277. layer.close(index);
  278. }
  279. })
  280. }
  281. })
  282. } else if (obj.event === "delete"){
  283. var content ={
  284. _method:'DELETE'
  285. };
  286. layer.alert('确认要删除吗?',{icon: 8}, function(index){
  287. $.ajax({
  288. url: 'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/reomveStatus/'+obj.data.id,
  289. method: 'post',
  290. dataType: 'json',
  291. data: content,
  292. success: function (res) {
  293. if (res.code === '200'){
  294. layer.msg('删除成功', {icon: 1});
  295. table.reload('idstetaTable');
  296. } else{
  297. layer.msg('删除失败', {icon: 2});
  298. table.reload('idstetaTable');
  299. }
  300. layer.close(index);
  301. },
  302. error:function () {
  303. layer.msg('请检查网络', {icon: 2});
  304. layer.close(index);
  305. }
  306. });
  307. });
  308. }
  309. });
  310. // 添加状态
  311. // 打开添加弹窗
  312. $(".addState").click(function () {
  313. layer.open({
  314. type: 2,
  315. id: 'addState',
  316. title:'添加状态和提醒设置',
  317. shadeClose: true,
  318. scrollbar:true,
  319. shade: 0.3,
  320. maxmin: true,
  321. skin: 'oaBtn',
  322. btn: ['确认', '取消'],
  323. area: ['500px', '500px'],
  324. content: addStateHtml,
  325. success: function (layero, index) {
  326. var body = layer.getChildFrame('body', index);
  327. },
  328. yes: function (index, layero) {
  329. var body = layer.getChildFrame('body', index);
  330. var item = body.find('.a_itmes .a_itme');
  331. var a_colour = body.find('.a_colour');
  332. var json =[];
  333. var arr = [];
  334. var color =[];
  335. var obj = {statusColor:'',statusContent:'',zIndex:''};
  336. a_colour.each(function () {
  337. var value = $(this).find('span').attr("color_data");
  338. color.push(value);
  339. });
  340. item.each(function () {
  341. var value = $(this).find('input').val();
  342. arr.push(value);
  343. });
  344. for (var j = 0; j < arr.length; j++) {
  345. obj = {};
  346. obj.statusColor = color[j];
  347. obj.statusContent = arr[j];
  348. obj.zIndex = j+1;
  349. json.push(obj);
  350. }
  351. var addStetaInfo = {
  352. departmentId:belpID,
  353. statusContent:body.find('#stetaName').val(),
  354. statusItems:json
  355. };
  356. $.ajax({
  357. url:'http://apptest.jieweizhineng.com/api/swagger/api/status/v1/addStatus',
  358. method:'POST',
  359. dataType: 'json',
  360. data: addStetaInfo,
  361. success:function (res) {
  362. if(res.code === '200'){
  363. layer.msg('添加成功', {icon: 1});
  364. table.reload('idstetaTable');
  365. layer.close(index);
  366. }else{
  367. layer.msg('添加失败', {icon: 2});
  368. table.reload('idstetaTable')
  369. }
  370. },
  371. error:function (err) {
  372. layer.msg('网络错误', {icon: 2});
  373. }
  374. })
  375. }
  376. })
  377. })
  378. });