Browse Source

业绩目标

zhaoxiaohai 2 years ago
parent
commit
f18ac984a6
2 changed files with 264 additions and 344 deletions
  1. 206 275
      packageA/target/index.js
  2. 58 69
      packageA/target/index.wxml

+ 206 - 275
packageA/target/index.js

@@ -1,280 +1,211 @@
 const _Http = getApp().globalData.http;
 
 Page({
-    data: {
-        pickerIndex: 0,
-        showText: "全部",
-        popupShow: false,
-        activeId: null,
-        mainActiveIndex: 0,
-        targetYear: null,
-        hrid: null,
-        departmentid: null,
-        "year": new Date().getFullYear().toString(),
-        "content": {
-            "nocache": true,
-            "year": new Date().getFullYear().toString(), //年
-            "targettype": "人员目标", //1
-            "type": 1, //
-            "where": {
-                "condition": ""
-            }
-        },
-        target: null, //目标
-        showActions: false,
-        actionSheet: "开票金额",
-        actions: [{
-            name: '开票金额',
-            value: "1"
-        }, {
-            name: '订单金额',
-            value: "2"
-        }, {
-            name: '出货金额',
-            value: "3"
-        }],
-    },
-    onLoad(options) {
-        /* 获取部门列表 */
-        _Http.basic({
-            "id": 20220922113302,
-            "content": {
-                pageSize: 9999
-            }
-        }).then(res => {
-            if (res.msg != '成功') return wx.showToast({
-                title: res.msg,
-                icon: "none"
-            })
-            let hrList = res.data.map(v => {
-                v.hr.unshift({
-                    name: v.depname + ' (包含所有下级)',
-                    hrid: v.departmentid
-                })
-                return {
-                    id: v.departmentid,
-                    text: v.depname,
-                    children: v.hr.map(value => {
-                        const text = value.position ? value.name + ` (${value.position})` : value.name
-                        return {
-                            id: value.hrid,
-                            text
-                        }
-                    })
-                }
-            })
-            this.setData({
-                hrList
-            })
-        });
-        this.getYear(true)
+	data: {
+		tradefieldIndex: 0,
+		pickerIndex: 0,
+		targetYear: null,
+		hrid: null,
+		"year": new Date().getFullYear().toString(),
+		"content": {
+			"nocache": true,
+			"year": new Date().getFullYear().toString(), //年
+			"type": 1,
+			"where": {
+				"condition": ""
+			}
+		},
+		target: null, //目标
+		showActions: false,
+		actionSheet: "开票金额",
+		actions: [{
+			name: '开票金额',
+			value: "1"
+		}, {
+			name: '订单金额',
+			value: "2"
+		}, {
+			name: '出货金额',
+			value: "3"
+		}],
+	},
+	onLoad(options) {
+		this.getYear(true)
+	},
+	getYear(init = false) {
+		/* 获取年份 */
+		_Http.basic({
+			"classname": "sysmanage.develop.optiontype.optiontype",
+			"method": "optiontypeselect",
+			"content": {
+				pageSize: 999,
+				"typename": 'targetyearofpersonal',
+				"parameter": {
+					"siteid": wx.getStorageSync('siteP').siteid
+				}
+			}
+		}).then(res => {
+			if (res.msg != '成功') return wx.showToast({
+				title: res.msg,
+				icon: "none"
+			})
+			this.setData({
+				userYearList: res.data.map(v => v.year),
+				"content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year,
+				year: res.data.length ? res.data[res.data.length - 1].year : this.data.year,
+				pickerIndex: res.data.length - 1
+			})
+			if (init) this.getData();
+		})
+		/* 获取年份 */
+		_Http.basic({
+			"classname": "sysmanage.develop.optiontype.optiontype",
+			"method": "optiontypeselect",
+			"content": {
+				pageSize: 999,
+				"typename": 'targetyearofproject',
+				"parameter": {
+					"siteid": wx.getStorageSync('siteP').siteid
+				}
+			}
+		}).then(res => {
+			console.log('项目分类', res)
+			if (res.msg != '成功') return wx.showToast({
+				title: res.msg,
+				icon: "none"
+			})
+			this.setData({
+				projectYearList: res.data.map(v => v.year)
+			})
+		})
+	},
+	onShow() {
+		this.getData();
+	},
+	getData() {
+		let content = this.data.content;
+		_Http.basic({
+			"id": wx.getStorageSync('userrole') == '业务员' ? 20230111163102 : 20230110151902,
+			content
+		}).then(res => {
+			console.log("业绩目标", res)
+			if (res.msg != '成功') return wx.showToast({
+				title: res.data,
+				icon: "none"
+			})
+			this.setData({
+				list: res.data,
+				tradefieldIndex: 0
+			})
+			this.setShowData();
 
-    },
-    getYear(init = false) {
-        /* 获取年份 */
-        _Http.basic({
-            "classname": "sysmanage.develop.optiontype.optiontype",
-            "method": "optiontypeselect",
-            "content": {
-                pageSize: 999,
-                "typename": 'targetyearofpersonal',
-                "parameter": {
-                    "siteid": wx.getStorageSync('siteP').siteid
-                }
-            }
-        }).then(res => {
-            if (res.msg != '成功') return wx.showToast({
-                title: res.msg,
-                icon: "none"
-            })
-            this.setData({
-                userYearList: res.data.map(v => v.year),
-                "content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year,
-                year: res.data.length ? res.data[res.data.length - 1].year : this.data.year,
-                pickerIndex: res.data.length - 1
-            })
-            if (init) this.getData();
-        })
-        /* 获取年份 */
-        _Http.basic({
-            "classname": "sysmanage.develop.optiontype.optiontype",
-            "method": "optiontypeselect",
-            "content": {
-                pageSize: 999,
-                "typename": 'targetyearofproject',
-                "parameter": {
-                    "siteid": wx.getStorageSync('siteP').siteid
-                }
-            }
-        }).then(res => {
-            console.log('项目分类', res)
-            if (res.msg != '成功') return wx.showToast({
-                title: res.msg,
-                icon: "none"
-            })
-            this.setData({
-                projectYearList: res.data.map(v => v.year)
-            })
-        })
-    },
-    onShow() {
-        this.getData();
-    },
-    onClickNav({
-        detail
-    }) {
-        this.setData({
-            mainActiveIndex: detail.index
-        })
-    },
-    onClickItem({
-        detail
-    }) {
-        let hrid = null,
-            departmentid = null;
-        if (detail.text.includes('包含所有下级')) {
-            departmentid = detail.id
-        } else {
-            hrid = detail.id
-        };
-        let text = detail.text.split("(")[0];
-        this.setData({
-            hrid,
-            departmentid,
-            activeId: detail.id,
-            text
-        })
-    },
-    /* 切换分析对象 */
-    openPupop() {
-        this.setData({
-            popupShow: true
-        })
-    },
-    onClose() {
-        this.setData({
-            popupShow: false
-        })
-    },
-    toDetail() {
-        wx.navigateTo({
-            url: `./person?year=${this.data.content.year}&yearArr=${this.data.userYearList}&pickerIndex=${this.data.pickerIndex}`
-        })
-    },
-    getData(e) {
-        if (e) this.setData({
-            showText: this.data.text ? this.data.text : '全部'
-        })
-        let content = this.data.content;
-        if (this.data.hrid) content.hrid = this.data.hrid;
-        if (this.data.departmentid) content.departmentid = this.data.departmentid;
-        _Http.basic({
-            "id": 20220920133102,
-            content
-        }).then(res => {
-            this.onClose()
-            if (res.msg != '成功') return wx.showToast({
-                title: res.data,
-                icon: "none"
-            })
-            let lineData = [],
-                histogram = [];
-            res.data.month.forEach(v => {
-                lineData = lineData.concat([{
-                        label: v.month + '月',
-                        value: v.l,
-                        type: "基本目标金额"
-                    },
-                    {
-                        label: v.month + '月',
-                        value: v.h,
-                        type: "挑战目标金额"
-                    },
-                    {
-                        label: v.month + '月',
-                        value: v.a,
-                        type: "实际订单金额"
-                    }
-                ])
-                histogram = histogram.concat([{
-                        label: v.month + '月',
-                        value: v.pl,
-                        type: "基础目标实际完成率"
-                    },
-                    {
-                        label: v.month + '月',
-                        value: v.ph,
-                        type: "挑战目标实际完成率"
-                    }
-                ])
-            });
-            //绘制线图
-            this.selectComponent("#line").render(lineData);
-            this.selectComponent("#histogram").render(histogram);
-            this.setData({
-                targetYear: {
-                    yl: res.data.y1l,
-                    yh: res.data.y1h,
-                    ya: res.data.y1a,
-                }
-            });
-            if (this.data.year == this.data.content.year) {
-                const m = new Date().getMonth() + 1;
-                let s = [
-                    [1, 2, 3],
-                    [4, 5, 6],
-                    [7, 8, 9],
-                    [10, 11, 12]
-                ].findIndex(v => v.some(va => va == m)) + 1;
-                this.setData({
-                    targetSeason: {
-                        sl: res.data[`s${s}l`],
-                        sh: res.data[`s${s}h`],
-                        sa: res.data[`s${s}a`],
-                    },
-                    targetMonth: {
-                        ml: res.data[`m${m}l`],
-                        mh: res.data[`m${m}h`],
-                        ma: res.data[`m${m}a`]
-                    }
-                })
-            }
-        })
-    },
-    /* 弹出选择 */
-    select({
-        detail
-    }) {
-        if (this.data.actionSheet == detail.name) return;
-        this.setData({
-            actionSheet: detail.name,
-            "content.type": detail.value,
-            showActions: false
-        });
-        this.getData();
-    },
-    cancelActions() {
-        this.setData({
-            showActions: false
-        })
-    },
-    openActions() {
-        this.setData({
-            showActions: true
-        })
-    },
-    /* 选择年份 */
-    bindDateChange({
-        detail
-    }) {
-        let index = detail.value;
-        let year = this.data.userYearList[index];
-        if (year == detail.value) return;
-        this.setData({
-            "content.year": year,
-            pickerIndex: index
-        });
-        this.getData();
-    },
-    onShareAppMessage() {}
+		})
+	},
+	bindTradefieldChange(e) {
+		this.setData({
+			tradefieldIndex: e.detail.value
+		})
+		this.setShowData()
+	},
+	setShowData() {
+		let data = this.data.list[this.data.tradefieldIndex];
+		let lineData = [],
+			histogram = [];
+		data.month.forEach(v => {
+			lineData = lineData.concat([{
+					label: v.month + '月',
+					value: v.l,
+					type: "基本目标金额"
+				},
+				{
+					label: v.month + '月',
+					value: v.h,
+					type: "挑战目标金额"
+				},
+				{
+					label: v.month + '月',
+					value: v.a,
+					type: "实际订单金额"
+				}
+			])
+			histogram = histogram.concat([{
+					label: v.month + '月',
+					value: v.pl,
+					type: "基础目标实际完成率"
+				},
+				{
+					label: v.month + '月',
+					value: v.ph,
+					type: "挑战目标实际完成率"
+				}
+			])
+		});
+		//绘制线图
+		this.selectComponent("#line").render(lineData);
+		this.selectComponent("#histogram").render(histogram);
+		this.setData({
+			targetYear: {
+				yl: data.y1l,
+				yh: data.y1h,
+				ya: data.y1a,
+			}
+		});
+		if (this.data.year == this.data.content.year) {
+			const m = new Date().getMonth() + 1;
+			let s = [
+				[1, 2, 3],
+				[4, 5, 6],
+				[7, 8, 9],
+				[10, 11, 12]
+			].findIndex(v => v.some(va => va == m)) + 1;
+			this.setData({
+				targetSeason: {
+					sl: data[`s${s}l`],
+					sh: data[`s${s}h`],
+					sa: data[`s${s}a`],
+				},
+				targetMonth: {
+					ml: data[`m${m}l`],
+					mh: data[`m${m}h`],
+					ma: data[`m${m}a`]
+				}
+			})
+		}
+	},
+	/* 弹出选择 */
+	select({
+		detail
+	}) {
+		if (this.data.actionSheet == detail.name) return;
+		this.setData({
+			actionSheet: detail.name,
+			"content.type": detail.value,
+			showActions: false
+		});
+		this.getData();
+	},
+	cancelActions() {
+		this.setData({
+			showActions: false
+		})
+	},
+	openActions() {
+		this.setData({
+			showActions: true
+		})
+	},
+	/* 选择年份 */
+	bindDateChange({
+		detail
+	}) {
+		let index = detail.value;
+		let year = this.data.userYearList[index];
+		if (year == detail.value) return;
+		this.setData({
+			"content.year": year,
+			pickerIndex: index
+		});
+		this.getData();
+	},
+	onShareAppMessage() {}
 })

