select.js 5.2 KB

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