area.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. use common\helpers\Html;
  3. ?>
  4. <?= $form->field($model, $provincesName)->hiddenInput(['id' => 'provinceIds'])->label(false) ?>
  5. <?php if ($level >= 2) {
  6. echo $form->field($model, $cityName)->hiddenInput(['id' => 'cityIds'])->label(false);
  7. } ?>
  8. <?php if ($level >= 3) {
  9. echo $form->field($model, $areaName)->hiddenInput(['id' => 'areaIds'])->label(false);
  10. } ?>
  11. <style>
  12. .rf-area .table > thead > tr > th,
  13. .rf-area .table > tbody > tr > th,
  14. .rf-area .table > tfoot > tr > th,
  15. .rf-area .table > thead > tr > td,
  16. .rf-area .table > tbody > tr > td,
  17. .rf-area .table > tfoot > tr > td {
  18. border-top: 1px solid #fff;
  19. padding: 3px;
  20. }
  21. </style>
  22. <!--模拟框加载 -->
  23. <div class="modal fade" id="ajaxModalLgForExpress" aria-hidden="true">
  24. <div class="modal-dialog modal-xl">
  25. <div class="modal-content">
  26. <div class="modal-header">
  27. <h4 class="modal-title">选择地区</h4>
  28. <button type="button" class="close closeAjaxModalLgForExpress" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  29. </div>
  30. <div class="modal-body rf-area" style="overflow: visible">
  31. <table class="table">
  32. <tbody>
  33. <?php foreach ($addressList as $key => $item) { ?>
  34. <tr>
  35. <td width="20%" align="center">
  36. <?= Html::checkbox('region', false, [
  37. 'data-first-index' => $key,
  38. ]) ?>
  39. <label for=""><?= $key; ?></label>
  40. </td>
  41. <td class="js-regions">
  42. <?php foreach ($item as $province) { ?>
  43. <div class="shopProvinces">
  44. <?= Html::checkbox('province[]', false, [
  45. 'data-second-parent-index' => $key,
  46. 'data-is-disabled' => $province['is_disabled'],
  47. 'data-province-id' => $province['id'],
  48. 'data-province-name' => $province['title'],
  49. 'value' => $province['id'],
  50. 'disabled' => $province['is_disabled']
  51. ]); ?>
  52. <label for=""><?= $province['title']; ?></label>
  53. <!-- 显示市-->
  54. <?php if ($level >= 2) { ?>
  55. <i class="icon ion-arrow-down-b drop-down" data-level="province"
  56. data-open="0"></i>
  57. <div class="shopCitys">
  58. <?php foreach ($province['-'] as $city) { ?>
  59. <div>
  60. <?= Html::checkbox('city[]', false, [
  61. 'data-third-parent-index' => $key,
  62. 'data-is-disabled' => $city['is_disabled'],
  63. 'data-province-id' => $province['id'],
  64. 'data-city-id' => $city['id'],
  65. 'value' => $city['id'],
  66. 'disabled' => $city['is_disabled']
  67. ]) ?>
  68. <label for=""><?= $city['title']; ?></label>
  69. <!-- 显示区-->
  70. <?php if ($level >= 3) { ?>
  71. <i class="icon ion-arrow-down-b drop-down" data-level="city"
  72. data-open="0"></i>
  73. <div class="shopAreas">
  74. <?php foreach ($city['-'] as $area) { ?>
  75. <span>
  76. <?= Html::checkbox('area[]', false, [
  77. 'data-four-parent-index' => $key,
  78. 'data-is-disabled' => $area['is_disabled'],
  79. 'data-province-id' => $province['id'],
  80. 'data-city-id' => $city['id'],
  81. 'value' => $area['id'],
  82. 'disabled' => $area['is_disabled']
  83. ]); ?>
  84. <label for=""><?= $area['title']; ?></label>
  85. </span>
  86. <?php } ?>
  87. </div>
  88. <?php } ?>
  89. </div>
  90. <?php } ?>
  91. </div>
  92. <?php } ?>
  93. </div>
  94. <?php } ?>
  95. </td>
  96. </tr>
  97. <?php } ?>
  98. </tbody>
  99. </table>
  100. </div>
  101. <div class="modal-footer">
  102. <button type="button" class="btn btn-white closeAjaxModalLgForExpress">关闭</button>
  103. <button type="button" class="btn btn-primary js-confirm closeAjaxModalLgForExpress">保存</button>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <input type="hidden" id="feeId" value="<?= $model['id'] ?>"/>
  109. <script>
  110. /**
  111. * 确定选择地区
  112. */
  113. $(".js-confirm").click(function () {
  114. setProvinceIdArray();
  115. setCityIdArray();
  116. setDistrictIdArray();
  117. $(".js-region-info").html(getRegions());
  118. });
  119. // 隐藏model
  120. $(".closeAjaxModalLgForExpress").click(function () {
  121. $('#ajaxModalLgForExpress').modal("hide");
  122. });
  123. // 小模拟框清除
  124. $('#ajaxModalLgForExpress').on('hide.bs.modal', function () {
  125. $('.shopCitys').removeClass('show');
  126. $('.shopAreas').removeClass('show');
  127. $('.shopProvinces').removeClass('open');
  128. });
  129. // 选择下拉框
  130. $('.drop-down').click(function () {
  131. var level = $(this).data('level');
  132. if (level == 'province') {
  133. $('.shopCitys').removeClass('show');
  134. $('.shopAreas').removeClass('show');
  135. $('.shopProvinces').removeClass('open');
  136. if ($(this).data('open') == 0) {
  137. $(this).next().addClass('show');
  138. $(this).parent().addClass('open');
  139. $(this).data('open', 1);
  140. } else {
  141. $(this).data('open', 0);
  142. }
  143. } else {
  144. var left = $(this).prev().position().left - 25;
  145. var top = $(this).position().top + 22;
  146. $('.shopAreas').removeClass('show');
  147. if ($(this).data('open') == 0) {
  148. $(this).next().addClass('show');
  149. $(this).next().css({
  150. 'left': left,
  151. 'top': top,
  152. });
  153. $(this).data('open', 1);
  154. } else {
  155. $(this).data('open', 0);
  156. }
  157. }
  158. });
  159. /**
  160. * 修改运费模板时,把弹出框的地区选择选中
  161. */
  162. if (parseInt($("#feeId").val())) {
  163. //省id组
  164. if ($("#provinceIds").val()) {
  165. var province_id_array = $("#provinceIds").val().split(",");
  166. for (var i = 0; i < province_id_array.length; i++) {
  167. if (province_id_array[i]) {
  168. $("input[data-second-parent-index][value='" + province_id_array[i] + "']").prop("checked", true);
  169. }
  170. }
  171. }
  172. //市id组
  173. if ($("#cityIds").val()) {
  174. var city_id_array = $("#cityIds").val().split(",");
  175. for (var i = 0; i < city_id_array.length; i++) {
  176. if (city_id_array[i]) {
  177. $("input[data-third-parent-index][value='" + city_id_array[i] + "']").prop("checked", true);
  178. }
  179. }
  180. }
  181. //区县id组
  182. if ($("#areaIds").val()) {
  183. var district_id_array = $("#areaIds").val().split(",");
  184. for (var i = 0; i < district_id_array.length; i++) {
  185. if (district_id_array[i]) {
  186. $("input[data-four-parent-index][value='" + district_id_array[i] + "']").prop("checked", true);
  187. }
  188. }
  189. }
  190. $(".js-region-info").html(getRegions());
  191. }
  192. /**
  193. * 一级地区(大类)例如:华北、华东、东北、西北、港澳台等
  194. * 根据当前地区的选中状态对应的改变它的子地区
  195. */
  196. $("input[data-first-index]").change(function () {
  197. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  198. var curr = $(this);//当前对象
  199. var index = curr.attr("data-first-index");//索引
  200. var checked = curr.is(":checked");//选中状态
  201. //省
  202. if ($("input[data-second-parent-index='" + index + "']").length) {
  203. $("input[data-second-parent-index='" + index + "']").each(function () {
  204. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  205. $(this).prop("checked", checked);
  206. }
  207. });
  208. //市
  209. if ($("input[data-third-parent-index='" + index + "']").length) {
  210. $("input[data-third-parent-index='" + index + "']").each(function () {
  211. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  212. $(this).prop("checked", checked);
  213. }
  214. });
  215. //区县
  216. if ($("input[data-four-parent-index='" + index + "']").length) {
  217. $("input[data-four-parent-index='" + index + "']").each(function () {
  218. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  219. $(this).prop("checked", checked);
  220. }
  221. });
  222. }
  223. }
  224. }
  225. }
  226. });
  227. /**
  228. * 二级地区(省)例如:山西省、山东省、河北省等
  229. * 根据当前地区的选中状态对应的改变它的子地区
  230. */
  231. $("input[data-second-parent-index]").change(function () {
  232. var curr = $(this);//当前对象
  233. var checked = curr.is(":checked");//选中状态
  234. if (curr.parent().find("div input[type='checkbox']").length) {
  235. curr.parent().find("div input[type='checkbox']").each(function () {
  236. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  237. $(this).prop("checked", checked);
  238. }
  239. });
  240. }
  241. });
  242. /**
  243. * 三级地区(市区)例如:太原市、运城市等
  244. * 只要改变了三级地区那它的上一级为不选中状态
  245. */
  246. $("input[data-third-parent-index]").change(function () {
  247. var curr = $(this);//当前对象
  248. var checked = curr.is(":checked");//选中状态
  249. if (curr.parent().find("div input[type='checkbox']").length) {
  250. curr.parent().find("div input[type='checkbox']").each(function () {
  251. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  252. $(this).prop("checked", checked);
  253. }
  254. });
  255. }
  256. //一个没有选择,父级则不选中
  257. if (curr.parent().parent().children("div").children("input[type='checkbox']:checked").length == 0) {
  258. curr.parent().parent().parent().children("input").prop("checked", false);
  259. }
  260. //选中一个,父类则选中
  261. if (checked) curr.parent().parent().parent().children("input").prop("checked", true);
  262. });
  263. // 四级地区(区县)选择一个区县,父类(省市就选中)
  264. $("input[data-four-parent-index]").change(function () {
  265. var curr = $(this);
  266. var checked = curr.is(":checked");//选中状态
  267. var index = curr.attr("data-four-parent-index");//下标
  268. var province_id = curr.attr("data-province-id");//父级,省id
  269. var city_id = curr.attr("data-city-id");//父级,市id
  270. //一个没有选择,父级则不选中
  271. if (curr.parent().parent().children("span").children("input[type='checkbox']:checked").length == 0) {
  272. curr.parent().parent().parent().children("input").prop("checked", false);
  273. }
  274. //选中一个,父类则选中
  275. if (checked) {
  276. $("[data-second-parent-index='" + index + "'][data-province-id='" + province_id + "']").prop("checked", true);
  277. $("[data-third-parent-index='" + index + "'][data-city-id='" + city_id + "']").prop("checked", true);
  278. }
  279. });
  280. // 获取选中的地区(只显示省),逗号隔开
  281. function getRegions() {
  282. var regions_arr = [];
  283. if ($(".js-regions input[data-second-parent-index]:checked").length) {
  284. $(".js-regions input[data-second-parent-index]:checked").each(function () {
  285. regions_arr.push($(this).attr("data-province-name"));
  286. });
  287. }
  288. return regions_arr.toString();//.replace(",","&nbsp;,&nbsp;");
  289. }
  290. // 保存选中的省id组
  291. function setProvinceIdArray() {
  292. var id_arr = [];
  293. if ($(".js-regions input[data-second-parent-index]:checked").length) {
  294. $(".js-regions input[data-second-parent-index]:checked").each(function () {
  295. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  296. id_arr.push($(this).val());
  297. }
  298. });
  299. }
  300. $("#provinceIds").val(id_arr.toString());
  301. }
  302. // 保存选中的市id组
  303. function setCityIdArray() {
  304. var id_arr = [];
  305. if ($(".js-regions input[data-third-parent-index]:checked").length) {
  306. $(".js-regions input[data-third-parent-index]:checked").each(function () {
  307. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  308. id_arr.push($(this).val());
  309. }
  310. });
  311. }
  312. $("#cityIds").val(id_arr);// 市id
  313. }
  314. // 保存选中的区县id组
  315. function setDistrictIdArray() {
  316. var id_arr = [];
  317. if ($(".js-regions input[data-four-parent-index]:checked").length) {
  318. $(".js-regions input[data-four-parent-index]:checked").each(function () {
  319. if (!$(this).is(":disabled") && !$(this).attr("data-is-disabled")) {
  320. id_arr.push($(this).val());
  321. }
  322. });
  323. }
  324. $("#areaIds").val(id_arr);// 区县id
  325. }
  326. </script>
粤ICP备19079148号