+ 58 - 69
packageA/target/index.wxml

@@ -1,81 +1,70 @@
 <!-- 过滤 -->
 <view class="filtrate">
-    <view bindtap="openPupop">{{showText}}<text class="iconfont icon-daoruxialajiantou" /></view>
-    <view catchtap="openActions">
-        {{actionSheet}}<text class="iconfont icon-daoruxialajiantou" />
-    </view>
-    <picker bindchange="bindDateChange" value="{{pickerIndex}}" range="{{active=='业绩目标'?userYearList:projectYearList}}">
-        <view class="picker"><text class="iconfont icon-niandu" style="margin-right: 10rpx; color: #999;" />{{content.year}}<text class="iconfont icon-daoruxialajiantou" /></view>
-    </picker>
+	<picker bindchange="bindTradefieldChange" value="{{tradefieldIndex}}" range-key='tradefield' range="{{list}}">
+		<view class="picker">{{list[tradefieldIndex].tradefield}}<text class="iconfont icon-daoruxialajiantou" /></view>
+	</picker>
+	<view catchtap="openActions">
+		{{actionSheet}}<text class="iconfont icon-daoruxialajiantou" />
+	</view>
+	<picker bindchange="bindDateChange" value="{{pickerIndex}}" range="{{projectYearList}}">
+		<view class="picker"><text class="iconfont icon-niandu" style="margin-right: 10rpx; color: #999;" />{{content.year}}<text class="iconfont icon-daoruxialajiantou" /></view>
+	</picker>
 </view>
 <van-action-sheet show="{{ showActions }}" actions="{{ actions }}" bind:select='select' bind:cancel='cancelActions' cancel-text="取消" />
