微信小程序
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.

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