selectRegion.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <style scoped>
  2. .transfer {
  3. display: flex;
  4. }
  5. .transfer .transfer-box {
  6. width: 350px;
  7. height: 250px;
  8. border: 1px solid #dadfe3;
  9. display: flex;
  10. overflow-x: auto;
  11. overflow-y: hidden;
  12. box-sizing: border-box;
  13. margin-right: 25px;
  14. }
  15. .content-box {
  16. min-width: 174px;
  17. width: 100%;
  18. height: 100%;
  19. border-right: 1px solid #dadfe3;
  20. }
  21. .content-box .content-title {
  22. width: 100%;
  23. background: #f8f9fa;
  24. border-bottom: 1px solid #dadfe3;
  25. padding: 5px 15px;
  26. font-size: 16px;
  27. font-weight: 700;
  28. line-height: 30px;
  29. }
  30. .content-box .content {
  31. width: 100%;
  32. height: 85%;
  33. overflow: auto;
  34. }
  35. .content-box .content p:hover {
  36. background: #edf1f5;
  37. cursor: pointer;
  38. }
  39. .content-box .content p:hover span {
  40. display: inline-block;
  41. }
  42. .content-box .content p span {
  43. display: none;
  44. }
  45. p {
  46. padding: 5px;
  47. margin-bottom: 0;
  48. border-bottom: 1px solid #f2f2f2;
  49. }
  50. .backgroundOnly {
  51. background: #edf1f5;
  52. }
  53. </style>
  54. <style>
  55. .transfer .ant-checkbox-group {
  56. width: 100px;
  57. overflow-x: hidden;
  58. }
  59. .transfer .ant-checkbox-group-item {
  60. display: inline-block;
  61. margin-right: 8px;
  62. width: 100%;
  63. }
  64. </style>
  65. <template>
  66. <div class="transfer">
  67. <div class="transfer-box">
  68. <div class="content-box">
  69. <p class="content-title">省份</p>
  70. <div class="content" style="position:relative">
  71. <!-- <div style="position:absolute;top:0;left:0;width:100%;height:100%;background: rgba(0, 0, 0, 0.5)"
  72. v-if="loading"></div> -->
  73. <p><input type="checkbox" class="select_all" @change="checkAllBox" v-model="checkAll" /> 全选</p>
  74. <p v-for="(item, index) of province" :key="item.value" :class="{ backgroundOnly: provinceIndex == index }">
  75. <input class="checkItem" type="checkbox" :value="item.value" :id="item.value" v-model="checkMatched"
  76. @change="checkOne(item, index)" />
  77. <span @click="showCity(item, index)" style="color:black;display:inline-block;margin-left:5px;width:80%">{{
  78. item.label
  79. }}</span>
  80. </p>
  81. </div>
  82. </div>
  83. <div class="content-box" :style="{ borderRight: !showClass ? '0px' : '1px solid #dadfe3' }" v-show="showCityData">
  84. <p class="content-title">城市</p>
  85. <div class="content">
  86. <!-- <p>
  87. <input
  88. type="checkbox"
  89. class="select_all"
  90. @change="checkAllBoxCity"
  91. v-model="checkAllCity"
  92. /> 全选
  93. </p>-->
  94. <p v-for="(item, index) of city" :key="item.id" :class="{ backgroundOnly: cityIndex == index }">
  95. <input class="checkItem" type="checkbox" :value="item.value" :id="item.value" v-model="checkMatchedCity"
  96. @change="checkOneCity(item, index)" />
  97. {{ item.label }}
  98. </p>
  99. </div>
  100. </div>
  101. </div>
  102. <div class="transfer-box" style="width:176px">
  103. <div class="content-box">
  104. <p class="content-title">
  105. 已选
  106. <span style="float:right;font-weight:normal;color:blue;cursor: pointer;font-size:14px"
  107. @click="clear">清空</span>
  108. </p>
  109. <div class="content">
  110. <p v-for="(item, index) of checkData" :key="index">
  111. {{ item.label }}
  112. <!-- <span
  113. style="float:right;font-weight:normal;color:blue;cursor: pointer;font-size:14px"
  114. @click="detele(item,index)"
  115. >删除</span>-->
  116. </p>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </template>
  122. <script>
  123. import {
  124. JeecgListMixin
  125. } from '@/mixins/JeecgListMixin'
  126. import {
  127. getProvince,
  128. postAction
  129. } from '@/api/manage'
  130. import $ from 'jquery'
  131. export default {
  132. name: 'ByteDanceUserOrientationTemplateList',
  133. components: {},
  134. props: ['dataValue'],
  135. data() {
  136. return {
  137. showClass: false,
  138. showCityData: false,
  139. checkData: [],
  140. checkMatched: [],
  141. province: [],
  142. city: [],
  143. area: [],
  144. CityData: '/kuaishou/batch/getRegion',
  145. provinceIndex: null,
  146. cityIndex: null,
  147. checkAll: false,
  148. checkMatchedCity: [],
  149. checkAllCity: false,
  150. nowProvince: null,
  151. loading: false
  152. }
  153. },
  154. computed: {},
  155. mounted() {
  156. this.$nextTick(() => {
  157. this.getData().then(() => {
  158. if (this.dataValue&&this.dataValue.length>0&&this.dataValue[0].value) {
  159. return
  160. } else {
  161. postAction('/kuaishou/batch/getRegionDetail', {
  162. regionArr: this.dataValue
  163. }).then(res => {
  164. if (res.success) {
  165. // this.populationData.allForm.region = res.result
  166. this.checkData = res.result
  167. this.checkMatched = res.result.map(item => {
  168. return item.value
  169. })
  170. this.checkMatchedCity = res.result.map(item => {
  171. return item.value
  172. })
  173. this.$emit('update:checkData', this.checkData)
  174. }
  175. })
  176. }
  177. // if (this.dataValue.length > 0) {
  178. // }
  179. })
  180. })
  181. },
  182. watch: {
  183. dataValue: {
  184. deep: true,
  185. immediate: true, // immediate选项可以开启首次赋值监听
  186. handler(n, o) {
  187. if (n&&n.length > 0 && n[0].value) {
  188. // this.getData().then(() => {
  189. // if (n.length > 0) {
  190. this.$nextTick(() => {
  191. this.checkData = n
  192. this.checkMatched = n.map(item => {
  193. return item.value
  194. })
  195. this.checkMatchedCity = n.map(item => {
  196. return item.value
  197. })
  198. this.$emit('update:checkData', this.checkData)
  199. })
  200. // }
  201. // })
  202. }
  203. }
  204. }
  205. },
  206. methods: {
  207. getData() {
  208. this.loading = true
  209. var that = this
  210. return new Promise(function (resolve, reject) {
  211. getProvince(that.CityData, {
  212. level: 1
  213. }).then(res => {
  214. if (res.code == '0') {
  215. // this.province.push(...res.result.records)
  216. that.province = res.result.map(item => {
  217. return {
  218. label: item.name,
  219. value: item.regionId
  220. }
  221. })
  222. that.province = that.province.filter(item => {
  223. return item.label != '台湾' && item.label != '香港' && item.label != '澳门'
  224. })
  225. that.loading = false
  226. resolve()
  227. }
  228. })
  229. })
  230. },
  231. showCity(item, index) {
  232. this.city = []
  233. this.showCityData = false
  234. this.showClass = false
  235. this.provinceIndex = index
  236. this.cityIndex = null
  237. this.nowProvince = item
  238. this.checkMatchedCity = []
  239. getProvince(this.CityData, {
  240. parent: item.value
  241. }).then(res => {
  242. if (res.code == '0') {
  243. this.city = res.result.map(item => {
  244. return {
  245. label: item.name,
  246. value: item.regionId
  247. }
  248. })
  249. if (this.checkMatched.indexOf(item.value) != -1) {
  250. this.checkAllCity = true
  251. this.checkMatchedCity = this.city.map(item => {
  252. return item.value
  253. })
  254. } else {
  255. this.checkMatchedCity = this.checkData.map(item => {
  256. return item.value
  257. })
  258. }
  259. // this.city.push(...res.result.records)
  260. this.showCityData = true
  261. }
  262. })
  263. },
  264. checkAllBox() {
  265. this.checkMatched = []
  266. this.checkData = []
  267. if (this.checkAll) {
  268. this.checkMatched = this.province.map(item => {
  269. return item.value
  270. })
  271. this.checkData.push(...this.province)
  272. } else {
  273. this.checkMatched = []
  274. this.checkData = []
  275. this.checkMatchedCity = []
  276. }
  277. this.$emit('update:checkData', this.checkData)
  278. },
  279. checkOne(item, index) {
  280. if (this.checkMatched.indexOf(item.value) == -1) {
  281. var index1 = this.checkData.findIndex(v => v.value === item.value)
  282. this.checkData.splice(index1, 1)
  283. if (this.nowProvince) {
  284. if (this.nowProvince.value == item.value) {
  285. this.checkMatchedCity = []
  286. }
  287. }
  288. } else {
  289. this.checkData.push(item)
  290. var data = []
  291. getProvince(this.CityData, {
  292. parent: item.value
  293. }).then(res => {
  294. if (res.code == '0') {
  295. data = res.result.map(item => {
  296. return {
  297. label: item.name,
  298. value: item.regionId
  299. }
  300. })
  301. for (var i = 0; i < this.checkData.length; i++) {
  302. for (let j = 0; j < data.length; j++) {
  303. if (this.checkData[i].value == data[j].value) {
  304. this.checkData.splice(i, 1)
  305. }
  306. }
  307. }
  308. }
  309. })
  310. if (this.nowProvince) {
  311. if (item.value == this.nowProvince.value) {
  312. this.checkMatchedCity = this.city.map(item => {
  313. return item.value
  314. })
  315. }
  316. }
  317. }
  318. if (this.checkMatched.length == this.province.length) {
  319. this.checkAll = true
  320. } else {
  321. this.checkAll = false
  322. }
  323. this.$emit('update:checkData', this.checkData)
  324. },
  325. checkAllBoxCity() {
  326. this.checkMatchedCity = []
  327. if (this.checkAllCity) {
  328. this.checkMatchedCity = this.city.map(item => {
  329. return item.value
  330. })
  331. this.checkMatched.push(this.nowProvince.value)
  332. this.checkData.push(this.nowProvince)
  333. } else {
  334. this.checkMatchedCity = []
  335. var index = this.checkData.findIndex(v => v.value === this.nowProvince.value)
  336. var index1 = this.checkMatched.findIndex(v => v === this.nowProvince.value)
  337. this.checkData.splice(index, 1)
  338. this.checkMatched.splice(index1, 1)
  339. }
  340. this.$emit('update:checkData', this.checkData)
  341. },
  342. checkOneCity(item, index) {
  343. var allCity = this.checkMatchedCity.filter(v => {
  344. return v.toString().slice(0, 2) == this.nowProvince.value
  345. })
  346. if (allCity.length == this.city.length) {
  347. this.checkMatched.push(this.nowProvince.value)
  348. this.checkData.push(this.nowProvince)
  349. for (var i = 0; i < allCity.length; i++) {
  350. for (var j = 0; j < this.checkData.length; j++) {
  351. if (allCity[i] == this.checkData[j].value) {
  352. this.checkData.splice(j, 1)
  353. j--
  354. }
  355. }
  356. }
  357. }
  358. if (this.checkMatchedCity.indexOf(item.value) != -1) {
  359. if (allCity.length != this.city.length) {
  360. this.checkData.push(item)
  361. }
  362. if (this.checkMatched.length == this.province.length) {
  363. this.checkAll = true
  364. } else {
  365. this.checkAll = false
  366. }
  367. } else {
  368. if (this.checkMatched.indexOf(this.nowProvince.value) != -1) {
  369. var index1 = this.checkData.findIndex(v => v.value === this.nowProvince.value)
  370. var index2 = this.checkMatched.findIndex(v => v === this.nowProvince.value)
  371. this.checkData.splice(index1, 1)
  372. this.checkMatched.splice(index2, 1)
  373. this.checkAll = false
  374. var data = this.city.filter(v => {
  375. return v.value != item.value
  376. })
  377. this.checkData.push(...data)
  378. } else {
  379. var index1 = this.checkData.findIndex(v => v.value === item.value)
  380. this.checkData.splice(index1, 1)
  381. }
  382. }
  383. this.$emit('update:checkData', this.checkData)
  384. },
  385. clear() {
  386. this.checkData = []
  387. this.checkMatched = []
  388. this.checkMatchedCity = []
  389. this.checkAll = false
  390. this.$emit('update:checkData', this.checkData)
  391. },
  392. detele(item, index) {
  393. // if (this.checkMatched.indexOf(this.nowProvince.value) != -1) {
  394. var index1 = this.checkMatched.findIndex(v => v === item.value)
  395. var index2 = this.checkData.findIndex(v => v.value === item.value)
  396. this.checkData.splice(index2, 1)
  397. this.checkMatched.splice(index1, 1)
  398. this.checkAll = false
  399. // } else {
  400. // }
  401. this.$emit('update:checkData', this.checkData)
  402. }
  403. }
  404. }
  405. </script>