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

457 regels
13 KiB

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