mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-23 09:50:25 +08:00
Update form.html
This commit is contained in:
parent
7c070386fe
commit
6407bbaa82
@ -22,9 +22,9 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="item in rules">
|
<tr ng-repeat="item in rules">
|
||||||
<td>
|
<td>
|
||||||
<span class="margin-right-5" ng-repeat="city in item.city" ng-if="ShowProvinceStatus(city)">
|
<span class="margin-right-5" ng-repeat="province in item.city" ng-if="ShowProvinceStatus(province)">
|
||||||
<b class="font-w7" ng-bind="city.name"></b>
|
<b class="font-w7" ng-bind="province.name"></b>
|
||||||
<b class="color-desc">({{ShowRuleCityName(city)}})</b>
|
<b class="color-desc">({{ShowProvinceCityName(province)}})</b>
|
||||||
</span>
|
</span>
|
||||||
<a class="margin-left-5" ng-click="EditRuleItem(item)">编辑</a>
|
<a class="margin-left-5" ng-click="EditRuleItem(item)">编辑</a>
|
||||||
<a class="margin-left-5" ng-click="RemoveRuleItem(item)">删除</a>
|
<a class="margin-left-5" ng-click="RemoveRuleItem(item)">删除</a>
|
||||||
@ -95,7 +95,7 @@
|
|||||||
<script>
|
<script>
|
||||||
require(['angular'], function () {
|
require(['angular'], function () {
|
||||||
var app = angular.module("TruckForm", []).run(callback);
|
var app = angular.module("TruckForm", []).run(callback);
|
||||||
var citys = document.getElementById('CityData').value || '[]';
|
var _data = document.getElementById('CityData').value || '[]';
|
||||||
var _rule = {city: [], rule: {firstNumber: 1, firstAmount: 1.00, repeatNumber: 1, repeatAmount: 1.00}};
|
var _rule = {city: [], rule: {firstNumber: 1, firstAmount: 1.00, repeatNumber: 1, repeatAmount: 1.00}};
|
||||||
angular.bootstrap(document.getElementById(app.name), [app.name]);
|
angular.bootstrap(document.getElementById(app.name), [app.name]);
|
||||||
|
|
||||||
@ -103,7 +103,7 @@
|
|||||||
$rootScope.rule = angular.fromJson(angular.toJson(_rule));
|
$rootScope.rule = angular.fromJson(angular.toJson(_rule));
|
||||||
$rootScope.rules = [];
|
$rootScope.rules = [];
|
||||||
$rootScope.city = {subs: []};
|
$rootScope.city = {subs: []};
|
||||||
$rootScope.citys = angular.fromJson(citys) || [];
|
$rootScope.citys = angular.fromJson(_data) || [];
|
||||||
/*! 默认显示所有城市 */
|
/*! 默认显示所有城市 */
|
||||||
$rootScope.citys.forEach(function (item) {
|
$rootScope.citys.forEach(function (item) {
|
||||||
delete item.id, delete item.pid;
|
delete item.id, delete item.pid;
|
||||||
@ -145,31 +145,29 @@
|
|||||||
/*! 确认规则选项 */
|
/*! 确认规则选项 */
|
||||||
$rootScope.SetRuleItem = function () {
|
$rootScope.SetRuleItem = function () {
|
||||||
layui.layer.closeAll();
|
layui.layer.closeAll();
|
||||||
$rootScope.rules.forEach(function (rule) {
|
$rootScope.rule.city.forEach(function (province) {
|
||||||
rule.city.forEach(function (item) {
|
province.subs.forEach(function (city) {
|
||||||
item.subs.forEach(function (item) {
|
if (city.status) city.show = false;
|
||||||
if (item.status) item.show = false;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/*! 配送区域城市名称显示处理 */
|
/*! 配送区域城市名称显示处理 */
|
||||||
$rootScope.ShowRuleCityName = function (city) {
|
$rootScope.ShowProvinceCityName = function (province) {
|
||||||
var citys = [];
|
var citys = [];
|
||||||
city.subs.forEach(function (item) {
|
province.subs.forEach(function (city) {
|
||||||
if (item.status) citys.push(item.name);
|
if (city.status) citys.push(city.name);
|
||||||
});
|
});
|
||||||
return citys.join('、');
|
return citys.join('、');
|
||||||
};
|
};
|
||||||
/*! 检查是否还拥有可以选择的项目 */
|
/*! 检查是否还拥有可以选择的项目 */
|
||||||
$rootScope.ShowProvinceShow = function (city) {
|
$rootScope.ShowProvinceShow = function (province) {
|
||||||
return city.subs.some(function (item) {
|
return province.subs.some(function (item) {
|
||||||
if (item.show) return true;
|
if (item.show) return true;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/*! 检查是否还拥有可以选择的项目 */
|
/*! 检查是否还拥有可以选择的项目 */
|
||||||
$rootScope.ShowProvinceStatus = function (city) {
|
$rootScope.ShowProvinceStatus = function (province) {
|
||||||
return city.subs.some(function (item) {
|
return province.subs.some(function (item) {
|
||||||
if (item.status) return true;
|
if (item.status) return true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -188,41 +186,54 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
/*! 展开省份下的城市 */
|
/*! 展开省份下的城市 */
|
||||||
$rootScope.SwitchActiveProvince = function (city) {
|
$rootScope.SwitchActiveProvince = function (province) {
|
||||||
$rootScope.city = city;
|
$rootScope.city = province;
|
||||||
city.subs.forEach(function (item) {
|
province.subs.forEach(function (item) {
|
||||||
item.status = !!city.status;
|
if (item.show) item.status = !!province.status;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
$rootScope.showDailog = function () {
|
$rootScope.showDailog = function () {
|
||||||
layui.layer.open({
|
layui.layer.open({
|
||||||
type: 1, shade: false, area: '800px', title: '选择配送区域',
|
type: 1, shade: false, area: '800px', title: '选择配送区域',
|
||||||
content: $('#RegionDialog').removeClass('layui-hide'), end: function () {
|
content: $('#RegionDialog').removeClass('layui-hide'), end: function () {
|
||||||
$('#RegionDialog').addClass('layui-hide')
|
$('#RegionDialog').addClass('layui-hide');
|
||||||
|
$rootScope.SetRuleItem();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
$rootScope.$watch('citys', function () {
|
$rootScope.$watch('citys', function () {
|
||||||
// 子集联动上级选择
|
/*! 城市集联动省份选项选择 */
|
||||||
$rootScope.city.status = $rootScope.city.subs.some(function (item) {
|
$rootScope.city.status = $rootScope.city.subs.some(function (item) {
|
||||||
if (item.show && item.status) return true;
|
if (item.show && item.status) return true;
|
||||||
});
|
});
|
||||||
// 记录当前操作值
|
/*! 合并当前操作数据到缓存 */
|
||||||
var cache = {};
|
var _province_cache = {}, _city_cache = {};
|
||||||
$rootScope.rule.city.forEach(function (item) {
|
$rootScope.rule.city.forEach(function (province) {
|
||||||
cache[item.name] = item;
|
_province_cache[province.name] = province;
|
||||||
|
province.subs.forEach(function (city) {
|
||||||
|
_city_cache[province.name + '-' + city.name] = true;
|
||||||
});
|
});
|
||||||
$rootScope.citys.forEach(function (item) {
|
});
|
||||||
var subs = [];
|
/*! 筛选出当前选中的城市 */
|
||||||
item.subs.forEach(function (item) {
|
$rootScope.citys.forEach(function (province) {
|
||||||
if (item.status && item.show) subs.push(item);
|
_province_cache[province.name] = _province_cache[province.name] || {name: province.name, subs: []};
|
||||||
})
|
province.subs.forEach(function (city) {
|
||||||
if (subs.length > 0) {
|
if (city.status && city.show && !_city_cache[province.name + '-' + city.name]) {
|
||||||
if (cache[item.name]) subs = cache[item.name].subs.concat(subs);
|
_province_cache[province.name].subs.push(city);
|
||||||
else $rootScope.rule.city.push({name: item.name, subs: subs});
|
_city_cache[province.name + '-' + city.name] = true;
|
||||||
cache[item.name] = subs;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
/* 将临时数据转换为区域规则选项 */
|
||||||
|
var provinces = [], province = {};
|
||||||
|
for (var i in _province_cache) {
|
||||||
|
province = {name: _province_cache[i].name, subs: []};
|
||||||
|
_province_cache[i].subs.forEach(function (item) {
|
||||||
|
if (item.status) province.subs.push(item);
|
||||||
|
});
|
||||||
|
if (province.subs.length > 0) provinces.push(province);
|
||||||
|
}
|
||||||
|
$rootScope.rule.city = provinces;
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user