-<van-popup show="{{ popupShow }}" position="bottom" custom-style="height:100%;" round closeable bind:close="onClose">
-    <view class="header">选择分析对象</view>
-    <view style="height: 90rpx;" />
-    <van-tree-select items="{{ hrList }}" content-item-class='content-item-class' content-active-class='content-active-class' height='calc(100% - 170rpx)' main-active-index="{{ mainActiveIndex }}" active-id="{{ activeId }}" bind:click-nav="onClickNav" bind:click-item="onClickItem" />
-    <view class="footer" style="height: 170rpx;">
-        <van-button custom-class='but' catchtap="getData">确定</van-button>
-    </view>
-</van-popup>
-
 <view class="box">
-    <view class="label">
-        <text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju" />
-        <text>目标完成情况(金额:万元)</text>
-    </view>
-    <view class="content">
-        <view class="col1">
-            <view style="margin-top: 62rpx;">年度:</view>
-            <block wx:if="{{content.year==year}}">
-                <view>本季:</view>
-                <view>本月:</view>
-            </block>
-        </view>
-        <view class="col2">
-            <view class="title">
-                <view>基本目标</view>
-                <view>挑战目标</view>
-                <view>实际完成</view>
-            </view>
-            <view class="row">
-                <view>{{targetYear.yl}}</view>
-                <view>{{targetYear.yh}}</view>
-                <view><text>{{targetYear.ya}}</text></view>
-            </view>
-            <block wx:if="{{content.year==year}}">
-                <view class="row">
-                    <view>{{targetSeason.sl}}</view>
-                    <view>{{targetSeason.sh}}</view>
-                    <view><text>{{targetSeason.sa}}</text></view>
-                </view>
-                <view class="row">
-                    <view>{{targetMonth.ml}}</view>
-                    <view>{{targetMonth.mh}}</view>
-                    <view><text>{{targetMonth.ma}}</text></view>
-                </view>
-            </block>
-        </view>
-    </view>
-    <view style="height:20rpx" />
+	<view class="label">
+		<text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju" />
+		<text>目标完成情况(金额:万元)</text>
+	</view>
+	<view class="content">
+		<view class="col1">
+			<view style="margin-top: 62rpx;">年度:</view>
+			<block wx:if="{{content.year==year}}">
+				<view>本季:</view>
+				<view>本月:</view>
+			</block>
+		</view>
+		<view class="col2">
+			<view class="title">
+				<view>基本目标</view>
+				<view>挑战目标</view>
+				<view>实际完成</view>
+			</view>
+			<view class="row">
+				<view>{{targetYear.yl}}</view>
+				<view>{{targetYear.yh}}</view>
+				<view><text>{{targetYear.ya}}</text></view>
+			</view>
+			<block wx:if="{{content.year==year}}">
+				<view class="row">
+					<view>{{targetSeason.sl}}</view>
+					<view>{{targetSeason.sh}}</view>
+					<view><text>{{targetSeason.sa}}</text></view>
+				</view>
+				<view class="row">
+					<view>{{targetMonth.ml}}</view>
+					<view>{{targetMonth.mh}}</view>
+					<view><text>{{targetMonth.ma}}</text></view>
+				</view>
+			</block>
+		</view>
+	</view>
+	<view style="height:20rpx" />
 </view>
 <!-- 目标完成情况 -->
 <view class="box">
-    <view class="label">
-        <text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju" />
-        <text>目标完成情况(金额:万元)</text>
-    </view>
-    <brokenLine id='line' />
+	<view class="label">
+		<text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju" />
+		<text>目标完成情况(金额:万元)</text>
+	</view>
+	<brokenLine id='line' />
 </view>
 <!-- 目标完成率 -->
 <view class="box">
-    <view class="label">
-        <text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju" />
-        <text>目标完成率(实际相对目标的完成率)</text>
-    </view>
-    <histogram id='histogram' />
+	<view class="label">
+		<text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju" />
+		<text>目标完成率(实际相对目标的完成率)</text>
+	</view>
+	<histogram id='histogram' />
 </view>
-
-<view style="height: 130rpx;" />
-<view class="footer">
-    <van-button custom-class='but' bindtap="toDetail">{{active=='业绩目标'?'我的业绩目标':'我的项目目标'}}</van-button>
-</view>
+<view style="height: 40rpx;" />