select.js 9.8 KB

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