index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="addaddress">
  3. <!-- header -->
  4. <cu-custom isBack bgColor="bg-gradual-blue"><view slot="content">{{status ? "修改地址" : '新增地址'}}</view></cu-custom>
  5. <!-- section -->
  6. <view class="section">
  7. <form>
  8. <view class="cu-form-group">
  9. <view class="title">姓名</view>
  10. <input :value="name" @input="e=>name=e.detail.value" placeholder="收货人姓名" />
  11. </view>
  12. <view class="cu-form-group">
  13. <view class="title">电话</view>
  14. <input @input="e=>tel=e.detail.value" placeholder="收货人电话" />
  15. <view class="cu-capsule radius">
  16. <view class="cu-tag bg-blue">+86</view>
  17. <view class="cu-tag line-blue">中国大陆</view>
  18. </view>
  19. </view>
  20. <view class="cu-form-group">
  21. <view class="title">收货地址</view>
  22. <picker mode="region" @change="e=>region=e.detail.value" :value="region">
  23. <view v-if="region.length>0" class="picker">{{ region[0] }},{{ region[1] }},{{ region[2] }}</view>
  24. <view v-else class="text-grey picker">
  25. 选择省 / 市 / 区
  26. </view>
  27. </picker>
  28. </view>
  29. <view class="cu-form-group align-start">
  30. <view class="title">详细地址</view>
  31. <textarea maxlength="-1" :value="textarea" @input="e=>textarea=e.detail.value" placeholder="街道门牌/楼层房间号等信息"></textarea>
  32. <text @click="addSelect" class="margin-left margin-top cuIcon-locationfill text-orange"></text>
  33. </view>
  34. <view class="cu-form-group">
  35. <view class="title">设置为默认收货地址</view>
  36. <switch @change="e=>checked=e.detail.value" :checked="checked"></switch>
  37. </view>
  38. </form>
  39. </view>
  40. <!-- footer -->
  41. <view class="footer">
  42. <view class="footer-content padding bg-white"><button class="cu-btn block">保存</button></view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {getSetting,openSetting,chooseLocation} from "@/common/device/index.js"
  48. export default {
  49. data() {
  50. return {
  51. status:false,//false 新增 true 修改
  52. // 参数
  53. name:"",
  54. tel:"",
  55. checked: true,
  56. region: [],
  57. textarea: ''
  58. };
  59. },
  60. methods: {
  61. async addSelect(){
  62. try{
  63. var address;
  64. var res=await getSetting();
  65. if(res.authSetting['scope.userLocation']===false){
  66. let result=await openSetting();
  67. if(result.authSetting['scope.userLocation']===true) address=await chooseLocation();
  68. }
  69. if(res.authSetting['scope.userLocation.userLocation'] === undefined || result.authSetting['scope.userLocation.userLocation'] === true){
  70. address=await chooseLocation();
  71. }
  72. this.textarea=address.address;
  73. }catch(err){
  74. console.log(err.message)
  75. }
  76. },
  77. },
  78. onLoad(options) {
  79. let {status}=options;
  80. this.status = status || false;
  81. }
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. .addaddress {
  86. .footer {
  87. height: 140upx;
  88. height: calc(140rpx + env(safe-area-inset-bottom) / 2);
  89. padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  90. .footer-content {
  91. position: fixed;
  92. bottom: 0;
  93. left: 0;
  94. width: 100%;
  95. button {
  96. background-color: #ee0a24;
  97. color: #fff;
  98. height: 80upx;
  99. border-radius: 80upx;
  100. }
  101. }
  102. }
  103. }
  104. </style>