addAddress.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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="确定"></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. validator: (rule, value, callback) => {
  38. return uni.$u.test.mobile(value);
  39. },
  40. message: '请输入正确手机号码',
  41. trigger: ['change', 'blur'],
  42. }],
  43. address: {
  44. required: true,
  45. message: '请输入地址',
  46. trigger: ['blur', 'change']
  47. },
  48. },
  49. valueNewly: '',
  50. operationType: 'sender',
  51. }
  52. },
  53. onUnload() {
  54. // console.log('页面销毁')
  55. uni.removeStorageSync('currentAddress')
  56. },
  57. onLoad(value) {
  58. this.valueNewly = value.newly
  59. this.operationType = value.type
  60. let address = uni.getStorageSync('currentAddress')
  61. if (address) {
  62. this.recipientsModel = address
  63. }
  64. if (value.newly == 'true') {
  65. if (value.type == 'sender') {
  66. this.headline = '新增寄件地址'
  67. } else if (value.type == 'consignee') {
  68. this.headline = '新增收件地址'
  69. }
  70. } else {
  71. if (value.type == 'sender') {
  72. this.headline = '编辑寄件地址'
  73. } else if (value.type == 'consignee') {
  74. this.headline = '编辑收件地址'
  75. }
  76. }
  77. },
  78. methods: {
  79. addAddress() {
  80. let params = {
  81. id: '',
  82. name: this.recipientsModel.name,
  83. phone: this.recipientsModel.phone,
  84. address: this.recipientsModel.address,
  85. addressType: this.operationType,
  86. }
  87. if (this.valueNewly == 'true') {
  88. // 新增
  89. delete params.id
  90. console.log(params, 22)
  91. this.$api.post('/api/address', params).then(res => {
  92. if (res.code == 200) {
  93. uni.showLoading({
  94. icon: 'success',
  95. title: '新增成功'
  96. });
  97. setTimeout(function() {
  98. uni.hideLoading();
  99. uni.navigateBack({
  100. delta: 1
  101. });
  102. }, 1000);
  103. }
  104. })
  105. } else {
  106. params.id = this.recipientsModel.id
  107. // 修改
  108. this.$api.put('/api/address', params).then(res => {
  109. if (res.code == 200) {
  110. uni.showLoading({
  111. icon: 'success',
  112. title: '修改成功'
  113. });
  114. setTimeout(function() {
  115. uni.hideLoading();
  116. uni.navigateBack({
  117. delta: 1
  118. });
  119. }, 1000);
  120. }
  121. })
  122. }
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. page {
  129. background-color: #fff !important;
  130. }
  131. </style>