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

410 line
11 KiB

  1. // pages/Bookkeeping/Bookkeeping.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. result:[],
  12. result2:[],
  13. showGroup:true,
  14. flowList:[],
  15. showProjectFundType:false,
  16. checkedStatusText:'未提交',
  17. checkedStatus:'1',
  18. incomeExpensesType:'1'
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. var that = this;
  25. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'checked_status', {method:'GET'}, {
  26. success: (res) => {
  27. that.setData({
  28. capitalExpenditureTypeOptions:res.data,
  29. })
  30. }
  31. })
  32. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'income_type', {method:'GET'}, {
  33. success: (res) => {
  34. that.setData({
  35. incomeTypeOptions:res.data,
  36. })
  37. }
  38. })
  39. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'capital_expenditure_type', {method:'GET'}, {
  40. success: (res) => {
  41. that.setData({
  42. expenditureTypeOptions:res.data,
  43. })
  44. }
  45. })
  46. that.SRSelect();
  47. that.ZCSelect();
  48. },
  49. SRSelect(){
  50. var that = this;
  51. //收入事项
  52. let data = {
  53. pageNum:'1',
  54. pageSize:'999',
  55. accountType:'',
  56. checkedStatus:that.data.checkedStatus,
  57. incomeExpensesType:'1',
  58. }
  59. UTIL.httpRequest(API.URL_GET_GETFLOWLIST,data ,{
  60. success: (res) => {
  61. if (res.code == API.SUCCESS_CODE) {
  62. let list = res.rows;
  63. for (let i = 0; i < list.length; i++) {
  64. const element = list[i];
  65. list[i].checkedStatusText = UTIL.getTransform(element.checkedStatus,that.data.capitalExpenditureTypeOptions);
  66. list[i].incomeTypeText = UTIL.getTransform(element.incomeType,that.data.incomeTypeOptions);
  67. }
  68. this.setData({
  69. flowListSR:list,
  70. flowListSRNum:res.total
  71. });
  72. }
  73. }
  74. })
  75. },
  76. ZCSelect(){
  77. var that = this;
  78. //支出事项
  79. let data2 = {
  80. pageNum:'1',
  81. pageSize:'999',
  82. accountType:'',
  83. checkedStatus:that.data.checkedStatus,
  84. incomeExpensesType:'2',
  85. }
  86. UTIL.httpRequest(API.URL_GET_GETFLOWLIST,data2 ,{
  87. success: (res) => {
  88. if (res.code == API.SUCCESS_CODE) {
  89. let list = res.rows;
  90. for (let i = 0; i < list.length; i++) {
  91. const element = list[i];
  92. list[i].checkedStatusText = UTIL.getTransform(element.checkedStatus,that.data.capitalExpenditureTypeOptions);
  93. list[i].expenditureTypeText = UTIL.getTransform(element.expenditureType,that.data.expenditureTypeOptions);
  94. }
  95. this.setData({
  96. flowListZC:list,
  97. flowListZCNum:res.total
  98. });
  99. }
  100. }
  101. })
  102. },
  103. onChange(event) {
  104. this.setData({result:event.detail})
  105. },
  106. onChange2(event) {
  107. this.setData({result2:event.detail})
  108. },
  109. switchTab(e){
  110. var that = this;
  111. this.setData({
  112. showGroup:e.currentTarget.dataset.gid,
  113. result:[],
  114. result2:[],
  115. })
  116. if(e.currentTarget.dataset.gid){
  117. //收入事项
  118. let data = {
  119. pageNum:'1',
  120. pageSize:'999',
  121. accountType:'',
  122. checkedStatus:this.data.checkedStatus,
  123. incomeExpensesType:'1',
  124. }
  125. UTIL.httpRequest(API.URL_GET_GETFLOWLIST,data ,{
  126. success: (res) => {
  127. if (res.code == API.SUCCESS_CODE) {
  128. let list = res.rows;
  129. for (let i = 0; i < list.length; i++) {
  130. const element = list[i];
  131. list[i].checkedStatusText = UTIL.getTransform(element.checkedStatus,that.data.capitalExpenditureTypeOptions);
  132. list[i].incomeTypeText = UTIL.getTransform(element.incomeType,that.data.incomeTypeOptions);
  133. }
  134. this.setData({
  135. flowListSR:list,
  136. flowListSRNum:res.total
  137. });
  138. }
  139. }
  140. })
  141. }else{
  142. let data2 = {
  143. pageNum:'1',
  144. pageSize:'999',
  145. accountType:'',
  146. checkedStatus:this.data.checkedStatus,
  147. incomeExpensesType:'2',
  148. }
  149. UTIL.httpRequest(API.URL_GET_GETFLOWLIST,data2 ,{
  150. success: (res) => {
  151. if (res.code == API.SUCCESS_CODE) {
  152. let list = res.rows;
  153. for (let i = 0; i < list.length; i++) {
  154. const element = list[i];
  155. list[i].checkedStatusText = UTIL.getTransform(element.checkedStatus,that.data.capitalExpenditureTypeOptions);
  156. list[i].expenditureTypeText = UTIL.getTransform(element.expenditureType,that.data.expenditureTypeOptions);
  157. }
  158. this.setData({
  159. flowListZC:list,
  160. flowListZCNum:res.total
  161. });
  162. }
  163. }
  164. })
  165. }
  166. },
  167. back:function(){
  168. wx.navigateBack({
  169. delta: 1
  170. })
  171. },
  172. /**
  173. * 生命周期函数--监听页面初次渲染完成
  174. */
  175. onReady() {
  176. },
  177. /**
  178. * 生命周期函数--监听页面显示
  179. */
  180. onShow() {
  181. var that = this ;
  182. that.SRSelect();
  183. that.ZCSelect();
  184. },
  185. openPopup(even){
  186. this.setData({
  187. showProjectFundType:true
  188. })
  189. },
  190. onConfirmPick(event){
  191. var that = this;
  192. this.setData({
  193. [event.currentTarget.dataset.name]: false,
  194. checkedStatus: event.detail.value.dictValue,
  195. checkedStatusText: event.detail.value.dictLabel,
  196. result:[],
  197. result2:[]
  198. });
  199. let data = {
  200. pageNum:'1',
  201. pageSize:'999',
  202. accountType:'',
  203. checkedStatus:event.detail.value.dictValue,
  204. incomeExpensesType:'1',
  205. }
  206. UTIL.httpRequest(API.URL_GET_GETFLOWLIST,data ,{
  207. success: (res) => {
  208. if (res.code == API.SUCCESS_CODE) {
  209. let list = res.rows;
  210. for (let i = 0; i < list.length; i++) {
  211. const element = list[i];
  212. element.checkedStatusText = UTIL.getTransform(element.checkedStatus,that.data.capitalExpenditureTypeOptions);
  213. element.incomeTypeText = UTIL.getTransform(element.incomeType,that.data.incomeTypeOptions);
  214. }
  215. this.setData({
  216. flowListSR:list,
  217. flowListSRNum:res.total
  218. });
  219. }
  220. }
  221. })
  222. let data2 = {
  223. pageNum:'1',
  224. pageSize:'999',
  225. accountType:'',
  226. checkedStatus:event.detail.value.dictValue,
  227. incomeExpensesType:'2',
  228. }
  229. UTIL.httpRequest(API.URL_GET_GETFLOWLIST,data2 ,{
  230. success: (res) => {
  231. if (res.code == API.SUCCESS_CODE) {
  232. let list = res.rows;
  233. for (let i = 0; i < list.length; i++) {
  234. const element = list[i];
  235. list[i].checkedStatusText = UTIL.getTransform(element.checkedStatus,that.data.capitalExpenditureTypeOptions);
  236. list[i].expenditureTypeText = UTIL.getTransform(element.expenditureType,that.data.expenditureTypeOptions);
  237. }
  238. this.setData({
  239. flowListZC:list,
  240. flowListZCNum:res.total
  241. });
  242. }
  243. }
  244. })
  245. },
  246. closeBox(even){
  247. console.log(even.currentTarget.dataset.name);
  248. this.setData({
  249. [even.currentTarget.dataset.name]:false
  250. })
  251. },
  252. goSubmit(){
  253. var that = this ;
  254. console.log(that.data.showGroup);
  255. if(that.data.showGroup){
  256. if(that.data.result.length==0){
  257. UTIL.showToastNoneIcon('至少选择一个收入事项!');
  258. return;
  259. }
  260. let url = API.URL_GET_GETBOOKKEEP
  261. wx.request({
  262. url,
  263. method:"POST",
  264. timeout: 60000,
  265. data:that.data.result,
  266. header: {
  267. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  268. },
  269. success: function (response) {
  270. wx.showToast({
  271. title: "提交成功!",
  272. duration: 2000,
  273. icon:"success"
  274. })
  275. that.setData({
  276. result:[]
  277. })
  278. that.SRSelect();
  279. }
  280. })
  281. }else{
  282. if(that.data.result2.length==0){
  283. UTIL.showToastNoneIcon('至少选择一个支出事项!');
  284. return;
  285. }
  286. let url = API.URL_GET_GETBOOKKEEP
  287. wx.request({
  288. url,
  289. method:"POST",
  290. timeout: 60000,
  291. data:that.data.result2,
  292. header: {
  293. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  294. },
  295. success: function (response) {
  296. wx.showToast({
  297. title: "提交成功!",
  298. duration: 2000,
  299. icon:"success"
  300. })
  301. that.setData({
  302. result2:[]
  303. })
  304. that.ZCSelect();
  305. }
  306. })
  307. }
  308. },
  309. goSee(event){
  310. wx.navigateTo({
  311. url: '/pages/Bookkeeping/seeBook/seeBook?id='+event.currentTarget.dataset.id,
  312. })
  313. },
  314. goSeeZC(event){
  315. wx.navigateTo({
  316. url: '/pages/Bookkeeping/seeBookZC/seeBookZC?id='+event.currentTarget.dataset.id,
  317. })
  318. },
  319. goUpdate(event){
  320. wx.navigateTo({
  321. url: '/pages/Bookkeeping/update/update?id='+event.currentTarget.dataset.id,
  322. })
  323. },
  324. goUpdateZC(event){
  325. wx.navigateTo({
  326. url: '/pages/Bookkeeping/updateZC/update?id='+event.currentTarget.dataset.id,
  327. })
  328. },
  329. delete(e){
  330. console.log(e);
  331. var that = this;
  332. UTIL.httpRequest(API.URL_GET_FLOWREMOVE + e.currentTarget.dataset.id, {method:'GET'},{
  333. success: (res) => {
  334. if (res.code == API.SUCCESS_CODE) {
  335. that.data.flowListSR.splice(e.currentTarget.dataset.index, 1);
  336. wx.showToast({
  337. title: '删除成功!',
  338. icon: 'success',
  339. duration: 2000
  340. })
  341. that.setData({
  342. flowListSR : that.data.flowListSR,
  343. flowListSRNum:that.data.flowListSRNum-1
  344. })
  345. }
  346. }
  347. })
  348. },
  349. delete2(e){
  350. console.log(e);
  351. var that = this;
  352. UTIL.httpRequest(API.URL_GET_FLOWREMOVE + e.currentTarget.dataset.id, {method:'GET'},{
  353. success: (res) => {
  354. if (res.code == API.SUCCESS_CODE) {
  355. that.data.flowListZC.splice(e.currentTarget.dataset.index, 1);
  356. wx.showToast({
  357. title: '删除成功!',
  358. icon: 'success',
  359. duration: 2000
  360. })
  361. that.setData({
  362. flowListZC : that.data.flowListZC,
  363. flowListZCNum:that.data.flowListZCNum-1
  364. })
  365. }
  366. }
  367. })
  368. },
  369. /**
  370. * 生命周期函数--监听页面隐藏
  371. */
  372. onHide() {
  373. },
  374. /**
  375. * 生命周期函数--监听页面卸载
  376. */
  377. onUnload() {
  378. },
  379. /**
  380. * 页面相关事件处理函数--监听用户下拉动作
  381. */
  382. onPullDownRefresh() {
  383. },
  384. /**
  385. * 页面上拉触底事件的处理函数
  386. */
  387. onReachBottom() {
  388. },
  389. /**
  390. * 用户点击右上角分享
  391. */
  392. onShareAppMessage() {
  393. }
  394. })