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

380 rivejä
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. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'common_attach', {method:'GET'}, {
  61. success: (res) => {
  62. if(res.data.length>0){
  63. this.setData({
  64. uploadOptions:res.data,
  65. })
  66. }
  67. }
  68. })
  69. this.getList();
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady() {
  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. 'itemIndex':e.currentTarget.dataset.index,
  161. "showPopupDel":true
  162. });
  163. },
  164. cancelTemDel:function(e){
  165. this.setData({
  166. "itemId":"",
  167. "itemIndex":"",
  168. "showPopupDel":false
  169. });
  170. },
  171. confirmTemDel:function(e){
  172. this.setData({
  173. "showPopupDel":false
  174. });
  175. UTIL.httpRequest(API.URL_GET_PERMANENTDELETE + this.data.itemId , {method:'GET'}, {
  176. success: (res) => {
  177. if(res.code==200){
  178. let new_list = this.data.list
  179. new_list.splice(this.data.index,1)
  180. this.setData({'list':new_list})
  181. UTIL.showToastNoneIcon('删除成功!');
  182. }else{
  183. UTIL.showToastNoneIcon('删除失败!');
  184. }
  185. }
  186. })
  187. },
  188. upload(e){
  189. this.setData({itemId:e.currentTarget.dataset.id});
  190. this.asyncFun(e.currentTarget.dataset.id)
  191. },
  192. asyncFun(id){
  193. this.setData({"fileList":[]})
  194. let uploadList = this.data.uploadOptions
  195. let newList = []
  196. let _this = this
  197. uploadList.map( res => {
  198. let oData = {
  199. tableId: id,
  200. tableName: "t_asset_permanent", //上传表
  201. bizPath: "asset",
  202. fileType: res.dictValue, //附件类型 1原始发票 2会议纪要 3会议照片 4 参会人员签字
  203. method:'GET'
  204. }
  205. UTIL.httpRequest(API.URL_GET_ATTACHMENTLIST, oData, {
  206. success: (rr) => {
  207. if(rr.rows.length>0){
  208. rr.rows.map((rrr,index) => {
  209. rrr.url = URL_PREFIX + rrr.fileUrl
  210. if(index==rr.rows.length-1){
  211. newList.push(Object.assign({},res,{"list":rr.rows}))
  212. _this.setData({"fileList":_this.data.fileList.concat(newList)});
  213. _this.setData({"showUpload":true})
  214. }
  215. })
  216. }else{
  217. let newuploadList = uploadList
  218. newuploadList.map(rd => {
  219. rd.list = newList
  220. })
  221. _this.setData({"fileList":newuploadList});
  222. _this.setData({"showUpload":true})
  223. }
  224. }
  225. })
  226. })
  227. },
  228. closeBox(){
  229. this.setData({"showUpload":false})
  230. },
  231. deleteImg(event){
  232. this.setData({"fileEvent":event})
  233. this.setData({"showPopup":true});
  234. },
  235. cancelTem:function(e){
  236. this.setData({"fileEvent":"{}"});
  237. this.setData({"showPopup":false});
  238. },
  239. confirmTem:function(e){
  240. let event = this.data.fileEvent
  241. UTIL.httpRequest(API.URL_GET_GETFILEREMOVE+event.detail.file.id , {method:'GET'}, {
  242. success: (res) => {
  243. if(res.code==200){
  244. let ll = this.data.fileList
  245. var jsonlist = ll[event.target.dataset.idx].list;
  246. jsonlist.splice(event.detail.index, 1)
  247. ll[event.target.dataset.idx].list = jsonlist
  248. this.setData({"fileList":ll})
  249. this.setData({showPopup:false});
  250. wx.showToast({
  251. title: '删除成功!',
  252. icon: 'success',
  253. duration: 2000,
  254. })
  255. }
  256. }
  257. })
  258. },
  259. uploadFile(uploadFile,event) {
  260. let _this = this
  261. return new Promise((resolve, reject) => {
  262. wx.uploadFile({
  263. url: API.URL_GET_UPLOAD,
  264. filePath: uploadFile.file.file.url,
  265. name: 'file',
  266. header: {
  267. "Content-Type": "multipart/form-data",//记得设置
  268. "chartset":"utf-8",
  269. 'Authorization':'Bearer '+getApp().globalData.userInfo.token
  270. },
  271. formData:uploadFile,
  272. success: (res) => {
  273. res.data = JSON.parse(res.data);
  274. if(res.statusCode == 200){
  275. let files = _this.data.fileList
  276. let fName = res.data.fileUrl.split('/')
  277. let fLength = fName.length
  278. files[event.currentTarget.dataset.idx].list.push({
  279. "fileName": fName[fLength-1],
  280. "fileType": "0",
  281. "fileUrl":res.data.fileUrl ,
  282. "id": res.data.id,
  283. "tableId": 6,
  284. "url":URL_PREFIX+res.data.fileUrl
  285. })
  286. _this.setData({"fileList":files})
  287. wx.hideLoading()
  288. }
  289. },
  290. fail: (err) => {
  291. //上传失败:修改pedding为reject
  292. reject(err)
  293. }
  294. });
  295. })
  296. },
  297. afterRead(event) {
  298. let _this = this
  299. wx.showLoading({
  300. title: '上传中...'
  301. })
  302. let fileForm={
  303. file: event.detail,
  304. fileType:event.currentTarget.dataset.idx,
  305. tableName: "t_asset_permanent", //上传表
  306. bizPath: "asset",
  307. tableId:_this.data.itemId
  308. }
  309. this.uploadFile(fileForm,event)
  310. },
  311. lookDown(file,detail){
  312. // 获取指定字符串最后一次出现的位置,返回index
  313. var index1 = file.detail.url.lastIndexOf('.');
  314. // substr(start, length) 抽取从start下标开始的length个字符,返回新的字符串;
  315. var style = file.detail.url.substr(index1 + 1)
  316. //判断图片类型,不需要下载,不做处理
  317. if(style=='png'||style=='jpg'||style=='jpeg'||style=='bmp'||style=='gif'||style=='webp'||style=='psd'||style== 'svg'||style=='tiff'){
  318. //判断非图片类型
  319. }else{
  320. wx.downloadFile({
  321. url: file.detail.url,
  322. success(data){
  323. wx.openDocument({
  324. filePath: data.tempFilePath,
  325. fileType: style,
  326. showMenu:true,
  327. success(res){
  328. }
  329. })
  330. }
  331. })
  332. }
  333. },
  334. /**
  335. * 生命周期函数--监听页面显示
  336. */
  337. onShow() {
  338. this.setData({'pageNums':1})
  339. this.getList();
  340. },
  341. /**
  342. * 生命周期函数--监听页面隐藏
  343. */
  344. onHide() {
  345. },
  346. /**
  347. * 生命周期函数--监听页面卸载
  348. */
  349. onUnload() {
  350. },
  351. /**
  352. * 页面相关事件处理函数--监听用户下拉动作
  353. */
  354. onPullDownRefresh() {
  355. },
  356. /**
  357. * 页面上拉触底事件的处理函数
  358. */
  359. onReachBottom() {
  360. },
  361. /**
  362. * 用户点击右上角分享
  363. */
  364. onShareAppMessage() {
  365. }
  366. })