embargoedArea.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. define({
  2. name: "embargoedArea",
  3. template: `
  4. <div id='re_content'>
  5. <div class="con">
  6. <div class="setting">
  7. <el-form ref="form" label-width="15%">
  8. <div class="block">
  9. <div class="title"><span
  10. style="width: 4px;height: 18px;background-color: #29ba9c;margin-right:15px;display:inline-block;"></span><b>禁运区设置</b>
  11. </div>
  12. <el-form-item label="不配送区域">
  13. <div style="font-size:12px;font-weight:600;line-height:18px;margin-right: 15px">
  14. {{areas}}
  15. </div>
  16. <el-button size="small" @click="openVisible()">选择区域</el-button>
  17. <div style="color:#737373;font-size:12px;">只针对平台自营商品订单,不包括供应商、门店</div>
  18. </el-form-item>
  19. </div>
  20. </el-form>
  21. </div>
  22. </div>
  23. <el-dialog title="请选择地区" :visible.sync="centerDialogVisible" center v-if="showVisible"
  24. :before-close="beforeClose">
  25. <el-tree
  26. v-loading="loading"
  27. :props="props"
  28. node-key="id"
  29. :default-checked-keys="area_ids"
  30. :default-expanded-keys="province_ids"
  31. show-checkbox
  32. lazy
  33. @check-change="checkAreas"
  34. ref="addressTree"
  35. :data="treeData"
  36. :load="loadNode"
  37. style="height:500px;overflow:auto"
  38. >
  39. </el-tree>
  40. <span slot="footer" class="dialog-footer">
  41. <el-button @click="beforeClose">取 消</el-button>
  42. <el-button type="primary" @click="saveAreas">确 定</el-button>
  43. </span>
  44. </el-dialog>
  45. </div>
  46. `,
  47. data() {
  48. return {
  49. activeName: 'one',
  50. forms: {},
  51. area_ids: [],
  52. province_ids: [],
  53. areas: '',
  54. areaIds: '',
  55. provinceIds: '',
  56. chooseAreas: [],
  57. chooseAreaIds: [],
  58. chooseProvinceIds: [],
  59. centerDialogVisible: false,
  60. showVisible: false,
  61. loading: false,
  62. treeData: [],
  63. props: {
  64. label: 'areaname',
  65. children: 'children',
  66. isLeaf: 'isLeaf'
  67. },
  68. };
  69. },
  70. style: `
  71. <style>
  72. .panel {
  73. margin-bottom: 10px !important;
  74. padding-left: 20px;
  75. border-radius: 10px;
  76. }
  77. .panel .active a {
  78. background-color: #29ba9c !important;
  79. border-radius: 18px !important;
  80. color: #fff;
  81. }
  82. .panel a {
  83. border: none !important;
  84. background-color: #fff !important;
  85. }
  86. .content {
  87. background: #eff3f6;
  88. padding: 10px !important;
  89. }
  90. .con {
  91. padding-bottom: 20px;
  92. position: relative;
  93. border-radius: 8px;
  94. min-height: 100vh;
  95. background-color: #fff;
  96. }
  97. .con .setting .block {
  98. padding: 10px;
  99. background-color: #fff;
  100. border-radius: 8px;
  101. }
  102. .con .setting .block .title {
  103. font-size: 18px;
  104. margin-bottom: 15px;
  105. display: flex;
  106. align-items: center;
  107. }
  108. .confirm-btn {
  109. width: calc(100% - 266px);
  110. position: fixed;
  111. bottom: 0;
  112. right: 0;
  113. margin-right: 10px;
  114. line-height: 63px;
  115. background-color: #ffffff;
  116. box-shadow: 0px 8px 23px 1px rgba(51, 51, 51, 0.3);
  117. background-color: #fff;
  118. text-align: center;
  119. }
  120. b {
  121. font-size: 14px;
  122. }
  123. `,
  124. mounted() {
  125. this.getData()
  126. },
  127. methods: {
  128. getData() {
  129. if (JSON.stringify(this.form) !== '[]') {
  130. this.area_ids = this.form.area_ids;
  131. this.province_ids = this.form.province_ids;
  132. this.areas = this.form.areas;
  133. }
  134. },
  135. openVisible() {
  136. this.centerDialogVisible = true;
  137. this.showVisible = true;
  138. if(this.area_ids){
  139. this.area_ids.forEach((item, index) => {
  140. this.area_ids[index] = Number(item)
  141. });
  142. }
  143. },
  144. loadNode(node, resolve) {
  145. this.loading = true;
  146. if (!node.data.id) {
  147. //省份
  148. node.data.id = 0;
  149. this.$http.get(this.http_url + "area.list&parent_id=0").then(response => {
  150. response.data.data.forEach(function (province) {
  151. province.isLeaf = false;
  152. });
  153. resolve(response.data.data);
  154. this.loading = false;
  155. }, response => {
  156. console.log(response);
  157. });
  158. } else {
  159. //城市
  160. this.$http.get(this.http_url + "area.list&parent_id=" + node.data.id).then(response => {
  161. //城市没有子节点
  162. response.data.data.forEach(function (city) {
  163. city.isLeaf = true;
  164. })
  165. resolve(response.data.data);
  166. // 载入数据后,刷新已选中
  167. this.loading = false;
  168. }, response => {
  169. console.log(response);
  170. });
  171. }
  172. },
  173. checkAreas(node, checked, children) {
  174. if (node.isLeaf) {
  175. return;
  176. }
  177. if (checked) {
  178. if (!this.province_ids) {
  179. this.province_ids = [];
  180. }
  181. this.province_ids.push(node.id)
  182. }
  183. },
  184. saveAreas() {
  185. let areas = [];
  186. let area_ids = [];
  187. let province_ids = [];
  188. this.$refs.addressTree.getCheckedNodes().forEach(function (node) {
  189. if (node.level == 1) {
  190. province_ids.push(node.id);
  191. } else if (node.level == 2) {
  192. area_ids.push(node.id);
  193. areas.push(node.areaname)
  194. }
  195. });
  196. this.$refs.addressTree.getHalfCheckedNodes().forEach(function (node) {
  197. if (node.level == 1) {
  198. province_ids.push(node.id);
  199. }
  200. });
  201. this.province_ids = province_ids;
  202. this.area_ids = area_ids;
  203. this.areas = areas.join(";");
  204. this.areaIds = area_ids.join(";");
  205. this.provinceIds = province_ids.join(";");
  206. this.centerDialogVisible = false
  207. this.showVisible = false;
  208. },
  209. beforeClose() {
  210. this.centerDialogVisible = false;
  211. this.showVisible = false;
  212. },
  213. handleClose(area) {
  214. this.forms.areas.splice(this.forms.areas.indexOf(area), 1);
  215. },
  216. validate(){
  217. return {
  218. area_ids:this.area_ids ? this.area_ids : [],
  219. province_ids:this.province_ids ? this.province_ids : [],
  220. areas: this.areas ? this.areas : "",
  221. }
  222. }
  223. },
  224. props: {
  225. form: {
  226. default() {
  227. return {};
  228. },
  229. },
  230. http_url:{
  231. type:String,
  232. default() {
  233. return "";
  234. },
  235. }
  236. },
  237. });