select.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. params: {}, //请求体
  10. result: [], //返回结果
  11. radio: false, //是否为单选
  12. idname: "sa_orderid", //idkey
  13. showName: "sonum", //表单用 显示名称
  14. filtratelist: [{
  15. label: "订单类型",
  16. index: null,
  17. showName: "name", //显示字段
  18. valueKey: "type", //返回Key
  19. selectKey: "name", //传参 代表选着字段 不传参返回整个选择对象
  20. value: "", //选中值
  21. list: [{
  22. name: "标准订单"
  23. }, {
  24. name: "特殊订单"
  25. }, {
  26. name: "项目订单"
  27. }, {
  28. name: "促销订单"
  29. }, {
  30. name: "工具订单"
  31. }]
  32. }],
  33. },
  34. openFiltrate() {
  35. this.setData({
  36. showFiltrate: true
  37. })
  38. },
  39. handleFilter(e) {
  40. e.detail.condition = this.data.params.content.where.condition;
  41. this.data.params.content.where = e.detail;
  42. this.getList(true);
  43. },
  44. onLoad(options) {
  45. console.log(options)
  46. if (options.params) {
  47. let params = JSON.parse(options.params);
  48. if (!params.content.pageNumber || !params.content.pageTotal) {
  49. params.content.pageNumber = 1;
  50. params.content.pageTotal = 1;
  51. }
  52. this.setData({
  53. params
  54. });
  55. }
  56. if (options.title) wx.setNavigationBarTitle({
  57. title: options.title,
  58. })
  59. this.setData({
  60. radio: options.radio ? true : false,
  61. idname: options.idname || this.data.idname,
  62. showName: options.showName || this.data.showName,
  63. aitText: options.aitText || ''
  64. });
  65. this.getList()
  66. _Http.basic({
  67. "id": 20221223141802,
  68. "content": {
  69. "pageNumber": 1,
  70. "pageSize": 9999,
  71. "where": {
  72. "condition": ""
  73. }
  74. }
  75. }, false).then(res => {
  76. console.log("获取领域", res)
  77. if (res.msg == '成功') {
  78. this.data.filtratelist.push({
  79. label: "领域",
  80. index: null,
  81. showName: "tradefield", //显示字段
  82. valueKey: "tradefield", //返回Key
  83. selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
  84. value: "", //选中值
  85. list: res.data
  86. })
  87. this.setData({
  88. filtratelist: this.data.filtratelist
  89. })
  90. }
  91. })
  92. },
  93. getList(init = false) {
  94. //init 用于初始化分页
  95. if (init.detail != undefined) init = init.detail;
  96. let params = this.data.params;
  97. if (init) params.content.pageNumber = 1;
  98. if (params.content.pageNumber > params.content.pageTotal) return;
  99. _Http.basic(params).then(res => {
  100. console.log("选择订单列表", res)
  101. this.selectComponent('#ListBox').RefreshToComplete();
  102. if (res.msg != '成功') return wx.showToast({
  103. title: res.data,
  104. icon: "none"
  105. })
  106. res.data = res.data.map(v => {
  107. v.defaultamount = CNY(v.defaultamount);
  108. v.amount = CNY(v.amount);
  109. return v
  110. })
  111. this.setData({
  112. 'params.content.pageNumber': res.pageNumber + 1,
  113. 'params.content.pageTotal': res.pageTotal,
  114. 'params.content.total': res.total,
  115. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  116. })
  117. })
  118. },
  119. /* 删除项 */
  120. deteleItem(id) {
  121. this.setData({
  122. list: this.data.list.filter(v => v[this.data.idname] != id),
  123. "params.content.total": this.data.params.content.total - 1
  124. })
  125. },
  126. /* 选中 */
  127. changeResult(e) {
  128. let {
  129. id
  130. } = e.currentTarget.dataset, result = this.data.result;
  131. if (this.data.radio) {
  132. result = [id];
  133. } else {
  134. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  135. }
  136. this.setData({
  137. result
  138. });
  139. if (this.data.radio) this.submit();
  140. },
  141. /* 提交 */
  142. submit() {
  143. let result = this.data.result,
  144. obj = this.data.radio ? {
  145. id: result,
  146. item: this.data.list.find(value => value[this.data.idname] == result),
  147. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  148. } : {
  149. result,
  150. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  151. value: [result.map(v => {
  152. let data = this.data.list.find(value => value[this.data.idname] == v);
  153. return data ? data[this.data.showName] : ""
  154. }), result]
  155. }
  156. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  157. },
  158. /* 开始搜索 */
  159. startSearch({
  160. detail
  161. }) {
  162. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  163. if (detail == condition) return;
  164. this.setData({
  165. 'content.where.condition': detail,
  166. 'params.content.where.condition': detail
  167. });
  168. this.getList(true);
  169. },
  170. /* 取消搜索 */
  171. onClear() {
  172. this.setData({
  173. 'content.where.condition': "",
  174. 'params.content.where.condition': ""
  175. });
  176. this.getList(true);
  177. },
  178. onReady() {
  179. this.selectComponent("#ListBox").setHeight(".div", this);
  180. },
  181. onUnload() { //回收数据
  182. getApp().globalData.handleSelect = null;
  183. }
  184. })