微信小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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