| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- /*******************************************************************************
- * Copyright(c) 2022 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:组件-面板
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 于继渤 2024-03-20 1.00 新建
- *******************************************************************************/
- const util = require('@/utils/util.js')
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- // 数据源
- list: {
- type: Array,
- value: []
- },
- // 内容
- content: {
- type: Array,
- value: []
- },
- // 回显名称
- nameKey: {
- type: String
- },
- idKey: {
- type: String
- },
- //类型key
- typeKey: {
- type: String
- },
- },
- options: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- },
- /**
- * 组件的方法列表
- */
- methods: {
- /**
- * @desc : checkBox选中/取消事件
- * @date : 2024/3/20 15:49
- * @author : 于继渤
- */
- onChangeFlag(event) {
- let allIsMain = false
- let index = event.currentTarget.dataset.index
- var _this = this
- var list = _this.data.list
- var content = _this.data.content
- let colSwitchList = content.filter(res => {
- return res.type == 'switch'
- })
- let commissionList = content.filter(res => {
- return res.type == 'commission'
- })
- let switchCode = null
- let commissionCode = null
- if (colSwitchList.length > 0) {
- switchCode = colSwitchList[0].code
- }
- if (commissionList.length > 0) {
- commissionCode = commissionList[0].code
- }
- // 设置点击的项目checkbox的值
- for (let i = 0; i < list.length; i++) {
- if (i == index) {
- list[i].checked = !list[i].checked
- break;
- }
- }
- if (list[index].checked) {
- var isMain = false;
- for (let i = 0; i < list.length; i++) {
- if (list[i][switchCode]) {
- isMain = true;
- break;
- }
- }
- list[index][switchCode] = !isMain;
- } else {
- if (switchCode) {
- list[index][switchCode] = false;
- }
- if (commissionCode) {
- list[index][commissionCode] = parseFloat(100).toFixed(2)
- }
- }
- //实现一个关闭出现一换个主业务员
- for (let i = 0; i < list.length; i++) {
- if (list[i][switchCode]) {
- allIsMain = true
- }
- }
- if (!allIsMain) {
- for (let i = 0; i < list.length; i++) {
- if (list[i].checked) {
- list[i][switchCode] = true
- break
- }
- }
- }
- this.calculationScale(list, commissionCode, switchCode)
- // 选择条数
- _this.setData({
- list: list
- })
- },
- /**
- * @desc : Switch切换事件
- * @date : 2024/3/20 15:49
- * @author : 于继渤
- */
- onChangeSwitch(e) {
- var _this = this
- var list = _this.data.list
- var index = e.target.dataset.index
- //如果没有选中就不能触发这个主从的勾选
- if (!list[index].checked) {
- return;
- }
- //获取需要需改的 key
- var content = _this.data.content
- let colSwitchList = content.filter(res => {
- return res.type == 'switch'
- })
- let switchCode = null
- if (colSwitchList.length > 0) {
- switchCode = colSwitchList[0].code
- }
- // 设置点击的项目checkbox的值
- for (let i = 0; i < list.length; i++) {
- if (i == index && list[i].checked) {
- list[i][switchCode] = !list[i][switchCode]
- continue;
- }
- list[i][switchCode] = false;
- }
- // 选择条数
- _this.setData({
- list: list,
- })
- },
- /**
- * @desc : 输入提成比例的
- * @date : 2024/3/20 15:49
- * @author : 于继渤
- */
- inputChange(e) {
- let list = this.data.list;
- let index = e.currentTarget.dataset.index;
- var content = this.data.content
- let commissionList = content.filter(res => {
- return res.type == 'commission'
- })
- let commissionCode = null
- if (commissionList.length > 0) {
- commissionCode = commissionList[0].code
- }
- if (commissionCode) {
- list[index][commissionCode] = e.detail.value
- }
- this.setData({
- list: list
- })
- },
- /**
- * @desc : 输入提成比例 离开焦点事件
- * @date : 2024/3/20 15:49
- * @author : 于继渤
- */
- inputBlurChange(e) {
- let value = null
- let index = e.currentTarget.dataset.index
- let id = e.currentTarget.dataset.id
- let list = this.data.list
- let valueBlur = e.detail.value
- if (Number(valueBlur) == 0 || Number(valueBlur)) {
- value = Number(valueBlur)
- if (Number(valueBlur) > 100) {
- value = Number(100)
- }
- if (Number(valueBlur) < 0) {
- value = Number(0)
- }
- }
- var content = this.data.content
- let commissionList = content.filter(res => {
- return res.type == 'commission'
- })
- let commissionCode = null
- let idKey = null
- if (commissionList.length > 0) {
- commissionCode = commissionList[0].code
- idKey = commissionList[0].idKey
- }
- if (commissionCode) {
- list[index][commissionCode] = value.toFixed(2)
- }
- this.setData({
- list,
- inputBlurChange: true
- })
- let number = Number(100 - value.toFixed(2))
- let showListTemp = []
- list.forEach(it => {
- if (id != it[idKey] && it.checked) {
- showListTemp.push(it)
- }
- })
- let allocationRatio = (number / showListTemp.length).toFixed(2)
- let allocationRatioTotal = 0
- //数据取余2为0
- if (number % showListTemp.length == 0) {
- //循环将计算好的百分比放入数据中
- for (let i in showListTemp) {
- showListTemp[i][commissionCode] = Number(allocationRatio).toFixed(2)
- }
- list.forEach(item1 => {
- showListTemp.forEach(item2 => {
- if (item1[idKey] == item2[idKey]) {
- item1[commissionCode] = Number(item2[commissionCode]).toFixed(2)
- }
- })
- })
- this.setData({
- list
- })
- } else {
- let showListTemp2 = [...showListTemp]
- let endList = showListTemp2.splice(-1)
- for (let i = 0; i < showListTemp2.length; i++) {
- allocationRatioTotal = allocationRatioTotal + Number(allocationRatio)
- showListTemp2[i][commissionCode] = Number(allocationRatio).toFixed(2)
- }
- if (endList[0]) {
- endList[0][commissionCode] = (number - allocationRatioTotal).toFixed(2)
- }
- list.forEach(item1 => {
- showListTemp2.forEach(item2 => {
- if (item1[idKey] == item2[idKey]) {
- item1[commissionCode] = item2[commissionCode]
- }
- })
- })
- this.setData({
- list
- })
- }
- },
- /**
- * @desc : 选择计算事件
- * @date : 2024/3/20 15:49
- * @author : 于继渤
- */
- calculationScale(list, commissionCode) {
- list = list.filter((item) => {
- return item.checked == true
- })
- let allocationRatio = (100 / list.length).toFixed(2)
- let allocationRatioTotal = 0
- //数据取余2为0
- if (100 % list.length == 0) {
- //循环将计算好的百分比放入数据中
- for (let i in list) {
- list[i][commissionCode] = Number(allocationRatio).toFixed(2)
- }
- } else { //数据取余2不为0
- //获取最后选中checkbox数组中最后一个元素
- let endList = list.splice(-1)
- for (let i = 0; i < list.length; i++) {
- allocationRatioTotal = allocationRatioTotal + Number(allocationRatio)
- list[i][commissionCode] = Number(allocationRatio).toFixed(2)
- }
- if (endList[0]) {
- endList[0][commissionCode] = (100 - allocationRatioTotal).toFixed(2)
- }
- }
- },
- //设置控件信息
- setDataFromPage(data) {
- this.setData({
- list:data
- })
- },
- /**
- * 确定
- * @param {*} e
- */
- btnOK(e) {
- var content = this.data.content
- let colSwitchList = content.filter(res => {
- return res.type == 'switch'
- })
- let commissionList = content.filter(res => {
- return res.type == 'commission'
- })
- let switchCode = null
- let commissionCode = null
- if (colSwitchList.length > 0) {
- switchCode = colSwitchList[0].code
- }
- if (commissionList.length > 0) {
- commissionCode = commissionList[0].code
- }
- var indexswitch = 0;
- // 判断是否有选择的checkbox
- var allcheck = false;
- var allswitch = false;
- var list = this.data.list;
- for (let i = 0; i < list.length; i++) {
- if (list[i].checked) {
- allcheck = true;
- break;
- }
- }
- // 校验
- if (!allcheck) {
- util.showToast('请至少选择一条数据');
- return;
- }
- if (switchCode) {
- for (let i = 0; i < list.length; i++) {
- if (list[i][switchCode]) {
- allswitch = true;
- indexswitch = i;
- break;
- }
- }
- // 校验
- if (!allswitch) {
- util.showToast('请选择' + colSwitchList[0].title);
- return;
- }
- }
- if (commissionCode) {
- let commission = Number(0)
- for (let i = 0; i < list.length; i++) {
- if (list[i].checked) {
- commission += Number(list[i][commissionCode])
- }
- }
- if (commission !== 100) {
- util.showToast('提成比例不足 100');
- return;
- }
- let sum = 0
- list.forEach(res => {
- if (res.checked) {
- sum += parseFloat(res[commissionCode])
- }
- })
- if (sum > 100 || sum < 100) {
- util.showToast('提成比率不正确');
- return;
- }
- }
- let nameKey = this.data.nameKey
- let idKey = this.data.idKey
- let typeKey = this.data.typeKey
- let names = []
- let ids = []
- let tableDataList = []
- let main = {}
- list.forEach(item => {
- if (item.checked) {
- item.allocationRatio = commissionCode ? item[commissionCode] : null
- item.ownerFlag = switchCode ? item[switchCode] : null
- tableDataList.push(item)
- if (nameKey) {
- names.push(item[nameKey])
- }
- if (idKey) {
- ids.push(item[idKey])
- }
- if (item[switchCode]) {
- main = item
- }
- }
- })
- // 给父页面传递数据
- let obj = {
- main: main,
- list: tableDataList
- }
- obj['item'] = {
- text: names,
- value: ids
- }
- this.triggerEvent("toMulti", obj)
- },
- }
- })
|