select.js 5.1 KB

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