select.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const _Http = getApp().globalData.http,
  2. getHeight = require("../../../utils/getRheRemainingHeight");
  3. Page({
  4. data: {
  5. params: {}, //请求体
  6. result: [], //返回结果
  7. radio: false, //是否为单选
  8. idname: "sa_quotedpriceid", //idkey
  9. showName: "billno", //表单用 显示名称
  10. },
  11. onLoad(options) {
  12. if (options.params) {
  13. let params = JSON.parse(options.params);
  14. if (!params.content.pageNumber || !params.content.pageTotal) {
  15. params.content.pageNumber = 1;
  16. params.content.pageTotal = 1;
  17. }
  18. this.setData({
  19. params
  20. });
  21. }
  22. if (options.title) wx.setNavigationBarTitle({
  23. title: options.title,
  24. })
  25. this.setData({
  26. radio: options.radio ? true : false,
  27. idname: options.idname || this.data.idname,
  28. showName: options.showName || this.data.showName,
  29. });
  30. this.getList()
  31. },
  32. getList(init = false) {
  33. //init 用于初始化分页
  34. if (init.detail != undefined) init = init.detail;
  35. let params = this.data.params;
  36. if (init) params.content.pageNumber = 1;
  37. if (params.content.pageNumber > params.content.pageTotal) return;
  38. _Http.basic(params).then(res => {
  39. console.log("选择报价单列表", res)
  40. this.selectComponent('#ListBox').RefreshToComplete();
  41. if (res.msg != '成功') return wx.showToast({
  42. title: res.data,
  43. icon: "none"
  44. })
  45. this.setData({
  46. 'params.content.pageNumber': res.pageNumber + 1,
  47. 'params.content.pageTotal': res.pageTotal,
  48. 'params.content.total': res.total,
  49. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  50. })
  51. this.getTags();
  52. })
  53. },
  54. /* 获取列表标签 */
  55. getTags() {
  56. let list = this.data.list,
  57. ownerids = list.map(v => v.sa_quotedpriceid);
  58. _Http.basic({
  59. "id": 20221018102001,
  60. "content": {
  61. nocache: true,
  62. "ownertable": "sa_quotedprice",
  63. ownerids
  64. }
  65. }).then(res => {
  66. console.log("标签", res)
  67. for (let key in res.data) {
  68. let index = list.findIndex(v => v.sa_quotedpriceid == key);
  69. list[index].tags = res.data[key]
  70. };
  71. this.setData({
  72. list
  73. })
  74. })
  75. },
  76. /* 删除项 */
  77. deteleItem(id) {
  78. this.setData({
  79. list: this.data.list.filter(v => v[this.data.idname] != id),
  80. "params.content.total": this.data.params.content.total - 1
  81. })
  82. },
  83. /* 选中 */
  84. changeResult(e) {
  85. let {
  86. id
  87. } = e.currentTarget.dataset, result = this.data.result;
  88. if (this.data.radio) {
  89. result = [id];
  90. } else {
  91. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  92. }
  93. this.setData({
  94. result
  95. });
  96. if (this.data.radio) this.submit();
  97. },
  98. /* 提交 */
  99. submit() {
  100. let result = this.data.result,
  101. obj = this.data.radio ? {
  102. id: result,
  103. item: this.data.list.find(value => value[this.data.idname] == result),
  104. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  105. } : {
  106. result,
  107. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  108. value: [result.map(v => {
  109. let data = this.data.list.find(value => value[this.data.idname] == v);
  110. return data ? data[this.data.showName] : ""
  111. }), result]
  112. }
  113. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  114. },
  115. /* 开始搜索 */
  116. startSearch({
  117. detail
  118. }) {
  119. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  120. if (detail == condition) return;
  121. this.setData({
  122. 'content.where.condition': detail,
  123. 'params.content.where.condition': detail
  124. });
  125. this.getList(true);
  126. },
  127. /* 取消搜索 */
  128. onClear() {
  129. this.setData({
  130. 'content.where.condition': "",
  131. 'params.content.where.condition': ""
  132. });
  133. this.getList(true);
  134. },
  135. onReady() {
  136. getHeight.getHeight('.total', this).then(res => this.setData({
  137. listHeight: res
  138. }));
  139. },
  140. onUnload() {
  141. //回收数据
  142. getApp().globalData.handleSelect = null;
  143. }
  144. })