select.js 4.7 KB

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