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

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