微信小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

391 Zeilen
10 KiB

  1. // pages/bank/bank.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. list:[],
  17. isLoading:false,
  18. pageNums:1,
  19. scrollHeight:"",
  20. name:"",
  21. showUpload:false,
  22. uploadOptions:[],
  23. fileList:[],
  24. showPopup:false,
  25. fileEvent:{},
  26. itemId:"",
  27. assetTypeOptions:[]
  28. },
  29. goAdd(){
  30. wx.navigateTo({
  31. url: 'add/add',
  32. })
  33. },
  34. back:function(){
  35. wx.navigateBack({
  36. delta: 1
  37. })
  38. },
  39. assetTypeDict(val){
  40. this.data.assetTypeOptions.map(res => {
  41. if(res.dictValue == val){
  42. return res.dictLabel
  43. }
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad(options) {
  50. var that = this;
  51. let qu = wx.createSelectorQuery()
  52. qu.select("#top_view").boundingClientRect()
  53. qu.select("#top_ban").boundingClientRect()
  54. qu.exec(res => {
  55. that.setData({
  56. scrollHeight:wx.getSystemInfoSync().windowHeight-res[0].height-res[0].top
  57. })
  58. })
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady() {
  64. //获取附件字典
  65. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'common_attach', {method:'GET'}, {
  66. success: (res) => {
  67. if(res.data.length>0){
  68. this.setData({
  69. uploadOptions:res.data,
  70. })
  71. }
  72. }
  73. })
  74. this.getList();
  75. },
  76. getList:function(){
  77. let params = {
  78. pageNum:this.data.pageNums,
  79. pageSize:10,
  80. name:this.data.name
  81. }
  82. UTIL.httpRequest(API.URL_GET_PERMANENTLIST,params,{
  83. success: (res) => {
  84. let _this = this
  85. if(res.code == 200){
  86. if(this.data.pageNums!=1&&this.data.list.length<res.total){
  87. let lists = []
  88. res.rows.map((rr,index) => {
  89. rr.originalValue = Number(rr.originalValue ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
  90. return $1 + ","; }).replace(/\.$/, "")
  91. if(index==(res.rows.length-1)){
  92. lists = _this.data.list.concat(res.rows)
  93. }
  94. })
  95. //获取资产类别
  96. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_type', {method:'GET'}, {
  97. success: (r) => {
  98. if(r.data.length>0){
  99. let li = lists.map( res => {
  100. r.data.map(rr => {
  101. if(res.assetType == rr.dictValue){
  102. res.assetType = rr.dictLabel
  103. }
  104. })
  105. return res
  106. })
  107. _this.setData({list:li})
  108. }else{
  109. _this.setData({list:lists})
  110. }
  111. }
  112. })
  113. }else if(this.data.pageNums==1){
  114. //获取资产类别
  115. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_type', {method:'GET'}, {
  116. success: (r) => {
  117. if(r.data.length>0){
  118. let li = res.rows.map( ress => {
  119. ress.originalValue = Number(ress.originalValue ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
  120. return $1 + ","; }).replace(/\.$/, "")
  121. r.data.map(rr => {
  122. if(ress.assetType == rr.dictValue){
  123. ress.assetType = rr.dictLabel
  124. }
  125. })
  126. return ress
  127. })
  128. _this.setData({list:li})
  129. }else{
  130. _this.setData({list:res.rows})
  131. }
  132. }
  133. })
  134. }
  135. }else{
  136. UTIL.showToastNoneIcon(res.msg);
  137. }
  138. }
  139. })
  140. },
  141. paging(){
  142. this.setData({
  143. pageNums:this.data.pageNums+1,
  144. })
  145. this.getList();
  146. },
  147. goSearch(e){
  148. this.setData({name:e.detail});
  149. this.setData({pageNums:1});
  150. this.getList();
  151. },
  152. goUpdate(e){
  153. wx.navigateTo({
  154. url: '/pages/fixedAssets/add/add?id='+e.currentTarget.dataset.id,
  155. })
  156. },
  157. delete(e){
  158. this.setData({
  159. 'itemId':e.currentTarget.dataset.id,
  160. "showPopupDel":true
  161. });
  162. },
  163. // cancelTemDel:function(e){
  164. // this.setData({
  165. // "itemId":"",
  166. // "showPopupDel":false
  167. // });
  168. // },
  169. // confirmTemDel:function(e){
  170. // this.setData({
  171. // "showPopupDel":false
  172. // });
  173. // UTIL.httpRequest(API.URL_GET_CONTRACTDELETE+this.data.itemId , {method:'GET'}, {
  174. // success: (res) => {
  175. // if(res.code==200){
  176. // let new_list = this.data.list
  177. // new_list.splice(e.currentTarget.dataset.index,1)
  178. // this.setData({'list':new_list})
  179. // UTIL.showToastNoneIcon('删除成功!');
  180. // }else{
  181. // UTIL.showToastNoneIcon('删除失败!');
  182. // }
  183. // }
  184. // })
  185. // },
  186. // delete(e){
  187. // UTIL.httpRequest(API.URL_GET_PERMANENTDELETE + e.currentTarget.dataset.id, {method:'GET'}, {
  188. // success: (res) => {
  189. // if(res.code==200){
  190. // let new_list = this.data.list
  191. // new_list.splice(e.currentTarget.dataset.index,1)
  192. // this.setData({'list':new_list})
  193. // UTIL.showToastNoneIcon('删除成功!');
  194. // }else{
  195. // UTIL.showToastNoneIcon('删除失败!');
  196. // }
  197. // }
  198. // })
  199. // },
  200. upload(e){
  201. this.setData({itemId:e.currentTarget.dataset.id});
  202. this.asyncFun(e.currentTarget.dataset.id)
  203. },
  204. asyncFun(id){
  205. this.setData({"fileList":[]})
  206. let uploadList = this.data.uploadOptions
  207. let newList = []
  208. let _this = this
  209. uploadList.map( res => {
  210. let oData = {
  211. tableId: id,
  212. tableName: "t_asset_permanent", //上传表
  213. bizPath: "asset",
  214. fileType: res.dictValue, //附件类型 1原始发票 2会议纪要 3会议照片 4 参会人员签字
  215. method:'GET'
  216. }
  217. UTIL.httpRequest(API.URL_GET_ATTACHMENTLIST, oData, {
  218. success: (rr) => {
  219. if(rr.rows.length>0){
  220. rr.rows.map((rrr,index) => {
  221. rrr.url = URL_PREFIX + rrr.fileUrl
  222. if(index==rr.rows.length-1){
  223. newList.push(Object.assign({},res,{"list":rr.rows}))
  224. _this.setData({"fileList":_this.data.fileList.concat(newList)});
  225. _this.setData({"showUpload":true})
  226. }
  227. })
  228. }else{
  229. let newuploadList = uploadList
  230. newuploadList.map(rd => {
  231. rd.list = newList
  232. })
  233. _this.setData({"fileList":newuploadList});
  234. _this.setData({"showUpload":true})
  235. }
  236. }
  237. })
  238. })
  239. },
  240. closeBox(){
  241. this.setData({"showUpload":false})
  242. },
  243. deleteImg(event){
  244. this.setData({"fileEvent":event})
  245. this.setData({"showPopup":true});
  246. },
  247. cancelTem:function(e){
  248. this.setData({"fileEvent":"{}"});
  249. this.setData({"showPopup":false});
  250. },
  251. confirmTem:function(e){
  252. let event = this.data.fileEvent
  253. UTIL.httpRequest(API.URL_GET_GETFILEREMOVE+event.detail.file.id , {method:'GET'}, {
  254. success: (res) => {
  255. if(res.code==200){
  256. let ll = this.data.fileList
  257. var jsonlist = ll[event.target.dataset.idx].list;
  258. jsonlist.splice(event.detail.index, 1)
  259. ll[event.target.dataset.idx].list = jsonlist
  260. this.setData({"fileList":ll})
  261. this.setData({showPopup:false});
  262. wx.showToast({
  263. title: '删除成功!',
  264. icon: 'success',
  265. duration: 2000,
  266. })
  267. }
  268. }
  269. })
  270. },
  271. uploadFile(uploadFile,event) {
  272. let _this = this
  273. return new Promise((resolve, reject) => {
  274. wx.uploadFile({
  275. url: API.URL_GET_UPLOAD,
  276. filePath: uploadFile.file.file[0].url,
  277. name: 'file',
  278. header: {
  279. "Content-Type": "multipart/form-data",//记得设置
  280. "chartset":"utf-8",
  281. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  282. },
  283. formData:uploadFile,
  284. success: (res) => {
  285. res.data = JSON.parse(res.data);
  286. if(res.statusCode == 200){
  287. let files = _this.data.fileList
  288. let fName = res.data.fileUrl.split('/')
  289. let fLength = fName.length
  290. files[event.currentTarget.dataset.idx].list.push({
  291. "fileName": fName[fLength-1],
  292. "fileType": "0",
  293. "fileUrl":res.data.fileUrl ,
  294. "id": res.data.id,
  295. "tableId": 6,
  296. "url":URL_PREFIX+res.data.fileUrl
  297. })
  298. _this.setData({"fileList":files})
  299. wx.hideLoading()
  300. }
  301. },
  302. fail: (err) => {
  303. //上传失败:修改pedding为reject
  304. reject(err)
  305. }
  306. });
  307. })
  308. },
  309. afterRead(event) {
  310. let _this = this
  311. wx.showLoading({
  312. title: '上传中...'
  313. })
  314. let fileForm={
  315. file: event.detail,
  316. fileType:event.currentTarget.dataset.idx,
  317. tableName: "t_asset_permanent", //上传表
  318. bizPath: "asset",
  319. tableId:_this.data.itemId
  320. }
  321. this.uploadFile(fileForm,event)
  322. },
  323. lookDown(file,detail){
  324. // 获取指定字符串最后一次出现的位置,返回index
  325. var index1 = file.detail.url.lastIndexOf('.');
  326. // substr(start, length) 抽取从start下标开始的length个字符,返回新的字符串;
  327. var style = file.detail.url.substr(index1 + 1)
  328. //判断图片类型,不需要下载,不做处理
  329. if(style=='png'||style=='jpg'||style=='jpeg'||style=='bmp'||style=='gif'||style=='webp'||style=='psd'||style== 'svg'||style=='tiff'){
  330. //判断非图片类型
  331. }else{
  332. wx.downloadFile({
  333. url: file.detail.url,
  334. success(data){
  335. wx.openDocument({
  336. filePath: data.tempFilePath,
  337. fileType: style,
  338. showMenu:true,
  339. success(res){
  340. }
  341. })
  342. }
  343. })
  344. }
  345. },
  346. /**
  347. * 生命周期函数--监听页面显示
  348. */
  349. onShow() {
  350. },
  351. /**
  352. * 生命周期函数--监听页面隐藏
  353. */
  354. onHide() {
  355. },
  356. /**
  357. * 生命周期函数--监听页面卸载
  358. */
  359. onUnload() {
  360. },
  361. /**
  362. * 页面相关事件处理函数--监听用户下拉动作
  363. */
  364. onPullDownRefresh() {
  365. },
  366. /**
  367. * 页面上拉触底事件的处理函数
  368. */
  369. onReachBottom() {
  370. },
  371. /**
  372. * 用户点击右上角分享
  373. */
  374. onShareAppMessage() {
  375. }
  376. })