index.js 10 KB

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