select.js 6.2 KB

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