91862dc9104e321ea85ae6a09db9d820b11ebf79.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div>
  3. <el-select
  4. v-model="value"
  5. placeholder="请选择"
  6. filterable
  7. autoComplete = "off"
  8. :filter-method="filterMethod"
  9. @change='chooseChange'
  10. >
  11. <el-option
  12. v-for="item in searchDataList"
  13. :key="item.code"
  14. :value="item.code"
  15. :label="item.villageName"
  16. >
  17. <span style="float: left;color:rgba(0,0,0,0.5);font-size:small" v-if="item.value == '无相应村'">*如无相应村</span>
  18. <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.value == '无相应村'">
  19. <el-button type="text" size='mini' plain @click="insertCun">添加行政村</el-button>
  20. </span>
  21. <span style="float: left">{{ item.villageName }}</span>
  22. <span style="float: right; color: #8492a6; font-size: 13px">{{ item.townName }}</span>
  23. </el-option>
  24. </el-select>
  25. <el-dialog
  26. title="添加行政村"
  27. :visible.sync="dialogVisible"
  28. width="30%"
  29. :modal="false"
  30. >
  31. <el-form :model="newCunForm" label-width="120px">
  32. <p style="margin-top:10px;margin-bottom: 10px"><i class="el-icon-caret-right"></i><span style="width:120px;padding-left: 10px">行政村基本信息</span><span class="hrs"></span></p>
  33. <el-form-item label="行政村名">
  34. <el-input v-model="newCunForm.adName" style="width:70%;"></el-input>
  35. </el-form-item>
  36. <el-form-item label="所在乡镇">
  37. <inuptWithXiang v-model="newCunForm.adName" :initalValue="newCunForm.adFcode" autocomplete="off" :rootCode = "rootCode" @provTreeSelectChange="provTreeSelectChangeHandler" style="width:70%;"></inuptWithXiang>
  38. </el-form-item>
  39. <el-form-item label="操作">
  40. <el-button @click="dialogVisible = false">取 消</el-button>
  41. <el-button type="primary" @click="submitInsertCun">确 定</el-button>
  42. </el-form-item>
  43. </el-form>
  44. </el-dialog>
  45. </div>
  46. </template>
  47. <script>
  48. import { getVillageList_ny ,submitInsertCun} from "../api/duChaTianBao.js";
  49. import inuptWithXiang from './inuptWithXiang.vue'
  50. export default {
  51. props: ['rootCode','initalValue'],
  52. components:{
  53. 'inuptWithXiang':inuptWithXiang
  54. },
  55. data() {
  56. return {
  57. dataList: [],
  58. value: '',
  59. dialogVisible:false,
  60. searchDataList:[],
  61. timeout: null,
  62. xianlistData:[],
  63. newCunForm:{
  64. "adAbbrName": "",
  65. "adFcode": "",
  66. "adFullName": "",
  67. "adName": "",
  68. },
  69. }
  70. },
  71. computed:{
  72. },
  73. mounted(){
  74. this.value = this.initalValue;
  75. console.log(this.value);
  76. this.querySearchAsync();
  77. },
  78. watch: {
  79. rootCode:function(){
  80. this.querySearchAsync();
  81. },
  82. initalValue:function(){
  83. this.value = this.initalValue;
  84. console.log(this.value);
  85. this.querySearchAsync();
  86. }
  87. },
  88. methods:{
  89. provTreeSelectChangeHandler:function(params){
  90. console.log(params)
  91. this.newCunForm.adFcode = params.code;
  92. },
  93. submitInsertCun:function(){
  94. submitInsertCun(this.newCunForm.adName,this.newCunForm.adFcode).then(
  95. (res) => {
  96. console.log(res);
  97. this.querySearchAsync();
  98. this. newCunForm={
  99. "adAbbrName": "",
  100. "adFcode": "",
  101. "adFullName": "",
  102. "adName": "",
  103. };
  104. this.dialogVisible = false;
  105. }
  106. );
  107. },
  108. insertCun:function(){
  109. this.dialogVisible = true;
  110. },
  111. chooseChange:function(p){
  112. console.log(p);
  113. this.dataList.forEach((element) => {
  114. if(element.code == p){
  115. console.log(element);
  116. this.$emit("provTreeSelectChange", { 'code':element.code, 'name': element.villageName});
  117. }
  118. });
  119. },
  120. filterMethod:function(text){
  121. console.log(text);
  122. this.value = text;
  123. let filterResult = [{
  124. 'value':'无相应村',
  125. 'label':'添加'
  126. }];
  127. this.dataList.forEach((element) =>{
  128. if(element.villageName.indexOf(text)>=0 || element.townName.indexOf(text)>=0){
  129. filterResult.push(element);
  130. }
  131. });
  132. this.searchDataList = filterResult;
  133. },
  134. querySearchAsync() {
  135. // cb(results);
  136. getVillageList_ny(this.rootCode).then((res) =>{
  137. console.log(res);
  138. var children = [];
  139. let lists = [];
  140. res.data.list.forEach((element,index)=>{
  141. element.list.forEach((eleChild) =>{
  142. children.push({
  143. 'name':eleChild.villageName,
  144. 'code':eleChild.villageCode,
  145. });
  146. lists.push({
  147. 'value':eleChild.villageName,
  148. 'villageName':eleChild.villageName,
  149. 'townName':element.townName,
  150. 'code':eleChild.villageCode,
  151. 'label':eleChild.villageName+element.townName
  152. });
  153. })
  154. this.xianlistData.push({'label':element.townName,'code':element.townCode});
  155. });
  156. this.dataList = lists;
  157. this.searchDataList = lists;
  158. console.log(this.xianlistData);
  159. },(err) =>{});
  160. },
  161. },
  162. }
  163. </script>
  164. <style>
  165. </style>