index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. params: {}, //请求体
  5. result: [], //返回结果
  6. radio: false, //是否为单选
  7. idname: "itemid", //idkey
  8. showName: "enterprisename", //表单用 显示名称
  9. sColors: getApp().globalData.sColors,
  10. active: "Receive",
  11. filterShow:true,
  12. filtratelist:[ {
  13. label: "阅读状态",
  14. index: null,
  15. showName: "name", //显示字段
  16. valueKey: "readstatus", //返回Key
  17. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  18. value: "", //选中值
  19. list: [{
  20. name: "全部",
  21. value: ""
  22. }, {
  23. name: "已读",
  24. value: "1"
  25. }, {
  26. name: "未读",
  27. value: "0"
  28. }]
  29. }]
  30. },
  31. onLoad(options) {
  32. if (options.params) {
  33. let params = JSON.parse(options.params);
  34. if (!params.content.pageNumber || !params.content.pageTotal) {
  35. params.content.pageNumber = 1;
  36. params.content.pageTotal = 1;
  37. }
  38. this.setData({
  39. params
  40. });
  41. }
  42. this.setData({
  43. radio: options.radio ? true : false,
  44. idname: options.idname || this.data.idname,
  45. showName: options.showName || this.data.showName
  46. });
  47. this.getList()
  48. },
  49. getList(init = false) {
  50. //init 用于初始化分页
  51. if (init.detail != undefined) init = init.detail;
  52. let params = this.data.params;
  53. if (init) params.content.pageNumber = 1;
  54. if (params.content.pageNumber > params.content.pageTotal) return;
  55. //init 用于初始化分页
  56. _Http.basic(params).then(res => {
  57. console.log("选择产品列表", res)
  58. this.selectComponent('#ListBox').RefreshToComplete();
  59. if (res.code != '1') return wx.showToast({
  60. title: res.data,
  61. icon: "none"
  62. })
  63. res.data = res.data.map(v => {
  64. v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
  65. return v
  66. })
  67. this.setData({
  68. 'params.content.pageNumber': res.pageNumber + 1,
  69. 'params.content.pageTotal': res.pageTotal,
  70. 'params.content.total': res.total,
  71. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  72. })
  73. })
  74. },
  75. uploadList() {
  76. let params = JSON.parse(JSON.stringify(this.data.params));
  77. params.content.pageSize = (params.content.pageNumber - 1) * params.content.pageSize;
  78. params.content.pageNumber = 1;
  79. _Http.basic(params).then(res => {
  80. console.log("更新列表", res);
  81. if (res.code != '1') return wx.showToast({
  82. title: res.data,
  83. icon: "none"
  84. })
  85. res.data = res.data.map(v => {
  86. v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
  87. return v
  88. })
  89. this.setData({
  90. 'params.content.total': res.total,
  91. list: res.data
  92. })
  93. })
  94. },
  95. /* 选中 */
  96. changeResult(e) {
  97. let {
  98. id
  99. } = e.currentTarget.dataset, result = this.data.result;
  100. if (this.data.radio) {
  101. result = [id];
  102. } else {
  103. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  104. }
  105. this.setData({
  106. result
  107. });
  108. if (this.data.radio) this.submit();
  109. },
  110. /* 提交 */
  111. submit() {
  112. let result = this.data.result,
  113. obj = this.data.radio ? {
  114. id: result,
  115. item: this.data.list.find(value => value[this.data.idname] == result),
  116. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  117. } : {
  118. result,
  119. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  120. value: [result.map(v => {
  121. let data = this.data.list.find(value => value[this.data.idname] == v);
  122. return data ? data[this.data.showName] : ""
  123. }), result]
  124. }
  125. _Http.handleSelect && _Http.handleSelect(obj)
  126. },
  127. /* 开始搜索 */
  128. startSearch({
  129. detail
  130. }) {
  131. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  132. if (detail == condition) return;
  133. this.setData({
  134. 'content.where.condition': detail,
  135. 'params.content.where.condition': detail
  136. });
  137. this.getList(true);
  138. },
  139. /* 取消搜索 */
  140. onClear() {
  141. this.setData({
  142. 'content.where.condition': "",
  143. 'params.content.where.condition': ""
  144. });
  145. this.getList(true);
  146. },
  147. onUnload() {
  148. //回收数据
  149. getApp().globalData.handleSelect = null;
  150. },
  151. /* 筛选 */
  152. handleFilter({
  153. detail
  154. }) {
  155. detail.condition = this.data.where.condition;
  156. detail.today = 0
  157. detail.lastthreedays = 0
  158. detail.lastWeek = 0
  159. if (detail.date) detail[detail.date] = 1;
  160. detail.begindate = detail.startdate || ''
  161. this.data.where = detail;
  162. this.selectComponent("#" + this.data.active).getList(true);
  163. },
  164. onClick() {
  165. console.log('执行11111')
  166. this.setData({
  167. filterShow: true
  168. })
  169. console.log(this.filterShow,'返回结果')
  170. }
  171. })