add.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="address-form">
  3. <form @submit="formSubmit" @reset="formReset">
  4. <view class="bg-white p-0-30 f30">
  5. <view class="d-s-c border-b-d9">
  6. <text class="key-name">收货人</text>
  7. <input class="ml20 flex-1 f32 p-30-0" name="name" type="text" placeholder-class="grary9" v-model="address.name"
  8. placeholder="请输入收货人姓名" />
  9. </view>
  10. <view class="d-s-c border-b-d9">
  11. <text class="key-name">联系方式</text>
  12. <input class="ml20 flex-1 f32 p-30-0" name="phone" type="text" placeholder-class="grary9" v-model="address.phone"
  13. placeholder="请输入收货人手机号" />
  14. </view>
  15. <view class="d-s-c border-b-d9">
  16. <text class="key-name">所在地区</text>
  17. <view class="input-box flex-1">
  18. <input class="ml20 f32 flex-1 p-30-0" type="text" value="" placeholder-class="grary9" placeholder="" v-model="selectCity"
  19. disabled="true" @click="showMulLinkageThreePicker" />
  20. </view>
  21. </view>
  22. <view class="d-s-c border-b-d9">
  23. <text class="key-name">详细地址</text>
  24. <textarea class="ml20 flex-1 p-30-0 lh150" name="detail" :auto-height="true" v-model="address.detail"
  25. placeholder-class="grary9" placeholder="请输入街道小区楼牌号等"></textarea>
  26. </view>
  27. </view>
  28. <view class="p30"><button type="primary" form-type="submit" class="btn-gcred f32 mt60 addBtn">保存</button></view>
  29. </form>
  30. <mpvue-city-picker v-if="is_load" ref="mpvueCityPicker" :province="province" :city="city" :area="area" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker>
  31. </view>
  32. </template>
  33. <script>
  34. import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue';
  35. export default {
  36. components: {
  37. mpvueCityPicker
  38. },
  39. data() {
  40. return {
  41. cityPickerValueDefault: [0, 0, 0],
  42. selectCity: '选择省,市,区',
  43. province_id: 0,
  44. city_id: 0,
  45. region_id: 0,
  46. address: {},
  47. delta: 1,
  48. province: [],
  49. city: [],
  50. area: [],
  51. is_load: false
  52. };
  53. },
  54. onLoad: function(options) {
  55. this.delta = options.delta;
  56. this.getData();
  57. },
  58. methods: {
  59. // 获取省市区
  60. getData(){
  61. let self = this;
  62. self._post('settings/getRegion', {}, function(res) {
  63. self.province = res.data.regionData[0];
  64. self.city = res.data.regionData[1];
  65. self.area = res.data.regionData[2];
  66. self.is_load = true;
  67. });
  68. },
  69. /*提交*/
  70. formSubmit: function(e) {
  71. let self = this;
  72. var formdata = e.detail.value;
  73. formdata.province_id = self.province_id;
  74. formdata.city_id = self.city_id;
  75. formdata.region_id = self.region_id;
  76. if (formdata.name == '') {
  77. uni.showToast({
  78. title: '请输入收货人姓名',
  79. duration: 1000,
  80. icon: 'none'
  81. });
  82. return false;
  83. }
  84. if (formdata.phone == '') {
  85. uni.showToast({
  86. title: '请输入手机号码',
  87. duration: 1000,
  88. icon: 'none'
  89. });
  90. return false;
  91. }
  92. /*let reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/;
  93. if (!reg.test(formdata.phone)) {
  94. uni.showToast({
  95. title: '手机号码格式不正确',
  96. duration: 1000,
  97. icon: 'none'
  98. });
  99. return false;
  100. }*/
  101. if (formdata.province_id == 0 || formdata.city_id == 0 || formdata.region_id) {
  102. if (formdata.detail == '') {
  103. uni.showToast({
  104. title: '请选择完整省市区',
  105. duration: 1000,
  106. icon: 'none'
  107. });
  108. return false;
  109. }
  110. }
  111. if (formdata.detail == '') {
  112. uni.showToast({
  113. title: '请输入街道小区楼牌号等',
  114. duration: 1000,
  115. icon: 'none'
  116. });
  117. return false;
  118. }
  119. self._post('user.address/add', formdata, function(res) {
  120. self.showSuccess(res.msg, function() {
  121. // #ifndef H5
  122. uni.navigateBack({
  123. delta: parseInt(self.delta)
  124. });
  125. // #endif
  126. // #ifdef H5
  127. history.go(-self.delta);
  128. // #endif
  129. });
  130. });
  131. },
  132. formReset: function(e) {
  133. console.log('清空数据');
  134. },
  135. /*三级联动选择*/
  136. showMulLinkageThreePicker() {
  137. this.$refs.mpvueCityPicker.show();
  138. },
  139. /*确定选择的省市区*/
  140. onConfirm(e) {
  141. this.selectCity = e.label;
  142. this.province_id = e.cityCode[0];
  143. this.city_id = e.cityCode[1];
  144. this.region_id = e.cityCode[2];
  145. }
  146. }
  147. };
  148. </script>
  149. <style>
  150. page {
  151. background-color: #FFFFFF;
  152. }
  153. .address-form {
  154. /* border-top: 16rpx solid #f2f2f2; */
  155. }
  156. .address-form .key-name {
  157. width: 140rpx;
  158. font-size: 32rpx
  159. }
  160. .address-form .btn-red {
  161. height: 88rpx;
  162. line-height: 88rpx;
  163. border-radius: 44rpx;
  164. box-shadow: 0 8rpx 16rpx 0 rgba(226, 35, 26, .6);
  165. }
  166. .addBtn {
  167. height: 80rpx;
  168. line-height: 80rpx;
  169. border-radius: 40rpx;
  170. }
  171. </style>