select.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../utils/matchingFeilType"),
  3. currency = require("../../../utils/currency"),
  4. CNY = value => currency(value, {
  5. symbol: "¥",
  6. precision: 2
  7. }).format();
  8. Page({
  9. data: {
  10. params: {}, //请求体
  11. result: [], //返回结果
  12. radio: false, //是否为单选
  13. idname: "itemid", //idkey
  14. showName: "itemname", //表单用 显示名称
  15. filtrate: false,
  16. filtratelist: [{
  17. label: "领域",
  18. index: null,
  19. showName: "tradefield", //显示字段
  20. valueKey: "tradefield", //返回Key
  21. selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
  22. value: "", //选中值
  23. list: null
  24. }, {
  25. label: "标准",
  26. index: null,
  27. showName: "value", //显示字段
  28. valueKey: "standards", //返回Key
  29. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  30. value: "", //选中值
  31. list: null
  32. }, {
  33. label: "材质",
  34. index: null,
  35. showName: "value", //显示字段
  36. valueKey: "material", //返回Key
  37. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  38. value: "", //选中值
  39. list: null
  40. }, {
  41. label: "品牌",
  42. index: null,
  43. showName: "brandname", //显示字段
  44. valueKey: "sa_brandid", //返回Key
  45. selectKey: "sa_brandid", //传参 代表选着字段 不传参返回整个选择对象
  46. value: "", //选中值
  47. interrupt: true,
  48. list: null
  49. }, ]
  50. },
  51. onLoad(options) {
  52. if (options.params) {
  53. let params = JSON.parse(options.params);
  54. if (!params.content.pageNumber || !params.content.pageTotal) {
  55. params.content.pageNumber = 1;
  56. params.content.pageTotal = 1;
  57. }
  58. this.setData({
  59. params
  60. });
  61. }
  62. if (options.title) wx.setNavigationBarTitle({
  63. title: options.title,
  64. })
  65. this.setData({
  66. radio: options.radio ? true : false,
  67. idname: options.idname || this.data.idname,
  68. showName: options.showName || this.data.showName,
  69. });
  70. this.getList()
  71. },
  72. getList(init = false) {
  73. //init 用于初始化分页
  74. if (init.detail != undefined) init = init.detail;
  75. let params = this.data.params;
  76. if (init) params.content.pageNumber = 1;
  77. if (params.content.pageNumber > params.content.pageTotal) return;
  78. //init 用于初始化分页
  79. _Http.basic(params).then(res => {
  80. console.log("选择产品列表", res)
  81. this.selectComponent('#ListBox').RefreshToComplete();
  82. if (res.msg != '成功') return wx.showToast({
  83. title: res.data,
  84. icon: "none"
  85. })
  86. res.data = res.data.map(value => {
  87. if (value.attinfos.length == 0) return value;
  88. value.attinfos = file.fileList(value.attinfos)
  89. let image = value.attinfos.find(v => v.fileType == "image");
  90. value.cover = image ? image.cover : "";
  91. value.showMarketprice = CNY(value.marketprice);
  92. value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
  93. value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
  94. return value;
  95. })
  96. this.setData({
  97. 'params.content.pageNumber': res.pageNumber + 1,
  98. 'params.content.pageTotal': res.pageTotal,
  99. 'params.content.total': res.total,
  100. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  101. })
  102. })
  103. },
  104. /* 选中 */
  105. changeResult(e) {
  106. let {
  107. id
  108. } = e.currentTarget.dataset, result = this.data.result;
  109. if (this.data.radio) {
  110. result = [id];
  111. } else {
  112. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  113. }
  114. this.setData({
  115. result
  116. });
  117. if (this.data.radio) this.submit();
  118. },
  119. /* 提交 */
  120. submit() {
  121. let result = this.data.result,
  122. obj = this.data.radio ? {
  123. id: result,
  124. item: this.data.list.find(value => value[this.data.idname] == result),
  125. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  126. } : {
  127. result,
  128. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  129. value: [result.map(v => {
  130. let data = this.data.list.find(value => value[this.data.idname] == v);
  131. return data ? data[this.data.showName] : ""
  132. }), result]
  133. }
  134. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  135. },
  136. /* 开始搜索 */
  137. startSearch({
  138. detail
  139. }) {
  140. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  141. if (detail == condition) return;
  142. this.setData({
  143. 'content.where.condition': detail,
  144. 'params.content.where.condition': detail
  145. });
  146. this.getList(true);
  147. },
  148. /* 取消搜索 */
  149. onClear() {
  150. this.setData({
  151. 'content.where.condition': "",
  152. 'params.content.where.condition': ""
  153. });
  154. this.getList(true);
  155. },
  156. /* 预览图片 */
  157. viewImage(e) {
  158. const {
  159. file
  160. } = e.currentTarget.dataset;
  161. if (file.length) wx.previewMedia({
  162. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  163. return {
  164. url: v.url,
  165. type: v.fileType
  166. }
  167. }),
  168. current: 0,
  169. showmenu: true
  170. })
  171. },
  172. onReady() {
  173. this.selectComponent("#ListBox").setHeight(".total", this);
  174. },
  175. onUnload() {
  176. //回收数据
  177. getApp().globalData.handleSelect = null;
  178. },
  179. async openFiltrate() {
  180. if (this.data.filtratelist[0].list == null) {
  181. let res = await Promise.all([this.gettradefields(), this.getitemstandards(), this.getitemmaterial(), this.getBrand()]);
  182. console.log(res)
  183. res.forEach((v, i) => this.data.filtratelist[i].list = v.data);
  184. this.setData({
  185. filtratelist: this.data.filtratelist,
  186. filtrate: true
  187. })
  188. } else {
  189. this.setData({
  190. filtrate: true
  191. })
  192. }
  193. },
  194. /* 处理筛选 */
  195. handleFilter(e) {
  196. this.data.params.content.where.itemclassid = e.detail.itemclassid || "";
  197. this.data.params.content.where.sa_brandid = e.detail.sa_brandid || "";
  198. this.data.params.content.where.tradefield = e.detail.tradefield || "";
  199. this.data.params.content.where.standards = e.detail.standards || "";
  200. this.data.params.content.where.material = e.detail.material || "";
  201. this.getList(true)
  202. },
  203. /* 获取品牌列表 */
  204. getBrand() {
  205. return _Http.basic({
  206. "id": "20220922085103",
  207. "version": 1,
  208. "content": {
  209. "where": {
  210. "condition": ""
  211. }
  212. }
  213. })
  214. },
  215. /* 获取领域列表 */
  216. gettradefields() {
  217. return _Http.basic({
  218. "id": 20221223141802,
  219. "content": {
  220. "pageNumber": 1,
  221. "pageSize": 99999,
  222. "where": {
  223. "condition": ""
  224. }
  225. }
  226. })
  227. },
  228. /* 标准 */
  229. getitemstandards() {
  230. return _Http.basic({
  231. "classname": "sysmanage.develop.optiontype.optiontype",
  232. "method": "optiontypeselect",
  233. "content": {
  234. "pageNumber": 1,
  235. "pageSize": 1000,
  236. "typename": "itemstandards",
  237. "parameter": {}
  238. },
  239. })
  240. },
  241. /* 材质 */
  242. getitemmaterial() {
  243. return _Http.basic({
  244. "classname": "sysmanage.develop.optiontype.optiontype",
  245. "method": "optiontypeselect",
  246. "content": {
  247. "pageNumber": 1,
  248. "pageSize": 1000,
  249. "typename": "itemmaterial",
  250. "parameter": {}
  251. },
  252. })
  253. },
  254. /* 打断 */
  255. interrupt(e) {
  256. let {
  257. name,
  258. index,
  259. item,
  260. list
  261. } = e.detail;
  262. if (name == "sa_brandid") _Http.basic({
  263. "id": "20220922110403",
  264. "content": {
  265. nocache: true,
  266. "sa_brandid": item.sa_brandid,
  267. }
  268. }).then(res => {
  269. console.log("分类列表", res)
  270. if (res.msg != '成功') return wx.showToast({
  271. title: res.msg,
  272. icon: "none"
  273. })
  274. if (!res.data[0].ttemclass) return;
  275. list[4] = {
  276. label: "分类",
  277. index: null,
  278. type: "multilevelClass",
  279. showName: "itemclassname", //显示字段
  280. valueKey: "itemclassid", //返回Key
  281. selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
  282. value: "", //选中值
  283. list: res.data[0].ttemclass
  284. }
  285. this.setData({
  286. filtratelist: list
  287. })
  288. })
  289. },
  290. })