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

paymentTemplate.js 10 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. // pages/apply/paymentTemplate/paymentTemplate.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 DISTRIBUTE_ENVIROMENT = 'IMGURL';
  6. let {
  7. URL_PREFIX,
  8. } = EVN_CONFIG[DISTRIBUTE_ENVIROMENT];
  9. const app = getApp();
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. isIPX: app.globalData.isIPX,
  16. show: false,
  17. countMoney:0,
  18. form:{},
  19. SJimage: [],
  20. FPimage: [],
  21. QTimage: [],
  22. fileForm:[],
  23. },
  24. showPopup() {
  25. this.setData({ show: true });
  26. },
  27. bindNameInput(even){
  28. this.setData({
  29. ["form.approvalItemTemplate.templateName"]:even.detail.value
  30. })
  31. },
  32. goSubmit(e){
  33. var that = this;
  34. if(e.currentTarget.dataset.type == 1){
  35. if(that.data.form.approvalItemTemplate.templateName == ''){
  36. UTIL.showToastNoneIcon('请输入模板名称!');
  37. return;
  38. }
  39. }
  40. if(e.currentTarget.dataset.type == 3){
  41. for (let i = 0; i < that.data.form.transfers.length; i++) {
  42. that.data.form.transfers[i].approvalMode = '2';
  43. }
  44. that.data.form.approvalItemTemplate.dataType = e.currentTarget.dataset.type
  45. }
  46. that.data.form.method = 'POST';
  47. that.data.form.approvalItemTemplate.dataType = e.currentTarget.dataset.type;
  48. that.data.form.approvalItemTemplate.id = null;
  49. for (let i = 0; i < that.data.form.transfers.length; i++) {
  50. that.data.form.transfers[i].id = null;
  51. }
  52. console.log(that.data.form);
  53. UTIL.httpRequest(API.URL_GET_SAVE, that.data.form, {
  54. success: (res) => {
  55. if (res.code == API.SUCCESS_CODE) {
  56. console.log(that.data.form);
  57. for (let j = 0; j < res.data.transfers.length; j++) {
  58. if(that.data.form.transfers[j].fileForm == undefined){continue;}
  59. for (let i = 0; i < that.data.form.transfers[j].fileForm.length; i++) {
  60. that.data.form.transfers[j].fileForm[i].tableId = res.data.transfers[j].id
  61. const element = that.data.form.transfers[j].fileForm[i];
  62. wx.uploadFile({
  63. url: API.URL_GET_UPLOAD,
  64. filePath: element.file,
  65. name: 'file',
  66. header: {
  67. "Content-Type": "multipart/form-data",//记得设置
  68. "chartset":"utf-8",
  69. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  70. },
  71. formData:element,
  72. success (response){
  73. console.log(res);
  74. },
  75. fail(res){
  76. console.log(res)
  77. }
  78. })
  79. }
  80. }
  81. if(e.currentTarget.dataset.type == 0){
  82. wx.navigateTo({
  83. url: '/pages/apply/approval/approval?id='+res.data.approvalItemTemplate.id+'&deptId='+res.data.approvalItemTemplate.deptId,
  84. })
  85. }
  86. if(e.currentTarget.dataset.type == 3){
  87. UTIL.httpRequest(API.URL_GET_TOREVIEWSUBMIT+res.data.approvalItemTemplate.id , {method:'POST'}, {
  88. success: (res2) => {
  89. if (res2.code == API.SUCCESS_CODE) {
  90. wx.showToast({
  91. title: '操作成功',
  92. icon: 'success',
  93. duration: 2000,
  94. complete(){
  95. setTimeout(function(){
  96. that.back();
  97. },2000)
  98. }
  99. })
  100. }else{
  101. wx.showToast({
  102. title: '操作失败',
  103. icon: 'success',
  104. duration: 2000
  105. })
  106. }
  107. }
  108. })
  109. }
  110. }
  111. }
  112. })
  113. },
  114. onClose() {
  115. this.setData({ show: false });
  116. },
  117. goApproval(){
  118. wx.navigateTo({
  119. url: '../approval/approval',
  120. })
  121. },
  122. goSee(){
  123. let array = JSON.stringify(this.data.form)
  124. wx.navigateTo({
  125. url: 'see/see?array='+array+"&index="+e.currentTarget.dataset.index,
  126. })
  127. },
  128. goUpdate(e){
  129. let array = JSON.stringify(this.data.form)
  130. wx.navigateTo({
  131. url: 'add/add?type=update&array='+array+'&add='+e.currentTarget.dataset.add,
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面加载
  136. */
  137. onLoad(options) {
  138. var that = this ;
  139. UTIL.httpRequest(API.URL_GET_APPROVALITEMS + options.id, {method:'GET'}, {
  140. success: (res) => {
  141. let transList = res.data.transfers;
  142. let countMoney = that.data.countMoney
  143. transList.forEach((item,index) => {
  144. item.num = UTIL.convertToChinaNum(index+1)
  145. countMoney += parseInt(item.expenditureAmount);
  146. //收据附件
  147. UTIL.httpRequest(
  148. API.URL_GET_FINDLIST,
  149. {
  150. method:'GET',
  151. tableName:'t_yinnong_transfer',
  152. tableId:item.id,
  153. fileType:1
  154. },
  155. {
  156. success: (res) => {
  157. let list = [];
  158. res.data.forEach((item2,index2)=>{
  159. wx.downloadFile({
  160. url: URL_PREFIX+item2.fileUrl, //仅为示例,并非真实的资源
  161. success (response) {
  162. if (response.statusCode === 200) {
  163. let fileForm = item.fileForm?item.fileForm:[];
  164. fileForm.push({
  165. file: response.tempFilePath,
  166. fileType:'1',
  167. bizPath:'transfer',
  168. tableName:'t_yinnong_transfer',
  169. tableId:''
  170. })
  171. console.log("--------------fileForm2 start----------------");
  172. console.log(fileForm);
  173. console.log("--------------fileForm2 end----------------");
  174. list.push({
  175. tempFilePath:response.tempFilePath
  176. })
  177. that.setData({
  178. ["form.transfers["+index+"].SJimage"]:list,
  179. ["form.transfers["+index+"].fileForm"]:fileForm
  180. });
  181. }
  182. }
  183. })
  184. })
  185. }
  186. })
  187. //发票
  188. UTIL.httpRequest(
  189. API.URL_GET_FINDLIST,
  190. {
  191. method:'GET',
  192. tableName:'t_yinnong_transfer',
  193. tableId:item.id,
  194. fileType:2
  195. },
  196. {
  197. success: (res) => {
  198. let list = [];
  199. res.data.forEach((item2,index2)=>{
  200. wx.downloadFile({
  201. url: URL_PREFIX+item2.fileUrl, //仅为示例,并非真实的资源
  202. success (response) {
  203. if (response.statusCode === 200) {
  204. let fileForm = item.fileForm?item.fileForm:[];
  205. fileForm.push({
  206. file: response.tempFilePath,
  207. fileType:'2',
  208. bizPath:'transfer',
  209. tableName:'t_yinnong_transfer',
  210. tableId:item.id
  211. })
  212. list.push({
  213. tempFilePath:response.tempFilePath
  214. })
  215. that.setData({
  216. ["form.transfers["+index+"].FPimage"]:list,
  217. ["form.transfers["+index+"].fileForm"]:fileForm
  218. });
  219. }
  220. }
  221. })
  222. })
  223. }
  224. })
  225. //其他
  226. UTIL.httpRequest(
  227. API.URL_GET_FINDLIST,
  228. {
  229. method:'GET',
  230. tableName:'t_yinnong_transfer',
  231. tableId:item.id,
  232. fileType:3
  233. },
  234. {
  235. success: (res) => {
  236. let list = [];
  237. let fileForm = item.fileForm?item.fileForm:[];
  238. res.data.forEach((item2,index2)=>{
  239. wx.downloadFile({
  240. url: URL_PREFIX+item2.fileUrl, //仅为示例,并非真实的资源
  241. success (response) {
  242. if (response.statusCode === 200) {
  243. let fileForm = item.fileForm?item.fileForm:[];
  244. fileForm.push({
  245. file: response.tempFilePath,
  246. fileType:'3',
  247. bizPath:'transfer',
  248. tableName:'t_yinnong_transfer',
  249. tableId:item.id
  250. })
  251. list.push({
  252. tempFilePath:response.tempFilePath
  253. })
  254. that.setData({
  255. ["form.transfers["+index+"].QTimage"]:list,
  256. ["form.transfers["+index+"].fileForm"]:fileForm
  257. });
  258. }
  259. }
  260. })
  261. })
  262. }
  263. })
  264. });
  265. res.data.transfers = transList
  266. that.setData({
  267. form:res.data,
  268. countMoney:countMoney
  269. });
  270. }
  271. })
  272. },
  273. /**
  274. * 生命周期函数--监听页面初次渲染完成
  275. */
  276. onReady() {
  277. },
  278. goDelete(e){
  279. var that = this;
  280. if(that.data.form.transfers.length<2){
  281. UTIL.showToastNoneIcon('最少保留一条事项');
  282. return;
  283. }
  284. let countMoney = that.data.countMoney;
  285. console.log(that.data.form);
  286. countMoney -= parseInt(that.data.form.transfers[e.currentTarget.dataset.index].expenditureAmount);
  287. that.data.form.transfers.splice(e.currentTarget.dataset.index, 1);
  288. that.setData({
  289. form : that.data.form,
  290. countMoney:countMoney
  291. })
  292. UTIL.showToastNoneIcon('删除成功!');
  293. },
  294. back:function(){
  295. wx.navigateBack({
  296. delta: 1
  297. })
  298. },
  299. /**
  300. * 生命周期函数--监听页面显示
  301. */
  302. onShow() {
  303. },
  304. /**
  305. * 生命周期函数--监听页面隐藏
  306. */
  307. onHide() {
  308. },
  309. /**
  310. * 生命周期函数--监听页面卸载
  311. */
  312. onUnload() {
  313. },
  314. /**
  315. * 页面相关事件处理函数--监听用户下拉动作
  316. */
  317. onPullDownRefresh() {
  318. },
  319. /**
  320. * 页面上拉触底事件的处理函数
  321. */
  322. onReachBottom() {
  323. },
  324. /**
  325. * 用户点击右上角分享
  326. */
  327. onShareAppMessage() {
  328. }
  329. })