add.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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" maxlength="11" 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: 'phone', checkType: 'phoneno', errorMsg: '手机号格式不对' },
  67. { name: 'area', checkType: 'notnull', errorMsg: '请选择省市区' },
  68. { name: 'street', checkType: 'notnull', errorMsg: '请输入详细地址' }
  69. ];
  70. if (!this.verify.check(this.item, rule)) {
  71. uni.showModal({ content: this.verify.error, showCancel: false });
  72. return false;
  73. }
  74. this.http.request({
  75. url: '/level-two-server/app/address/saveOrUpdate',
  76. method: 'POST',
  77. data: this.item,
  78. success: res => {
  79. uni.showToast({ title: '操作成功' });
  80. setTimeout(() => {
  81. uni.$emit('address');
  82. uni.navigateBack();
  83. }, 1000);
  84. }
  85. });
  86. },
  87. del(id) {
  88. uni.showModal({
  89. title: '提示',
  90. content: '确定删除该地址?',
  91. success: res => {
  92. if (res.confirm) {
  93. this.http.request({
  94. url: '/level-two-server/app/address/delete/' + this.item.id,
  95. success: res => {
  96. uni.showToast({ title: '删除成功' });
  97. setTimeout(() => {
  98. uni.$emit('address');
  99. uni.navigateBack();
  100. }, 1000);
  101. }
  102. });
  103. }
  104. }
  105. });
  106. }
  107. }
  108. };
  109. </script>
  110. <style lang="scss">
  111. .btn {
  112. border-radius: 5px;
  113. width: 100%;
  114. }
  115. </style>