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

527 line
15 KiB

  1. // pages/apply/index.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. let EVN_CONFIG = require('../../../env/env');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. isIPX: app.globalData.isIPX,
  12. bookName:'', //付款单位
  13. formData:{
  14. accountType:'', //账户类型
  15. accountDate:'', //收入时间
  16. jieAmount:'', //收入金额
  17. accountName:'', //存入账户
  18. incomeType:'', //收入类型
  19. billNum:'', //单据编码
  20. accountSummary:'', //备注说明
  21. contractionId:'', //合同编码
  22. incomeExpensesType:1, //收支类别
  23. isBill:0
  24. },
  25. incomeTypeOptions:[], //收入类型选项
  26. incomeTypeText:'222', //收入类型显示文字
  27. contractionOptions:[], //付款人合同信息列表接口
  28. showHt:false,
  29. payerText:'', //付款人
  30. sjPics:[], //收据图片列表数据
  31. fpPics:[], //发票图片列表数据
  32. qtPics:[], //其他图片列表数据
  33. //收入时间弹窗显隐
  34. srShow:false,
  35. minDate: new Date(2021, 6, 1).getTime(),
  36. maxDate: new Date(2023, 0, 31).getTime(),
  37. crzhShow:false,
  38. accountListOptions:[], //存入账户类型选项
  39. crlxShow:false, //收入类型弹窗显隐
  40. subjectOptions:[],//科目类型
  41. showKm:false,
  42. fileForm:[],//上传文件列表
  43. fileNum:0,//附件总数
  44. },
  45. selectKM(){
  46. this.setData({showKm:true})
  47. },
  48. closeBoxKM(){
  49. this.setData({showKm:false})
  50. },
  51. onConfirmContractionKm(value){
  52. console.log(value);
  53. let obj = value.detail.value;
  54. this.setData({
  55. 'formData.subjectNameAll':obj.subjectNameAll,
  56. showKm:false,
  57. 'formData.subjectId':obj.subjectId,
  58. })
  59. },
  60. onCancelcrlx(){
  61. this.setData({crlxShow:false,})
  62. },
  63. oncrlxShow(){ this.setData({crlxShow:true})},
  64. onCancelcrzh(){
  65. this.setData({crzhShow:false})
  66. },
  67. oncrzhShow(){ this.setData({crzhShow:true})},
  68. onConfirmcrzh(e){
  69. let data = e.detail.value;
  70. this.setData({
  71. crzhShow:false,
  72. 'formData.accountName':data.accountName,
  73. 'formData.accountId':data.id,
  74. 'formData.accountType':data.accountType
  75. })
  76. },
  77. onsrDate(){
  78. this.setData({srShow:true})
  79. },
  80. onClose(){ this.setData({srShow:false})},
  81. onConfirm(e){
  82. let data = this.getNewDate(new Date(e.detail));
  83. this.setData({'formData.accountDate':data})
  84. this.setData({srShow:false})
  85. },
  86. closeBox(){
  87. this.setData({showHt:false})
  88. },
  89. getNewDate(date){
  90. //date是传过来的时间戳,注意需为13位,10位需*1000
  91. //也可以不传,获取的就是当前时间
  92. var time = new Date(date);
  93. var year= time.getFullYear() //年
  94. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  95. var day = ("0" + time.getDate()).slice(-2); //日
  96. var mydate = year + "-" + month + "-" + day;
  97. return mydate
  98. },
  99. onConfirmContraction(value){
  100. let obj = value.detail.value;
  101. this.setData({
  102. payerText:obj.name,
  103. showHt:false,
  104. 'formData.contractionId':obj.id,
  105. contractionIdID:obj.code
  106. })
  107. },
  108. selectContraction(){
  109. this.setData({showHt:true})
  110. },
  111. bindPickerChange (e) {
  112. let obj = e.detail.value;
  113. this.setData({
  114. crlxShow:false,
  115. 'formData.incomeType':obj.dictValue,
  116. incomeTypeText:obj.dictLabel
  117. })
  118. },
  119. inputChange(e){
  120. this.setData({
  121. [e.currentTarget.dataset.prop]: e.detail.value
  122. })
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. onShow: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onLoad: function (options) {
  133. var that = this;
  134. that.setData({
  135. tableId:options.id
  136. })
  137. //获取附件字典
  138. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'bookkeeping_type', {method:'GET'}, {//查询附件字典
  139. success: (res) => {
  140. if(res.data.length>0){
  141. this.setData({
  142. uploadOptions:res.data,
  143. })
  144. let uploadList = res.data
  145. uploadList.map( (item,index) => {
  146. console.log(index);
  147. let oData = {
  148. tableId: options.id,
  149. fileType:index+1,
  150. bizPath:'transfer',
  151. tableName:'t_cashier_account_flow',
  152. method:'GET'
  153. }
  154. UTIL.httpRequest( API.URL_GET_FINDLIST, oData ,{//查询每个附件字典下的附件
  155. success: (res2) => {
  156. console.log(res2);
  157. let list = [];
  158. let fileForm = that.data.fileForm?that.data.fileForm:[];
  159. res2.data.forEach((item2,index2)=>{
  160. fileForm.push({
  161. file: wx.getStorageSync('dressCode')+item2.fileUrl,
  162. fileType:index+1,
  163. bizPath:'transfer',
  164. tableName:'t_cashier_account_flow',
  165. tableId:''
  166. })
  167. list.push({
  168. tempFilePath:wx.getStorageSync('dressCode')+item2.fileUrl,
  169. id:item2.id
  170. })
  171. })
  172. that.setData({
  173. ["uploadOptions["+index+"].Pics"]:list,
  174. fileForm:fileForm,
  175. fileNum:fileForm.length
  176. });
  177. console.log(that.data)
  178. }
  179. })
  180. })
  181. }
  182. }
  183. })
  184. //查询收入详情
  185. UTIL.httpRequest(API.URL_GET_FLOWGET + options.id , {method:'GET'}, {
  186. success: (res) => {
  187. if(res.data.incomeType == 2){
  188. UTIL.httpRequest(API.URL_GET_INFOGET + res.data.contractionId , {method:'GET'}, {
  189. success: (res3) => {
  190. that.setData({
  191. contractionIdID:res3.data.code,
  192. payerText:res3.data.name,
  193. })
  194. }
  195. })
  196. }
  197. //获取收入类型状态
  198. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'income_type', {method:'GET'}, {
  199. success: (res2) => {
  200. if(res2.data.length>0){
  201. that.setData({
  202. incomeTypeOptions:res2.data,
  203. })
  204. that.setData({
  205. formData:res.data,
  206. contractionIdID:res.data.code,
  207. incomeTypeText:UTIL.getTransform(res.data.incomeType,res2.data)
  208. })
  209. }
  210. }
  211. })
  212. console.log(res);
  213. }
  214. })
  215. UTIL.httpRequest(API.URL_GET_SUBJECTLIST , {method:'GET'}, {
  216. success: (res2) => {
  217. if(res2.rows.length>0){
  218. that.setData({
  219. subjectOptions:res2.rows,
  220. })
  221. }
  222. }
  223. })
  224. },
  225. /**
  226. * 生命周期函数--监听页面显示
  227. */
  228. onReady: function () {
  229. let that = this;
  230. //获取收入单位
  231. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  232. success: (res) => {
  233. if (res.code == API.SUCCESS_CODE) {
  234. this.setData({bookName:res.user.bookName})
  235. }
  236. }
  237. })
  238. // 获取合同信息列表
  239. UTIL.httpRequest(API.URL_GET_CONTRACTIONLIST , {method:'GET'}, {
  240. success: (res) => {
  241. that.setData({
  242. contractionOptions:res.rows,
  243. })
  244. }
  245. })
  246. //获取当前账套付款账户列表
  247. UTIL.httpRequest(API.URL_GET_ACCOUNTLIST , {method:'GET'}, {
  248. success: (res) => {
  249. that.setData({
  250. accountListOptions:res.rows,
  251. })
  252. }
  253. })
  254. },
  255. deleteimg:function(e){
  256. var that = this ;
  257. let oData = e.currentTarget.dataset;
  258. let index = oData.index
  259. let file = that.data.fileForm;
  260. console.log(that.data.uploadOptions[index].Pics);
  261. for (let i = 0; i < file.length; i++) {
  262. const element = file[i];
  263. if(element.file == that.data.uploadOptions[index].Pics[oData.id].tempFilePath){
  264. file.splice(i,1);
  265. }
  266. }
  267. that.data.uploadOptions[index].Pics.splice(oData.id,1);
  268. // let length = this.data.form.transfers[e.currentTarget.dataset.parentsindex].fileNum - 1;
  269. this.setData({
  270. // ["form.transfers["+e.currentTarget.dataset.parentsindex+"].fileNum"]:length,
  271. [oData.status]:that.data.uploadOptions[index],
  272. fileForm:file,
  273. fileNum:that.data.fileNum-1
  274. })
  275. UTIL.httpRequest(API.URL_GET_GETFILEREMOVE+e.currentTarget.dataset.imgid , {method:'GET'}, {
  276. success: (res) => {
  277. wx.showToast({
  278. title: '删除成功!',
  279. icon: 'success',
  280. duration: 2000,
  281. })
  282. }
  283. })
  284. },
  285. back:function(){
  286. wx.navigateBack({
  287. delta: 1
  288. })
  289. },
  290. uploadSjPics: function (e) { //这里是选取图片的方法
  291. var that = this;
  292. var detailPics = that.data.uploadOptions[e.currentTarget.dataset.index].Pics;
  293. if (detailPics.length >= that.data.count) {
  294. wx.showToast({
  295. title: '最多选择' + that.data.count + '张!',
  296. })
  297. return;
  298. }
  299. wx.chooseImage({
  300. count: that.data.count, // 最多可以选择的图片张数,默认9
  301. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  302. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  303. success: function (res) {
  304. console.log(res)
  305. let fileForm = that.data.fileForm;
  306. let tem = that.data.uploadOptions[e.currentTarget.dataset.index].Pics?that.data.uploadOptions[e.currentTarget.dataset.index].Pics:[];
  307. res.tempFilePaths.forEach(item => {
  308. fileForm.push({
  309. file: item,
  310. fileType:e.currentTarget.dataset.index+1,
  311. bizPath:'cashier',
  312. tableName:'t_cashier_account_flow',
  313. tableId:''
  314. })
  315. tem.push({
  316. tempFilePath:item
  317. })
  318. })
  319. that.setData({
  320. ['uploadOptions['+e.currentTarget.dataset.index+'].Pics']:tem,
  321. fileForm:fileForm,
  322. fileNum:fileForm.length
  323. })
  324. },
  325. })
  326. },
  327. uploadFpPics: function (e) { //这里是选取图片的方法
  328. var that = this;
  329. var pics = [];
  330. var detailPics = that.data.fpPics;
  331. if (detailPics.length >= that.data.count) {
  332. wx.showToast({
  333. title: '最多选择' + that.data.count + '张!',
  334. })
  335. return;
  336. }
  337. wx.chooseImage({
  338. count: that.data.count, // 最多可以选择的图片张数,默认9
  339. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  340. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  341. success: function (res) {
  342. let fileForm = that.data.fpPics
  343. res.tempFilePaths.forEach(item => {
  344. fileForm.push({
  345. file: item,
  346. fileType:'2',
  347. bizPath:'cashier',
  348. tableName:'t_cashier_account_flow',
  349. tableId:''
  350. })
  351. })
  352. that.setData({
  353. fpPics:fileForm
  354. })
  355. },
  356. })
  357. },
  358. uploadQtPics: function (e) { //这里是选取图片的方法
  359. var that = this;
  360. var pics = [];
  361. var detailPics = that.data.qtPics;
  362. if (detailPics.length >= that.data.count) {
  363. wx.showToast({
  364. title: '最多选择' + that.data.count + '张!',
  365. })
  366. return;
  367. }
  368. wx.chooseImage({
  369. count: that.data.count, // 最多可以选择的图片张数,默认9
  370. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  371. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  372. success: function (res) {
  373. let fileForm = that.data.qtPics
  374. res.tempFilePaths.forEach(item => {
  375. fileForm.push({
  376. file: item,
  377. fileType:'3',
  378. bizPath:'cashier',
  379. tableName:'t_cashier_account_flow',
  380. tableId:''
  381. })
  382. })
  383. that.setData({
  384. qtPics:fileForm
  385. })
  386. },
  387. })
  388. },
  389. swichAccounting:function(e){
  390. var that = this;
  391. let codeStr = e.currentTarget.dataset.code;
  392. let formDataObj = this.data.formData;
  393. if(formDataObj.jieAmount==''){ //收入金额
  394. UTIL.showToastNoneIcon('请填写收入金额!');
  395. return false;
  396. }else if(formDataObj.accountName==''){ //存入账户
  397. UTIL.showToastNoneIcon('请选择存入账户!');
  398. return false;
  399. }else if(formDataObj.accountSummary==''){ //备注说明
  400. UTIL.showToastNoneIcon('请输入备注说明!');
  401. return false;
  402. }else if(formDataObj.incomeType == '2' && formDataObj.contractionId==''){
  403. UTIL.showToastNoneIcon('收入类型为发包收入,必须选择关联合同!');
  404. return false;
  405. }
  406. let data = this.data.formData;
  407. data.method = "POST";
  408. data.checkedStatus = codeStr;
  409. console.log(data);
  410. UTIL.httpRequest(API.URL_POST_GERFLOWEDIT,data,{
  411. success: (res) => {
  412. if(res.code == 200){
  413. let vouerId = that.data.tableId;
  414. // let vouerId = 1;
  415. // let updataList = [...this.data.sjPics,...this.data.fpPics,...this.data.qtPics];
  416. let updataList = that.data.fileForm;
  417. console.log(updataList);
  418. for(let i=0; i<updataList.length; i++){
  419. let arrData=updataList[i];
  420. arrData.tableId = vouerId;
  421. wx.uploadFile({
  422. url: API.URL_GET_UPLOAD,
  423. filePath: arrData.file,
  424. name: 'file',
  425. header: {
  426. "Content-Type": "multipart/form-data",//记得设置
  427. "chartset":"utf-8",
  428. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  429. },
  430. formData:arrData,
  431. success (response){
  432. console.log(response);
  433. },
  434. fail(res){
  435. console.log(response)
  436. }
  437. })
  438. }
  439. wx.showToast({
  440. title: '修改成功',
  441. icon: 'success',
  442. duration: 2000
  443. })
  444. setTimeout(function(){
  445. wx.navigateBack({
  446. delta: 1
  447. })
  448. },2000)
  449. }else{
  450. UTIL.showToastNoneIcon(res.msg);
  451. }
  452. }
  453. })
  454. },
  455. onChange(event){
  456. this.setData({
  457. [event.currentTarget.dataset.value]: event.detail,
  458. })
  459. },
  460. imgPreviewImage(e){
  461. let array = [];
  462. console.log(e);
  463. e.currentTarget.dataset.option.forEach(item=>{
  464. array.push(item.tempFilePath)
  465. })
  466. console.log(array);
  467. wx.previewImage({
  468. urls: array,
  469. showmenu:true,
  470. current:array[e.currentTarget.dataset.index]
  471. })
  472. },
  473. /**
  474. * 生命周期函数--监听页面隐藏
  475. */
  476. onHide: function () {
  477. },
  478. /**
  479. * 生命周期函数--监听页面卸载
  480. */
  481. onUnload: function () {
  482. },
  483. /**
  484. * 页面相关事件处理函数--监听用户下拉动作
  485. */
  486. onPullDownRefresh: function () {
  487. },
  488. /**
  489. * 页面上拉触底事件的处理函数
  490. */
  491. onReachBottom: function () {
  492. },
  493. /**
  494. * 用户点击右上角分享
  495. */
  496. onShareAppMessage: function () {
  497. }
  498. })