微信小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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