微信小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

fixedAssets.js 12 KiB

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