addAddress.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <view class="address-box">
  5. <textarea class="textarea" v-model="content" placeholder="请粘贴或输入文本,点击'识别'自动识别姓名、电话、地址,格式:深圳市龙岗区坂田街道长坑路西2巷2号202 黄大大 18888888888" />
  6. <view class="btns" >
  7. <view class="btn parse" @click="parseAddress()">识别</view>
  8. </view>
  9. </view>
  10. <view class="form-box">
  11. <view class="form-item">
  12. <text class="label">联系人</text>
  13. <input type="text" v-model="form.realName" maxlength="10" placeholder="姓名" class="form-input" />
  14. </view>
  15. <view class="form-item">
  16. <text class="label">手机号</text>
  17. <input type="number" v-model="form.phone" maxlength="11" placeholder="手机号" class="form-input" />
  18. </view>
  19. <view class="form-item">
  20. <text class="label">所在地区</text>
  21. <picker :value="multiIndex" class="birth-picker" mode="multiSelector" range-key="n" :range="addressList" @change="pickerChange" @columnchange="pickerColumnchange">
  22. <view class="right-box">
  23. <view class="input-box">
  24. <input type="text" v-model="form.address" placeholder="请选择" class="form-input" disabled="disabled" />
  25. </view>
  26. <image class="arrow" src="/static/images/arrow_gray.png" mode=""></image>
  27. </view>
  28. </picker>
  29. </view>
  30. <view class="form-item">
  31. <text class="label">详细地址</text>
  32. <textarea class="form-textarea" v-model="form.detail" placeholder="请输入详细地址" />
  33. </view>
  34. </view>
  35. <!-- 设为默认地址 -->
  36. <view class="setting-box">
  37. <text class="label">设为默认地址</text>
  38. <evan-switch v-model="isDefault" activeColor="#0bb3f2" inactiveColor="rgba(0, 0, 0, 0.1)"></evan-switch>
  39. </view>
  40. </view>
  41. <view class="btn-box">
  42. <view class="sub-btn" @click="submit()">保存地址</view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. addAddress, // 添加地址
  49. editAddress, // 编辑地址
  50. getCitys//获取省市区
  51. } from "@/api/order.js"
  52. // import {parseAddress,getCity,getCitys,getAddressById,addAddress,editAddress} from '@/api/address'
  53. import EvanSwitch from '@/components/evan-switch/evan-switch.vue'
  54. export default {
  55. components: {
  56. EvanSwitch
  57. },
  58. data() {
  59. return {
  60. content:null,
  61. type:null,
  62. addressId:null,
  63. isDefault: false,
  64. addressList:[[],[],[]],
  65. multiIndex:[0,0,0],
  66. address:[],
  67. form: {
  68. realName:null,
  69. phone:null,
  70. detail:null,
  71. address: null,
  72. isDefault: 0,
  73. }
  74. }
  75. },
  76. onLoad(option) {
  77. console.log("option",option)
  78. this.type=option.type;
  79. if(this.type=='edit'){
  80. uni.setNavigationBarTitle({
  81.   title:"修改收货地址"
  82. })
  83. this.addressId=option.addressId;
  84. // this.getAddressById();
  85. }
  86. else{
  87. uni.setNavigationBarTitle({
  88.   title:"新增收货地址"
  89. })
  90. }
  91. this.getCitys()
  92. },
  93. methods: {
  94. // parseAddress(){
  95. // if(this.content==null||this.content==""){
  96. // uni.showToast({ icon:'none',title: '请输入地址信息'});
  97. // return;
  98. // }
  99. // var data={content:this.content};
  100. // parseAddress(data).then(
  101. // res => {
  102. // if(res.code==200){
  103. // this.form.realName=res.data.name
  104. // this.form.phone=res.data.mobile
  105. // this.form.address=res.data.provinceName+res.data.cityName+res.data.expAreaName
  106. // this.form.province=res.data.provinceName
  107. // this.form.city=res.data.cityName
  108. // this.form.district=res.data.expAreaName
  109. // this.form.detail=res.data.streetName+res.data.address
  110. // }else{
  111. // uni.showToast({
  112. // icon:'none',
  113. // title: res.msg,
  114. // });
  115. // }
  116. // },
  117. // rej => {}
  118. // );
  119. // },
  120. // getAddressById(){
  121. // var data={id:this.id};
  122. // getAddressById(data).then(
  123. // res => {
  124. // if(res.code==200){
  125. // this.form=res.data;
  126. // this.isDefault=this.form.isDefault==1?true:false;
  127. // this.form.address=this.form.province+this.form.city+this.form.district
  128. // }else{
  129. // uni.showToast({
  130. // icon:'none',
  131. // title: res.msg,
  132. // });
  133. // }
  134. // },
  135. // rej => {}
  136. // );
  137. // },
  138. submit(){
  139. if(this.type=="add"){
  140. this.addAddress()
  141. }
  142. else if(this.type=="edit"){
  143. this.editAddress()
  144. }
  145. },
  146. editAddress(){
  147. this.form.isDefault=this.isDefault?1:0
  148. editAddress(this.form).then(
  149. res => {
  150. if(res.code==200){
  151. uni.showToast({
  152. icon:'success',
  153. title: "操作成功",
  154. });
  155. setTimeout(function() {
  156. uni.$emit('refreshAddress');
  157. uni.navigateBack({
  158. delta: 1
  159. })
  160. }, 500);
  161. }else{
  162. uni.showToast({
  163. icon:'none',
  164. title: res.msg,
  165. });
  166. }
  167. },
  168. rej => {}
  169. );
  170. },
  171. addAddress(){
  172. this.form.isDefault=this.isDefault?1:0
  173. addAddress(this.form).then(
  174. res => {
  175. if(res.code==200){
  176. uni.showToast({
  177. icon:'success',
  178. title: "操作成功",
  179. });
  180. setTimeout(function() {
  181. uni.$emit('refreshAddress');
  182. uni.navigateBack({
  183. delta: 1
  184. })
  185. }, 500);
  186. }else{
  187. uni.showToast({
  188. icon:'none',
  189. title: res.msg,
  190. });
  191. }
  192. },
  193. rej => {}
  194. );
  195. },
  196. // 地区选择
  197. pickerChange(e) {
  198. this.multiIndex = e.detail.value;
  199. // 数组内的下标
  200. // 获取一级类目
  201. // 获取二级类目
  202. // 获取三级类目
  203. this.form.address=this.addressList[0][this.multiIndex[0]].n+this.addressList[1][this.multiIndex[1]].n+this.addressList[2][this.multiIndex[2]].n
  204. this.form.province=this.addressList[0][this.multiIndex[0]].n
  205. this.form.city=this.addressList[1][this.multiIndex[1]].n
  206. this.form.district=this.addressList[2][this.multiIndex[2]].n
  207. this.form.cityId=this.addressList[1][this.multiIndex[1]].v;
  208. },
  209. pickerColumnchange(e){
  210. // 第一列滑动
  211. if(e.detail.column === 0){
  212. this.multiIndex[0] = e.detail.value
  213. // console.log('第一列滑动');
  214. this.addressList[1] = this.address[this.multiIndex[0]].c;
  215. this.addressList[2] = this.address[this.multiIndex[0]].c[0].c
  216. // 第一列滑动 第二列 和第三列 都变为第一个
  217. this.multiIndex.splice(1, 1, 0)
  218. this.multiIndex.splice(2, 1, 0)
  219. }
  220. // 第二列滑动
  221. if(e.detail.column === 1){
  222. this.multiIndex[1] = e.detail.value
  223. // console.log('第二列滑动');
  224. // console.log(this.multiIndex)
  225. this.addressList[2] = this.address[this.multiIndex[0]].c[this.multiIndex[1]].c
  226. // 第二列 滑动 第三列 变成第一个
  227. this.multiIndex.splice(2, 1, 0)
  228. }
  229. // 第三列滑动
  230. if(e.detail.column === 2){
  231. this.multiIndex[2] = e.detail.value
  232. }
  233. },
  234. getCitys(){
  235. getCitys().then(
  236. res => {
  237. if(res.code==200){
  238. this.address=res.data
  239. for(var i=0; i<this.address.length; i++){
  240. this.addressList[0].push(this.address[i])
  241. }
  242. for(var i=0; i<this.address[0].c.length; i++){
  243. this.addressList[1].push(this.address[0].c[i])
  244. }
  245. for(var i=0; i<this.address[0].c[0].c.length; i++){
  246. this.addressList[2].push(this.address[0].c[0].c[i])
  247. }
  248. }else{
  249. uni.showToast({
  250. icon:'none',
  251. title: "请求失败",
  252. });
  253. }
  254. },
  255. rej => {}
  256. );
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="scss">
  262. page{
  263. height: 100%;
  264. }
  265. .content{
  266. height: 100%;
  267. display: flex;
  268. flex-direction: column;
  269. justify-content: space-between;
  270. .inner{
  271. height: calc(100% - 120upx);
  272. padding: 20upx;
  273. .address-box{
  274. padding: 30upx;
  275. background: #FFFFFF;
  276. border-radius: 16upx;
  277. margin-bottom: 20upx;
  278. position: relative;
  279. .textarea{
  280. width: 100%;
  281. height: 200upx;
  282. font-size: 30upx;
  283. color: #999999;
  284. padding-bottom:100rpx;
  285. }
  286. .btns{
  287. right:10rpx;
  288. bottom:10rpx;
  289. position: absolute;
  290. .btn{
  291. width: 155upx;
  292. height: 64upx;
  293. line-height: 64upx;
  294. font-size: 26upx;
  295. font-family: PingFang SC;
  296. font-weight: 500;
  297. text-align: center;
  298. border-radius: 32upx;
  299. &.parse{
  300. background: #0bb3f2;
  301. color: #FFFFFF;
  302. }
  303. }
  304. }
  305. }
  306. .form-box{
  307. padding: 0 30upx;
  308. background: #FFFFFF;
  309. border-radius: 16upx;
  310. .form-item{
  311. padding: 30upx 0;
  312. display: flex;
  313. align-items: flex-start;
  314. border-bottom: 1px solid #F1F1F1;
  315. &:last-child{
  316. border-bottom: none;
  317. }
  318. .label{
  319. width: 180upx;
  320. text-align: left;
  321. font-size: 30upx;
  322. line-height: 44upx;
  323. font-family: PingFang SC;
  324. font-weight: 500;
  325. color: #222222;
  326. flex-shrink: 0;
  327. }
  328. input{
  329. text-align: left;
  330. }
  331. .form-input{
  332. font-size: 30upx;
  333. font-family: PingFang SC;
  334. font-weight: 500;
  335. color: #999999;
  336. text-align: left;
  337. }
  338. .form-textarea{
  339. font-size: 30upx;
  340. color: #999999;
  341. height: 100upx;
  342. padding: 4upx 0;
  343. }
  344. .birth-picker {
  345. flex: 1;
  346. display: flex;
  347. align-items: center;
  348. .right-box{
  349. width: 100%;
  350. display: flex;
  351. align-items: center;
  352. .input-box{
  353. width: 470upx;
  354. }
  355. .arrow{
  356. width: 13upx;
  357. height: 23upx;
  358. margin-left: 20upx;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. .setting-box{
  365. height: 88upx;
  366. background: #FFFFFF;
  367. border-radius: 16upx;
  368. margin-top: 20upx;
  369. padding: 0 30upx;
  370. display: flex;
  371. align-items: center;
  372. justify-content: space-between;
  373. .label{
  374. font-size: 28upx;
  375. font-family: PingFang SC;
  376. font-weight: 500;
  377. color: #111111;
  378. }
  379. }
  380. }
  381. .btn-box{
  382. height: 120upx;
  383. padding: 0 30upx;
  384. display: flex;
  385. align-items: center;
  386. justify-content: center;
  387. background: #FFFFFF;
  388. .sub-btn{
  389. width: 100%;
  390. height: 88upx;
  391. line-height: 88upx;
  392. text-align: center;
  393. font-size: 30upx;
  394. font-family: PingFang SC;
  395. font-weight: bold;
  396. color: #FFFFFF;
  397. background: #0bb3f2;
  398. border-radius: 44upx;
  399. }
  400. }
  401. }
  402. </style>