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

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