diff --git a/frontend/public/config.js b/frontend/public/config.js index ecf37712..7555cf81 100644 --- a/frontend/public/config.js +++ b/frontend/public/config.js @@ -3,7 +3,8 @@ var CONFIG = { login_background: '/assets/login_background.jpg', logo_big: '/assets/logo_big.png', logo_small: '/assets/logo_small.png', - url: (window.location.hostname === 'localhost') ? 'http://vd.dipp.ink/' : '/' + url: (window.location.hostname === 'localhost') ? 'http://vd.dipp.ink/' : '/', + ascsUrl: (window.location.hostname === 'localhost') ? 'http://172.16.14.91:8080/' : '/' }; //http://vd.dipp.ink/ //http://127.0.0.1:8000/ diff --git a/frontend/src/api/virtual/properties.js b/frontend/src/api/virtual/properties.js index 5bcaae32..a170e192 100644 --- a/frontend/src/api/virtual/properties.js +++ b/frontend/src/api/virtual/properties.js @@ -8,9 +8,9 @@ * @return {[type]} [description] */ export function settings(data) { - return service.get('api/virtual/properties/settings', { - params: data - }); + return service.get('api/virtual/properties/settings', { + params: data + }); } /** @@ -19,9 +19,9 @@ export function settings(data) { * @return {[type]} [description] */ export function agents(data) { - return service.get('api/virtual/properties/agents', { - params: data - }); + return service.get('api/virtual/properties/agents', { + params: data + }); } /** @@ -30,7 +30,7 @@ export function agents(data) { * @return {[type]} [description] */ export function settingsStore(data) { - return service.post('api/virtual/properties/settings', data); + return service.post('api/virtual/properties/settings', data); } /** @@ -39,9 +39,9 @@ export function settingsStore(data) { * @return {[type]} [description] */ export function index(data) { - return service.get('api/virtual/properties/index', { - params: data - }); + return service.get('api/virtual/properties/index', { + params: data + }); } /** @@ -50,7 +50,7 @@ export function index(data) { * @return {[type]} [description] */ export function store(data) { - return serviceForm.post('api/virtual/properties/store', data); + return serviceForm.post('api/virtual/properties/store', data); } /** @@ -59,9 +59,9 @@ export function store(data) { * @return {[type]} [description] */ export function exportExcel(data) { - return service.get('api/virtual/properties/export', { - params: data - }); + return service.get('api/virtual/properties/export', { + params: data + }); } /** @@ -70,15 +70,93 @@ export function exportExcel(data) { * @return {[type]} [description] */ export function importExcel(file) { - let config = { - headers: { - 'Content-Type': 'multipart/form-data' - } - }; + let config = { + headers: { + 'Content-Type': 'multipart/form-data' + } + }; - let params = new FormData(); + let params = new FormData(); - params.append('file', file); + params.append('file', file); - return service.post('api/virtual/properties/import', params, config); + return service.post('api/virtual/properties/import', params, config); } + +/** + * [getCarAndplatformList 展示所有的平台车辆] + * @param {[type]} data [description] + * @return {[type]} [description] + */ + +export function getCarTypeToPlatformList(data) { + return fetch.get('property/list', { params: data }) +} + +/** + * [import 展示所有的平台车辆] + * @param {[type]} data [description] + * @return {[type]} [description] + */ + +export function saveCarTypeToPlatform(data) { + return fetch.post('property/update', data) +} + +/** + * [getPlatformList 展示公司应用] + * @param {[type]} data [description] + * @return {[type]} [description] + */ + +export function getApplyList(data) { + return fetch.get('properties/platform', { params: data }) +} + +/** + * [getPlatformList 展示公司下级机构] + * @param {[type]} data [description] + * @return {[type]} [description] + */ + +export function getAgentsList(data) { + return fetch.get('properties/agents', { params: data }) +} + +/** + * [getPlatformList 展示公司所属套餐] + * @param {[type]} data [description] + * @return {[type]} [description] + */ + +export function getPackageList(data) { + return fetch.get('properties/package', { params: data }) +} + +/** + * [getPlatformSetList 展示平台配置列表] + * @param {[type]} data [description] + * @return {[type]} [description] + */ +export function getPlatformSetList(data) { + return fetch.get('setting/list', { params: data }) +} + + +/** + * [savePlatformSet 保存平台配置] + * @param {[type]} data [description] + * @return {[type]} [description] + */ +export function savePlatformSet(data) { + return fetch.post('setting/save', data) +} + +/** + * [delPlatformSet 删除平台配置] + * @param {[type]} data [description] + * @return {[type]} [description] + */ +export function delPlatformSet(data) { + return fetch.post('setting/delete', data) +} \ No newline at end of file diff --git a/frontend/src/main.js b/frontend/src/main.js index 754a852f..34592e27 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -7,7 +7,7 @@ import iView from "iview"; import iviewArea from "iview-area"; import Cookies from "js-cookie"; import Treeselect from "@riophae/vue-treeselect"; -import { service, serviceForm } from "service/service"; +import { service, serviceForm,fetch} from "service/service"; import App from "./App"; import router from "./router"; import store from "./store"; @@ -52,3 +52,4 @@ window.md5 = md5; window.jquery = window.$ = jquery; window.service = service; window.serviceForm = serviceForm; +window.fetch = fetch; diff --git a/frontend/src/service/service.js b/frontend/src/service/service.js index 6436b617..e0af02bb 100644 --- a/frontend/src/service/service.js +++ b/frontend/src/service/service.js @@ -6,85 +6,104 @@ let domain = window.CONFIG.url; // 创建axios实例 export const service = axios.create({ - timeout: 1800000, - headers: { - post: { - 'Content-Type': 'application/x-www-form-urlencoded' - } - }, - baseURL: domain + timeout: 1800000, + headers: { + post: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + }, + baseURL: domain }); export const serviceForm = axios.create({ - timeout: 1800000, - headers: { - post: { - 'Content-Type': 'multipart/form-data' - } - }, - baseURL: domain + timeout: 1800000, + headers: { + post: { + 'Content-Type': 'multipart/form-data' + } + }, + baseURL: domain }); -// http request 拦截器 -let request = function(config) { - const token = getToken(); - // 判断是否存在token,如果存在的话,则每个http header都加上token - if (token) { - config.headers.Authorization = `Bearer ${token}`; - } +export const fetch = axios.create({ + timeout: 1800000, + headers: { + post: { + 'Content-Type': 'application/json; charset=utf-8' + } + }, + baseURL: window.CONFIG.ascsUrl +}) - // 配置取消请求 - if (window._source) { - config.cancelToken = window._source.token; - } - return config; +// http request 拦截器 +let request = function (config) { + const token = getToken(); + // 判断是否存在token,如果存在的话,则每个http header都加上token + if (token) { + config.headers.Authorization = `Bearer ${token}`; + } + + // 配置取消请求 + if (window._source) { + config.cancelToken = window._source.token; + } + return config; }; -let request_err = function(err) { - Message.error('请求超时'); - return Promise.reject(err); +//fetch 的 http request 拦截器 +let fetchRequest = function (config) { + // 配置取消请求 + if (window._source) { + config.cancelToken = window._source.token; + } + return config; +}; + +let request_err = function (err) { + Message.error('请求超时'); + return Promise.reject(err); }; // http response 拦截器 -let response = function(res) { - const data = res.data; - const message = data.message || '未知错误'; +let response = function (res) { + const data = res.data; + const message = data.message || '未知错误'; - if (res.status) { - switch (res.status) { - case 200: - if (data.code !== 0) { - Message.error(message); + if (res.status) { + switch (res.status) { + case 200: + if (data.code !== 0) { + Message.error(message); + } + break; } - break; } - } - return data; + return data; }; -let response_err = function(err) { - if (err.response) { - const data = err.response.data; - const message = data.message ? data.message : '未知错误'; - switch (err.response.status) { - case 401: - if ([40001, 40002, 40003, 40008].includes(data.code)) { - // 40001未登录、40002未激活、40003已禁用、40008token未传递 - localStorage.clear(); - removeToken(); - vm.$router.replace({ path: '/login', query: { redirect: encodeURIComponent(vm.$route.fullPath) } }); - Message.error(message); +let response_err = function (err) { + if (err.response) { + const data = err.response.data; + const message = data.message ? data.message : '未知错误'; + switch (err.response.status) { + case 401: + if ([40001, 40002, 40003, 40008].includes(data.code)) { + // 40001未登录、40002未激活、40003已禁用、40008token未传递 + localStorage.clear(); + removeToken(); + vm.$router.replace({ path: '/login', query: { redirect: encodeURIComponent(vm.$route.fullPath) } }); + Message.error(message); + } + break; + case 500: + Message.error('服务器忙,请稍后再试'); + break; + default: + Message.error(message); + break; } - break; - case 500: - Message.error('服务器忙,请稍后再试'); - break; - default: - Message.error(message); - break; } - } - return Promise.resolve(err); + return Promise.resolve(err); }; service.interceptors.request.use(request, request_err); @@ -93,6 +112,9 @@ service.interceptors.response.use(response, response_err); serviceForm.interceptors.request.use(request, request_err); serviceForm.interceptors.response.use(response, response_err); +fetch.interceptors.request.use(fetchRequest, request_err); +fetch.interceptors.response.use(response, response_err); + axios.interceptors.response.use(response, response_err); window.axios = axios; diff --git a/frontend/src/views/virtual/properties/index.vue b/frontend/src/views/virtual/properties/index.vue index c9e6370f..bccaba14 100644 --- a/frontend/src/views/virtual/properties/index.vue +++ b/frontend/src/views/virtual/properties/index.vue @@ -1,139 +1,106 @@ diff --git a/frontend/src/views/virtual/properties/js/index.js b/frontend/src/views/virtual/properties/js/index.js index 641702b4..3dc8d5b2 100644 --- a/frontend/src/views/virtual/properties/js/index.js +++ b/frontend/src/views/virtual/properties/js/index.js @@ -1,516 +1,561 @@ import * as API from 'api/virtual/properties'; export default { - name: 'Products', - components: { - UiEdit: resolve => require(['views/virtual/properties/edit'], resolve), - UiAgent: resolve => require(['views/virtual/properties/agent'], resolve), - UiSettings: resolve => require(['views/virtual/properties/settings'], resolve) - }, - data() { - return { - properties: new Map(), - showData: [], - params: { - company_id: '', - package_id: '' - }, - only: ['company_id', 'package_id', 'product', 'vehicle_type', 'company', 'platform', 'customer', 'province', 'agent'], - updates: new Map(), - settingsShow: false, - settingsData: {}, - agentsData: {}, - agentsProp: [], - editModel: false, - editObj: { - show: false, - isUpdate: false, - data: null - }, - agentObj: { - show: false, - isUpdate: false, - data: null - }, - search: { - show: true - }, - page: { - total: 0, - limit: 10, - page: 1 - }, - companies: [], - companyFilters: [], - packages: [], - packageFilters: [], - data: [], - columns: [ - { - title: '序号', - key: '', - width: 80, - render: (h, context) => { - return h('span', context.row._index + 1); - } - }, - { - title: '企业名称', - key: 'company_name', - width: 210, - tooltip: true - }, - { - title: '套餐名称', - key: 'package_name', - width: 120 - }, - { - title: '月流量', - key: 'flows', - width: 100 - }, - { - title: '销售数', - key: 'counts', - width: 100 - }, - { - title: '活跃数', - key: 'actives', - width: 100 - }, - { - title: '公司类型', - key: 'company', - minWidth: 170, - render: (h, context) => { - return this.editRender('company', h, context); - } - }, - { - title: '平台/API', - key: 'platform', - minWidth: 120, - render: (h, context) => { - return this.editRender('platform', h, context); - } - }, - { - title: '客户类型', - key: 'customer', - minWidth: 120, - render: (h, context) => { - return this.editRender('customer', h, context); - } - }, - { - title: '产品类型', - key: 'product', - minWidth: 130, - render: (h, context) => { - return this.editRender('product', h, context); - } - }, - { - title: '套餐类型', - key: 'package_type', - width: 100, - render: (h, context) => { - return h('span', this.productPackageTypes[context.row.product]); - } - }, - { - title: '车辆类型', - key: 'vehicle_type', - minWidth: 120, - render: (h, context) => { - return this.editRender('vehicle_type', h, context); - } - }, - { - title: '车型分类', - key: 'vehicle_group', - minWidth: 120, - render: (h, context) => { - return h('span', this.vehicleTypeVehicleGroups[context.row.vehicle_type]); - } - }, - { - title: '销售省份', - key: 'action', - width: 150, - render: (h, { - row, - column, - index - }) => { - let html = []; - - if (this.haveJurisdiction('update')) { - let button = h('Button', { - props: { - type: row.province ? 'success' : 'error', - size: 'small' - }, - class: ['btn'], - on: { - click: (event) => { - this.editObj = { show: true, data: row, isUpdate: this.editModel }; - } - } - }, this.editModel ? '设置' : '查看'); - - html.push(h('Tooltip', { - props: { - content: row.province ? '已设置' : '省份未设置' - } - }, [button])); - } - - if (html.length) { - return h('div', html); - } - } - }, - { - title: '机构', - key: 'action', - width: 150, - render: (h, { - row, - column, - index - }) => { - let html = []; - - if (this.haveJurisdiction('update')) { - let button = h('Button', { - props: { - type: row.agent ? 'success' : 'error', - size: 'small' - }, - class: ['btn'], - on: { - click: (event) => { - this.agentObj = { show: true, data: row, isUpdate: this.editModel }; - this.agentsProp = this.agentsData[row.company_id] ? this.agentsData[row.company_id] : []; - } - } - }, this.editModel ? '设置' : '查看'); - - html.push(h('Tooltip', { - props: { - content: row.agent ? '已设置' : '机构未设置' - } - }, [button])); - } - - if (html.length) { - return h('div', html); - } - } - } - ] - }; - }, - watch: { - editModel(value) { - this.columns = this.columns; - this.$refs.table.handleResize(); - } - }, - computed: { - productPackageTypes() { - let obj = {}; - - let packages = this.settingsData.package ? this.settingsData.package : {}; - - for (const key in packages) { - const element = packages[key]; - - for (let index = 0; index < element.length; index++) { - const value = element[index]; - obj[value] = key; - } - } - - return obj; + name: 'Products', + components: { + UiEdit: resolve => require(['views/virtual/properties/edit'], resolve), + UiAgent: resolve => require(['views/virtual/properties/agent'], resolve), + UiSettings: resolve => require(['views/virtual/properties/settings'], resolve), + UiConfigure: resolve => require(['views/virtual/properties/configure'], resolve), + platformSet: resolve => require(['views/virtual/properties/platform_set'], resolve), }, - vehicleTypeVehicleGroups() { - let obj = {}; + data() { + return { + properties: new Map(), + showData: [], + params: { + company_id: '', + package_id: '' + }, + only: ['company_id', 'package_id', 'product', 'vehicle_type', 'company', 'platform', 'customer', 'province', 'agent'], + updates: new Map(), + configureShow: false, + platform: { + show: false, + id: '', + name: '', + }, + settingsShow: false, + settingsData: {}, + agentsData: {}, + agentsProp: [], + editModel: false, + editObj: { + show: false, + isUpdate: false, + data: null + }, + agentObj: { + show: false, + isUpdate: false, + data: null + }, + search: { + show: true + }, + page: { + total: 0, + limit: 10, + page: 1 + }, + companies: [], + companyFilters: [], + packages: [], + packageFilters: [], + data: [], + columns: [ + { + title: '序号', + key: '', + width: 80, + render: (h, context) => { + return h('span', context.row._index + 1); + } + }, + { + title: '企业名称', + key: 'company_name', + width: 210, + tooltip: true + }, + { + title: '套餐名称', + key: 'package_name', + width: 120 + }, + { + title: '月流量', + key: 'flows', + width: 100 + }, + { + title: '销售数', + key: 'counts', + width: 100 + }, + { + title: '活跃数', + key: 'actives', + width: 100 + }, + { + title: '公司类型', + key: 'company', + minWidth: 170, + render: (h, context) => { + return this.editRender('company', h, context); + } + }, + // { + // title: '平台/API', + // key: 'platform', + // minWidth: 120, + // render: (h, context) => { + // return this.editRender('platform', h, context); + // } + // }, + // { + // title: '客户类型', + // key: 'customer', + // minWidth: 120, + // render: (h, context) => { + // return this.editRender('customer', h, context); + // } + // }, + // { + // title: '产品类型', + // key: 'product', + // minWidth: 130, + // render: (h, context) => { + // return this.editRender('product', h, context); + // } + // }, + // { + // title: '套餐类型', + // key: 'package_type', + // width: 100, + // render: (h, context) => { + // return h('span', this.productPackageTypes[context.row.product]); + // } + // }, + // { + // title: '车辆类型', + // key: 'vehicle_type', + // minWidth: 120, + // render: (h, context) => { + // return this.editRender('vehicle_type', h, context); + // } + // }, + // { + // title: '车型分类', + // key: 'vehicle_group', + // minWidth: 120, + // render: (h, context) => { + // return h('span', this.vehicleTypeVehicleGroups[context.row.vehicle_type]); + // } + // }, + { + title: '销售省份', + key: 'action', + width: 150, + render: (h, { + row, + column, + index + }) => { + let html = []; - let vehicles = this.settingsData.vehicle ? this.settingsData.vehicle : {}; + if (this.haveJurisdiction('update')) { + let button = h('Button', { + props: { + type: row.province ? 'success' : 'error', + size: 'small' + }, + class: ['btn'], + on: { + click: (event) => { + this.editObj = { show: true, data: row, isUpdate: this.editModel }; + } + } + }, this.editModel ? '设置' : '查看'); - for (const key in vehicles) { - const element = vehicles[key]; + html.push(h('Tooltip', { + props: { + content: row.province ? '已设置' : '省份未设置' + } + }, [button])); + } - for (let index = 0; index < element.length; index++) { - const value = element[index]; - obj[value] = key; + if (html.length) { + return h('div', html); + } + } + }, + { + title: '代理商', + key: 'action', + width: 150, + render: (h, { + row, + column, + index + }) => { + let html = []; + + if (this.haveJurisdiction('update')) { + let button = h('Button', { + props: { + type: row.agent ? 'success' : 'error', + size: 'small' + }, + class: ['btn'], + on: { + click: (event) => { + this.agentObj = { show: true, data: row, isUpdate: this.editModel }; + this.agentsProp = this.agentsData[row.company_id] ? this.agentsData[row.company_id] : []; + } + } + }, this.editModel ? '设置' : '查看'); + + html.push(h('Tooltip', { + props: { + content: row.agent ? '已设置' : '代理商未设置' + } + }, [button])); + } + + if (html.length) { + return h('div', html); + } + } + }, + { + title: '平台配置', + key: 'action', + width: 150, + render: (h, { + row, + column, + index + }) => { + let html = []; + + if (this.haveJurisdiction('update')) { + let button = h('Button', { + props: { + type: 'success', + size: 'small' + }, + class: ['btn'], + on: { + click: (event) => { + this.platform.show=true; + this.platform.id=row.company_id; + this.platform.name=row.company_name; + this.platform.packagetype=row.package[0]; + this.platform.propertyId=row.id; + } + } + }, '配置'); + + html.push(button); + } + + if (html.length) { + return h('div', html); + } + } + } + ] + }; + }, + watch: { + editModel(value) { + this.columns = this.columns; + this.$refs.table.handleResize(); } - } + }, + computed: { + productPackageTypes() { + let obj = {}; - return obj; - } - }, - created() { - this.index(); - this.settings(); - this.agents(); - }, - methods: { - editRender(key, h, context) { - if (!this.editModel) { - return h('span', context.row[key]); - } + let packages = this.settingsData.package ? this.settingsData.package : {}; - let options = []; + for (const key in packages) { + const element = packages[key]; - let arr; - if (key === 'product') { - arr = Object.values(this.settingsData['package']).join(",").split(","); - } else if (key === 'vehicle_type') { - arr = Object.values(this.settingsData['vehicle']).join(",").split(","); - } else { - arr = this.settingsData[key]; - } + for (let index = 0; index < element.length; index++) { + const value = element[index]; + obj[value] = key; + } + } - for (let index = 0; index < arr.length; index++) { - const element = arr[index]; - options.push(h('Option', { - props: { - value: element - } - }, element)); - } - - return h('Select', { - props: { - value: context.row[key], - size: 'small', - transfer: true + return obj; }, - on: { - input: (value) => { - let index = this.getIndex(context.row); - let property = this.properties.get(index); - property[key] = value; - this.properties.set(index, property); + vehicleTypeVehicleGroups() { + let obj = {}; + + let vehicles = this.settingsData.vehicle ? this.settingsData.vehicle : {}; + + for (const key in vehicles) { + const element = vehicles[key]; + + for (let index = 0; index < element.length; index++) { + const value = element[index]; + obj[value] = key; + } + } + + return obj; + } + }, + created() { + this.index(); + this.settings(); + this.agents(); + }, + methods: { + editRender(key, h, context) { + if (!this.editModel) { + return h('span', context.row[key]); + } + + let options = []; + + let arr; + if (key === 'product') { + arr = Object.values(this.settingsData['package']).join(",").split(","); + } else if (key === 'vehicle_type') { + arr = Object.values(this.settingsData['vehicle']).join(",").split(","); + } else { + arr = this.settingsData[key]; + } + + for (let index = 0; index < arr.length; index++) { + const element = arr[index]; + options.push(h('Option', { + props: { + value: element + } + }, element)); + } + + return h('Select', { + props: { + value: context.row[key], + size: 'small', + transfer: true + }, + on: { + input: (value) => { + let index = this.getIndex(context.row); + let property = this.properties.get(index); + property[key] = value; + this.properties.set(index, property); + this.changePage(this.page.page); + this.updates.set(index, this.properties.get(index)); + } + } + }, options); + }, + /** + * [index 列表] + * @param {Number} company_id [description] + * @return {[type]} [description] + */ + index(page = 1) { + if (!this.properties.size) { + this.isShowLoading(true); + API.index().then(res => { + if (res.code === 0) { + let properties = new Map(); + + res.data.forEach(element => { + properties.set(this.getIndex(element), element); + }); + + this.properties = properties; + this.changePage(page); + this.complete(); + } + this.isShowLoading(false); + }); + } else { + this.changePage(page); + } + }, + complete() { + let companies = {}; + + let properties = Array.from(this.properties.values()); + + properties.forEach((item) => { + companies[item.company_id] = item.company_name; + }); + + let companyArray = []; + + for (const key in companies) { + companyArray.push({ id: key, name: companies[key] }); + } + + this.companies = companyArray; + + let packages = {}; + + properties.forEach((item) => { + packages[item.package_id] = item.package_name; + }); + + let packageArray = []; + + for (const key in packages) { + packageArray.push({ id: key, name: packages[key] }); + } + + this.packages = packageArray; + }, + /** + * [request 刷新] + * @return {[type]} [description] + */ + request() { + this.properties = []; + this.index(); + }, + resetSearch() { + for (let k in this.params) { + this.params[k] = ''; + } + this.index(1); + }, + changeLimit(limit) { + this.page.limit = limit; + this.changePage(1); + }, + changePage(page) { + this.page.page = page; + + let properties = Array.from(this.properties.values()); + + if (this.params.company_id !== '' && this.params.company_id !== undefined) { + properties = properties.filter(el => { return el.company_id == this.params.company_id; }); + } + + if (this.params.package_id !== '' && this.params.package_id !== undefined) { + properties = properties.filter(el => { return el.package_id == this.params.package_id; }); + } + + if (this.params.status !== '' && this.params.status !== undefined) { + if (this.params.status === 0) { + properties = properties.filter(el => { return el.product !== '' && el.province !== null; }); + } else if (this.params.status === 1) { + properties = properties.filter(el => { return el.product === '' || el.province === null; }); + } + } + + this.page.total = properties.length; + + this.showData = properties.slice((page - 1) * this.page.limit, page * this.page.limit); + }, + agents() { + if (!this.agentsData.length) { + API.agents().then(res => { + if (res.code === 0) { + this.agentsData = res.data; + } + }); + } + }, + settings() { + if (!this.settingsData.length) { + API.settings().then(res => { + if (res.code === 0) { + this.settingsData = res.data; + } + }); + } + }, + updateSettings(values) { + this.settingsData = values; + }, + ok() { + if (!this.updates.size) { + this.$Message.warning('数据未修改'); + this.editModel = false; + return; + } + + this.isShowLoading(true); + + let updates = []; + + this.updates.forEach((element) => { + let obj = {}; + for (const key in element) { + if (this.only.indexOf(key) !== -1) { + obj[key] = element[key]; + } + } + updates.push(obj); + }); + + console.log("updates", updates); + + API.store({ data: updates }).then(res => { + if (res.code === 0) { + this.updates = new Map(); + this.editModel = false; + } + this.isShowLoading(false); + }); + }, + handleProvinceSuccess(data) { + let index = this.getIndex(data); + this.properties.set(index, data); this.changePage(this.page.page); this.updates.set(index, this.properties.get(index)); - } - } - }, options); - }, - /** - * [index 列表] - * @param {Number} company_id [description] - * @return {[type]} [description] - */ - index(page = 1) { - if (!this.properties.size) { - this.isShowLoading(true); - API.index().then(res => { - if (res.code === 0) { - let properties = new Map(); + }, + handleAgentSuccess(data) { + let index = this.getIndex(data); + this.properties.set(index, data); + this.changePage(this.page.page); + this.updates.set(index, this.properties.get(index)); + }, + exportExcel() { + let params = {}; - res.data.forEach(element => { - properties.set(this.getIndex(element), element); + for (const key in this.params) { + const element = this.params[key]; + + if (element !== '' && element !== undefined) { + params[key] = element; + } + } + + this.isShowLoading(true); + + API.exportExcel(params).then(res => { + if (res.code === 0) { + if (res.data) { + this.downloadFile(res.data); + } else { + this.$Modal.success({ + title: '提示', + content: '当前导出数据量大,已进入后台队列导出模式,请稍后至导出列表查看下载。' + }); + } + } + this.isShowLoading(false); + }).catch(() => { + this.isShowLoading(false); + }); + }, + importExcel(file) { + this.isShowLoading(true); + API.importExcel(file).then(res => { + if (res.code === 0) { + this.request(); + this.$Message.success(res.message); + } + + this.isShowLoading(false); }); - this.properties = properties; - this.changePage(page); - this.complete(); - } - this.isShowLoading(false); - }); - } else { - this.changePage(page); - } - }, - complete() { - let companies = {}; - - let properties = Array.from(this.properties.values()); - - properties.forEach((item) => { - companies[item.company_id] = item.company_name; - }); - - let companyArray = []; - - for (const key in companies) { - companyArray.push({ id: key, name: companies[key] }); - } - - this.companies = companyArray; - - let packages = {}; - - properties.forEach((item) => { - packages[item.package_id] = item.package_name; - }); - - let packageArray = []; - - for (const key in packages) { - packageArray.push({ id: key, name: packages[key] }); - } - - this.packages = packageArray; - }, - /** - * [request 刷新] - * @return {[type]} [description] - */ - request() { - this.properties = []; - this.index(); - }, - resetSearch() { - for (let k in this.params) { - this.params[k] = ''; - } - this.index(1); - }, - changeLimit(limit) { - this.page.limit = limit; - this.changePage(1); - }, - changePage(page) { - this.page.page = page; - - let properties = Array.from(this.properties.values()); - - if (this.params.company_id !== '' && this.params.company_id !== undefined) { - properties = properties.filter(el => { return el.company_id == this.params.company_id; }); - } - - if (this.params.package_id !== '' && this.params.package_id !== undefined) { - properties = properties.filter(el => { return el.package_id == this.params.package_id; }); - } - - if (this.params.status !== '' && this.params.status !== undefined) { - if (this.params.status === 0) { - properties = properties.filter(el => { return el.product !== '' && el.province !== null; }); - } else if (this.params.status === 1) { - properties = properties.filter(el => { return el.product === '' || el.province === null; }); + return false; + }, + getIndex(row) { + return row.company_id + '_' + row.package_id; } - } - - this.page.total = properties.length; - - this.showData = properties.slice((page - 1) * this.page.limit, page * this.page.limit); - }, - agents() { - if (!this.agentsData.length) { - API.agents().then(res => { - if (res.code === 0) { - this.agentsData = res.data; - } - }); - } - }, - settings() { - if (!this.settingsData.length) { - API.settings().then(res => { - if (res.code === 0) { - this.settingsData = res.data; - } - }); - } - }, - updateSettings(values) { - this.settingsData = values; - }, - ok() { - if (!this.updates.size) { - this.$Message.warning('数据未修改'); - this.editModel = false; - return; - } - - this.isShowLoading(true); - - let updates = []; - - this.updates.forEach((element) => { - let obj = {}; - for (const key in element) { - if (this.only.indexOf(key) !== -1) { - obj[key] = element[key]; - } - } - updates.push(obj); - }); - - console.log("updates", updates); - - API.store({ data: updates }).then(res => { - if (res.code === 0) { - this.updates = new Map(); - this.editModel = false; - } - this.isShowLoading(false); - }); - }, - handleProvinceSuccess(data) { - let index = this.getIndex(data); - this.properties.set(index, data); - this.changePage(this.page.page); - this.updates.set(index, this.properties.get(index)); - }, - handleAgentSuccess(data) { - let index = this.getIndex(data); - this.properties.set(index, data); - this.changePage(this.page.page); - this.updates.set(index, this.properties.get(index)); - }, - exportExcel() { - let params = {}; - - for (const key in this.params) { - const element = this.params[key]; - - if (element !== '' && element !== undefined) { - params[key] = element; - } - } - - this.isShowLoading(true); - - API.exportExcel(params).then(res => { - if (res.code === 0) { - if (res.data) { - this.downloadFile(res.data); - } else { - this.$Modal.success({ - title: '提示', - content: '当前导出数据量大,已进入后台队列导出模式,请稍后至导出列表查看下载。' - }); - } - } - this.isShowLoading(false); - }).catch(() => { - this.isShowLoading(false); - }); - }, - importExcel(file) { - this.isShowLoading(true); - API.importExcel(file).then(res => { - if (res.code === 0) { - this.request(); - this.$Message.success(res.message); - } - - this.isShowLoading(false); - }); - - return false; - }, - getIndex(row) { - return row.company_id + '_' + row.package_id; } - } };