|
|
@@ -0,0 +1,460 @@
|
|
|
+const app = getApp()
|
|
|
+const Constants = require('../../../utils/Constants.js');
|
|
|
+const api = require('../../../utils/api.js');
|
|
|
+import Dialog from '../../../dist/dialog/dialog.js'
|
|
|
+const util = require('../../../utils/util.js')
|
|
|
+Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ loading: false,
|
|
|
+ orgIsMain: {
|
|
|
+ allocationRatio: 100,
|
|
|
+ checked: true,
|
|
|
+ commission: 100,
|
|
|
+ erpOrgCode: "",
|
|
|
+ isMain: true,
|
|
|
+ organizationId: 32402,
|
|
|
+ organizationName: "北海富安居店",
|
|
|
+ ownerFlag: true
|
|
|
+ },
|
|
|
+ orgItem: {
|
|
|
+ goodsListFlag: true,
|
|
|
+ text: [
|
|
|
+ "北海富安居店"
|
|
|
+ ],
|
|
|
+ value: [
|
|
|
+ 32402
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ organizationIds: [
|
|
|
+ 32402
|
|
|
+ ],
|
|
|
+ organizationList: [
|
|
|
+ {
|
|
|
+ allocationRatio: 100,
|
|
|
+ cpId: 20760,
|
|
|
+ erpOrgCode: "",
|
|
|
+ erpStaffCode: null,
|
|
|
+ flgValid: true,
|
|
|
+ multiId: 21978,
|
|
|
+ orderId: 11954,
|
|
|
+ orgCode: "GXBH1002",
|
|
|
+ orgId: 32402,
|
|
|
+ ownerFlag: true,
|
|
|
+ ownerId: 32402,
|
|
|
+ ownerName: "北海富安居店",
|
|
|
+ ownerType: 1,
|
|
|
+ staffCode: null,
|
|
|
+ staffId: null
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ organizationName: [
|
|
|
+ "北海富安居店"
|
|
|
+ ],
|
|
|
+ showList: [
|
|
|
+ {
|
|
|
+ checked: true,
|
|
|
+ commission: 100,
|
|
|
+ defWhId: 552,
|
|
|
+ erpOrgCode: "",
|
|
|
+ flgStore: true,
|
|
|
+ isMain: true,
|
|
|
+ orgId: 32402,
|
|
|
+ organizationCode: "GXBH1002",
|
|
|
+ organizationId: 32402,
|
|
|
+ organizationName: "北海富安居店",
|
|
|
+ salesChannel: 1,
|
|
|
+ salesChannelName: "零售",
|
|
|
+ warehouseId: 552,
|
|
|
+ warehouseName: "钦州运营仓",
|
|
|
+ whId: 552,
|
|
|
+ whId_Name: "钦州运营仓",
|
|
|
+ whIdsName: "钦州运营仓"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ inputBlurChange(e) {
|
|
|
+ let value = null
|
|
|
+ let index = e.currentTarget.dataset.index
|
|
|
+ let id = e.currentTarget.dataset.id
|
|
|
+ let showList = this.data.showList
|
|
|
+ if (Number(e.detail.value) == 0 || Number(e.detail.value) ) {
|
|
|
+ value = Number(e.detail.value)
|
|
|
+ if(Number(e.detail.value) > 100){
|
|
|
+ value = Number(100)
|
|
|
+ }
|
|
|
+ if(Number(e.detail.value) < 0){
|
|
|
+ value = Number(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ showList[index].commission = value.toFixed(2)
|
|
|
+ this.setData({
|
|
|
+ showList,
|
|
|
+ inputBlurChange:true
|
|
|
+ })
|
|
|
+ // let number = Number(100 - value.toFixed(2))
|
|
|
+ // let showListTemp = []
|
|
|
+ // showList.forEach(it => {
|
|
|
+ // if (id != it.orgId && it.checked) {
|
|
|
+ // console.log('it', it)
|
|
|
+ // 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].commission = Number(allocationRatio).toFixed(2)
|
|
|
+ // }
|
|
|
+ // showList.forEach(item1 => {
|
|
|
+ // showListTemp.forEach(item2 => {
|
|
|
+ // if (item1.orgId == item2.orgId) {
|
|
|
+ // item1.commission = item2.commission.toFixed(2)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // this.setData({
|
|
|
+ // showList
|
|
|
+ // })
|
|
|
+ // } else {
|
|
|
+ // let showListTemp2 = [...showListTemp]
|
|
|
+ // let endList = showListTemp2.splice(-1)
|
|
|
+ // for (let i = 0; i < showListTemp2.length; i++) {
|
|
|
+ // console.log('showListTemp[i]', showListTemp2[i])
|
|
|
+ // allocationRatioTotal = allocationRatioTotal + Number(allocationRatio)
|
|
|
+ // showListTemp2[i].commission = Number(allocationRatio).toFixed(2)
|
|
|
+ // }
|
|
|
+ // if (endList[0]) {
|
|
|
+ // endList[0].commission = (number - allocationRatioTotal)
|
|
|
+ // }
|
|
|
+ // showList.forEach(item1 => {
|
|
|
+ // showListTemp2.forEach(item2 => {
|
|
|
+ // if (item1.orgId == item2.orgId) {
|
|
|
+ // item1.commission = item2.commission.toFixed(2)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // this.setData({
|
|
|
+ // showList
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ calculationScale(showList) {
|
|
|
+
|
|
|
+
|
|
|
+ showList = showList.filter((item) => {
|
|
|
+ return item.checked == true
|
|
|
+ })
|
|
|
+ let allocationRatio = (100 / showList.length).toFixed(2)
|
|
|
+ let allocationRatioTotal = 0
|
|
|
+ //数据取余2为0
|
|
|
+ if (100 % showList.length == 0) {
|
|
|
+ //循环将计算好的百分比放入数据中
|
|
|
+ for (let i in showList) {
|
|
|
+ showList[i].commission = Number(allocationRatio).toFixed(2)
|
|
|
+ }
|
|
|
+ } else { //数据取余2不为0
|
|
|
+ //获取最后选中checkbox数组中最后一个元素
|
|
|
+ let endList = showList.splice(-1)
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ allocationRatioTotal = allocationRatioTotal + Number(allocationRatio)
|
|
|
+ showList[i].commission = Number(allocationRatio).toFixed(2)
|
|
|
+ }
|
|
|
+ if (endList[0]) {
|
|
|
+ endList[0].commission = (100 - allocationRatioTotal).toFixed(2)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 确定
|
|
|
+ * @author : 于继渤
|
|
|
+ * @date : 2022/6/10 12:16
|
|
|
+ */
|
|
|
+ btnOK() {
|
|
|
+ let TempOrgTable = []
|
|
|
+ // 判断是否有选择的checkbox
|
|
|
+ var allcheck = false;
|
|
|
+ var allswitch = false;
|
|
|
+ var indexswitch = 0;
|
|
|
+ var showList = this.data.showList;
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (showList[i].checked) {
|
|
|
+ allcheck = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (showList[i].isMain) {
|
|
|
+ allswitch = true;
|
|
|
+ indexswitch = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let commission = Number(0)
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (showList[i].checked) {
|
|
|
+ commission += Number(showList[i].commission)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (commission !== 100) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '提成比例不足 100',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 校验
|
|
|
+ if (!allcheck) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请至少选择一个业务部门',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 校验
|
|
|
+ if (!allswitch) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请选择主业务部门',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let sum = 0
|
|
|
+ showList.forEach(res => {
|
|
|
+ if (res.checked) {
|
|
|
+ sum += parseFloat(res.commission)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (sum > 100 || sum < 100) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '提成比率不正确',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取出被选中的数据
|
|
|
+ let organizationList = []
|
|
|
+ let organizationNames = []
|
|
|
+ let organizationIds = []
|
|
|
+ for (let index = 0; index < showList.length; index++) {
|
|
|
+ if (showList[index].checked) {
|
|
|
+ showList[index].allocationRatio = showList[index].commission
|
|
|
+ showList[index].ownerFlag = showList[index].isMain
|
|
|
+ showList[index].organizationId = showList[index].organizationId
|
|
|
+ organizationList.push(showList[index])
|
|
|
+ // organizationNames.push(showList[index].organizationName)
|
|
|
+ organizationIds.push(showList[index].organizationId)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var pages = getCurrentPages();
|
|
|
+ var prevPage = pages[pages.length - 2]; //上一个页面
|
|
|
+ let salesChannelItem = {}
|
|
|
+ let orgMain = []
|
|
|
+ organizationList.forEach(res2 => {
|
|
|
+ if (res2.isMain) {
|
|
|
+ orgMain = res2
|
|
|
+ salesChannelItem = { text: res2.salesChannelName, value: res2.salesChannel }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ // orgItem
|
|
|
+ let orgGoodsListFlag = false
|
|
|
+ if (this.data.orgIsMain) {
|
|
|
+ let orgMainTemp = this.data.orgIsMain
|
|
|
+
|
|
|
+ if (orgMainTemp.organizationId != orgMain.organizationId) {
|
|
|
+ orgGoodsListFlag = true
|
|
|
+ } else {
|
|
|
+ orgGoodsListFlag = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!this.data.orgIsMain && this.data.orgItem) {
|
|
|
+ let orgItemTemp = this.data.orgItem
|
|
|
+ if (orgItemTemp.value && orgItemTemp.value.length > 0 && (orgItemTemp.value[0].organizationId != orgMain.organizationId)) {
|
|
|
+ orgGoodsListFlag = true
|
|
|
+ } else {
|
|
|
+ orgGoodsListFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ let organizationNamesTemp = organizationList.sort((a, b) => b.isMain - a.isMain);
|
|
|
+
|
|
|
+ organizationNamesTemp.forEach(res => {
|
|
|
+ organizationNames.push(res.organizationName)
|
|
|
+ })
|
|
|
+
|
|
|
+ let organizationItem = {
|
|
|
+ orgMain: orgMain,
|
|
|
+ orgItem: {
|
|
|
+ text: organizationNames.join(','),
|
|
|
+ value: organizationIds
|
|
|
+ },
|
|
|
+ salesChannelItem: salesChannelItem,
|
|
|
+ organizationList: organizationList,
|
|
|
+ organizationNames: organizationNames.join(',')
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ prevPage.setData({
|
|
|
+ organizationItem: organizationItem,
|
|
|
+ orgGoodsListFlag: orgGoodsListFlag,
|
|
|
+ orgGoodsListFlagCopy: true
|
|
|
+ })
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ //输入提成比例的
|
|
|
+ inputChange(e) {
|
|
|
+ let showList = this.data.showList;
|
|
|
+ showList[e.currentTarget.dataset.index].commission = e.detail.value;
|
|
|
+ showList[e.currentTarget.dataset.index].allocationRatio = e.detail.value;
|
|
|
+ this.setData({
|
|
|
+ showList: showList
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 列表选中
|
|
|
+ */
|
|
|
+ onChangeFlag(event) {
|
|
|
+ var allIsMain = false
|
|
|
+ var _this = this
|
|
|
+ var showList = _this.data.showList
|
|
|
+ let index = event.currentTarget.dataset.index
|
|
|
+ // 设置点击的项目checkbox的值
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (i == index) {
|
|
|
+ showList[i].checked = !showList[i].checked
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果电机的是选中的
|
|
|
+ if (showList[index].checked) {
|
|
|
+ var isMain = false;
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (showList[i].isMain) {
|
|
|
+ isMain = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ showList[index].isMain = !isMain;
|
|
|
+ } else {
|
|
|
+ showList[index].isMain = false;
|
|
|
+ showList[index].commission = parseFloat(100).toFixed(2)
|
|
|
+ }
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (showList[i].isMain) {
|
|
|
+ allIsMain = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!allIsMain) {
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (showList[i].checked) {
|
|
|
+ showList[i].isMain = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // showList.forEach(it => {
|
|
|
+ // if (it.checked) {
|
|
|
+ // it.commission = parseFloat(100 / showList.filter(item => item.checked == true).length).toFixed(2)
|
|
|
+ // } else {
|
|
|
+ // it.commission = parseFloat(100).toFixed(2)
|
|
|
+ // }
|
|
|
+
|
|
|
+ // })
|
|
|
+ if(!this.data.inputBlurChange){
|
|
|
+ this.calculationScale(showList)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择条数
|
|
|
+ _this.setData({
|
|
|
+ showList: showList,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 主从业务部门的勾选
|
|
|
+ * @param {*} e
|
|
|
+ */
|
|
|
+ onChangeSwitch(e) {
|
|
|
+ var _this = this
|
|
|
+ var showList = _this.data.showList
|
|
|
+ //如果没有选中就不能触发这个主从的勾选
|
|
|
+ if (!showList[e.target.dataset.index].checked) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 设置点击的项目checkbox的值
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (i == e.target.dataset.index && showList[i].checked) {
|
|
|
+ showList[i].isMain = !showList[i].isMain
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ showList[i].isMain = false;
|
|
|
+ }
|
|
|
+ // 选择条数
|
|
|
+ _this.setData({
|
|
|
+ showList: showList,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+* 主从业务员的勾选
|
|
|
+* @param {*} e
|
|
|
+*/
|
|
|
+ onChangeSwitch(e) {
|
|
|
+ var _this = this
|
|
|
+ var showList = _this.data.showList
|
|
|
+ //如果没有选中就不能触发这个主从的勾选
|
|
|
+ if (!showList[e.target.dataset.index].checked) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 设置点击的项目checkbox的值
|
|
|
+ for (let i = 0; i < showList.length; i++) {
|
|
|
+ if (i == e.target.dataset.index && showList[i].checked) {
|
|
|
+ showList[i].isMain = !showList[i].isMain
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ showList[i].isMain = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择条数
|
|
|
+ _this.setData({
|
|
|
+ showList: showList,
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: function (options) {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+})
|