select.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. getApp().globalData.Language.getLanguagePackage(this, options.title || '选择订单');
  57. this.setData({
  58. radio: options.radio ? true : false,
  59. idname: options.idname || this.data.idname,
  60. showName: options.showName || this.data.showName,
  61. aitText: options.aitText || ''
  62. });
  63. this.getList()
  64. _Http.basic({
  65. "id": 20221223141802,
  66. "content": {
  67. "pageNumber": 1,
  68. "pageSize": 9999,
  69. "where": {
  70. "condition": ""
  71. }
  72. }
  73. }, false).then(res => {
  74. console.log("获取领域", res)
  75. if (res.code == '1') {
  76. this.data.filtratelist.push({
  77. label: "领域",
  78. index: null,
  79. showName: "tradefield", //显示字段
  80. valueKey: "tradefield", //返回Key
  81. selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
  82. value: "", //选中值
  83. list: res.data
  84. })
  85. this.setData({
  86. filtratelist: this.data.filtratelist
  87. })
  88. }
  89. })
  90. },
  91. getList(init = false) {
  92. //init 用于初始化分页
  93. if (init.detail != undefined) init = init.detail;
  94. let params = this.data.params;
  95. if (init) params.content.pageNumber = 1;
  96. if (params.content.pageNumber > params.content.pageTotal) return;
  97. _Http.basic(params).then(res => {
  98. console.log("选择订单列表", res)
  99. this.selectComponent('#ListBox').RefreshToComplete();
  100. if (res.code != '1') return wx.showToast({
  101. title: res.data,
  102. icon: "none"
  103. })
  104. res.data = res.data.map(v => {
  105. v.defaultamount = CNY(v.defaultamount);
  106. v.amount = CNY(v.amount);
  107. return v
  108. })
  109. this.setData({
  110. 'params.content.pageNumber': res.pageNumber + 1,
  111. 'params.content.pageTotal': res.pageTotal,
  112. 'params.content.total': res.total,
  113. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  114. })
  115. })
  116. },
  117. /* 删除项 */
  118. deteleItem(id) {
  119. this.setData({
  120. list: this.data.list.filter(v => v[this.data.idname] != id),
  121. "params.content.total": this.data.params.content.total - 1
  122. })
  123. },
  124. /* 选中 */
  125. changeResult(e) {
  126. let {
  127. id
  128. } = e.currentTarget.dataset, result = this.data.result;
  129. if (this.data.radio) {
  130. result = [id];
  131. } else {
  132. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  133. }
  134. this.setData({
  135. result
  136. });
  137. if (this.data.radio) this.submit();
  138. },
  139. /* 提交 */
  140. submit() {
  141. let result = this.data.result,
  142. obj = this.data.radio ? {
  143. id: result,
  144. item: this.data.list.find(value => value[this.data.idname] == result),
  145. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  146. } : {
  147. result,
  148. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  149. value: [result.map(v => {
  150. let data = this.data.list.find(value => value[this.data.idname] == v);
  151. return data ? data[this.data.showName] : ""
  152. }), result]
  153. }
  154. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  155. },
  156. /* 开始搜索 */
  157. startSearch({
  158. detail
  159. }) {
  160. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  161. if (detail == condition) return;
  162. this.setData({
  163. 'content.where.condition': detail,
  164. 'params.content.where.condition': detail
  165. });
  166. this.getList(true);
  167. },
  168. /* 取消搜索 */
  169. onClear() {
  170. this.setData({
  171. 'content.where.condition': "",
  172. 'params.content.where.condition': ""
  173. });
  174. this.getList(true);
  175. },
  176. onReady() {
  177. this.selectComponent("#ListBox").setHeight(".div", this);
  178. },
  179. onUnload() { //回收数据
  180. getApp().globalData.handleSelect = null;
  181. }
  182. })