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

396 行
11 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(2008, 5, 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 (options) {
  108. this.setData({
  109. ["formData.accountDate"]:this.getNewDate(new Date())
  110. })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onLoad: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onReady: function () {
  121. let that = this;
  122. //获取收入单位
  123. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  124. success: (res) => {
  125. if (res.code == API.SUCCESS_CODE) {
  126. this.setData({bookName:res.user.bookName})
  127. }
  128. }
  129. })
  130. //获取收入类型状态
  131. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'income_type', {method:'GET'}, {
  132. success: (res) => {
  133. if(res.data.length>0){
  134. that.setData({
  135. incomeTypeOptions:res.data,
  136. incomeTypeText:res.data[0].dictLabel,
  137. 'formData.incomeType':res.data[0].dictValue
  138. })
  139. }
  140. }
  141. })
  142. // 获取合同信息列表
  143. UTIL.httpRequest(API.URL_GET_CONTRACTIONLIST , {method:'GET'}, {
  144. success: (res) => {
  145. that.setData({
  146. contractionOptions:res.rows,
  147. })
  148. }
  149. })
  150. //获取当前账套付款账户列表
  151. UTIL.httpRequest(API.URL_GET_ACCOUNTLIST , {method:'GET'}, {
  152. success: (res) => {
  153. that.setData({
  154. accountListOptions:res.rows,
  155. })
  156. }
  157. })
  158. },
  159. deleteimg:function(e){
  160. let oData = e.currentTarget.dataset;
  161. let file = this.data[oData.status];
  162. file.splice(oData.id,1)
  163. this.setData({
  164. [oData.status]:file
  165. })
  166. },
  167. back:function(){
  168. wx.navigateBack({
  169. delta: 1
  170. })
  171. },
  172. uploadSjPics: function (e) { //这里是选取图片的方法
  173. var that = this;
  174. var detailPics = that.data.sjPics;
  175. if (detailPics.length >= that.data.count) {
  176. wx.showToast({
  177. title: '最多选择' + that.data.count + '张!',
  178. })
  179. return;
  180. }
  181. wx.chooseImage({
  182. count: that.data.count, // 最多可以选择的图片张数,默认9
  183. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  184. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  185. success: function (res) {
  186. let fileForm = that.data.sjPics
  187. res.tempFilePaths.forEach(item => {
  188. fileForm.push({
  189. file: item,
  190. fileType:'1',
  191. bizPath:'cashier',
  192. tableName:'t_cashier_account_flow',
  193. tableId:''
  194. })
  195. })
  196. that.setData({
  197. sjPics:fileForm
  198. })
  199. },
  200. })
  201. },
  202. uploadFpPics: function (e) { //这里是选取图片的方法
  203. var that = this;
  204. var pics = [];
  205. var detailPics = that.data.fpPics;
  206. if (detailPics.length >= that.data.count) {
  207. wx.showToast({
  208. title: '最多选择' + that.data.count + '张!',
  209. })
  210. return;
  211. }
  212. wx.chooseImage({
  213. count: that.data.count, // 最多可以选择的图片张数,默认9
  214. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  215. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  216. success: function (res) {
  217. let fileForm = that.data.fpPics
  218. res.tempFilePaths.forEach(item => {
  219. fileForm.push({
  220. file: item,
  221. fileType:'2',
  222. bizPath:'cashier',
  223. tableName:'t_cashier_account_flow',
  224. tableId:''
  225. })
  226. })
  227. that.setData({
  228. fpPics:fileForm
  229. })
  230. },
  231. })
  232. },
  233. uploadQtPics: function (e) { //这里是选取图片的方法
  234. var that = this;
  235. var pics = [];
  236. var detailPics = that.data.qtPics;
  237. if (detailPics.length >= that.data.count) {
  238. wx.showToast({
  239. title: '最多选择' + that.data.count + '张!',
  240. })
  241. return;
  242. }
  243. wx.chooseImage({
  244. count: that.data.count, // 最多可以选择的图片张数,默认9
  245. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  246. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  247. success: function (res) {
  248. let fileForm = that.data.qtPics
  249. res.tempFilePaths.forEach(item => {
  250. fileForm.push({
  251. file: item,
  252. fileType:'3',
  253. bizPath:'cashier',
  254. tableName:'t_cashier_account_flow',
  255. tableId:''
  256. })
  257. })
  258. that.setData({
  259. qtPics:fileForm
  260. })
  261. },
  262. })
  263. },
  264. swichAccounting:function(e){
  265. let codeStr = e.currentTarget.dataset.code;
  266. let formDataObj = this.data.formData;
  267. if(formDataObj.jieAmount==''){ //收入金额
  268. UTIL.showToastNoneIcon('请填写收入金额!');
  269. return false;
  270. }else if(formDataObj.accountName==''){ //存入账户
  271. UTIL.showToastNoneIcon('请选择存入账户!');
  272. return false;
  273. }else if(formDataObj.billNum==''){ //单据编码
  274. UTIL.showToastNoneIcon('请输入单据编码!');
  275. return false;
  276. }else if(formDataObj.accountSummary==''){ //备注说明
  277. UTIL.showToastNoneIcon('请输入备注说明!');
  278. return false;
  279. }else if(formDataObj.incomeType == '2' && formDataObj.contractionId==''){
  280. UTIL.showToastNoneIcon('收入类型为发包收入,必须选择关联合同!');
  281. return false;
  282. }
  283. let data = this.data.formData;
  284. data.method = "POST";
  285. data.checkedStatus = codeStr;
  286. UTIL.httpRequest(API.URL_POST_GERFLOWADD,data,{
  287. success: (res) => {
  288. if(res.code == 200){
  289. let vouerId = res.data;
  290. // let vouerId = 1;
  291. let updataList = [...this.data.sjPics,...this.data.fpPics,...this.data.qtPics];
  292. for(let i=0; i<updataList.length; i++){
  293. let arrData=updataList[i];
  294. arrData.tableId = vouerId;
  295. wx.uploadFile({
  296. url: API.URL_GET_UPLOAD,
  297. filePath: arrData.file,
  298. name: 'file',
  299. header: {
  300. "Content-Type": "multipart/form-data",//记得设置
  301. "chartset":"utf-8",
  302. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  303. },
  304. formData:arrData,
  305. success (response){
  306. console.log(response);
  307. },
  308. fail(res){
  309. console.log(response)
  310. }
  311. })
  312. }
  313. wx.redirectTo({
  314. url: '/pages/index/index'
  315. })
  316. }else{
  317. UTIL.showToastNoneIcon(res.msg);
  318. }
  319. }
  320. })
  321. },
  322. onChange(event){
  323. this.setData({
  324. [event.currentTarget.dataset.value]: event.detail,
  325. })
  326. },
  327. imgPreviewImage(e){
  328. let currentImgList = e.currentTarget.dataset;
  329. //获取当前附件列表
  330. let currentStatus = this.data[currentImgList.status];
  331. //当前选中图片index
  332. let currentIndex = currentImgList.id;
  333. let imgList = []
  334. for(let i = 0; i<currentStatus.length; i++){
  335. imgList.push(currentStatus[i].file)
  336. }
  337. wx.previewImage({
  338. current: imgList[currentIndex], // 当前显示图片的http链接
  339. urls: imgList // 需要预览的图片http链接列表
  340. })
  341. },
  342. /**
  343. * 生命周期函数--监听页面隐藏
  344. */
  345. onHide: function () {
  346. },
  347. /**
  348. * 生命周期函数--监听页面卸载
  349. */
  350. onUnload: function () {
  351. },
  352. /**
  353. * 页面相关事件处理函数--监听用户下拉动作
  354. */
  355. onPullDownRefresh: function () {
  356. },
  357. /**
  358. * 页面上拉触底事件的处理函数
  359. */
  360. onReachBottom: function () {
  361. },
  362. /**
  363. * 用户点击右上角分享
  364. */
  365. onShareAppMessage: function () {
  366. }
  367. })