add.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view>
  3. <view class="forms">
  4. <view class="form_group pt0">
  5. <view class="lable re">收件人</view>
  6. <input placeholder="请输入" v-model="item.name" />
  7. </view>
  8. <view class="form_group">
  9. <view class="lable re">联系电话</view>
  10. <input type="number" placeholder="请输入" v-model="item.phone" />
  11. </view>
  12. <view class="form_group">
  13. <view class="lable re">省市区</view>
  14. <uni-data-picker :localdata="cityData" v-model="item.area" :map="{ text: 'name', value: 'name' }" popup-title="选择省市区" @change="change"></uni-data-picker>
  15. </view>
  16. <view class="form_group">
  17. <view class="lable re">详细地址</view>
  18. <textarea v-model="item.street" placeholder="请输入"></textarea>
  19. </view>
  20. </view>
  21. <view class="mfooter">
  22. <view class="flex">
  23. <view class="f" v-if="item.id">
  24. <button class="save btn" @click="del()">删除</button>
  25. </view>
  26. <view class="f">
  27. <button class="btn" @click="save()">保存</button>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import city from '../../../../../common/data.js';
  35. export default {
  36. data() {
  37. return {
  38. cityData: city.data.data,
  39. item: {}
  40. };
  41. },
  42. onLoad(e) {
  43. if (e.id) {
  44. this.http.request({
  45. url: '/level-two-server/app/address/getById/' + e.id,
  46. success: res => {
  47. this.item = res.data.data;
  48. uni.setNavigationBarTitle({ title: '编辑地址' });
  49. }
  50. });
  51. }
  52. },
  53. methods: {
  54. change(e) {
  55. if (e.detail.value.length > 0) {
  56. this.item.province = e.detail.value[0].value; //省
  57. this.item.city = e.detail.value[1].value; //市
  58. this.item.area = e.detail.value[e.detail.value.length - 1].value; //区
  59. }
  60. this.$forceUpdate();
  61. },
  62. save() {
  63. let rule = [
  64. { name: 'name', checkType: 'notnull', errorMsg: '请输入收件人姓名' },
  65. { name: 'phone', checkType: 'notnull', errorMsg: '请输入联系电话' },
  66. { name: 'area', checkType: 'notnull', errorMsg: '请选择省市区' },
  67. { name: 'street', checkType: 'notnull', errorMsg: '请输入详细地址' }
  68. ];
  69. if (!this.verify.check(this.item, rule)) {
  70. uni.showModal({ content: this.verify.error, showCancel: false });
  71. return false;
  72. }
  73. this.http.request({
  74. url: '/level-two-server/app/address/saveOrUpdate',
  75. method: 'POST',
  76. data: this.item,
  77. success: res => {
  78. uni.showToast({ title: '操作成功' });
  79. setTimeout(() => {
  80. uni.$emit('address');
  81. uni.navigateBack();
  82. }, 1000);
  83. }
  84. });
  85. },
  86. del(id) {
  87. uni.showModal({
  88. title: '提示',
  89. content: '确定删除该地址?',
  90. success: res => {
  91. if (res.confirm) {
  92. this.http.request({
  93. url: '/level-two-server/app/address/delete/' + this.item.id,
  94. success: res => {
  95. uni.showToast({ title: '删除成功' });
  96. setTimeout(() => {
  97. uni.$emit('address');
  98. uni.navigateBack();
  99. }, 1000);
  100. }
  101. });
  102. }
  103. }
  104. });
  105. }
  106. }
  107. };
  108. </script>
  109. <style lang="scss">
  110. .btn {
  111. border-radius: 5px;
  112. width: 100%;
  113. }
  114. </style>