index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. params: {}, //请求体
  5. result: [], //返回结果
  6. radio: false, //是否为单选
  7. idname: "sa_doctorid", //idkey
  8. showName: "doctorname", //表单用 显示名称
  9. },
  10. onLoad(options) {
  11. console.log("options", options)
  12. if (options.params) {
  13. let params = JSON.parse(options.params);
  14. if (!params.content.pageNumber || !params.content.pageTotal) {
  15. params.content.pageNumber = 1;
  16. params.content.pageTotal = 1;
  17. }
  18. this.setData({
  19. params
  20. });
  21. }
  22. this.setData({
  23. radio: options.radio ? true : false,
  24. idname: options.idname || this.data.idname,
  25. showName: options.showName || this.data.showName
  26. });
  27. this.getList()
  28. },
  29. getList(init = false) {
  30. //init 用于初始化分页
  31. if (init.detail != undefined) init = init.detail;
  32. let params = this.data.params;
  33. if (init) params.content.pageNumber = 1;
  34. if (params.content.pageNumber > params.content.pageTotal) return;
  35. //init 用于初始化分页
  36. _Http.basic(params).then(res => {
  37. console.log("选择医生列表", res)
  38. this.selectComponent('#ListBox').RefreshToComplete();
  39. if (res.code != '1') return wx.showToast({
  40. title: res.data,
  41. icon: "none"
  42. })
  43. this.setData({
  44. 'params.content.pageNumber': res.pageNumber + 1,
  45. 'params.content.pageTotal': res.pageTotal,
  46. 'params.content.total': res.total,
  47. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  48. })
  49. })
  50. },
  51. uploadList() {
  52. let params = JSON.parse(JSON.stringify(this.data.params));
  53. params.content.pageSize = (params.content.pageNumber - 1) * params.content.pageSize;
  54. params.content.pageNumber = 1;
  55. _Http.basic(params).then(res => {
  56. console.log("更新列表", res);
  57. if (res.code != '1') return wx.showToast({
  58. title: res.data,
  59. icon: "none"
  60. })
  61. this.setData({
  62. 'params.content.total': res.total,
  63. list: res.data
  64. })
  65. })
  66. },
  67. /* 选中 */
  68. changeResult(e) {
  69. let {
  70. id
  71. } = e.currentTarget.dataset, result = this.data.result;
  72. if (this.data.radio) {
  73. result = [id];
  74. } else {
  75. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  76. }
  77. this.setData({
  78. result
  79. });
  80. if (this.data.radio) this.submit();
  81. },
  82. /* 提交 */
  83. submit() {
  84. let result = this.data.result,
  85. obj = this.data.radio ? {
  86. id: result,
  87. item: this.data.list.find(value => value[this.data.idname] == result),
  88. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  89. } : {
  90. result,
  91. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  92. value: [result.map(v => {
  93. let data = this.data.list.find(value => value[this.data.idname] == v);
  94. return data ? data[this.data.showName] : ""
  95. }), result]
  96. }
  97. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  98. },
  99. /* 开始搜索 */
  100. startSearch({
  101. detail
  102. }) {
  103. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  104. if (detail == condition) return;
  105. this.setData({
  106. 'content.where.condition': detail,
  107. 'params.content.where.condition': detail
  108. });
  109. this.getList(true);
  110. },
  111. /* 取消搜索 */
  112. onClear() {
  113. this.setData({
  114. 'content.where.condition': "",
  115. 'params.content.where.condition': ""
  116. });
  117. this.getList(true);
  118. },
  119. onUnload() {
  120. //回收数据
  121. getApp().globalData.handleSelect = null;
  122. },
  123. })