city.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <style>
  4. .smallplace .citys {
  5. width: auto;
  6. background-color: #fff;
  7. position: absolute;
  8. top: 33px;
  9. border: 1px solid #ccc;
  10. z-index: 100;
  11. display: none;
  12. }
  13. .smallplace .citys.on {
  14. display: block;
  15. }
  16. .smallplace .citys > i.jt {
  17. width: 0;
  18. height: 0;
  19. border-left: 8px solid transparent;
  20. border-right: 8px solid transparent;
  21. border-bottom: 10px solid #ccc;
  22. position: absolute;
  23. top: -10px;
  24. left: 20px;
  25. }
  26. .smallplace .citys .row-div {
  27. min-width: 250px;
  28. padding: 10px;
  29. box-sizing: border-box;
  30. }
  31. .clearfloat {
  32. zoom: 1;
  33. }
  34. .layui-input-block {
  35. margin-left: 0
  36. }
  37. .jt-mk{
  38. display: block;
  39. position: absolute;
  40. top: -10px;
  41. left: 20px;
  42. width: 252px;
  43. height: 10px;
  44. background-color: rgba(255, 255, 255, 0);
  45. margin-left: -21px;
  46. }
  47. </style>
  48. <div class="layui-fluid" style="background: #fff;margin-top: -10px;">
  49. <div class="layui-row layui-col-space15" id="app" v-cloak="">
  50. <div class="layui-col-md12">
  51. <div class="layui-card">
  52. <div class="layui-card-body" style="text-align: right">
  53. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" @click="save">确定</button>
  54. <button type="button" class="layui-btn layui-btn-warm layui-btn-sm" @click="clerl">取消</button>
  55. </div>
  56. <div class="layui-card-body">
  57. <form class="layui-form" action="">
  58. <div class="layui-form-item" pane="">
  59. <div class="layui-input-block" v-cloak="">
  60. <span @click="allCheckbox(true)">
  61. <input type="radio" name="select" title="全选">
  62. </span>
  63. <span @click="allCheckbox(false)">
  64. <input type="radio" name="select" title="取消">
  65. </span>
  66. </div>
  67. </div>
  68. <div class="layui-form-item" pane="">
  69. <div class="layui-input-block" v-cloak="">
  70. <div style="margin-top: 15px;position: relative"
  71. class="layui-col-md3 layui-col-lg3 layui-col-xs3 layui-col-sm3 selected"
  72. v-for="(item,index) in cityList" @click="checkedClick(index)">
  73. <input ref="checkbox" type="checkbox" lay-skin="primary" :title="item.name"
  74. :checked="item.checked ? true : false" lay-filter="city" :value="index">
  75. <span style="color: #ff0000">({{(item.count || 0) + '/' + item.children.length}})</span>
  76. <div class="smallplace" @click.stop="">
  77. <div class="citys" :class="item.on ? 'on' : ''">
  78. <i class="jt"><i></i></i>
  79. <i class="jt-mk"></i>
  80. <div class="row-div clearfloat" style="max-width: 300px">
  81. <div class="layui-form-item" pane="">
  82. <div class="layui-input-block" v-cloak="" style="margin-left: 0;">
  83. <span v-for="(val,i) in item.children"
  84. @click="primary(index,i)">
  85. <input type="checkbox" ref="primary" lay-skin="primary"
  86. :title="val.name"
  87. :checked="val.checked ? true : false">
  88. </span>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </form>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  104. {/block}
  105. {block name="script"}
  106. <script>
  107. var type=<?=$type?>;
  108. mpFrame.start(function (Vue) {
  109. new Vue({
  110. el: "#app",
  111. data: {
  112. cityList: [],
  113. areaList: [],
  114. selectList: {}
  115. },
  116. methods: {
  117. /**
  118. * 确认选中
  119. */
  120. save: function () {
  121. var that = this;
  122. var selectList = [];
  123. $.each(this.cityList, function (key, item) {
  124. var data = {};
  125. if (item.checked || item.children.find(function (k) {
  126. return !!k.checked;
  127. })) {
  128. data = {
  129. name: item.name,
  130. city_id: item.city_id,
  131. children: []
  132. };
  133. for (index in item.children) {
  134. if (!!item.children[index].checked) {
  135. data.children.push({
  136. city_id: item.children[index].city_id,
  137. });
  138. }
  139. }
  140. selectList.push(data);
  141. }
  142. });
  143. if(selectList.length ==0){
  144. return that.showMsg('至少选择一个省份或者城市');
  145. }
  146. parent.selectCity(selectList,type);
  147. var index = parent.layer.getFrameIndex(window.name);
  148. parent.layer.close(index);
  149. },
  150. /**
  151. * 关闭
  152. */
  153. clerl: function () {
  154. var index = parent.layer.getFrameIndex(window.name);
  155. parent.layer.close(index);
  156. },
  157. /**
  158. * 全选或者反选
  159. * @param checked
  160. */
  161. allCheckbox: function (checked) {
  162. var that = this;
  163. $.each(this.cityList, function (key, item) {
  164. that.$set(that.cityList[key], 'checked', checked);
  165. if (checked) {
  166. that.$set(that.cityList[key], 'count', that.cityList[key].children.length);
  167. } else {
  168. that.$set(that.cityList[key], 'count', 0);
  169. }
  170. $.each(that.cityList[key].children, function (k, val) {
  171. that.$set(that.cityList[key].children[k], 'checked', checked);
  172. })
  173. });
  174. this.render();
  175. },
  176. /**
  177. * 获取城市列表,绑定事件
  178. */
  179. getCityList() {
  180. var that = this;
  181. layList.baseGet(layList.U({a: "city_list", q: {id: 0}}), function (res) {
  182. that.$set(that, 'cityList', res.data);
  183. that.render();
  184. that.$nextTick(function () {
  185. this.$nextTick(function () {
  186. layList.form.render('radio');
  187. $('.selected').on({
  188. mouseover: function (event) {
  189. event.stopPropagation()
  190. $(this).find('.citys').addClass('on');
  191. },
  192. mouseout: function (event) {
  193. event.stopPropagation()
  194. $(this).find('.citys').removeClass('on');
  195. }
  196. })
  197. })
  198. });
  199. });
  200. },
  201. /**
  202. * 重新渲染checkbox
  203. */
  204. render: function () {
  205. this.$nextTick(function () {
  206. layList.form.render('checkbox');
  207. })
  208. },
  209. showMsg: function (msg, success) {
  210. layui.use(['layer'], function () {
  211. layui.layer.msg(msg, success);
  212. });
  213. },
  214. /**
  215. * 点击省
  216. * @param index
  217. */
  218. checkedClick: function (index) {
  219. var that = this;
  220. if (this.$refs.checkbox[index].checked) {
  221. that.$set(that.cityList[index], 'count', that.cityList[index].children.length);
  222. that.$set(that.cityList[index], 'checked', true);
  223. $.each(that.cityList[index].children, function (key, item) {
  224. that.$set(that.cityList[index].children[key], 'checked', true);
  225. })
  226. } else {
  227. that.$set(that.cityList[index], 'count', 0);
  228. that.$set(that.cityList[index], 'checked', false);
  229. $.each(that.cityList[index].children, function (key, item) {
  230. that.$set(that.cityList[index].children[key], 'checked', false);
  231. })
  232. }
  233. this.render();
  234. },
  235. /**
  236. * 点击市区
  237. * @param index
  238. * @param ind
  239. */
  240. primary: function (index, ind) {
  241. var checked = false, count = 0;
  242. if (this.cityList[index].children[ind].checked === undefined) {
  243. this.$set(this.cityList[index].children[ind], 'checked', true)
  244. } else {
  245. this.$set(this.cityList[index].children[ind], 'checked', !this.cityList[index].children[ind].checked);
  246. }
  247. $.each(this.cityList[index].children, function (key, item) {
  248. if (item.checked) {
  249. checked = true;
  250. count++;
  251. }
  252. });
  253. this.$set(this.cityList[index], 'count', count);
  254. this.$set(this.cityList[index], 'checked', checked);
  255. this.render();
  256. }
  257. },
  258. mounted: function () {
  259. this.getCityList();
  260. }
  261. })
  262. })
  263. </script>
  264. {/block}