add.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view>
  3. <view>
  4. <form report-submit="true" @submit="formSubmit">
  5. <view id="box">
  6. <view class="add-line">
  7. <view class="al-left">
  8. <text>收货人</text>
  9. </view>
  10. <view class="al-right">
  11. <input placeholder="收货人" placeholder-class="p-size" name="name" v-model="data.name" />
  12. </view>
  13. </view>
  14. <view class="add-line">
  15. <view class="al-left">
  16. <text>手机号码</text>
  17. </view>
  18. <view class="al-right">
  19. <input placeholder="手机号码" placeholder-class="p-size" name="tel" type="number" v-model="data.tel" />
  20. </view>
  21. </view>
  22. <view class="add-line">
  23. <view class="al-left">
  24. <text>所在地区</text>
  25. </view>
  26. <view class="al-right" @tap="showMulLinkageThreePicker">
  27. <view :style="'color:' + (data.region ? '#333' : '#585858') ">{{data.region ? data.region : "请选择"}}</view>
  28. <input type="text" name="region" v-show="false" :value="data.region"/>
  29. <view class="alr-jiantou">
  30. <image src="/static/img/ic_next.png"></image>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="add-line">
  35. <view class="al-left">
  36. <text>详细地址</text>
  37. </view>
  38. <view class="al-right">
  39. <textarea placeholder-class="p-size" name="address" placeholder="详细省份,城市,道路,门牌号,小区,楼栋号,单元室等(必填)" v-model="data.address" />
  40. </view>
  41. </view>
  42. <button class="nt add-btn" formType="submit">保存</button>
  43. </view>
  44. </form>
  45. </view>
  46. <mpvue-city-picker :themeColor="themeColor" ref="mpvueCityPicker" :pickerValueDefault="cityPickerValueDefault"
  47. @onCancel="onCancel" @onConfirm="onConfirm"></mpvue-city-picker>
  48. </view>
  49. </template>
  50. <script>
  51. import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue';
  52. import graceChecker from "../../../../library/utils/graceChecker.js";
  53. export default {
  54. components:{
  55. 'mpvue-city-picker': mpvueCityPicker
  56. },
  57. data() {
  58. return {
  59. cityPickerValueDefault: [0, 0, 0],
  60. themeColor: '#007AFF',
  61. data: {name:"",tel:"",address:"",region:"",City:0}
  62. }
  63. },
  64. onLoad(options) {
  65. this.id = options.id || 0;
  66. if(this.id > 0){
  67. uni.setNavigationBarTitle({
  68. title:"修改地址"
  69. })
  70. this.getData();
  71. }
  72. },
  73. methods: {
  74. getData(){
  75. this
  76. .request
  77. .post("userAddressInfo",{id:this.id})
  78. .then((res)=>{
  79. if(res.code == 200){
  80. this.data = res.data;
  81. }else{
  82. this.utils.Tip(res.msg);
  83. }
  84. }).catch(()=>{
  85. this.utils.Tip("网络错误,请稍后尝试");
  86. })
  87. },
  88. //表单提交
  89. formSubmit(e) {
  90. var that = this , formData = e.detail.value;
  91. //定义表单规则
  92. var rule = [
  93. {name:"name", checkType : "notnull", checkRule:"", errorMsg:"请输入收货人姓名"},
  94. {name:"tel", checkType : "phoneno", checkRule:"", errorMsg:"请输入正确的联系电话"},
  95. {name:"region", checkType : "notnull", checkRule:"", errorMsg:"请选择所在地区"},
  96. {name:"address", checkType : "notnull", checkRule:"", errorMsg:"请输入详细地址"}
  97. ];
  98. var checkRes = graceChecker.check(formData, rule);
  99. if(!checkRes){
  100. uni.showToast({ title: graceChecker.error, icon: "none" });
  101. return;
  102. }
  103. formData.id = this.id;
  104. formData.cityId = this.data.City;
  105. this.utils.loadIng("提交中...");
  106. this
  107. .request
  108. .post("userAddressSave",formData)
  109. .then(res=>{
  110. if(res.code == 200) {
  111. that.utils.Tip(res.msg);
  112. uni.$emit("addressEvent",{});
  113. uni.navigateBack();
  114. }else{
  115. that.utils.Tip(res.msg);
  116. }
  117. }).catch(function(){
  118. that.utils.Tip("网络错误,请稍后尝试");
  119. });
  120. },
  121. // 省市区选择
  122. showMulLinkageThreePicker() {
  123. this.$refs.mpvueCityPicker.show()
  124. },
  125. onCancel(e) {
  126. this.data.region = "";
  127. },
  128. onConfirm(e) {
  129. this.data.region = e.label;
  130. this.data.City = e.cityCode;
  131. },
  132. }
  133. }
  134. </script>
  135. <style>
  136. page {
  137. background: #F5F5F5;
  138. }
  139. .add-name{
  140. position: absolute;
  141. right: 15px;
  142. color: #4A4A4A;
  143. font-size: 13px;
  144. }
  145. .add-line{
  146. padding: 15px;
  147. display: flex;
  148. align-items: center;
  149. background: #fff;
  150. border-bottom: 1px #F5F5F5 solid;
  151. }
  152. .al-left{
  153. color: #585858;
  154. font-size: 14px;
  155. }
  156. .al-right{
  157. margin-left: auto;
  158. width: 75%;
  159. display: flex;
  160. align-items: center;
  161. justify-content: flex-end;
  162. }
  163. .al-right input{
  164. text-align: right;
  165. font-size: 14px;
  166. width: 100%;
  167. height: 100%;
  168. }
  169. .al-right textarea{
  170. width: 100%;
  171. height: 40px;
  172. font-size: 14px;
  173. }
  174. .p-size{
  175. color: #9B9B9B;
  176. }
  177. .alr-jiantou{
  178. width: 20px;
  179. height: 20px;
  180. margin-left: 6px;
  181. }
  182. .alr-jiantou image{
  183. width: 100%;
  184. height: 100%;
  185. display: block;
  186. }
  187. uni-picker{
  188. width: 100%;
  189. }
  190. button.add-btn{
  191. width: 90%;
  192. height: 50px;
  193. background: #db292b;
  194. color: #fff;
  195. border-radius: 100px;
  196. position: absolute;
  197. bottom: 50px;
  198. text-align: center;
  199. line-height: 50px;
  200. margin: 0 5%;
  201. }
  202. </style>