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

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