handleFile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. onShow() {
  17. this.getDocumentList()
  18. },
  19. // 获取档案列表
  20. getDocumentList () {
  21. var data = {
  22. currentPage: this.data.currentPage
  23. }
  24. wx.showLoading({
  25. title: '加载中...',
  26. mask: true
  27. })
  28. documentList(data).then(res => {
  29. wx.hideLoading()
  30. var response = res.data.vos
  31. response.map(item => {
  32. item.birthDay = item.birthday.split(' ')[0]
  33. })
  34. this.setData({
  35. hasNext: res.data.hasNext,
  36. fileList: response
  37. })
  38. }).catch(e => {
  39. wx.hideLoading()
  40. wx.showModal({
  41. content: e,
  42. confirmColor: '#333',
  43. showCancel: false
  44. })
  45. })
  46. },
  47. /**
  48. * 删除文档
  49. */
  50. handleDelFile() {
  51. var that = this
  52. var delArr = []
  53. var flag = this.data.delFileList.find(item => {
  54. return item == true
  55. })
  56. this.data.delFileList.forEach(item => {
  57. if (item) {
  58. delArr.push(item)
  59. }
  60. })
  61. console.log(this.data.delFileList, delArr);
  62. if (!flag) {
  63. wx.showToast({
  64. title: '请选择删除的档案!',
  65. icon: 'error',
  66. mask: true,
  67. duration: 2000
  68. })
  69. return
  70. }
  71. if (delArr.length > 1) {
  72. wx.showToast({
  73. title: '请选择一条数据!',
  74. icon: 'error',
  75. mask: true,
  76. duration: 2000
  77. })
  78. return
  79. }
  80. wx.showModal({
  81. title: '确定要删除档案信息吗?',
  82. content: '相对应的体检报告也会删除哦!',
  83. cancelColor: '#666',
  84. confirmColor: '#333',
  85. success (res) {
  86. if (res.confirm) {
  87. that.handleConfirm()
  88. }
  89. }
  90. })
  91. },
  92. /* 确定 */
  93. handleConfirm () {
  94. var delPara = {}
  95. for (let index = 0; index < this.data.delFileList.length; index++) {
  96. const element = this.data.delFileList[index];
  97. if (element) {
  98. delPara.documentId = this.data.fileList[index].documentId
  99. }
  100. }
  101. wx.showLoading({
  102. title: '删除中...',
  103. mask: true
  104. })
  105. deleteDocument(delPara).then(res => {
  106. wx.hideLoading()
  107. wx.showToast({
  108. title: '删除成功',
  109. icon: 'success'
  110. })
  111. wx.navigateBack()
  112. }).catch(e => {
  113. wx.hideLoading()
  114. wx.showModal({
  115. content: e,
  116. confirmColor: '#333',
  117. showCancel: false
  118. })
  119. })
  120. },
  121. /**
  122. * 用户点击 单选radio
  123. */
  124. handleRadio (e) {
  125. var choseIndex = e.currentTarget.dataset.index
  126. var currentList = this.data.fileList
  127. currentList[choseIndex].choseFlag = !currentList[choseIndex].choseFlag
  128. this.setData({
  129. fileList: currentList
  130. })
  131. this.initDelList()
  132. },
  133. /* 处理删除的数据 */
  134. initDelList () {
  135. var currentList = this.data.fileList
  136. var _a = []
  137. currentList.map(item => {
  138. _a.push(item.choseFlag)
  139. })
  140. this.setData({
  141. delFileList: _a
  142. })
  143. }
  144. })