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.

123 lines
3.0 KiB

3 years ago
  1. <template>
  2. <view class="app">
  3. <view class="cell row b-b">
  4. <text class="tit">收货人</text>
  5. <input class="input" type="text" maxlength="10" v-model="data.name" placeholder="请输入收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="cell row b-b">
  8. <text class="tit">手机号</text>
  9. <input class="input" type="number" maxlength="11" v-model="data.mobile" placeholder="请输入收货人手机号码" placeholder-class="placeholder" />
  10. </view>
  11. <view class="cell row b-b" @click="chooseAddress">
  12. <text class="tit">地址</text>
  13. <text class="input clamp" :class="{placeholder: !data.address.address}">
  14. {{ data.address.address ?
  15. data.address.address + ' ' + data.address.room :
  16. '请在地图选择收货地址'
  17. }}
  18. </text>
  19. <text class="mix-icon icon-you"></text>
  20. </view>
  21. <view class="cell row b-b">
  22. <text class="tit fill">设为默认地址</text>
  23. <switch :checked="data.is_default" color="#FF536F" @change="onSwitchChange" />
  24. </view>
  25. <mix-button ref="confirmBtn" text="提交" marginTop="60rpx" @onConfirm="submit"></mix-button>
  26. </view>
  27. </template>
  28. <script>
  29. import {checkStr} from '@/common/js/util'
  30. export default {
  31. data() {
  32. return {
  33. data: {
  34. is_default: true,
  35. address: {}
  36. }
  37. }
  38. },
  39. onLoad(options) {
  40. if(options.data){
  41. this.data = JSON.parse(options.data)
  42. }
  43. },
  44. methods: {
  45. async submit(){
  46. const data = this.data;
  47. if(!data.name){
  48. this.$util.msg('请输入收货人姓名');
  49. this.$refs.confirmBtn.stop();
  50. return;
  51. }
  52. if(!checkStr(data.mobile, 'mobile')){
  53. this.$util.msg('请输入正确的手机号码');
  54. this.$refs.confirmBtn.stop();
  55. return;
  56. }
  57. if(!data.address.address){
  58. this.$util.msg('请选择收货地址');
  59. this.$refs.confirmBtn.stop();
  60. return;
  61. }
  62. const operation = data._id ? 'update' : 'add';
  63. const res = await this.$request('address', operation, data);
  64. this.$util.msg(res.msg);
  65. if(res.status === 1){
  66. this.$util.prePage().loadData();
  67. setTimeout(()=>{
  68. uni.navigateBack();
  69. }, 1000)
  70. }
  71. },
  72. //选择地址
  73. chooseAddress(){
  74. let url = '/pages/chooseAddress/index';
  75. if(this.data.address.title){
  76. url += `?data=${JSON.stringify(this.data.address)}`;
  77. }
  78. this.navTo(url);
  79. },
  80. //选择地址回调
  81. setAddress(e){
  82. console.log(JSON.stringify(e));
  83. this.data.address = e;
  84. },
  85. onSwitchChange(e){
  86. this.data.is_default = e.detail.value;
  87. }
  88. }
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .app{
  93. padding: 10rpx 44rpx 0;
  94. }
  95. .cell{
  96. height: 106rpx;
  97. .tit{
  98. min-width: 130rpx;
  99. font-size: 30rpx;
  100. color: #333;
  101. }
  102. .input{
  103. flex: 1;
  104. font-size: 30rpx;
  105. color: #333;
  106. }
  107. .icon-you{
  108. flex-shrink: 0;
  109. margin-right: 8rpx;
  110. margin-left: 40rpx;
  111. font-size: 24rpx;
  112. color: #aaa;
  113. }
  114. switch{
  115. transform: scale(0.8) translateX(10rpx);
  116. transform-origin: center right;
  117. }
  118. }
  119. </style>