select2.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. params: {}, //请求体
  10. result: [], //返回结果
  11. radio: false, //是否为单选
  12. idname: "sa_projectid", //idkey
  13. showName: "projectname", //表单用 显示名称
  14. filtratelist: [],
  15. },
  16. openFiltrate() {
  17. this.setData({
  18. showFiltrate: true
  19. })
  20. },
  21. handleFilter(e) {
  22. e.detail.condition = this.data.params.content.where.condition;
  23. this.data.params.content.where = e.detail;
  24. this.getList(true);
  25. },
  26. onLoad(options) {
  27. if (options.params) {
  28. let params = JSON.parse(options.params);
  29. if (!params.content.pageNumber || !params.content.pageTotal) {
  30. params.content.pageNumber = 1;
  31. params.content.pageTotal = 1;
  32. }
  33. this.setData({
  34. params
  35. });
  36. }
  37. if (options.title) wx.setNavigationBarTitle({
  38. title: options.title,
  39. })
  40. this.setData({
  41. radio: options.radio ? true : false,
  42. idname: options.idname || this.data.idname,
  43. showName: options.showName || this.data.showName,
  44. });
  45. this.getList()
  46. _Http.basic({
  47. "classname": "sysmanage.develop.optiontype.optiontype",
  48. "method": "optiontypeselect",
  49. "content": {
  50. "nochace": true,
  51. "pageNumber": 1,
  52. "pageSize": 1000,
  53. "typename": "projecttype",
  54. "parameter": {
  55. "siteid": wx.getStorageSync('userMsg').siteid
  56. }
  57. }
  58. }).then(res => {
  59. console.log("项目类型", res)
  60. if (res.msg == '成功') {
  61. this.data.filtratelist.unshift({
  62. label: "项目类型",
  63. index: null,
  64. showName: "value", //显示字段
  65. valueKey: "projecttype", //返回Key
  66. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  67. value: "", //选中值
  68. list: res.data
  69. })
  70. this.setData({
  71. filtratelist: this.data.filtratelist
  72. })
  73. }
  74. })
  75. _Http.basic({
  76. "id": 20221223141802,
  77. "content": {
  78. "pageNumber": 1,
  79. "pageSize": 9999,
  80. "where": {
  81. "condition": ""
  82. }
  83. }
  84. }, false).then(res => {
  85. console.log("获取领域", res)
  86. if (res.msg == '成功') {
  87. this.data.filtratelist.push({
  88. label: "领域",
  89. index: null,
  90. showName: "tradefield", //显示字段
  91. valueKey: "tradefield", //返回Key
  92. selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
  93. value: "", //选中值
  94. list: res.data
  95. })
  96. this.setData({
  97. filtratelist: this.data.filtratelist
  98. })
  99. }
  100. })
  101. },
  102. getList(init = false) {
  103. //init 用于初始化分页
  104. if (init.detail != undefined) init = init.detail;
  105. let params = this.data.params;
  106. if (init) params.content.pageNumber = 1;
  107. if (params.content.pageNumber > params.content.pageTotal) return;
  108. _Http.basic(params).then(res => {
  109. console.log("选择项目列表", res)
  110. this.selectComponent('#ListBox').RefreshToComplete();
  111. if (res.msg != '成功') return wx.showToast({
  112. title: res.data,
  113. icon: "none"
  114. })
  115. res.data = res.data.map(v => {
  116. v.signamount_due = CNY(v.signamount_due);
  117. return v
  118. })
  119. this.setData({
  120. 'params.content.pageNumber': res.pageNumber + 1,
  121. 'params.content.pageTotal': res.pageTotal,
  122. 'params.content.total': res.total,
  123. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  124. })
  125. })
  126. },
  127. /* 获取列表标签 */
  128. getTags() {
  129. let list = this.data.list,
  130. ownerids = list.map(v => v.sa_projectid);
  131. _Http.basic({
  132. "id": 20221018102001,
  133. "content": {
  134. nocache: true,
  135. "ownertable": "sa_project",
  136. ownerids
  137. }
  138. }).then(res => {
  139. console.log("标签", res)
  140. for (let key in res.data) {
  141. let index = list.findIndex(v => v.sa_projectid == key);
  142. list[index].tags = res.data[key]
  143. };
  144. console.log(list)
  145. this.setData({
  146. list
  147. })
  148. })
  149. },
  150. /* 删除项 */
  151. deteleItem(id) {
  152. this.setData({
  153. list: this.data.list.filter(v => v[this.data.idname] != id),
  154. "params.content.total": this.data.params.content.total - 1
  155. })
  156. },
  157. /* 选中 */
  158. changeResult(e) {
  159. let {
  160. id
  161. } = e.currentTarget.dataset, result = this.data.result;
  162. if (this.data.radio) {
  163. result = [id];
  164. } else {
  165. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  166. }
  167. this.setData({
  168. result
  169. });
  170. if (this.data.radio) this.submit();
  171. },
  172. /* 提交 */
  173. submit() {
  174. let result = this.data.result,
  175. obj = this.data.radio ? {
  176. id: result,
  177. item: this.data.list.find(value => value[this.data.idname] == result),
  178. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  179. } : {
  180. result,
  181. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  182. value: [result.map(v => {
  183. let data = this.data.list.find(value => value[this.data.idname] == v);
  184. return data ? data[this.data.showName] : ""
  185. }), result]
  186. }
  187. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  188. },
  189. /* 开始搜索 */
  190. startSearch({
  191. detail
  192. }) {
  193. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  194. if (detail == condition) return;
  195. this.setData({
  196. 'content.where.condition': detail,
  197. 'params.content.where.condition': detail
  198. });
  199. this.getList(true);
  200. },
  201. /* 取消搜索 */
  202. onClear() {
  203. this.setData({
  204. 'content.where.condition': "",
  205. 'params.content.where.condition': ""
  206. });
  207. this.getList(true);
  208. },
  209. onReady() {
  210. this.selectComponent("#ListBox").setHeight(".div", this);
  211. },
  212. onUnload() { //回收数据
  213. getApp().globalData.handleSelect = null;
  214. }
  215. })