index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const _Http = getApp().globalData.http;
  2. import currency from "../../utils/currency";
  3. Page({
  4. data: {
  5. loading: true,
  6. params: {}, //请求体
  7. result: [], //返回结果
  8. radio: false, //是否为单选
  9. idname: "sa_workorderid", //idkey
  10. showName: "itemname"
  11. },
  12. onLoad(options) {
  13. if (options.params) {
  14. let params = JSON.parse(options.params);
  15. if (!params.content.pageNumber || !params.content.pageTotal) {
  16. params.content.pageNumber = 1;
  17. params.content.pageTotal = 1;
  18. }
  19. this.setData({
  20. params
  21. });
  22. };
  23. this.setData({
  24. radio: options.radio ? true : false,
  25. idname: options.idname || this.data.idname,
  26. showName: options.showName || this.data.showName
  27. });
  28. this.getList();
  29. },
  30. getList(init = false) {
  31. //init 用于初始化分页
  32. if (init.detail != undefined) init = init.detail;
  33. let params = this.data.params;
  34. if (init) params.content.pageNumber = 1
  35. if (params.content.pageNumber > params.content.pageTotal) return;
  36. _Http.basic(params).then(res => {
  37. console.log("选择产品列表", res)
  38. this.selectComponent('#ListBox').RefreshToComplete();
  39. if (res.msg != '成功') return wx.showToast({
  40. title: res.msg,
  41. icon: "none"
  42. })
  43. this.setData({
  44. 'params.content.pageNumber': res.pageNumber + 1,
  45. 'params.content.pageTotal': res.pageTotal,
  46. 'params.content.total': res.total,
  47. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  48. loading: false
  49. })
  50. })
  51. },
  52. /* 选中 */
  53. changeResult(e) {
  54. let {
  55. id,
  56. item
  57. } = e.currentTarget.dataset, result = this.data.result;
  58. if (this.data.radio) {
  59. result = [id];
  60. } else {
  61. let isAdd = result.some(v => v == id);
  62. if (!isAdd) {
  63. if (item.iscustomsize == 1) {
  64. if ((item.widthschemeid && item.width == 0) || (item.lengthschemeid && item.length == 0)) {
  65. item.pitchOn = true;
  66. this.bindChangeFun()
  67. if (item) this.selectComponent("#Custom").onClick(item)
  68. } else {
  69. result.push(id)
  70. }
  71. } else {
  72. result.push(id)
  73. }
  74. } else {
  75. result = result.filter(v => v != id)
  76. }
  77. }
  78. this.setData({
  79. result
  80. });
  81. if (this.data.radio) this.submit();
  82. },
  83. /* 提交 */
  84. submit() {
  85. let result = this.data.result,
  86. obj = this.data.radio ? {
  87. id: result,
  88. item: this.data.list.find(value => value[this.data.idname] == result),
  89. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  90. } : {
  91. result,
  92. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  93. value: [result.map(v => {
  94. let data = this.data.list.find(value => value[this.data.idname] == v);
  95. return data ? data[this.data.showName] : ""
  96. }), result]
  97. }
  98. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  99. },
  100. /* 开始搜索 */
  101. startSearch({
  102. detail
  103. }) {
  104. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  105. if (detail == condition) return;
  106. this.setData({
  107. 'content.where.condition': detail,
  108. 'params.content.where.condition': detail
  109. });
  110. this.getList(true);
  111. },
  112. /* 取消搜索 */
  113. onClear() {
  114. this.setData({
  115. 'content.where.condition': "",
  116. 'params.content.where.condition': ""
  117. });
  118. this.getList(true);
  119. }
  120. })