微信小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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