微信小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

approval.js 14 KiB

há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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.approvalLevel = 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. deptId : this.data.deptId,
  267. deptLevel:1,
  268. method:"GET"
  269. }
  270. UTIL.httpRequest(API.URL_GET_USERLIST,data ,{
  271. success: (res) => {
  272. if (res.code == API.SUCCESS_CODE) {
  273. res.rows.map(rr => {
  274. rr.approvalLevel = 2
  275. rr.approvalLevel = 1
  276. rr.approvalOrder = 0
  277. })
  278. this.setData({groups:res.rows});
  279. }
  280. }
  281. })
  282. },
  283. villageList:function(){
  284. let data = {
  285. deptId : this.data.deptId,
  286. deptLevel:2,
  287. method:"GET"
  288. }
  289. UTIL.httpRequest(API.URL_GET_USERLIST,data ,{
  290. success: (res) => {
  291. if (res.code == API.SUCCESS_CODE) {
  292. res.rows.map(rr => {
  293. rr.approvalLevel = 1
  294. rr.approvalLevel = 1
  295. rr.approvalOrder = 0
  296. })
  297. this.setData({villages:res.rows});
  298. }
  299. }
  300. })
  301. },
  302. onChange(event) {
  303. let _this = this
  304. this.setData({result:event.detail})
  305. this.setData({templateDetailList:[]})
  306. let list = _this.data.templateDetailList
  307. for (let j in event.detail){
  308. let str = event.detail[j]
  309. for(let i in _this.data.groups){
  310. if(_this.data.groups[i].userId == str){
  311. let sin = _this.data.groups[i]
  312. list.push(sin)
  313. _this.setData({templateDetailList:list})
  314. }
  315. }
  316. for(let i in _this.data.villages){
  317. if(_this.data.villages[i].userId == str){
  318. let sin = _this.data.villages[i]
  319. list.push(sin)
  320. _this.setData({templateDetailList:list})
  321. }
  322. }
  323. for(let i in _this.data.towns){
  324. if(_this.data.towns[i].userId == str){
  325. let sin = _this.data.towns[i]
  326. list.push(sin)
  327. _this.setData({templateDetailList:list})
  328. }
  329. }
  330. }
  331. let li = this.data.templateDetailList
  332. li = li.filter(function(e,i,s){
  333. s[i].name = i+1
  334. s[i].approvalOrder = i+1
  335. return true
  336. })
  337. this.setData({templateDetailList:li})
  338. },
  339. back:function(){
  340. wx.navigateBack({
  341. delta: 1
  342. })
  343. },
  344. save:function(){
  345. let _this = this
  346. let list = this.data.templateDetailList
  347. list = list.filter(function(e,i,s){
  348. s[i].name = i+1
  349. return true
  350. })
  351. if(this.data.temId==""||this.data.temId==null){
  352. let data={
  353. approvalTemplate:{
  354. name:this.data.temName,
  355. type:1,
  356. dataType:1
  357. },
  358. approvalTemplateDetailList:list,
  359. method:"POST"
  360. }
  361. UTIL.httpRequest(API.URL_POST_MOBILEADD,data,{
  362. success: (res) => {
  363. if (res.code == API.SUCCESS_CODE) {
  364. let list = this.data.templateList
  365. list.push(res.data)
  366. this.setData({
  367. temId:res.data.id,
  368. templateList:list,
  369. temName:""
  370. });
  371. let item_ = this.data.item
  372. item_.templateId = res.data.id
  373. item_.method = "POST"
  374. UTIL.httpRequest(API.URL_POST_APPROVALITEMSEDIT,item_,{
  375. success: (res) => {
  376. if (res.code == API.SUCCESS_CODE) {
  377. wx.showToast({
  378. title: "暂存成功!",
  379. duration: 2000,
  380. icon:"success"
  381. })
  382. }
  383. }
  384. })
  385. }
  386. }
  387. })
  388. }else{
  389. let url = API.URL_POST_TEMPLATEEDIT
  390. wx.request({
  391. url,
  392. data: list,
  393. method:"POST",
  394. timeout: 60000,
  395. header: {
  396. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  397. },
  398. success: function (response) {
  399. wx.showToast({
  400. title: "暂存成功!",
  401. duration: 2000,
  402. icon:"success"
  403. })
  404. },
  405. })
  406. }
  407. },
  408. submit:function(){
  409. let _this = this
  410. if(this.data.temId==""||this.data.temId==null){
  411. let data={
  412. approvalTemplate:{
  413. name:this.data.temName,
  414. type:1,
  415. dataType:1
  416. },
  417. approvalTemplateDetailList:this.data.templateDetailList,
  418. method:"POST"
  419. }
  420. UTIL.httpRequest(API.URL_POST_MOBILEADD,data,{
  421. success: (res) => {
  422. if (res.code == API.SUCCESS_CODE) {
  423. let list = this.data.templateList
  424. list.push(res.data)
  425. this.setData({
  426. temId:res.data.id,
  427. templateList:list,
  428. temName:""
  429. });
  430. let item_ = this.data.item
  431. item_.templateId = res.data.id
  432. item_.method = "POST"
  433. UTIL.httpRequest(API.URL_POST_APPROVALITEMSEDIT,item_,{
  434. success: (res) => {
  435. if (res.code == API.SUCCESS_CODE) {
  436. _this.requestSubmit()
  437. }
  438. }
  439. })
  440. }
  441. }
  442. })
  443. }else{
  444. let url = API.URL_POST_TEMPLATEEDIT
  445. wx.request({
  446. url,
  447. data: _this.data.templateDetailList,
  448. method:"POST",
  449. timeout: 60000,
  450. header: {
  451. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  452. },
  453. success: function (response) {
  454. _this.requestSubmit()
  455. },
  456. })
  457. }
  458. },
  459. requestSubmit:function(){
  460. let url = API.URL_POST_APPROVALITEMSSUBMIT+this.data.item.id+"/"+this.data.item.templateId
  461. wx.request({
  462. url,
  463. method:"POST",
  464. timeout: 60000,
  465. header: {
  466. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  467. },
  468. success: function (r) {
  469. if (r.data.code == API.SUCCESS_CODE) {
  470. wx.showToast({
  471. title: "提交成功!",
  472. duration: 2000,
  473. icon:"success"
  474. })
  475. setTimeout(function(){
  476. wx.switchTab({
  477. url: '/pages/index/index'
  478. })
  479. },2000)
  480. }else{
  481. wx.showToast({
  482. title: "操作失败!",
  483. duration: 2000,
  484. icon:"error"
  485. })
  486. }
  487. },
  488. })
  489. },
  490. openBox:function(){
  491. var that = this ;
  492. that.setData({
  493. show: true,
  494. })
  495. },
  496. closeBox:function(){
  497. var that = this ;
  498. that.setData({
  499. show: false
  500. })
  501. },
  502. showPopup() {
  503. this.setData({
  504. showPopup: true,
  505. temName:""
  506. });
  507. },
  508. onClose() {
  509. this.setData({ showPopup: false});
  510. },
  511. /**
  512. * 生命周期函数--监听页面初次渲染完成
  513. */
  514. onReady() {
  515. },
  516. /**
  517. * 生命周期函数--监听页面显示
  518. */
  519. onShow() {
  520. },
  521. /**
  522. * 生命周期函数--监听页面隐藏
  523. */
  524. onHide() {
  525. },
  526. /**
  527. * 生命周期函数--监听页面卸载
  528. */
  529. onUnload() {
  530. },
  531. /**
  532. * 页面相关事件处理函数--监听用户下拉动作
  533. */
  534. onPullDownRefresh() {
  535. },
  536. /**
  537. * 页面上拉触底事件的处理函数
  538. */
  539. onReachBottom() {
  540. },
  541. /**
  542. * 用户点击右上角分享
  543. */
  544. onShareAppMessage() {
  545. }
  546. })