select.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. params: {}, //请求体
  5. result: [], //返回结果
  6. radio: false, //是否为单选
  7. idname: "sa_customersid", //idkey
  8. showName: "enterprisename", //表单用 显示名称
  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. getApp().globalData.Language.getLanguagePackage(this, '选择客户');
  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.code != '1') return wx.showToast({
  40. title: res.data,
  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. })
  49. this.getTags();
  50. })
  51. },
  52. tabChange(e) {
  53. this.data.params.content.where.type = e.detail.name == '客户' ? 19 : 20;
  54. this.getList(true);
  55. },
  56. /* 获取列表标签 */
  57. getTags() {
  58. let list = this.data.list,
  59. ownerids = list.map(v => v.sa_customersid);
  60. _Http.basic({
  61. "id": 20221018102001,
  62. "content": {
  63. nocache: true,
  64. "ownertable": "sa_customers",
  65. ownerids
  66. }
  67. }).then(res => {
  68. console.log("标签", res)
  69. if (res.code != '1') return this.getTags1();
  70. for (let key in res.data) {
  71. let index = list.findIndex(v => v.sa_customersid == key);
  72. list[index].tags = res.data[key]
  73. };
  74. this.setData({
  75. list
  76. })
  77. })
  78. },
  79. /* 竞争对手标签 */
  80. getTags1() {
  81. let list = this.data.list,
  82. ownerids = list.map(v => v.sa_competitorid);
  83. _Http.basic({
  84. "id": 20221018102001,
  85. "content": {
  86. nocache: true,
  87. "ownertable": "sa_competitor",
  88. ownerids
  89. }
  90. }).then(res => {
  91. console.log("标签1", res)
  92. for (let key in res.data) {
  93. let index = list.findIndex(v => v.sa_competitorid == key);
  94. list[index].tags = res.data[key]
  95. };
  96. this.setData({
  97. list
  98. })
  99. })
  100. },
  101. /* 删除项 */
  102. deteleItem(id) {
  103. this.setData({
  104. list: this.data.list.filter(v => v[this.data.idname] != id),
  105. "params.content.total": this.data.params.content.total - 1
  106. })
  107. },
  108. /* 选中 */
  109. changeResult(e) {
  110. let {
  111. id
  112. } = e.currentTarget.dataset, result = this.data.result;
  113. if (this.data.radio) {
  114. result = [id];
  115. } else {
  116. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  117. }
  118. this.setData({
  119. result
  120. });
  121. if (this.data.radio) this.submit();
  122. },
  123. /* 提交 */
  124. submit() {
  125. let result = this.data.result,
  126. obj = this.data.radio ? {
  127. id: result,
  128. item: this.data.list.find(value => value[this.data.idname] == result),
  129. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  130. } : {
  131. result,
  132. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  133. value: [result.map(v => {
  134. let data = this.data.list.find(value => value[this.data.idname] == v);
  135. return data ? data[this.data.showName] : ""
  136. }), result]
  137. }
  138. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  139. },
  140. /* 开始搜索 */
  141. startSearch({
  142. detail
  143. }) {
  144. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  145. if (detail == condition) return;
  146. this.setData({
  147. 'content.where.condition': detail,
  148. 'params.content.where.condition': detail
  149. });
  150. this.getList(true);
  151. },
  152. /* 取消搜索 */
  153. onClear() {
  154. this.setData({
  155. 'content.where.condition': "",
  156. 'params.content.where.condition': ""
  157. });
  158. this.getList(true);
  159. },
  160. onUnload() {
  161. //回收数据
  162. getApp().globalData.handleSelect = null;
  163. }
  164. })