handleFile.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/handleFile/handleFile.js
  2. import { documentList, deleteDocument } from "../../api/document";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. currentPage: 1,
  9. hasNext: false,
  10. fileList: [],
  11. delFileList: []
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. },
  18. /**
  19. * 生命周期函数--监听页面初次渲染完成
  20. */
  21. onReady() {
  22. },
  23. /**
  24. * 生命周期函数--监听页面显示
  25. */
  26. onShow() {
  27. this.getDocumentList()
  28. },
  29. // 获取档案列表
  30. getDocumentList () {
  31. var data = {
  32. currentPage: this.data.currentPage
  33. }
  34. wx.showLoading({
  35. title: '加载中...',
  36. mask: true
  37. })
  38. documentList(data).then(res => {
  39. wx.hideLoading()
  40. var response = res.data.vos
  41. response.map(item => {
  42. item.birthDay = item.birthday.split(' ')[0]
  43. })
  44. this.setData({
  45. hasNext: res.data.hasNext,
  46. fileList: response
  47. })
  48. }).catch(e => {
  49. wx.hideLoading()
  50. wx.showModal({
  51. content: e,
  52. confirmColor: '#333',
  53. showCancel: false
  54. })
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面隐藏
  59. */
  60. onHide() {
  61. },
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload() {
  66. },
  67. /**
  68. * 删除文档
  69. */
  70. handleDelFile() {
  71. var that = this
  72. var delArr = []
  73. var flag = this.data.delFileList.find(item => {
  74. return item == true
  75. })
  76. this.data.delFileList.forEach(item => {
  77. if (item) {
  78. delArr.push(item)
  79. }
  80. })
  81. console.log(this.data.delFileList, delArr);
  82. if (!flag) {
  83. wx.showToast({
  84. title: '请选择删除的档案!',
  85. icon: 'error',
  86. mask: true,
  87. duration: 2000
  88. })
  89. return
  90. }
  91. if (delArr.length > 1) {
  92. wx.showToast({
  93. title: '请选择一条数据!',
  94. icon: 'error',
  95. mask: true,
  96. duration: 2000
  97. })
  98. return
  99. }
  100. wx.showModal({
  101. content: '确定要删除档案信息吗相对应的体检报告也会相应删除哦!',
  102. cancelColor: '#666',
  103. confirmColor: '#333',
  104. success (res) {
  105. if (res.confirm) {
  106. that.handleConfirm()
  107. }
  108. }
  109. })
  110. },
  111. /* 确定 */
  112. handleConfirm () {
  113. console.log(this.data.fileList);
  114. console.log(this.data.delFileList);
  115. var delPara = {}
  116. for (let index = 0; index < this.data.delFileList.length; index++) {
  117. const element = this.data.delFileList[index];
  118. if (element) {
  119. delPara.documentId = this.data.fileList[index].documentId
  120. }
  121. }
  122. wx.showLoading({
  123. title: '删除中...',
  124. mask: true
  125. })
  126. deleteDocument(delPara).then(res => {
  127. wx.hideLoading()
  128. wx.showToast({
  129. title: '删除成功',
  130. icon: 'success'
  131. })
  132. wx.navigateBack()
  133. }).catch(e => {
  134. wx.hideLoading()
  135. wx.showModal({
  136. content: e,
  137. confirmColor: '#333',
  138. showCancel: false
  139. })
  140. })
  141. },
  142. /**
  143. * 用户点击 单选radio
  144. */
  145. handleRadio (e) {
  146. var choseIndex = e.currentTarget.dataset.index
  147. var currentList = this.data.fileList
  148. currentList[choseIndex].choseFlag = !currentList[choseIndex].choseFlag
  149. this.setData({
  150. fileList: currentList
  151. })
  152. this.initDelList()
  153. },
  154. /* 处理删除的数据 */
  155. initDelList () {
  156. var currentList = this.data.fileList
  157. var _a = []
  158. currentList.map(item => {
  159. _a.push(item.choseFlag)
  160. })
  161. this.setData({
  162. delFileList: _a
  163. })
  164. }
  165. })