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

approval.js 16 KiB

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