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

593 line
14 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. let data = {
  213. method:"GET"
  214. }
  215. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  216. success: (res) => {
  217. if (res.code == API.SUCCESS_CODE) {
  218. that.setData({
  219. username:res.user.nickName,
  220. })
  221. }
  222. }
  223. })
  224. UTIL.httpRequest(API.URL_GET_GETAPPROVALBYID+e.currentTarget.dataset.id, data, {
  225. success: (res) => {
  226. if (res.code == API.SUCCESS_CODE) {
  227. let list = [];
  228. res.data.map((rr,index) => {
  229. if(rr.nickName == that.data.username){
  230. res.data.splice(index,1);
  231. }
  232. list.push(rr.userId+"")
  233. })
  234. this.setData({templateDetailList:res.data,result:list});
  235. this.closeBox();
  236. }
  237. }
  238. })
  239. },
  240. deleteTemplate:function(e){
  241. let ids = [e.currentTarget.dataset.id]
  242. let url = API.URL_GET_MOBILEREMOVE+ids
  243. let _this = this
  244. wx.request({
  245. url,
  246. method:"GET",
  247. timeout: 60000,
  248. header: {
  249. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  250. },
  251. success: function (response) {
  252. console.log(e);
  253. _this.data.templateList.splice(e.currentTarget.dataset.index, 1);
  254. wx.showToast({
  255. title: '删除成功!',
  256. icon: 'success',
  257. duration: 2000
  258. })
  259. _this.setData({
  260. templateList : _this.data.templateList,
  261. })
  262. _this.getApprovalItemList()
  263. }
  264. })
  265. },
  266. townList:function(){
  267. let _this = this
  268. let url = API.URL_GET_TOWNINFOBYDEPTID+0
  269. wx.request({
  270. url,
  271. method:"GET",
  272. timeout: 60000,
  273. header: {
  274. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  275. },
  276. success: function (response) {
  277. let d = {
  278. deptId:response.data.data.deptId,
  279. deptLevel:3,
  280. method:"GET"
  281. }
  282. UTIL.httpRequest(API.URL_GET_USERLIST,d,{
  283. success: (res) => {
  284. if (res.code == API.SUCCESS_CODE) {
  285. res.rows.map(rr => {
  286. rr.approvalLevel = 3
  287. rr.approvalType = 1
  288. rr.approvalOrder = 0
  289. })
  290. _this.setData({towns:res.rows});
  291. }
  292. }
  293. })
  294. }
  295. })
  296. },
  297. groupList:function(){
  298. let data = {
  299. method:"GET"
  300. }
  301. UTIL.httpRequest(API.URL_GET_USERLIST,data ,{
  302. success: (res) => {
  303. if (res.code == API.SUCCESS_CODE) {
  304. res.rows.map(rr => {
  305. rr.approvalLevel = 2
  306. rr.approvalType = 1
  307. rr.approvalOrder = 0
  308. })
  309. this.setData({groups:res.rows});
  310. }
  311. }
  312. })
  313. let parmes = {
  314. pageNum:'1',
  315. pageSize:'999'
  316. }
  317. UTIL.httpRequest(API.URL_GET_TEMPLATELIST,parmes ,{
  318. success: (res) => {
  319. if (res.code == API.SUCCESS_CODE) {
  320. this.setData({templateList:res.rows});
  321. }
  322. }
  323. })
  324. },
  325. villageList:function(){
  326. let data = {
  327. deptId : this.data.deptId,
  328. deptLevel:2,
  329. method:"GET"
  330. }
  331. UTIL.httpRequest(API.URL_GET_USERLIST,data ,{
  332. success: (res) => {
  333. if (res.code == API.SUCCESS_CODE) {
  334. res.rows.map(rr => {
  335. rr.approvalLevel = 1
  336. rr.approvalType = 1
  337. rr.approvalOrder = 0
  338. })
  339. this.setData({villages:res.rows});
  340. }
  341. }
  342. })
  343. },
  344. onChange(event) {
  345. let _this = this
  346. console.log(event);
  347. this.setData({result:event.detail})
  348. this.setData({templateDetailList:[]})
  349. let list = _this.data.templateDetailList
  350. for (let j in event.detail){
  351. let str = event.detail[j]
  352. for(let i in _this.data.groups){
  353. if(_this.data.groups[i].userId == str){
  354. let sin = _this.data.groups[i]
  355. list.push(sin)
  356. _this.setData({templateDetailList:list})
  357. }
  358. }
  359. for(let i in _this.data.villages){
  360. if(_this.data.villages[i].userId == str){
  361. let sin = _this.data.villages[i]
  362. list.push(sin)
  363. _this.setData({templateDetailList:list})
  364. }
  365. }
  366. for(let i in _this.data.towns){
  367. if(_this.data.towns[i].userId == str){
  368. let sin = _this.data.towns[i]
  369. list.push(sin)
  370. _this.setData({templateDetailList:list})
  371. }
  372. }
  373. }
  374. let li = this.data.templateDetailList
  375. console.log(li);
  376. li = li.filter(function(e,i,s){
  377. s[i].name = i+1
  378. s[i].approvalOrder = i+1
  379. return true
  380. })
  381. this.setData({templateDetailList:li})
  382. },
  383. back:function(){
  384. wx.navigateBack({
  385. delta: 1
  386. })
  387. },
  388. save:function(){
  389. let _this = this
  390. let list = this.data.templateDetailList
  391. list = list.filter(function(e,i,s){
  392. s[i].name = i+1
  393. return true
  394. })
  395. for (let index = 0; index < list.length; index++) {
  396. list[index].approvalTemplateId = _this.data.itemId;
  397. }
  398. let url = API.URL_GET_GETAPPROVALPROCESSADD
  399. wx.request({
  400. url,
  401. data: list,
  402. method:"POST",
  403. timeout: 60000,
  404. header: {
  405. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  406. },
  407. success: function (response) {
  408. wx.showToast({
  409. title: "保存成功!",
  410. duration: 2000,
  411. icon:"success"
  412. })
  413. setTimeout(function(){
  414. wx.reLaunch({
  415. url: '/pages/index/index'
  416. })
  417. },2000)
  418. },
  419. })
  420. },
  421. submit:function(){
  422. let _this = this
  423. let data={
  424. approvalTemplate:{
  425. name:this.data.temName,
  426. type:1,
  427. dataType:1
  428. },
  429. approvalTemplateDetailList:this.data.templateDetailList,
  430. method:"POST"
  431. }
  432. let list = this.data.templateDetailList
  433. list = list.filter(function(e,i,s){
  434. s[i].name = i+1
  435. return true
  436. })
  437. for (let index = 0; index < list.length; index++) {
  438. list[index].approvalTemplateId = _this.data.itemId;
  439. }
  440. let url = API.URL_GET_GETAPPROVALPROCESSADD
  441. wx.request({
  442. url,
  443. data: _this.data.templateDetailList,
  444. method:"POST",
  445. timeout: 60000,
  446. header: {
  447. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  448. },
  449. success: function (response) {
  450. _this.requestSubmit()
  451. },
  452. })
  453. // UTIL.httpRequest(API.URL_GET_GETAPPROVALPROCESSADD,this.data.templateDetailList,{
  454. // success: (res) => {
  455. // if (res.code == API.SUCCESS_CODE) {
  456. // let list = this.data.templateList
  457. // list.push(res.data)
  458. // this.setData({
  459. // temId:res.data.id,
  460. // templateList:list,
  461. // temName:""
  462. // });
  463. // let item_ = this.data.item
  464. // item_.templateId = res.data.id
  465. // item_.method = "POST"
  466. // _this.requestSubmit()
  467. // // UTIL.httpRequest(API.URL_POST_APPROVALITEMSEDIT,item_,{
  468. // // success: (res) => {
  469. // // if (res.code == API.SUCCESS_CODE) {
  470. // // }
  471. // // }
  472. // // })
  473. // }
  474. // }
  475. // })
  476. },
  477. requestSubmit:function(){
  478. let url = API.URL_POST_APPROVALITEMSSUBMIT+this.data.itemId
  479. wx.request({
  480. url,
  481. method:"POST",
  482. timeout: 60000,
  483. header: {
  484. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  485. },
  486. success: function (r) {
  487. if (r.data.code == API.SUCCESS_CODE) {
  488. wx.showToast({
  489. title: "提交成功!",
  490. duration: 2000,
  491. icon:"success"
  492. })
  493. setTimeout(function(){
  494. wx.reLaunch({
  495. url: '/pages/index/index'
  496. })
  497. },2000)
  498. }else{
  499. wx.showToast({
  500. title: "操作失败!",
  501. duration: 2000,
  502. icon:"error"
  503. })
  504. }
  505. },
  506. })
  507. },
  508. openBox:function(){
  509. var that = this ;
  510. that.setData({
  511. show: true,
  512. })
  513. },
  514. closeBox:function(){
  515. var that = this ;
  516. that.setData({
  517. show: false
  518. })
  519. },
  520. showPopup() {
  521. this.setData({
  522. showPopup: true,
  523. temName:""
  524. });
  525. },
  526. showPopupNew() {
  527. this.setData({
  528. showPopup2: true,
  529. temName:""
  530. });
  531. },
  532. onClose() {
  533. this.setData({ showPopup: false});
  534. },
  535. /**
  536. * 生命周期函数--监听页面初次渲染完成
  537. */
  538. onReady() {
  539. },
  540. /**
  541. * 生命周期函数--监听页面显示
  542. */
  543. onShow() {
  544. },
  545. /**
  546. * 生命周期函数--监听页面隐藏
  547. */
  548. onHide() {
  549. },
  550. /**
  551. * 生命周期函数--监听页面卸载
  552. */
  553. onUnload() {
  554. },
  555. /**
  556. * 页面相关事件处理函数--监听用户下拉动作
  557. */
  558. onPullDownRefresh() {
  559. },
  560. /**
  561. * 页面上拉触底事件的处理函数
  562. */
  563. onReachBottom() {
  564. },
  565. /**
  566. * 用户点击右上角分享
  567. */
  568. onShareAppMessage() {
  569. }
  570. })