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.
 
 
 
 
 
 

409 lines
9.2 KiB

  1. <template>
  2. <view class="popup-layout-wrap " :class="popuplayoutClass" >
  3. <view class="popup-layout-content" :class="popupContentClass" :style="[{height:height}]">
  4. <view class="link-address-wrap">
  5. <view class="link-adress-content">
  6. <view class="head-wrap">
  7. <text class="cancel" @click="btn_cancel">取消</text>
  8. <text class="confirm" @click="btn_confirm">确认</text>
  9. </view>
  10. <view class="head-selected">
  11. <text class="selected-txt">已选择:{{selected_address}}</text>
  12. </view>
  13. <view class="operation-wrap">
  14. <view class="operation-container">
  15. <view class="operation-content" v-for="(base_items,base_index) of linkAddress_area">
  16. <scroll-view
  17. scroll-y="true"
  18. class="province"
  19. show-scrollbar="false">
  20. <view
  21. @click="choosefun(base_items.clickfun,items.id)"
  22. v-model="items.id"
  23. v-for="(items , index) of base_items.info"
  24. :class="[index==base_items.current ? 'province-txt-click' : 'province-txt']"
  25. >
  26. {{items.name}}
  27. <view class="pic" v-show="index===base_items.current">
  28. <image src="../../static/xuan-linkAddress/yes.png"></image>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view v-if="maskShow" class="popup-layout-mask" @tap="close(maskClick)"></view>
  39. </view>
  40. </template>
  41. <script>
  42. import linkAddress_p from '../../static/xuan-linkAddress/get_linkAddress_p.js'
  43. export default{
  44. data(){
  45. return{
  46. newActive:"",
  47. newTransition:true,
  48. //省0市1区2
  49. linkAddress_area:[
  50. {
  51. current:null,
  52. info: [],
  53. clickfun:'province_txt_click'
  54. },
  55. {
  56. current:null,
  57. info: [],
  58. clickfun:'city_txt_click'
  59. },
  60. {
  61. current:null,
  62. info: [],
  63. clickfun:'district_txt_click'
  64. }
  65. ],
  66. /*请求提交的*/
  67. submission:{
  68. province:'',//省
  69. city:'',//市
  70. county:'',//区
  71. town:''//镇
  72. },
  73. /*用户选择的地址*/
  74. user_address:{
  75. province:'',//省
  76. city:'',//市
  77. district:''//区
  78. },
  79. selected_address:''
  80. };
  81. },
  82. props:{
  83. /*底部弹窗的属性*/
  84. active:{
  85. type:Boolean,
  86. default:false
  87. },
  88. height:{
  89. type:[String],
  90. default:"100%"
  91. },
  92. //遮盖层显示
  93. maskShow:{
  94. type:Boolean,
  95. default:true
  96. },
  97. //遮盖层点击
  98. maskClick:{
  99. type:Boolean,
  100. default:true
  101. },
  102. //回掉
  103. callback:{
  104. type:Function,
  105. default:function () {
  106. }
  107. },
  108. },
  109. computed:{
  110. popuplayoutClass:function(){
  111. let _class="";
  112. if(this.newActive){
  113. _class+="popup-layout-active";
  114. }
  115. _class+=" popup-layout-bottom";
  116. return _class;
  117. },
  118. popupContentClass:function () {
  119. let _class = "";
  120. if (this.newTransition&&this.transition!=='none') {
  121. _class+="popup-layout-transition-slider"
  122. }
  123. return _class;
  124. }
  125. },
  126. methods: {
  127. //显示弹窗
  128. show:function () {
  129. //提交的数据置为空
  130. this.submission={
  131. province:'',
  132. city:'',
  133. county:'',
  134. town:''
  135. },
  136. //请求市数据
  137. linkAddress_p.get_linkAddress(this,"province",this.submission,(revert)=>{
  138. this.submission.province='1';
  139. });
  140. this.newActive = true;
  141. let _this = this;
  142. setTimeout(function () {
  143. _this.newTransition = false;
  144. },50)
  145. },
  146. //关闭弹窗
  147. close:function (v) {
  148. let close = v || true;
  149. if (close) {
  150. this.newTransition = true;
  151. let _this=this;
  152. setTimeout(function () {
  153. _this.newActive = false;
  154. },300)
  155. }
  156. },
  157. //选择点击事件
  158. choosefun(targetfun,targetid){
  159. this[targetfun](targetid);
  160. },
  161. //省点击选择
  162. province_txt_click(target){
  163. //区数据置为空
  164. this.linkAddress_area[2].info= [];
  165. //市、区的选择计数置为null
  166. this.linkAddress_area[1].current=null;
  167. this.linkAddress_area[2].current=null;
  168. let province;
  169. //得到点击的数据,改变样式
  170. for (let i = 0; i < this.linkAddress_area[0].info.length; i++) {
  171. if (this.linkAddress_area[0].info[i].id === target) {
  172. this.linkAddress_area[0].current = i;
  173. province=this.linkAddress_area[0].info[i].name;
  174. break;
  175. }
  176. }
  177. //用户选择
  178. this.user_address={
  179. province:province,
  180. city:'',
  181. district:''
  182. }
  183. //请求提交的数据先置为空
  184. this.submission={
  185. province:'',
  186. city:'',
  187. county:'',
  188. town:''
  189. };
  190. //再赋值
  191. this.submission.province=target;
  192. this.selected_address=this.user_address.province;
  193. //请求市数据
  194. linkAddress_p.get_linkAddress(this,"city",this.submission,(revert)=>{
  195. });
  196. },
  197. //市点击选择
  198. city_txt_click(target){
  199. //区的选择计数置为null
  200. this.linkAddress_area[2].current=null;
  201. let city;
  202. //得到点击的数据,改变样式
  203. for (let i = 0; i < this.linkAddress_area[1].info.length; i++) {
  204. if (this.linkAddress_area[1].info[i].id === target) {
  205. this.linkAddress_area[1].current = i;
  206. city=this.linkAddress_area[1].info[i].name;
  207. break;
  208. }
  209. }
  210. //得到市
  211. this.user_address.city=city;
  212. //把区的信息置为空
  213. this.user_address.district='';
  214. this.submission.city=target;
  215. this.selected_address=this.user_address.province+"-"+this.user_address.city;
  216. //请求区数据
  217. linkAddress_p.get_linkAddress(this,"district",this.submission,(revert)=>{
  218. });
  219. },
  220. //区点击选择
  221. district_txt_click(target){
  222. let district;
  223. //得到点击的数据,改变样式
  224. for (let i = 0; i < this.linkAddress_area[2].info.length; i++) {
  225. if (this.linkAddress_area[2].info[i].id === target) {
  226. // this.district_current = i;
  227. this.linkAddress_area[2].current = i;
  228. district=this.linkAddress_area[2].info[i].name;
  229. break;
  230. }
  231. }
  232. //得到区信息
  233. this.user_address.district=district;
  234. this.selected_address=this.user_address.province+"-"+this.user_address.city+"-"+this.user_address.district;
  235. },
  236. //取消按钮
  237. btn_cancel:function(){
  238. this.close();
  239. //全部置为空
  240. this.submission={
  241. province:'',
  242. city:'',
  243. county:'',
  244. town:''
  245. }
  246. this.linkAddress_area[1].info= [];
  247. this.linkAddress_area[2].info= [];
  248. this.linkAddress_area[0].current=null;
  249. this.linkAddress_area[1].current=null;
  250. this.linkAddress_area[2].current=null;
  251. this.selected_address='';
  252. },
  253. //确定按钮
  254. btn_confirm:function(){
  255. this.close();
  256. console.log(this.user_address)
  257. //可以使用vuex传值
  258. this.$store.commit('commit_address',this.user_address);
  259. this.$emit('confirmCallback');
  260. }
  261. },
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. popup-layout-wrap{
  266. position: absolute;
  267. }
  268. .popup-layout-wrap{
  269. position: fixed;
  270. z-index: 998;
  271. left: 0;
  272. right: 0;
  273. top: 0;
  274. bottom: 0;
  275. height: 100%;
  276. width: 100%;
  277. display: flex;
  278. flex-flow: row nowrap;
  279. justify-content: center;
  280. align-items: center;
  281. display: none;
  282. &.popup-layout-active{
  283. display: flex;
  284. }
  285. &.popup-layout-bottom{
  286. align-items: flex-end;
  287. .popup-layout-transition-slider{
  288. transform: translate3d(0,100%,0);
  289. }
  290. }
  291. .popup-layout-content{
  292. background-color: #fff;
  293. z-index: 2;
  294. height: 100%;
  295. width: 100%;
  296. display: flex;
  297. flex-flow: row nowrap;
  298. justify-content: center;
  299. align-items: center;
  300. transform: translate3d(0,0,0) scale(1);
  301. opacity: 1;
  302. transition: transform .3s ease-in-out,opacity .3s ease-in-out;
  303. &.popup-layout-transition-fade{
  304. transform: translate3d(0,0,0) scale(0.3);
  305. opacity: 0;
  306. }
  307. }
  308. .popup-layout-mask{
  309. position: absolute;
  310. transition:all 1s ;
  311. z-index: 1;
  312. left: 0;
  313. right: 0;
  314. top: 0;
  315. bottom: 0;
  316. height: 100%;
  317. width: 100%;
  318. background-color: rgba(#000, 0.6);
  319. }
  320. }
  321. /***省市区选择器***/
  322. .link-address-wrap{
  323. height: 100%;
  324. width: 100%;
  325. background: #fff;
  326. }
  327. .link-address-wrap .link-adress-content{
  328. margin:8px 10px 10px 10px;
  329. .head-wrap{
  330. padding-bottom: 5px;
  331. display: flex;
  332. flex-direction: row;
  333. position: relative;
  334. .cancel{
  335. color: #999;
  336. }
  337. .confirm{
  338. position: absolute;
  339. right: 0px;
  340. }
  341. }
  342. .head-selected{
  343. text-align: center;
  344. color: #ccc;
  345. font-size: 17px;
  346. }
  347. .operation-wrap{
  348. .operation-container{
  349. display: flex;
  350. flex-direction: row;
  351. flex-wrap: wrap;
  352. .operation-content{
  353. display: flex;
  354. flex-direction: column;
  355. width: 33.333%;
  356. .province{
  357. //scroll-view区域的固定高度
  358. height: 420rpx;
  359. font-size: 17px;
  360. .province-txt{
  361. margin: 18px 12px;
  362. overflow: hidden;
  363. text-overflow:ellipsis;
  364. white-space: nowrap;
  365. }
  366. .province-txt-click{
  367. margin: 18px 12px;
  368. overflow: hidden;
  369. text-overflow:ellipsis;
  370. white-space: nowrap;
  371. color: red;
  372. font-size: 20px;
  373. display: flex;
  374. flex-direction: row;
  375. .pic{
  376. padding-left: 15rpx;
  377. width: 30rpx;
  378. height: 30rpx;
  379. display: flex;
  380. justify-content: center;
  381. text-align: center;
  382. margin: auto 0;
  383. image{
  384. width: 100%;
  385. height: auto;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. </style>