|
@@ -1,3 +1,6 @@
|
|
|
|
+const matched = window.location.search.match(/filter=(.+)/);
|
|
|
|
+const compilationID = matched && matched[1] || '';
|
|
|
|
+
|
|
// 节流
|
|
// 节流
|
|
function throttle(fn, time) {
|
|
function throttle(fn, time) {
|
|
let canRun = true;
|
|
let canRun = true;
|
|
@@ -37,6 +40,7 @@ let curLib = {};
|
|
function setCurLib(libID) {
|
|
function setCurLib(libID) {
|
|
curLib.id = libID;
|
|
curLib.id = libID;
|
|
curLib.name = $(`#${libID}`).text();
|
|
curLib.name = $(`#${libID}`).text();
|
|
|
|
+ curLib.compilationID = $(`#${libID}`).data('compilationid');
|
|
}
|
|
}
|
|
|
|
|
|
// 点击编辑按钮
|
|
// 点击编辑按钮
|
|
@@ -79,13 +83,82 @@ function handleDeleteConfirm() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 获取地区
|
|
|
|
+let curAreas = [];
|
|
|
|
+let curAreaMap = {};
|
|
|
|
+const getAreas = async () => {
|
|
|
|
+ const areas = await ajaxPost('/priceInfo/getAreas', { compilationID: curLib.compilationID });
|
|
|
|
+ return areas;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 获取地区下拉选项映射,key为父地区、value为子地区
|
|
|
|
+const getAreaMap = async () => {
|
|
|
|
+ curAreas = await getAreas();
|
|
|
|
+ const areaMap = {};
|
|
|
|
+ curAreas.forEach(item => {
|
|
|
|
+ const { name } = item;
|
|
|
|
+ if (name) {
|
|
|
|
+ let [parent, sub] = name.split('-');
|
|
|
|
+ if (!sub) {
|
|
|
|
+ sub = parent;
|
|
|
|
+ }
|
|
|
|
+ if (!areaMap[parent]) {
|
|
|
|
+ areaMap[parent] = [sub];
|
|
|
|
+ } else {
|
|
|
|
+ areaMap[parent].push(sub);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return areaMap;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 根据地区选项获取地区ID
|
|
|
|
+const getAreaIDByOption = ($parent, $sub) => {
|
|
|
|
+ const parentArea = $parent.val();
|
|
|
|
+ const subArea = $sub.val();
|
|
|
|
+ const areaItem = curAreas.find(item => [parentArea, `${parentArea}-${subArea}`].includes(item.name));
|
|
|
|
+ console.log(areaItem);
|
|
|
|
+ return areaItem?.ID;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 设置地区下拉项
|
|
|
|
+const setAreaOption = ($parent, $sub, areaMap) => {
|
|
|
|
+ $parent.unbind();
|
|
|
|
+ const parentAreas = Object.keys(areaMap);
|
|
|
|
+ $parent.empty();
|
|
|
|
+ const parentOptionsHtml = parentAreas.map(parentArea => `<option value="${parentArea}">${parentArea}</option>`).join('');
|
|
|
|
+ $parent.append(parentOptionsHtml);
|
|
|
|
+ const setSubs = (subsArea) => {
|
|
|
|
+ $sub.empty();
|
|
|
|
+ const subOptionsHtml = subsArea.map(subArea => `<option value="${subArea}">${subArea}</option>`).join('');
|
|
|
|
+ $sub.append(subOptionsHtml);
|
|
|
|
+ }
|
|
|
|
+ setSubs(areaMap[parentAreas[0]] || []);
|
|
|
|
+ $parent.change(() => {
|
|
|
|
+ const curParent = $parent.val();
|
|
|
|
+ setSubs(areaMap[curParent] || []);
|
|
|
|
+ getAreaIDByOption();
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
let importType = 'originalData';
|
|
let importType = 'originalData';
|
|
|
|
|
|
// 点击导入按钮
|
|
// 点击导入按钮
|
|
-function handleImportClick(libID, type) {
|
|
|
|
- setCurLib(libID);
|
|
|
|
- importType = type;
|
|
|
|
- $('#import').modal('show');
|
|
|
|
|
|
+async function handleImportClick(libID, type) {
|
|
|
|
+ try {
|
|
|
|
+ setCurLib(libID);
|
|
|
|
+ importType = type;
|
|
|
|
+ if (importType === 'keys') {
|
|
|
|
+ $('#import-area').show();
|
|
|
|
+ const areaMap = await getAreaMap();
|
|
|
|
+ setAreaOption($('#import-parent-area'), $('#import-sub-area'), areaMap);
|
|
|
|
+ } else {
|
|
|
|
+ $('#import-area').hide();
|
|
|
|
+ }
|
|
|
|
+ $('#import').modal('show');
|
|
|
|
+ } catch (error) {
|
|
|
|
+ alert(error.message);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 点击导出按钮
|
|
// 点击导出按钮
|
|
@@ -98,6 +171,10 @@ function handleImportConfirm() {
|
|
$.bootstrapLoading.start();
|
|
$.bootstrapLoading.start();
|
|
const self = $(this);
|
|
const self = $(this);
|
|
try {
|
|
try {
|
|
|
|
+ const areaID = getAreaIDByOption($('#import-parent-area'), $('#import-sub-area'));
|
|
|
|
+ if (!areaID) {
|
|
|
|
+ throw '请选择地区!';
|
|
|
|
+ }
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
const file = $("input[name='import_data']")[0];
|
|
const file = $("input[name='import_data']")[0];
|
|
if (file.files.length <= 0) {
|
|
if (file.files.length <= 0) {
|
|
@@ -105,6 +182,7 @@ function handleImportConfirm() {
|
|
}
|
|
}
|
|
formData.append('file', file.files[0]);
|
|
formData.append('file', file.files[0]);
|
|
formData.append('libID', curLib.id);
|
|
formData.append('libID', curLib.id);
|
|
|
|
+ formData.append('areaID', areaID);
|
|
formData.append('importType', importType);
|
|
formData.append('importType', importType);
|
|
$.ajax({
|
|
$.ajax({
|
|
url: '/priceInfo/importExcel',
|
|
url: '/priceInfo/importExcel',
|
|
@@ -200,8 +278,6 @@ function processChecking(key, cb) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const matched = window.location.search.match(/filter=(.+)/);
|
|
|
|
-const compilationID = matched && matched[1] || '';
|
|
|
|
// 爬取数据确认
|
|
// 爬取数据确认
|
|
function handleCrawlConfirm() {
|
|
function handleCrawlConfirm() {
|
|
const from = $('#period-start').val();
|
|
const from = $('#period-start').val();
|