select.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. params: {}, //请求体
  5. result: [], //返回结果
  6. radio: false, //是否为单选
  7. idname: "sa_customersid", //idkey
  8. showName: "enterprisename", //表单用 显示名称
  9. filtratelist: [],
  10. },
  11. openFiltrate() {
  12. this.setData({
  13. showFiltrate: true
  14. })
  15. },
  16. handleFilter(e) {
  17. e.detail.condition = this.data.params.content.where.condition;
  18. this.data.params.content.where = e.detail;
  19. this.getList(true);
  20. },
  21. onLoad(options) {
  22. getApp().globalData.Language.getLanguagePackage(this, '选择客户');
  23. if (options.params) {
  24. let params = JSON.parse(options.params);
  25. if (!params.content.pageNumber || !params.content.pageTotal) {
  26. params.content.pageNumber = 1;
  27. params.content.pageTotal = 1;
  28. }
  29. this.setData({
  30. params
  31. });
  32. }
  33. getApp().globalData.Language.getLanguagePackage(this,options.title || '');
  34. this.setData({
  35. radio: options.radio ? true : false,
  36. idname: options.idname || this.data.idname,
  37. showName: options.showName || this.data.showName,
  38. });
  39. this.getList()
  40. _Http.basic({
  41. "classname": "sysmanage.develop.optiontype.optiontype",
  42. "method": "optiontypeselect",
  43. "content": {
  44. "nochace": true,
  45. "pageNumber": 1,
  46. "pageSize": 1000,
  47. "typename": "customertypemx",
  48. "parameter": {
  49. "siteid": wx.getStorageSync('userMsg').siteid
  50. }
  51. }
  52. }).then(res => {
  53. console.log("医院类型", res)
  54. if (res.code == '1') {
  55. this.data.filtratelist.unshift({
  56. label: "项目类型",
  57. index: null,
  58. showName: "value", //显示字段
  59. valueKey: "type", //返回Key
  60. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  61. value: "", //选中值
  62. list: res.data
  63. })
  64. this.setData({
  65. filtratelist: this.data.filtratelist
  66. })
  67. }
  68. })
  69. },
  70. getList(init = false) {
  71. //init 用于初始化分页
  72. if (init.detail != undefined) init = init.detail;
  73. let params = this.data.params;
  74. if (init) params.content.pageNumber = 1;
  75. if (params.content.pageNumber > params.content.pageTotal) return;
  76. _Http.basic(params).then(res => {
  77. console.log("选择客户列表", res)
  78. this.selectComponent('#ListBox').RefreshToComplete();
  79. if (res.code != '1') return wx.showToast({
  80. title: res.data,
  81. icon: "none"
  82. })
  83. this.setData({
  84. 'params.content.pageNumber': res.pageNumber + 1,
  85. 'params.content.pageTotal': res.pageTotal,
  86. 'params.content.total': res.total,
  87. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  88. })
  89. })
  90. },
  91. /* 选中 */
  92. changeResult(e) {
  93. let {
  94. id
  95. } = e.currentTarget.dataset, result = this.data.result;
  96. if (this.data.radio) {
  97. result = [id];
  98. } else {
  99. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  100. }
  101. this.setData({
  102. result
  103. });
  104. if (this.data.radio) this.submit();
  105. },
  106. /* 提交 */
  107. submit() {
  108. let result = this.data.result,
  109. obj = this.data.radio ? {
  110. id: result,
  111. item: this.data.list.find(value => value[this.data.idname] == result),
  112. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  113. } : {
  114. result,
  115. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  116. value: [result.map(v => {
  117. let data = this.data.list.find(value => value[this.data.idname] == v);
  118. return data ? data[this.data.showName] : ""
  119. }), result]
  120. }
  121. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  122. },
  123. /* 开始搜索 */
  124. startSearch({
  125. detail
  126. }) {
  127. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  128. if (detail == condition) return;
  129. this.setData({
  130. 'content.where.condition': detail,
  131. 'params.content.where.condition': detail
  132. });
  133. this.getList(true);
  134. },
  135. /* 取消搜索 */
  136. onClear() {
  137. this.setData({
  138. 'content.where.condition': "",
  139. 'params.content.where.condition': ""
  140. });
  141. this.getList(true);
  142. },
  143. onUnload() { //回收数据
  144. getApp().globalData.handleSelect = null;
  145. }
  146. })