微信小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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