| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- params: {}, //请求体
- result: [], //返回结果
- radio: false, //是否为单选
- idname: "itemid", //idkey
- showName: "enterprisename", //表单用 显示名称
- sColors: getApp().globalData.sColors,
- active: "Receive",
- filterShow: true,
- filterSearchShow: false,
- filtratelist: []
- },
- async onLoad(options) {
- if (options.params) {
- let params = JSON.parse(options.params);
- if (!params.content.pageNumber || !params.content.pageTotal) {
- params.content.pageNumber = 1;
- params.content.pageTotal = 1;
- }
- this.setData({
- params
- });
- }
- let filtratelist = [{
- label: "品牌",
- index: null,
- showName: "brandname", //显示字段
- valueKey: "sa_brandid", //返回Key
- selectKey: "sa_brandid", //传参 代表选着字段 不传参返回整个选择对象
- value: '', //选中值
- interrupt: true,
- list: await _Http.basic({
- "id": "20220922085103",
- "content": {},
- }).then(res => {
- console.log("获取品牌", res)
- // this.data.sa_brandid = res.data[0].sa_brandid
- return res.code == 1 ? res.data : []
- })
- }, {
- label: "营销类别",
- index: null,
- showName: "itemclassname", //显示字段
- valueKey: "itemclassid", //返回Key
- selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
- value: "", //选中值
- type: 'multilevelClass',
- list: []
- }, {
- label: "备货分类",
- index: null,
- showName: "value", //显示字段
- valueKey: "goodstype", //返回Key
- selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
- value: "需定制", //选中值
- list: await _Http.getTypes('goodstype', _Http)
- }]
- this.setData({
- radio: options.radio ? true : false,
- idname: options.idname || this.data.idname,
- showName: options.showName || this.data.showName,
- filtratelist
- });
- this.getList()
- },
- getList(init = false) {
- //init 用于初始化分页
- if (init.detail != undefined) init = init.detail;
- let params = this.data.params;
- if (init) params.content.pageNumber = 1;
- if (params.content.pageNumber > params.content.pageTotal) return;
- //init 用于初始化分页
- _Http.basic(params).then(res => {
- console.log("选择产品列表", res)
- this.selectComponent('#ListBox').RefreshToComplete();
- if (res.code != '1') return wx.showToast({
- title: res.data,
- icon: "none"
- })
- res.data = res.data.map(v => {
- v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
- return v
- })
- // setTimeout(async() => {
- // if (res.pageNumber == 1 && res.data.length && !this.data.filtratelist.some(v => v.label == '品牌')) {
- // this.data.filtratelist.push({
- // label: "品牌",
- // index: null,
- // showName: "brandname", //显示字段
- // valueKey: "sa_brandid", //返回Key
- // selectKey: "sa_brandid", //传参 代表选着字段 不传参返回整个选择对象
- // value: '', //选中值
- // interrupt: true,
- // list: await _Http.basic({
- // "id": "20220922085103",
- // "content": {},
- // }).then(res => {
- // console.log("获取品牌", res)
- // // this.data.sa_brandid = res.data[0].sa_brandid
- // return res.code == 1 ? res.data : []
- // })
- // })
- // this.setData({
- // filtratelist: this.data.filtratelist
- // })
- // } else if (res.pageNumber == 1 && res.data.length && !this.data.filtratelist.some(v => v.label == '营销类别')) {
- // this.data.filtratelist.push({
- // label: "营销类别",
- // index: null,
- // showName: "itemclassname", //显示字段
- // valueKey: "itemclassid", //返回Key
- // selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
- // value: "", //选中值
- // type: 'multilevelClass',
- // list: []
- // })
- // this.setData({
- // filtratelist: this.data.filtratelist
- // })
- // }
- // }, 1500);
- this.setData({
- 'params.content.pageNumber': res.pageNumber + 1,
- 'params.content.pageTotal': res.pageTotal,
- 'params.content.total': res.total,
- params: _Http.paging(params, res),
- list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
- })
- })
- },
- uploadList() {
- let params = JSON.parse(JSON.stringify(this.data.params));
- params.content.pageSize = (params.content.pageNumber - 1) * params.content.pageSize;
- params.content.pageNumber = 1;
- _Http.basic(params).then(res => {
- console.log("更新列表", res);
- if (res.code != '1') return wx.showToast({
- title: res.data,
- icon: "none"
- })
- res.data = res.data.map(v => {
- v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
- return v
- })
- this.setData({
- 'params.content.total': res.total,
- list: res.data
- })
- })
- },
- /* 选中 */
- 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() {
- let result = this.data.result,
- obj = this.data.radio ? {
- id: result,
- item: this.data.list.find(value => value[this.data.idname] == result),
- value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
- } : {
- result,
- list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
- value: [result.map(v => {
- let data = this.data.list.find(value => value[this.data.idname] == v);
- return data ? data[this.data.showName] : ""
- }), result]
- }
- _Http.handleSelect && _Http.handleSelect(obj)
- },
- /* 开始搜索 */
- startSearch({
- detail
- }) {
- let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
- if (detail == condition) return;
- this.setData({
- 'content.where.condition': detail,
- 'params.content.where.condition': detail
- });
- this.getList(true);
- },
- /* 取消搜索 */
- onClear() {
- this.setData({
- 'content.where.condition': "",
- 'params.content.where.condition': ""
- });
- this.getList(true);
- },
- onUnload() {
- //回收数据
- getApp().globalData.handleSelect = null;
- },
- /* 筛选 */
- handleFilter({
- detail
- }) {
- console.log('执行筛选的功能')
- detail.condition = this.data.params.content.where.condition;
- this.data.params.content.where = detail;
- this.getList(true);
- },
- onClick() {
- this.setData({
- filterShow: true
- })
- console.log(this.filterShow, '返回结果')
- },
- async selsectClick() {
- this.setData({
- filterSearchShow: true,
- })
- },
- interrupt(e) {
- console.log("2323", e)
- _Http.basic({
- "id": "20230325141103",
- "content": {
- sa_brandid: e.detail.data.value
- },
- }).then(res => {
- console.log("获取营销类别", res)
- if (res.code != 1) return
- e.detail.list.find(v => v.label == '营销类别').list = res.data[0].ttemclass
- e.detail.list.find(v => v.label == '品牌').value = e.detail.data.value
- this.setData({
- filtratelist: e.detail.list
- })
- })
- }
- })
|