index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. params: {}, //请求体
  5. result: [], //返回结果
  6. radio: false, //是否为单选
  7. idname: "itemid", //idkey
  8. showName: "enterprisename", //表单用 显示名称
  9. sColors: getApp().globalData.sColors,
  10. active: "Receive",
  11. filterShow: true,
  12. filterSearchShow: false,
  13. filtratelist: []
  14. },
  15. async onLoad(options) {
  16. if (options.params) {
  17. let params = JSON.parse(options.params);
  18. if (!params.content.pageNumber || !params.content.pageTotal) {
  19. params.content.pageNumber = 1;
  20. params.content.pageTotal = 1;
  21. }
  22. this.setData({
  23. params
  24. });
  25. }
  26. let filtratelist = [{
  27. label: "品牌",
  28. index: null,
  29. showName: "brandname", //显示字段
  30. valueKey: "sa_brandid", //返回Key
  31. selectKey: "sa_brandid", //传参 代表选着字段 不传参返回整个选择对象
  32. value: '', //选中值
  33. interrupt: true,
  34. list: await _Http.basic({
  35. "id": "20220922085103",
  36. "content": {},
  37. }).then(res => {
  38. console.log("获取品牌", res)
  39. // this.data.sa_brandid = res.data[0].sa_brandid
  40. return res.code == 1 ? res.data : []
  41. })
  42. }, {
  43. label: "营销类别",
  44. index: null,
  45. showName: "itemclassname", //显示字段
  46. valueKey: "itemclassid", //返回Key
  47. selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
  48. value: "", //选中值
  49. type: 'multilevelClass',
  50. list: []
  51. }, {
  52. label: "备货分类",
  53. index: null,
  54. showName: "value", //显示字段
  55. valueKey: "goodstype", //返回Key
  56. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  57. value: "需定制", //选中值
  58. list: await _Http.getTypes('goodstype', _Http)
  59. }]
  60. this.setData({
  61. radio: options.radio ? true : false,
  62. idname: options.idname || this.data.idname,
  63. showName: options.showName || this.data.showName,
  64. filtratelist
  65. });
  66. this.getList()
  67. },
  68. getList(init = false) {
  69. //init 用于初始化分页
  70. if (init.detail != undefined) init = init.detail;
  71. let params = this.data.params;
  72. if (init) params.content.pageNumber = 1;
  73. if (params.content.pageNumber > params.content.pageTotal) return;
  74. //init 用于初始化分页
  75. _Http.basic(params).then(res => {
  76. console.log("选择产品列表", res)
  77. this.selectComponent('#ListBox').RefreshToComplete();
  78. if (res.code != '1') return wx.showToast({
  79. title: res.data,
  80. icon: "none"
  81. })
  82. res.data = res.data.map(v => {
  83. v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
  84. return v
  85. })
  86. // setTimeout(async() => {
  87. // if (res.pageNumber == 1 && res.data.length && !this.data.filtratelist.some(v => v.label == '品牌')) {
  88. // this.data.filtratelist.push({
  89. // label: "品牌",
  90. // index: null,
  91. // showName: "brandname", //显示字段
  92. // valueKey: "sa_brandid", //返回Key
  93. // selectKey: "sa_brandid", //传参 代表选着字段 不传参返回整个选择对象
  94. // value: '', //选中值
  95. // interrupt: true,
  96. // list: await _Http.basic({
  97. // "id": "20220922085103",
  98. // "content": {},
  99. // }).then(res => {
  100. // console.log("获取品牌", res)
  101. // // this.data.sa_brandid = res.data[0].sa_brandid
  102. // return res.code == 1 ? res.data : []
  103. // })
  104. // })
  105. // this.setData({
  106. // filtratelist: this.data.filtratelist
  107. // })
  108. // } else if (res.pageNumber == 1 && res.data.length && !this.data.filtratelist.some(v => v.label == '营销类别')) {
  109. // this.data.filtratelist.push({
  110. // label: "营销类别",
  111. // index: null,
  112. // showName: "itemclassname", //显示字段
  113. // valueKey: "itemclassid", //返回Key
  114. // selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
  115. // value: "", //选中值
  116. // type: 'multilevelClass',
  117. // list: []
  118. // })
  119. // this.setData({
  120. // filtratelist: this.data.filtratelist
  121. // })
  122. // }
  123. // }, 1500);
  124. this.setData({
  125. 'params.content.pageNumber': res.pageNumber + 1,
  126. 'params.content.pageTotal': res.pageTotal,
  127. 'params.content.total': res.total,
  128. params: _Http.paging(params, res),
  129. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  130. })
  131. })
  132. },
  133. uploadList() {
  134. let params = JSON.parse(JSON.stringify(this.data.params));
  135. params.content.pageSize = (params.content.pageNumber - 1) * params.content.pageSize;
  136. params.content.pageNumber = 1;
  137. _Http.basic(params).then(res => {
  138. console.log("更新列表", res);
  139. if (res.code != '1') return wx.showToast({
  140. title: res.data,
  141. icon: "none"
  142. })
  143. res.data = res.data.map(v => {
  144. v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
  145. return v
  146. })
  147. this.setData({
  148. 'params.content.total': res.total,
  149. list: res.data
  150. })
  151. })
  152. },
  153. /* 选中 */
  154. changeResult(e) {
  155. let {
  156. id
  157. } = e.currentTarget.dataset, result = this.data.result;
  158. if (this.data.radio) {
  159. result = [id];
  160. } else {
  161. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  162. }
  163. this.setData({
  164. result
  165. });
  166. if (this.data.radio) this.submit();
  167. },
  168. /* 提交 */
  169. submit() {
  170. let result = this.data.result,
  171. obj = this.data.radio ? {
  172. id: result,
  173. item: this.data.list.find(value => value[this.data.idname] == result),
  174. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  175. } : {
  176. result,
  177. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  178. value: [result.map(v => {
  179. let data = this.data.list.find(value => value[this.data.idname] == v);
  180. return data ? data[this.data.showName] : ""
  181. }), result]
  182. }
  183. _Http.handleSelect && _Http.handleSelect(obj)
  184. },
  185. /* 开始搜索 */
  186. startSearch({
  187. detail
  188. }) {
  189. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  190. if (detail == condition) return;
  191. this.setData({
  192. 'content.where.condition': detail,
  193. 'params.content.where.condition': detail
  194. });
  195. this.getList(true);
  196. },
  197. /* 取消搜索 */
  198. onClear() {
  199. this.setData({
  200. 'content.where.condition': "",
  201. 'params.content.where.condition': ""
  202. });
  203. this.getList(true);
  204. },
  205. onUnload() {
  206. //回收数据
  207. getApp().globalData.handleSelect = null;
  208. },
  209. /* 筛选 */
  210. handleFilter({
  211. detail
  212. }) {
  213. console.log('执行筛选的功能')
  214. detail.condition = this.data.params.content.where.condition;
  215. this.data.params.content.where = detail;
  216. this.getList(true);
  217. },
  218. onClick() {
  219. this.setData({
  220. filterShow: true
  221. })
  222. console.log(this.filterShow, '返回结果')
  223. },
  224. async selsectClick() {
  225. this.setData({
  226. filterSearchShow: true,
  227. })
  228. },
  229. interrupt(e) {
  230. console.log("2323", e)
  231. _Http.basic({
  232. "id": "20230325141103",
  233. "content": {
  234. sa_brandid: e.detail.data.value
  235. },
  236. }).then(res => {
  237. console.log("获取营销类别", res)
  238. if (res.code != 1) return
  239. e.detail.list.find(v => v.label == '营销类别').list = res.data[0].ttemclass
  240. e.detail.list.find(v => v.label == '品牌').value = e.detail.data.value
  241. this.setData({
  242. filtratelist: e.detail.list
  243. })
  244. })
  245. }
  246. })