addAddress.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <!-- 新增地址 -->
  3. <view>
  4. <u-navbar :title="headline" autoBack placeholder></u-navbar>
  5. <x-form ref="recipients" :list="list" :model="recipientsModel" :rules="rules"></x-form>
  6. <view class="btn_print" @click="addAddress()">
  7. <u-button type="primary" text="确定" shape="circle"></u-button>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import {
  13. formRules,
  14. pickupRulesil
  15. } from "./waybill.js";
  16. export default {
  17. data() {
  18. return {
  19. headline: '地址簿',
  20. list: pickupRulesil(),
  21. recipientsModel: {
  22. name: '',
  23. phone: '',
  24. address: '',
  25. },
  26. rules: {
  27. name: {
  28. required: true,
  29. message: '请输入姓名',
  30. trigger: ['blur', 'change']
  31. },
  32. phone: {
  33. required: true,
  34. message: '请输入电话',
  35. trigger: ['blur', 'change']
  36. },
  37. address: {
  38. required: true,
  39. message: '请输入地址',
  40. trigger: ['blur', 'change']
  41. },
  42. },
  43. valueNewly: '',
  44. operationType: 'sender',
  45. }
  46. },
  47. onUnload() {
  48. // console.log('页面销毁')
  49. uni.removeStorageSync('currentAddress')
  50. },
  51. onLoad(value) {
  52. this.valueNewly = value.newly
  53. this.operationType = value.type
  54. let address = uni.getStorageSync('currentAddress')
  55. if (address) {
  56. this.recipientsModel = address
  57. }
  58. if (value.newly == 'true') {
  59. if (value.type == 'sender') {
  60. this.headline = '新增寄件地址'
  61. } else if (value.type == 'consignee') {
  62. this.headline = '新增收件地址'
  63. }
  64. } else {
  65. if (value.type == 'sender') {
  66. this.headline = '编辑寄件地址'
  67. } else if (value.type == 'consignee') {
  68. this.headline = '编辑收件地址'
  69. }
  70. }
  71. },
  72. methods: {
  73. addAddress() {
  74. let params = {
  75. id: '',
  76. name: this.recipientsModel.name,
  77. phone: this.recipientsModel.phone,
  78. address: this.recipientsModel.address,
  79. addressType: this.operationType,
  80. }
  81. if (this.valueNewly == 'true') {
  82. // 新增
  83. delete params.id
  84. console.log(params, 22)
  85. this.$api.post('/api/address', params).then(res => {
  86. if (res.code == 200) {
  87. uni.showLoading({
  88. icon: 'success',
  89. title: '新增成功'
  90. });
  91. setTimeout(function() {
  92. uni.hideLoading();
  93. uni.navigateBack({
  94. delta: 1
  95. });
  96. }, 1000);
  97. }
  98. })
  99. } else {
  100. params.id = this.recipientsModel.id
  101. // 修改
  102. this.$api.put('/api/address', params).then(res => {
  103. if (res.code == 200) {
  104. uni.showLoading({
  105. icon: 'success',
  106. title: '修改成功'
  107. });
  108. setTimeout(function() {
  109. uni.hideLoading();
  110. uni.navigateBack({
  111. delta: 1
  112. });
  113. }, 1000);
  114. }
  115. })
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. page {
  123. background-color: #fff !important;
  124. }
  125. </style>