代理记账中共新前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TopDeptChooser.vue 5.6 KiB

1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div class="top_main">
  3. <el-dropdown trigger="click" placement="bottom-start">
  4. <div class="select_address el-dropdown-link">
  5. <span class="sanjiao-right"></span>
  6. <p>{{cityName}}</p>
  7. </div>
  8. <el-dropdown-menu slot="dropdown" style="width: 8vw;text-align: center;">
  9. <el-dropdown-item v-for="(item,index) in deptOptions" :command="item.orgCode">
  10. <div class="selected" @click="chooseCity(item.orgCode)">
  11. <p>{{item.deptName}}</p>
  12. </div>
  13. </el-dropdown-item>
  14. </el-dropdown-menu>
  15. </el-dropdown>
  16. <el-dropdown trigger="click" placement="bottom-start" v-if="!hideTown">
  17. <div class="select_address el-dropdown-link">
  18. <span class="sanjiao-right"></span>
  19. <p>{{townName}}</p>
  20. </div>
  21. <el-dropdown-menu slot="dropdown" style="width: 8vw;text-align: center;">
  22. <el-dropdown-item v-for="(item,index) in townList" :command="item.orgCode">
  23. <div class="selected" @click="chooseTown(item.orgCode)">
  24. <p>{{item.deptName}}</p>
  25. </div>
  26. </el-dropdown-item>
  27. </el-dropdown-menu>
  28. </el-dropdown>
  29. <slot></slot>
  30. </div>
  31. </template>
  32. <script>
  33. import {cityTree} from "@/api/misc/misc_dept";
  34. export default {
  35. name: 'TopDeptChooser',
  36. props: {
  37. countyCode: String,
  38. townCode: String,
  39. rootId: [String, Number],
  40. allTown: {
  41. type: Boolean,
  42. default: false,
  43. },
  44. hideTown: {
  45. type: Boolean,
  46. default: false,
  47. },
  48. },
  49. created() {
  50. this.getDeptTree();
  51. },
  52. data() {
  53. return {
  54. deptOptions: [],
  55. icountyCode: this.countyCode || null,
  56. itownCode: this.townCode || null,
  57. };
  58. },
  59. methods: {
  60. getDeptTree() {
  61. cityTree({rootId: this.rootId}).then((resp) => {
  62. this.deptOptions = resp.data;
  63. if(this.deptOptions.length)
  64. {
  65. this.icountyCode = this.deptOptions[0].orgCode;
  66. this.emitUpdate(1);
  67. }
  68. });
  69. },
  70. chooseCity(cmd) {
  71. this.icountyCode = cmd;
  72. this.itownCode = null;
  73. this.emitUpdate(1 | 2);
  74. },
  75. chooseTown(cmd) {
  76. this.itownCode = cmd;
  77. this.emitUpdate(2);
  78. },
  79. emitUpdate(w) {
  80. if(w & 1)
  81. {
  82. this.$emit('update:countyCode', this.icountyCode);
  83. }
  84. if((w & 2) && !this.hideTown)
  85. {
  86. this.$emit('update:townCode', this.itownCode);
  87. }
  88. if(w & 1)
  89. {
  90. this.$emit('countyChanged', this.icountyCode, null);
  91. }
  92. if((w & 2) && !this.hideTown)
  93. {
  94. this.$emit('townChanged', this.itownCode, this.icountyCode);
  95. }
  96. if((w & 1) || ((w & 2) && !this.hideTown))
  97. {
  98. this.$emit('dataChanged', this.icountyCode, this.itownCode, w);
  99. }
  100. },
  101. },
  102. watch: {
  103. rootId(newVal) {
  104. this.getDeptTree();
  105. },
  106. countyCode(newVal) {
  107. if(this.icountyCode != newVal)
  108. {
  109. this.icountyCode = newVal;
  110. //this.emitUpdate(1);
  111. }
  112. },
  113. townCode(newVal) {
  114. if(this.itownCode != newVal)
  115. {
  116. this.itownCode = newVal;
  117. //this.emitUpdate(2);
  118. }
  119. },
  120. /* icountyCode(newVal) {
  121. if(this.countyCode != newVal)
  122. {
  123. this.emitUpdate(1);
  124. }
  125. },
  126. itownCode(newVal) {
  127. if(this.townCode != newVal)
  128. {
  129. this.emitUpdate(2);
  130. }
  131. },*/
  132. },
  133. computed: {
  134. cityName() {
  135. if(!this.deptOptions.length)
  136. return '';
  137. let dept = this.deptOptions.find((x) => x.orgCode === this.icountyCode);
  138. return dept ? dept.deptName : '';
  139. },
  140. townList() {
  141. if(!this.deptOptions.length)
  142. return [];
  143. let dept = this.deptOptions.find((x) => x.orgCode === this.icountyCode);
  144. let arr = [];
  145. if(this.allTown)
  146. arr.push({orgCode: '', deptName: '全部'});
  147. arr.push(...(dept ? dept.children || [] : []));
  148. return arr;
  149. },
  150. townName() {
  151. if(!this.townList.length)
  152. return '';
  153. if(this.allTown)
  154. {
  155. if(!this.itownCode)
  156. return '全部';
  157. }
  158. let dept = this.townList.find((x) => x.orgCode === this.itownCode);
  159. return dept ? dept.deptName : '';
  160. },
  161. },
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .el-dropdown-link {
  166. cursor: pointer;
  167. }
  168. .selected{
  169. display: flex;
  170. height: 4vh;
  171. p{
  172. width: 8vw;
  173. line-height: 4vh;
  174. text-align: center;
  175. }
  176. }
  177. p{margin: 0;line-height: 1;}
  178. .top_main{
  179. display: flex;
  180. align-items: center;
  181. position: relative;
  182. .selected{
  183. width: 16vw;
  184. background-color: #ffffff;
  185. position: absolute;
  186. top: 4vh;
  187. left: 10vw;
  188. z-index: 9;
  189. border-radius: 8px;
  190. box-shadow: 0 10px 10px #dedfe1;
  191. padding: 1vh 0;
  192. div{
  193. display: flex;
  194. height: 4vh;
  195. p{
  196. width: 8vw;
  197. line-height: 4vh;
  198. text-align: center;
  199. }
  200. }
  201. }
  202. .select_address{
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. margin-right: 2vw;
  207. background-color: #ffffff;
  208. padding: 0px 0px;
  209. border-radius: 8px;
  210. box-shadow: 0 0 10px #dedfe1;
  211. width: 8vw;
  212. height: 4vh;
  213. overflow: hidden;
  214. &:nth-child(2){
  215. margin-right: 0vw;
  216. }
  217. &:nth-child(3){
  218. margin-right: 0vw;
  219. border-top-left-radius: initial;
  220. border-bottom-left-radius: initial;
  221. }
  222. .sanjiao-right {
  223. display: inline-block;
  224. border-left: 8px solid #000;
  225. border-left-color: initial;
  226. border-top: 5px solid transparent;
  227. border-bottom: 5px solid transparent;
  228. margin-right: 5px;
  229. }
  230. .select_time{
  231. text-align: center;
  232. width: 100%;
  233. height: 4vh;
  234. line-height: 4vh;
  235. background-color: #3976ff;
  236. color: #ffffff;
  237. }
  238. }
  239. }
  240. </style>