byArea.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div class="by-area">
  3. <el-row>
  4. <el-col :span="6">
  5. <div class="area-box first">
  6. <div class="left-label">省:</div>
  7. <div class="right-area">
  8. <el-select v-model="provinceCode" clearable :disabled="attrs.disabled" class="areaSelect" :class="{'error':provinceError}" @change="onProvince" size="small" placeholder="请选择省">
  9. <el-option
  10. v-for="item in optionsProvince"
  11. :key="item.id"
  12. :label="item.name"
  13. :value="item.code">
  14. </el-option>
  15. </el-select>
  16. </div>
  17. </div>
  18. </el-col>
  19. <el-col :span="6" v-if="!attrs.show || attrs.show != 'province'">
  20. <div class="area-box">
  21. <div class="left-label">市:</div>
  22. <div class="right-area">
  23. <el-select v-model="cityCode" clearable :disabled="attrs.disabled" class="areaSelect" :class="{'error':cityError}" @change="onCity" size="small" placeholder="请选择市">
  24. <el-option
  25. v-for="item in optionsCity"
  26. :key="item.id"
  27. :label="item.name"
  28. :value="item.code">
  29. </el-option>
  30. </el-select>
  31. </div>
  32. </div>
  33. </el-col>
  34. <el-col :span="6" v-if="!attrs.show || (attrs.show != 'province' && attrs.show != 'city')">
  35. <div class="area-box last">
  36. <div class="left-label">区/县:</div>
  37. <div class="right-area">
  38. <el-select v-model="countyCode" clearable :disabled="attrs.disabled" class="areaSelect" :class="{'error':countyError}" @change="onCounty" size="small" placeholder="请选择区/县">
  39. <el-option
  40. v-for="item in optionsCounty"
  41. :key="item.id"
  42. :label="item.name"
  43. :value="item.code">
  44. </el-option>
  45. </el-select>
  46. </div>
  47. </div>
  48. </el-col>
  49. <el-col :span="6" v-if="!attrs.show || (attrs.show != 'province' && attrs.show != 'city' && attrs.show != 'county')" >
  50. <div class="area-box last">
  51. <div class="left-label">街道:</div>
  52. <div class="right-area">
  53. <el-select v-model="townCode" clearable :disabled="attrs.disabled" class="areaSelect" @change="onTown" size="small" placeholder="请选择街道">
  54. <el-option
  55. v-for="item in optionsTown"
  56. :key="item.id"
  57. :label="item.name"
  58. :value="item.code">
  59. </el-option>
  60. </el-select>
  61. </div>
  62. </div>
  63. </el-col>
  64. </el-row>
  65. </div>
  66. </template>
  67. <script lang="ts">
  68. /*
  69. config:{
  70. attr:{
  71. province:'' //省
  72. provinceCode:'' //省编码
  73. city:'' //市
  74. cityCode:'' //市编码
  75. county:'' //县/区
  76. countyCode:'' //县/区编码
  77. town:'' //街道
  78. townCode:'' //街道编码
  79. show:'province/city/county' //显示的层级
  80. }
  81. }
  82. */
  83. import { Component, Prop, Vue, Mixins,Watch } from "vue-property-decorator";
  84. import VueViews from '@/benyun/compVue/VueViews'
  85. @Component
  86. export default class ByArea extends VueViews {
  87. provinceCode='';
  88. cityCode='';
  89. countyCode='';
  90. townCode='';
  91. province='';
  92. city='';
  93. county='';
  94. town='';
  95. area='';
  96. areaCode='';
  97. optionsProvince:Array<any>=[];
  98. optionsCity:Array<any>=[];
  99. optionsCounty:Array<any>=[];
  100. optionsTown:Array<any>=[];
  101. provinceError = false;
  102. cityError = false;
  103. countyError = false;
  104. @Watch('propValue')
  105. propValueChange(v:any){
  106. this.setValue(v);
  107. }
  108. created(){
  109. if(this.propConfig){
  110. this.setConfig(this.propConfig)
  111. }
  112. if(this.parentValue){
  113. this.setAllValue(this.parentValue);
  114. }
  115. }
  116. mounted(){
  117. this.getProvince();
  118. }
  119. setAllValue(data:any){
  120. if(this.attrs.province){
  121. this.province=data[this.attrs.province];
  122. }
  123. if(this.attrs.provinceCode){
  124. this.provinceCode=data[this.attrs.provinceCode];
  125. }
  126. if(this.attrs.city){
  127. this.city=data[this.attrs.city];
  128. }
  129. if(this.attrs.cityCode){
  130. this.cityCode=data[this.attrs.cityCode];
  131. if(this.provinceCode){
  132. this.getCity(this.provinceCode);
  133. }
  134. }
  135. if(this.attrs.county){
  136. this.county=data[this.attrs.county];
  137. }
  138. if(this.attrs.countyCode){
  139. this.countyCode=data[this.attrs.countyCode];
  140. if(this.cityCode){
  141. this.getCounty(this.cityCode);
  142. }
  143. }
  144. if(this.attrs.town){
  145. this.town=data[this.attrs.town];
  146. }
  147. if(this.attrs.townCode){
  148. this.townCode=data[this.attrs.townCode];
  149. if(this.countyCode){
  150. this.getTown(this.countyCode);
  151. }
  152. }
  153. if(this.attrs.areaCode){
  154. this.areaCode=data[this.attrs.areaCode];
  155. }
  156. if(this.attrs.area){
  157. this.area=data[this.attrs.area];
  158. }
  159. }
  160. setValue(v?:any){
  161. this.setAllValue(this.parentValue);
  162. }
  163. clearValue(){
  164. this.provinceCode='';
  165. this.cityCode='';
  166. this.countyCode='';
  167. this.townCode='';
  168. this.province='';
  169. this.city='';
  170. this.county='';
  171. this.town='';
  172. this.area='';
  173. this.areaCode='';
  174. this.optionsCity=[];
  175. this.optionsCounty>=[];
  176. this.optionsTown=[];
  177. }
  178. onProvince(v:any){
  179. this.province = '';
  180. this.area = '';
  181. for(const item of this.optionsProvince){
  182. if(item.code == v){
  183. this.province = item.name;
  184. this.area = item.fullName;
  185. }
  186. }
  187. this.city='';
  188. this.cityCode = '';
  189. this.county='';
  190. this.countyCode = '';
  191. this.optionsCity = [];
  192. this.optionsCounty = [];
  193. this.townCode = '';
  194. this.town = '';
  195. this.optionsTown=[];
  196. this.areaCode = v;
  197. this.provinceError = false;
  198. if(v){
  199. this.getCity(v);
  200. }
  201. this.onChange();
  202. }
  203. onCity(v:any){
  204. this.city = '';
  205. this.area = '';
  206. for(const item of this.optionsCity){
  207. if(item.code == v){
  208. this.city = item.name;
  209. this.area = item.fullName;
  210. }
  211. }
  212. this.county='';
  213. this.countyCode = '';
  214. this.optionsCounty = [];
  215. this.townCode = '';
  216. this.town = '';
  217. this.optionsTown=[];
  218. this.areaCode = v;
  219. this.cityError = false;
  220. if(v){
  221. this.getCounty(v);
  222. }
  223. this.onChange();
  224. }
  225. onCounty(v:any){
  226. this.county = '';
  227. this.area = '';
  228. for(const item of this.optionsCounty){
  229. if(item.code == v){
  230. this.county = item.name;
  231. this.area = item.fullName;
  232. }
  233. }
  234. this.townCode = '';
  235. this.town = '';
  236. this.optionsTown=[];
  237. this.areaCode = v;
  238. this.countyError = false;
  239. if(v){
  240. this.getTown(v);
  241. }
  242. this.onChange();
  243. }
  244. onTown(v:any){
  245. this.town = '';
  246. this.area = '';
  247. for(const item of this.optionsTown){
  248. if(item.code == v){
  249. this.town = item.name;
  250. this.area = item.fullName;
  251. }
  252. }
  253. this.areaCode = v;
  254. this.onChange();
  255. }
  256. getValue(){
  257. let obj:any={};
  258. if(this.attrs.province){
  259. obj[this.attrs.province]=this.province;
  260. }
  261. if(this.attrs.provinceCode){
  262. obj[this.attrs.provinceCode]=this.provinceCode;
  263. }
  264. if(this.attrs.city){
  265. obj[this.attrs.city]=this.city;
  266. }
  267. if(this.attrs.cityCode){
  268. obj[this.attrs.cityCode]=this.cityCode
  269. }
  270. if(this.attrs.county){
  271. obj[this.attrs.county]=this.county;
  272. }
  273. if(this.attrs.countyCode){
  274. obj[this.attrs.countyCode]=this.countyCode
  275. }
  276. if(this.attrs.town){
  277. obj[this.attrs.town]=this.town;
  278. }
  279. if(this.attrs.townCode){
  280. obj[this.attrs.townCode]=this.townCode
  281. }
  282. if(this.attrs.areaCode){
  283. obj[this.attrs.areaCode]=this.areaCode;
  284. }
  285. if(this.attrs.area){
  286. obj[this.attrs.area]=this.area;
  287. }
  288. return obj;
  289. }
  290. onChange(){
  291. this.$emit('onChange',this.getValue())
  292. }
  293. //获取省数据
  294. getProvince(){
  295. this.request({
  296. params:{
  297. parentCode:'86'
  298. },
  299. success:(data:any) => {
  300. this.optionsProvince = data;
  301. }
  302. })
  303. }
  304. //获取市
  305. getCity(v:any){
  306. this.request({
  307. params:{
  308. parentCode:v
  309. },
  310. success:(data:any) => {
  311. this.optionsCity = data;
  312. }
  313. })
  314. }
  315. //获取县/区
  316. getCounty(v:any){
  317. this.request({
  318. params:{
  319. parentCode:v
  320. },
  321. success:(data:any) => {
  322. this.optionsCounty = data;
  323. }
  324. })
  325. }
  326. //获取街道
  327. getTown(v:any){
  328. this.request({
  329. params:{
  330. parentCode:v
  331. },
  332. success:(data:any) => {
  333. this.optionsTown = data;
  334. }
  335. })
  336. }
  337. request(data:any){
  338. let parame:any = {
  339. url:'/omsOrder/omsArea/getByParentCode',
  340. method: 'GET',
  341. };
  342. parame.params = data.params;
  343. parame.success = (res:any) => {
  344. data.success(res.data)
  345. }
  346. parame.fail = (err:any) => {
  347. }
  348. this.requestHandle(parame);
  349. }
  350. }
  351. </script>
  352. <style lang="scss" scoped>
  353. .by-area{
  354. width: 100%;
  355. .area-box{
  356. padding: 0 4px;
  357. display: flex;
  358. align-items: center;
  359. .left-label{
  360. width: 80px;
  361. text-align: right;
  362. // flex-shrink: 0;
  363. // .require{
  364. // color: #F00;
  365. // padding: 0 2px;
  366. // }
  367. }
  368. .right-area{
  369. width: 100%;
  370. }
  371. }
  372. .first{
  373. padding-left: 0;
  374. }
  375. .last{
  376. padding-right: 0;
  377. }
  378. }
  379. </style>