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

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