微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

628 lines
16 KiB

  1. // pages/apply/approval/approval.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. isIPX: app.globalData.isIPX,
  11. //事务总表对象
  12. item:{},
  13. detpId:"",
  14. itemId:"",
  15. active:0,
  16. result:[],
  17. show:false,
  18. showPopup:false,
  19. showPopup2:false,
  20. templateList:[],
  21. templateDetailList:[],
  22. groups:[],
  23. villages:[],
  24. towns:[],
  25. temName:"",
  26. temId:""
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. console.log(options);
  33. this.setData({
  34. itemId:options.id,
  35. deptId:options.deptId,
  36. form:JSON.parse(options.form)
  37. });
  38. console.log(JSON.parse(options.form));
  39. if(options.type == 'template'){
  40. let list = [];
  41. let array = JSON.parse(options.applyOptions).approvalTemplateDetailList;
  42. console.log(JSON.parse(options.applyOptions));
  43. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  44. success: (res2) => {
  45. JSON.parse(options.applyOptions).approvalTemplateDetailList.map((rr,index )=> {
  46. console.log(rr);
  47. console.log(JSON.parse(options.applyOptions).approvalTemplateDetailList);
  48. console.log(rr.nickName == res2.user.nickName);
  49. console.log(index);
  50. if(rr.nickName == res2.user.nickName){
  51. array.splice(index,1);
  52. }else{
  53. list.push(rr.userId+"")
  54. }
  55. })
  56. array.map((rrr,index)=>{
  57. array.name = index+1
  58. })
  59. this.setData({
  60. templateDetailList:array,
  61. result:list
  62. })
  63. }
  64. })
  65. }else{
  66. // this.townList();
  67. // this.villageList();
  68. this.getApprovalItemsById();
  69. }
  70. this.groupList();
  71. //this.getApprovalItemList();JSON.parse(options.array)
  72. },
  73. getApprovalItemsById(){
  74. let _this = this
  75. let url = API.URL_GET_APPROVALITEMSBYID+this.data.itemId
  76. wx.request({
  77. url,
  78. method:"GET",
  79. timeout: 60000,
  80. header: {
  81. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  82. },
  83. success: function (response) {
  84. _this.setData({item:response.data.data})
  85. if(_this.data.item.templateId!=""&&_this.data.item.templateId!=null){
  86. _this.setData({item:response.data.data,temId:_this.data.itemId})
  87. let d = {
  88. method:"GET"
  89. }
  90. console.log(_this.data.itemId);
  91. UTIL.httpRequest(API.URL_GET_TEMPLATEDETAIL + _this.data.itemId, d, {
  92. success: (r) => {
  93. console.log(r);
  94. if (r.code == API.SUCCESS_CODE) {
  95. _this.setData({templateDetailList:r.rows});
  96. let list = []
  97. r.rows.map(rr => {
  98. list.push(rr.userId+"")
  99. })
  100. _this.setData({result:list})
  101. }
  102. }
  103. })
  104. }else {
  105. _this.getApprovalItemList()
  106. }
  107. }
  108. })
  109. },
  110. inputTem:function(e){
  111. console.log(e)
  112. this.setData({temName:e.detail.value})
  113. },
  114. inputTem2:function(e){
  115. this.setData({temName2:e.detail.value})
  116. },
  117. confirmTemNew(e){
  118. var that = this;
  119. let data={
  120. approvalTemplate:{
  121. name:that.data.temName2,
  122. type:1,
  123. dataType:0
  124. },
  125. approvalTemplateDetailList:that.data.templateDetailList,
  126. applyData:that.data.form
  127. }
  128. let dataList = {
  129. templateName:that.data.temName2,
  130. templateContent:JSON.stringify(data),
  131. method:"POST"
  132. }
  133. UTIL.httpRequest(API.URL_GET_GETTEMPLATEADD,dataList,{
  134. success: (res) => {
  135. if (res.code == API.SUCCESS_CODE) {
  136. wx.showToast({
  137. title: "保存成功!",
  138. duration: 2000,
  139. icon:"success"
  140. })
  141. setTimeout(function(){
  142. that.setData({showPopup2:false,temName2:''})
  143. },2000)
  144. }
  145. }
  146. })
  147. },
  148. confirmTem:function(e){
  149. let data={
  150. approvalTemplate:{
  151. name:this.data.temName,
  152. type:1,
  153. dataType:0
  154. },
  155. approvalTemplateDetailList:this.data.templateDetailList,
  156. method:"POST"
  157. }
  158. UTIL.httpRequest(API.URL_POST_MOBILEADD,data,{
  159. success: (res) => {
  160. if (res.code == API.SUCCESS_CODE) {
  161. let list = this.data.templateList
  162. list.push(res.data)
  163. wx.showToast({
  164. title: "保存成功!",
  165. duration: 2000,
  166. icon:"success"
  167. })
  168. this.setData({
  169. temId:res.data.id,
  170. templateList:list,
  171. temName:"",
  172. showPopup:false
  173. });
  174. }
  175. }
  176. })
  177. },
  178. cancelTem:function(e){
  179. this.setData({temName:"",showPopup:false});
  180. },
  181. cancelTemNew:function(e){
  182. this.setData({temName2:"",showPopup2:false});
  183. },
  184. upItem:function(e){
  185. let index = e.currentTarget.dataset.id
  186. let item = this.data.templateDetailList[index]
  187. let list = this.data.templateDetailList
  188. if(index>0&&index<=list.length){
  189. list.splice(index,1)
  190. list.splice(index-1,0,item)
  191. for(let i = 0;i< list.length;i++){
  192. list[i].name = i+1
  193. }
  194. this.setData({templateDetailList:list});
  195. }
  196. },
  197. downItem:function(e){
  198. let index = e.currentTarget.dataset.id
  199. let item = this.data.templateDetailList[index]
  200. let list = this.data.templateDetailList
  201. if(index>=0&&index<list.length){
  202. list.splice(index,1)
  203. list.splice(index+1,0,item)
  204. for(let i = 0;i< list.length;i++){
  205. list[i].name = i+1
  206. }
  207. this.setData({templateDetailList:list});
  208. }
  209. },
  210. getApprovalItemList:function(){
  211. let data={
  212. method:"GET"
  213. }
  214. UTIL.httpRequest(API.URL_GET_TEMPLATEDETAIL+this.data.itemId,data, {
  215. success: (r) => {
  216. if (r.code == API.SUCCESS_CODE) {
  217. this.setData({templateDetailList:r.data});
  218. let list = []
  219. r.data.map(rr => {
  220. list.push(rr.userId+"")
  221. })
  222. this.setData({result:list})
  223. }
  224. }
  225. })
  226. },
  227. chooseTemplate:function(e){
  228. var that = this ;
  229. let data = {
  230. method:"GET"
  231. }
  232. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  233. success: (res2) => {
  234. if (res2.code == API.SUCCESS_CODE) {
  235. that.setData({
  236. username:res2.user.nickName,
  237. })
  238. UTIL.httpRequest(API.URL_GET_GETAPPROVALBYID+e.currentTarget.dataset.id, data, {
  239. success: (res) => {
  240. if (res.code == API.SUCCESS_CODE) {
  241. let list = [];
  242. res.data.map((rr,index) => {
  243. if(rr.nickName == res2.user.nickName){
  244. res.data.splice(index,1);
  245. }
  246. list.push(rr.userId+"")
  247. })
  248. res.data.map((rrr,index)=>{
  249. rrr.name = index+1
  250. })
  251. this.setData({templateDetailList:res.data,result:list});
  252. this.closeBox();
  253. }
  254. }
  255. })
  256. }
  257. }
  258. })
  259. },
  260. deleteTemplate:function(e){
  261. let ids =e.currentTarget.dataset.id;
  262. let data = {
  263. id:ids,
  264. status:"1"
  265. }
  266. let url = API.URL_GET_MOBILEREMOVE
  267. let _this = this
  268. wx.request({
  269. url,
  270. method:"POST",
  271. timeout: 60000,
  272. data:data,
  273. header: {
  274. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  275. },
  276. success: function (response) {
  277. console.log(e);
  278. console.log(response)
  279. _this.data.templateList.splice(e.currentTarget.dataset.index, 1);
  280. wx.showToast({
  281. title: '禁用成功!',
  282. icon: 'success',
  283. duration: 2000
  284. })
  285. _this.setData({
  286. templateList : _this.data.templateList,
  287. })
  288. _this.getApprovalItemList()
  289. }
  290. })
  291. },
  292. townList:function(){
  293. let _this = this
  294. let url = API.URL_GET_TOWNINFOBYDEPTID+0
  295. wx.request({
  296. url,
  297. method:"GET",
  298. timeout: 60000,
  299. header: {
  300. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  301. },
  302. success: function (response) {
  303. let d = {
  304. deptId:response.data.data.deptId,
  305. deptLevel:3,
  306. method:"GET"
  307. }
  308. UTIL.httpRequest(API.URL_GET_USERLIST,d,{
  309. success: (res) => {
  310. if (res.code == API.SUCCESS_CODE) {
  311. res.rows.map(rr => {
  312. rr.approvalLevel = 3
  313. rr.approvalType = 1
  314. rr.approvalOrder = 0
  315. })
  316. _this.setData({towns:res.rows});
  317. }
  318. }
  319. })
  320. }
  321. })
  322. },
  323. groupList:function(){
  324. let data = {
  325. method:"GET"
  326. }
  327. UTIL.httpRequest(API.URL_GET_USERLIST,data ,{
  328. success: (res) => {
  329. if (res.code == API.SUCCESS_CODE) {
  330. res.rows.map(rr => {
  331. rr.approvalLevel = 2
  332. rr.approvalType = 1
  333. rr.approvalOrder = 0
  334. })
  335. this.setData({groups:res.rows});
  336. }
  337. }
  338. })
  339. let parmes = {
  340. pageNum:'1',
  341. pageSize:'999',
  342. status:"0"
  343. }
  344. UTIL.httpRequest(API.URL_GET_TEMPLATELIST,parmes ,{
  345. success: (res) => {
  346. if (res.code == API.SUCCESS_CODE) {
  347. this.setData({templateList:res.rows});
  348. }
  349. }
  350. })
  351. },
  352. villageList:function(){
  353. let data = {
  354. deptId : this.data.deptId,
  355. deptLevel:2,
  356. method:"GET"
  357. }
  358. UTIL.httpRequest(API.URL_GET_USERLIST,data ,{
  359. success: (res) => {
  360. if (res.code == API.SUCCESS_CODE) {
  361. res.rows.map(rr => {
  362. rr.approvalLevel = 1
  363. rr.approvalType = 1
  364. rr.approvalOrder = 0
  365. })
  366. this.setData({villages:res.rows});
  367. }
  368. }
  369. })
  370. },
  371. onChange(event) {
  372. let _this = this
  373. console.log(event);
  374. this.setData({result:event.detail})
  375. this.setData({templateDetailList:[]})
  376. let list = _this.data.templateDetailList
  377. for (let j in event.detail){
  378. let str = event.detail[j]
  379. for(let i in _this.data.groups){
  380. if(_this.data.groups[i].userId == str){
  381. let sin = _this.data.groups[i]
  382. list.push(sin)
  383. _this.setData({templateDetailList:list})
  384. }
  385. }
  386. for(let i in _this.data.villages){
  387. if(_this.data.villages[i].userId == str){
  388. let sin = _this.data.villages[i]
  389. list.push(sin)
  390. _this.setData({templateDetailList:list})
  391. }
  392. }
  393. for(let i in _this.data.towns){
  394. if(_this.data.towns[i].userId == str){
  395. let sin = _this.data.towns[i]
  396. list.push(sin)
  397. _this.setData({templateDetailList:list})
  398. }
  399. }
  400. }
  401. let li = this.data.templateDetailList
  402. console.log(li);
  403. li = li.filter(function(e,i,s){
  404. s[i].name = i+1
  405. s[i].approvalOrder = i+1
  406. return true
  407. })
  408. this.setData({templateDetailList:li})
  409. },
  410. back:function(){
  411. wx.navigateBack({
  412. delta: 1
  413. })
  414. },
  415. save:function(){
  416. let _this = this
  417. let list = this.data.templateDetailList
  418. list = list.filter(function(e,i,s){
  419. s[i].name = i+1
  420. return true
  421. })
  422. for (let index = 0; index < list.length; index++) {
  423. list[index].approvalTemplateId = _this.data.itemId;
  424. }
  425. let url = API.URL_GET_GETAPPROVALPROCESSADD
  426. wx.request({
  427. url,
  428. data: list,
  429. method:"POST",
  430. timeout: 60000,
  431. header: {
  432. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  433. },
  434. success: function (response) {
  435. wx.showToast({
  436. title: "保存成功!",
  437. duration: 2000,
  438. icon:"success"
  439. })
  440. setTimeout(function(){
  441. wx.reLaunch({
  442. url: '/pages/index/index'
  443. })
  444. },2000)
  445. },
  446. })
  447. },
  448. submit:function(){
  449. let _this = this
  450. if(this.data.templateDetailList.length==0){
  451. wx.showToast({
  452. title: "请选择审批人",
  453. duration: 2000,
  454. icon:"error"
  455. })
  456. return;
  457. }
  458. let data={
  459. approvalTemplate:{
  460. name:this.data.temName,
  461. type:1,
  462. dataType:1
  463. },
  464. approvalTemplateDetailList:this.data.templateDetailList,
  465. method:"POST"
  466. }
  467. let list = this.data.templateDetailList
  468. list = list.filter(function(e,i,s){
  469. s[i].name = i+1
  470. return true
  471. })
  472. for (let index = 0; index < list.length; index++) {
  473. list[index].approvalTemplateId = _this.data.itemId;
  474. }
  475. let url = API.URL_GET_GETAPPROVALPROCESSADD
  476. wx.request({
  477. url,
  478. data: _this.data.templateDetailList,
  479. method:"POST",
  480. timeout: 60000,
  481. header: {
  482. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  483. },
  484. success: function (response) {
  485. _this.requestSubmit()
  486. },
  487. })
  488. // UTIL.httpRequest(API.URL_GET_GETAPPROVALPROCESSADD,this.data.templateDetailList,{
  489. // success: (res) => {
  490. // if (res.code == API.SUCCESS_CODE) {
  491. // let list = this.data.templateList
  492. // list.push(res.data)
  493. // this.setData({
  494. // temId:res.data.id,
  495. // templateList:list,
  496. // temName:""
  497. // });
  498. // let item_ = this.data.item
  499. // item_.templateId = res.data.id
  500. // item_.method = "POST"
  501. // _this.requestSubmit()
  502. // // UTIL.httpRequest(API.URL_POST_APPROVALITEMSEDIT,item_,{
  503. // // success: (res) => {
  504. // // if (res.code == API.SUCCESS_CODE) {
  505. // // }
  506. // // }
  507. // // })
  508. // }
  509. // }
  510. // })
  511. },
  512. requestSubmit:function(){
  513. let url = API.URL_POST_APPROVALITEMSSUBMIT+this.data.itemId
  514. wx.request({
  515. url,
  516. method:"POST",
  517. timeout: 60000,
  518. header: {
  519. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  520. },
  521. success: function (r) {
  522. if (r.data.code == API.SUCCESS_CODE) {
  523. wx.showToast({
  524. title: "提交成功!",
  525. duration: 2000,
  526. icon:"success"
  527. })
  528. setTimeout(function(){
  529. wx.reLaunch({
  530. url: '/pages/index/index'
  531. })
  532. },2000)
  533. }else{
  534. wx.showToast({
  535. title: "操作失败!",
  536. duration: 2000,
  537. icon:"error"
  538. })
  539. }
  540. },
  541. })
  542. },
  543. openBox:function(){
  544. var that = this ;
  545. that.setData({
  546. show: true,
  547. })
  548. },
  549. closeBox:function(){
  550. var that = this ;
  551. that.setData({
  552. show: false
  553. })
  554. },
  555. showPopup() {
  556. this.setData({
  557. showPopup: true,
  558. temName:""
  559. });
  560. },
  561. showPopupNew() {
  562. this.setData({
  563. showPopup2: true,
  564. temName:""
  565. });
  566. },
  567. onClose() {
  568. this.setData({ showPopup: false});
  569. },
  570. /**
  571. * 生命周期函数--监听页面初次渲染完成
  572. */
  573. onReady() {
  574. },
  575. /**
  576. * 生命周期函数--监听页面显示
  577. */
  578. onShow() {
  579. },
  580. /**
  581. * 生命周期函数--监听页面隐藏
  582. */
  583. onHide() {
  584. },
  585. /**
  586. * 生命周期函数--监听页面卸载
  587. */
  588. onUnload() {
  589. },
  590. /**
  591. * 页面相关事件处理函数--监听用户下拉动作
  592. */
  593. onPullDownRefresh() {
  594. },
  595. /**
  596. * 页面上拉触底事件的处理函数
  597. */
  598. onReachBottom() {
  599. },
  600. /**
  601. * 用户点击右上角分享
  602. */
  603. onShareAppMessage() {
  604. }
  605. })