index.js 10 KB

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