| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- const _Http = getApp().globalData.http,
- currency = require("../../utils/currency"),
- CNY = (value, symbol = "", precision = 2) => currency(value, {
- symbol,
- precision
- }).format();
- Page({
- data: {
- dropdownItem: 0,
- filtratelist: [],
- showFiltrate: false,
- active: {
- name: wx.getStorageSync('userMsg').name,
- userid: wx.getStorageSync('userMsg').userid,
- isleave: 1
- }
- },
- onLoad(options) {
- this.refreshData();
- getApp().globalData.Language.getLanguagePackage(this, '作业看板');
- this.setData({
- dropdown: [{
- text: getApp().globalData.Language.getMapText('作业看板'),
- value: 0
- },
- {
- text: getApp().globalData.Language.getMapText('线索'),
- value: 1
- },
- {
- text: getApp().globalData.Language.getMapText('客户'),
- value: 2
- },
- {
- text: getApp().globalData.Language.getMapText('项目商机'),
- value: 3
- },
- {
- text: getApp().globalData.Language.getMapText('作业单据'),
- value: 4
- }
- ]
- })
- },
- openFiltrate() {
- this.setData({
- showFiltrate: true
- })
- },
- handleFilter({
- detail
- }) {
- if (detail.name == 'reset') {
- this.selectComponent("#organization").setData({
- isleave: 1
- })
- this.selectComponent("#organization").initDepAndUser().then(active => {
- console.log("active", active)
- active.isleave = 1;
- this.setData({
- active
- })
- this.refreshData();
- this.refreshModel();
- });
- } else {
- this.setData({
- active: this.selectComponent("#organization").data.result
- })
- this.refreshData();
- this.refreshModel();
- }
- },
- refreshData() {
- const conversion = (n) => {
- const integer = (n + '').split(".")[0] + '',
- length = integer.length,
- regexp = /(?:\.0*|(\.\d+?)0+)$/
- if (length <= 4) {
- const index = 4 - length;
- return { //元
- show: CNY(n, "", index).replace(regexp, '$1'),
- value: CNY(n, '¥')
- }
- } else if (length <= 8) {
- return { //万-千万
- show: CNY(currency(n).divide(wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000)).replace(regexp, '$1') + getApp().globalData.Language.getMapText('万'),
- value: CNY(n)
- }
- } else {
- return { //亿
- show: CNY(currency(n).divide(100000000)).replace(regexp, '$1') + getApp().globalData.Language.getMapText('亿'),
- value: CNY(n)
- }
- }
- };
- const sortOut = (obj, data, isConversion = false) => {
- for (const key in obj) {
- if (key == 'tab') continue;
- for (const k in obj[key]) {
- obj[key][k] = isConversion ? conversion(data[key + k]) : data[key + k]
- }
- }
- return obj
- };
- const getData = (dataType) => {
- let active = this.data.active;
- let type = active.userid ? 0 : 1,
- dataid = type == 0 ? active.userid : active.departmentid,
- where = {
- isleave: active.isleave
- };
- return _Http.basic({
- "id": 20230616131404,
- "content": {
- nocache: true,
- dataType, // 1 作业数据 2 销售数据 3业绩数据
- type,
- dataid,
- where
- }
- }).then(res => {
- let data = {};
- switch (dataType) {
- case 1:
- data = {
- tab: {
- active: "by",
- list: [{
- name: getApp().globalData.Language.getMapText('本周'),
- id: "bz"
- }, {
- name: getApp().globalData.Language.getMapText('本月'),
- id: "by"
- }, {
- name: getApp().globalData.Language.getMapText('本年'),
- id: "bn"
- }]
- },
- bz: {
- khgj: 0,
- khxz: 0,
- xmgj: 0,
- xmxz: 0,
- xsxz: 0,
- xsgj: 0,
- },
- by: {
- khgj: 0,
- khxz: 0,
- xmgj: 0,
- xmxz: 0,
- xsxz: 0,
- xsgj: 0,
- },
- bn: {
- khgj: 0,
- khxz: 0,
- xmgj: 0,
- xmxz: 0,
- xsxz: 0,
- xsgj: 0,
- }
- }
- break;
- case 2:
- data = {
- tab: {
- active: "by",
- list: [{
- name: getApp().globalData.Language.getMapText('本周'),
- id: "bz"
- }, {
- name: getApp().globalData.Language.getMapText('本月'),
- id: "by"
- }, {
- name: getApp().globalData.Language.getMapText('本年'),
- id: "bn"
- }]
- },
- bz: {
- chje: 0,
- kpje: 0,
- skje: 0,
- xsje: 0
- },
- by: {
- chje: 0,
- kpje: 0,
- skje: 0,
- xsje: 0
- },
- bn: {
- chje: 0,
- kpje: 0,
- skje: 0,
- xsje: 0
- }
- }
- break;
- default:
- data = res.data
- data.tab = {
- active: "by",
- list: [{
- name: getApp().globalData.Language.getMapText('本月'),
- id: "by"
- }, {
- name: getApp().globalData.Language.getMapText('本季'),
- id: "bj"
- }, {
- name: getApp().globalData.Language.getMapText('本年'),
- id: "bn"
- }]
- }
- break;
- }
- return dataType == 3 ? data : sortOut(data, res.data, dataType == 2)
- })
- };
- wx.showLoading({
- title: getApp().globalData.Language.getMapText('加载中...'),
- mask: true
- })
- let languagecode = wx.getStorageSync('languagecode');
- Promise.all([getData(1), getData(2), getData(3)]).then(res => {
- wx.hideLoading()
- for (const key in res[2]) {
- if (key == 'tab') continue;
- res[2][key].target_l = conversion(res[2][key].target_l);
- //实际
- res[2][key].amount = conversion(res[2][key].amount);
- res[2][key].outamount = conversion(res[2][key].outamount);
- res[2][key].invoiceamount = conversion(res[2][key].invoiceamount);
- //差额
- res[2][key].unamount = CNY(res[2][key].unamount / (languagecode == 'ZH' ? 10000 : 1000), '');
- res[2][key].unamountcolor = res[2][key].unamount >= 0 ? '#5AB73F' : '#EB4B5C';
- res[2][key].unoutamount = CNY(res[2][key].unoutamount / (languagecode == 'ZH' ? 10000 : 1000), '');
- res[2][key].unoutamountcolor = res[2][key].unoutamount >= 0 ? '#5AB73F' : '#EB4B5C';
- res[2][key].uninvoiceamount = CNY(res[2][key].uninvoiceamount / (languagecode == 'ZH' ? 10000 : 1000), '');
- res[2][key].uninvoiceamountcolor = res[2][key].uninvoiceamount >= 0 ? '#5AB73F' : '#EB4B5C';
- //达成率
- res[2][key].wcamount = (res[2][key].wcamount * 100).toFixed(2) + '%';
- res[2][key].wcoutamount = (res[2][key].wcoutamount * 100).toFixed(2) + '%';
- res[2][key].wcinvoiceamount = (res[2][key].wcinvoiceamount * 100).toFixed(2) + '%';
- console.log("res[2][key].wcamount", res[2][key].wcamount)
- }
- this.setData({
- zysj: res[0],
- xssj: res[1],
- yjsj: res[2],
- })
- })
- },
- dropdownItemChange({
- detail
- }) {
- this.setData({
- dropdownItem: detail
- })
- this.refreshModel();
- },
- changeId(e) {
- const {
- id,
- name
- } = e.currentTarget.dataset;
- if (this.data[name].tab.active == id) return;
- this.setData({
- [`${name}.tab.active`]: id
- })
- },
- refreshModel() {
- const dropdownItem = this.data.dropdownItem;
- if (dropdownItem == 0) return;
- const model = this.selectComponent("#model" + dropdownItem);
- if (!model) return;
- const active = this.data.active;
- model.init(active.departmentid ? '1' : '0', active.departmentid || active.userid);
- },
- onReady() {
- this.selectComponent("#ListBox").setHeight(".head", this);
- this.selectComponent("#organization").setData({
- isleave: 1
- })
- this.selectComponent("#organization").initDepAndUser().then(active => {
- this.setData({
- active
- })
- this.refreshModel();
- });
- }
- })
|