widget-goods.blade.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <style>
  2. .el-dialog__wrapper {
  3. height: 100%;
  4. width: 100% !important;
  5. margin: 50px auto;
  6. background-color:transparent;
  7. }
  8. </style>
  9. <div class='panel panel-default'>
  10. <div class='panel-heading'>
  11. 禁运区域设置
  12. </div>
  13. <div class='panel-body'>
  14. <div id='embargoed_area_goods'>
  15. <div class="form-group">
  16. <label for="firstname" class="col-sm-2 control-label">不配送区域</label>
  17. <div class="col-sm-8 input-group ">
  18. <input type="hidden" name="widgets[embargoed_area][area_ids]" class="form-control" v-model="area_ids"/>
  19. <input type="hidden" name="widgets[embargoed_area][province_ids]" class="form-control" v-model="province_ids"/>
  20. <input type="hidden" name="widgets[embargoed_area][areas]" class="form-control" v-model="areas"/>
  21. <div v-html="areas"></div>
  22. <span class='help-block'>
  23. <input class="btn btn-success" type="button" @click="openVisible" value="选择区域" >
  24. </span>
  25. </div>
  26. </div>
  27. <div>
  28. <el-dialog title="请选择地区" :visible.sync="centerDialogVisible" center v-if="showVisible"
  29. :before-close="embargoedAreaBeforeClose">
  30. <el-tree
  31. v-loading="loading"
  32. :props="props"
  33. node-key="id"
  34. :default-checked-keys="area_ids"
  35. :default-expanded-keys="province_ids"
  36. show-checkbox
  37. lazy
  38. @check-change="checkAreas"
  39. ref="addressTree"
  40. :data="treeData"
  41. :load="loadNode"
  42. >
  43. </el-tree>
  44. <span slot="footer" class="dialog-footer">
  45. <el-button @click="embargoedAreaBeforeClose">取 消</el-button>
  46. <el-button type="primary" @click="saveAreas">确 定</el-button>
  47. </span>
  48. </el-dialog>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. <script>
  54. var vm = new Vue({
  55. el: "#embargoed_area_goods",
  56. delimiters: ['[[', ']]'],
  57. data() {
  58. return {
  59. activeName: 'one',
  60. area_ids: [],
  61. province_ids: [],
  62. areas: '',
  63. areaIds: '',
  64. provinceIds: '',
  65. chooseAreas: [],
  66. chooseAreaIds: [],
  67. chooseProvinceIds: [],
  68. centerDialogVisible: false,
  69. showVisible: false,
  70. loading: false,
  71. treeData: [],
  72. props: {
  73. label: 'areaname',
  74. children: 'children',
  75. isLeaf: 'isLeaf'
  76. },
  77. }
  78. },
  79. mounted() {
  80. // this.getData()
  81. },
  82. created: function () {
  83. this.getData()
  84. },
  85. methods: {
  86. getViewItem: function () {
  87. return {!! $item !!}
  88. },
  89. getData() {
  90. let initValue = this.getViewItem();
  91. if (initValue) {
  92. console.log(initValue);
  93. this.area_ids = initValue.area_ids;
  94. this.province_ids = initValue.province_ids;
  95. this.areas = initValue.areas;
  96. }
  97. },
  98. openVisible() {
  99. this.centerDialogVisible = true;
  100. this.showVisible = true;
  101. this.area_ids.forEach((item, index) => {
  102. this.area_ids[index] = Number(item)
  103. });
  104. this.province_ids.forEach((item, index) => {
  105. this.province_ids[index] = Number(item)
  106. });
  107. },
  108. loadNode(node, resolve) {
  109. this.loading = true;
  110. if (!node.data.id) {
  111. //省份
  112. node.data.id = 0;
  113. this.$http.get("{!! yzWebUrl('area.list', ['parent_id'=> 0]) !!}").then(response => {
  114. response.data.data.forEach(function (province) {
  115. province.isLeaf = false;
  116. });
  117. resolve(response.data.data);
  118. this.loading = false;
  119. }, response => {
  120. console.log(response);
  121. });
  122. } else {
  123. //城市
  124. this.$http.get("{!! yzWebUrl('area.list', ['parent_id'=> '']) !!}" + node.data.id).then(response => {
  125. //城市没有子节点
  126. response.data.data.forEach(function (city) {
  127. city.isLeaf = true;
  128. })
  129. resolve(response.data.data);
  130. // 载入数据后,刷新已选中
  131. this.loading = false;
  132. }, response => {
  133. console.log(response);
  134. });
  135. }
  136. },
  137. checkAreas(node, checked, children) {
  138. if (node.isLeaf) {
  139. return;
  140. }
  141. if (checked) {
  142. if (!this.province_ids) {
  143. this.province_ids = [];
  144. }
  145. this.province_ids.push(node.id)
  146. }
  147. },
  148. saveAreas() {
  149. let areas = [];
  150. let area_ids = [];
  151. let province_ids = [];
  152. this.$refs.addressTree.getCheckedNodes().forEach(function (node) {
  153. if (node.level == 1) {
  154. province_ids.push(node.id);
  155. } else if (node.level == 2) {
  156. area_ids.push(node.id);
  157. areas.push(node.areaname)
  158. }
  159. });
  160. this.$refs.addressTree.getHalfCheckedNodes().forEach(function (node) {
  161. if (node.level == 1) {
  162. province_ids.push(node.id);
  163. }
  164. });
  165. this.province_ids = province_ids;
  166. this.area_ids = area_ids;
  167. this.areas = areas.join(";");
  168. this.areaIds = area_ids.join(";");
  169. this.provinceIds = province_ids.join(";");
  170. this.centerDialogVisible = false;
  171. this.showVisible = false;
  172. },
  173. embargoedAreaBeforeClose() {
  174. this.centerDialogVisible = false;
  175. this.showVisible = false;
  176. },
  177. },
  178. });
  179. </script>