select2.js 7.2 KB

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