| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- radio: false, //是否为单选
- result: [], //返回结果
- id: 2026051510000002,
- content: {
- where: {
- condition: ""
- },
- pageNumber: 1,
- pageSize: 20
- },
- },
- onLoad(options) {
- this.getList()
- getApp().globalData.Language.getLanguagePackage(this, '添加物料');
- },
- getList(init = false) {
- if (init) this.selectComponent('#ListBox').goTop();
- _Http.init(this.data.content, init).then(content => {
- _Http.basic({
- id: this.data.id,
- content
- }).then(res => {
- this.selectComponent('#ListBox').RefreshToComplete();
- if (res.code != '1') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- const arr = res.data.map(item => {
- item.showBrand = Array.isArray(item.brand) ?
- item.brand.map(v => v.brandname).join(',') :
- '--'
- item.showClass = Array.isArray(item.itemClassList) ?
- item.itemClassList.map(v => v.className).join(',') :
- '--'
- // 图片:优先缩略图
- let imgSrc = ''
- if (Array.isArray(item.attinfos) && item.attinfos.length > 0) {
- const info = item.attinfos[0]
- if (Array.isArray(info.subfiles)) {
- const thumb = info.subfiles.find(s => s.type === 'thumbnail')
- if (thumb?.url) {
- imgSrc = thumb.url
- } else if (info.url) {
- imgSrc = info.url
- }
- } else if (info.url) {
- imgSrc = info.url
- }
- }
- item.imgUrl = imgSrc
- return item
- })
- this.setData({
- content: _Http.paging(content, res),
- list: res.pageNumber == 1 ? arr : this.data.list.concat(arr)
- })
- })
- })
- },
- startSearch({
- detail
- }) {
- const condition = this.data.content.where.condition;
- if (detail == condition) return;
- this.setData({
- 'content.where.condition': detail
- });
- this.getList(true);
- },
- onClear() {
- this.setData({
- 'content.where.condition': ""
- });
- this.getList(true);
- },
- changeResult(e) {
- let {
- id
- } = e.currentTarget.dataset, result = this.data.result;
- if (this.data.radio) {
- result = [id];
- } else {
- result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
- }
- this.setData({
- result
- });
- if (this.data.radio) this.submit();
- },
- submit() {
- const selectedItems = this.data.list.filter(item =>
- this.data.result.includes(item.sc_item_localid)
- ).map(item => ({
- sc_item_localid: item.sc_item_localid,
- }));
- if (getApp().globalData.handleMaterialSelect) {
- getApp().globalData.handleMaterialSelect({
- list: selectedItems
- });
- }
- },
- cancel() {
- this.setData({
- result: []
- });
- },
- })
|