import { ApiModel } from "../../utils/api" const _Http = new ApiModel(); Component({ /** * 组件的属性列表 */ properties: { /* 标题 */ title: { type: String, }, /* 选中列表 */ saleprodclass: { type: Array, value: [] }, /* 回调 */ saleprodChange: { type: Function }, /* 分类列表 */ dataList: { type: Array, value: [] }, /* 是否请求 */ isRequest: { type: Boolean, value: true } }, lifetimes: { attached: function () { //查询类目列表 if (this.data.isRequest) _Http.basic({ "accesstoken": wx.getStorageSync('userData').token, "classname": "enterprise.system.prodclass", "method": "query_typeselectList", "content": {} }).then(res => { if (res.msg != '成功') return; let dataList = []; for (let i = 0; i < res.data.length; i++) { dataList.push({ value: res.data[i], index: i, checked: false }) } //遍历选中数据 const arr = this.data.saleprodclass; for (let i = 0; i < arr.length; i++) { for (let k = 0; k < dataList.length; k++) { if (arr[i] == dataList[k].value) { dataList[k].checked = true; break; } } } this.setData({ dataList }) }) }, }, /** * 组件的初始数据 */ data: { pitchOnList: [], //选中列表 }, /** * 组件的方法列表 */ methods: { /* 确定 */ confirm() { this.triggerEvent("saleprodChange", this.data.pitchOnList) }, /* 多选框返回数值 */ checkedChange(e) { this.setData({ pitchOnList: e.detail.value }); }, /* 添加背景色 */ pitchOn(e) { let dataList = this.data.dataList; dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked this.setData({ dataList }) } } })