index.js 10 KB

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