微信小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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