add.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <view class="main">
  4. <view class="one">
  5. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  6. <uni-forms-item label="收货人" name="name">
  7. <uni-easyinput type="text" v-model="form.name" placeholder="请输入收货人" />
  8. </uni-forms-item>
  9. <uni-forms-item label="联系电话" name="phone">
  10. <uni-easyinput type="text" v-model="form.phone" placeholder="请输入联系电话" />
  11. </uni-forms-item>
  12. <uni-forms-item label="所在地区" name="deptname">
  13. <uni-data-picker placeholder="请选择省,市,区/街道" popup-title="选择省,市,区/街道" :localdata="provincial"
  14. @change="onchange" class="local">
  15. </uni-data-picker>
  16. <text class="localicon iconfont icon-dingweixiao"
  17. @click="tolocation('/pagesMy/address/location')">定位</text>
  18. </uni-forms-item>
  19. <uni-forms-item label="详细地址" name="address">
  20. <uni-easyinput type="text" v-model="form.address" placeholder="请输入所在小区/大厦/学校" />
  21. </uni-forms-item>
  22. <uni-forms-item label="楼牌号" name="num">
  23. <uni-easyinput type="text" v-model="form.num" placeholder="请输入楼牌号" />
  24. </uni-forms-item>
  25. <uni-forms-item label="设为默认" name="true">
  26. <switch :checked="check" @change="switchChange" />
  27. </uni-forms-item>
  28. </uni-forms>
  29. <view class="btn">
  30. <button type="primary" @click="onSubmit('form')" size="small">提交保存</button>
  31. </view>
  32. </view>
  33. </view>
  34. </mobile-frame>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. frameStyle: {
  41. useBar: false
  42. },
  43. form: {},
  44. rules: {
  45. name: {
  46. rules: [{
  47. required: true,
  48. errorMessage: '请输入收货人',
  49. }]
  50. },
  51. phone: {
  52. rules: [{
  53. required: true,
  54. errorMessage: '请输入联系电话',
  55. tel: true
  56. }]
  57. },
  58. deptname: {
  59. rules: [{
  60. required: true,
  61. errorMessage: '请输入机构名称'
  62. }]
  63. },
  64. address: {
  65. rules: [{
  66. required: true,
  67. errorMessage: '请输入详细地址'
  68. }]
  69. },
  70. },
  71. provincial: [],
  72. check: false,
  73. };
  74. },
  75. onLoad: function(e) {
  76. console.log(e);
  77. },
  78. onShow: function() {},
  79. methods: {
  80. toPath(e) {
  81. if (e && e.route) uni.redirectTo({
  82. url: `/${e.route}`
  83. })
  84. },
  85. // 是否设为默认地址
  86. switchChange(e) {
  87. const that = this;
  88. const {
  89. value
  90. } = e.detail;
  91. that.$set(that, `check`, value);
  92. },
  93. // 选择城市
  94. onchange() {},
  95. // 定位
  96. tolocation(route, e) {
  97. uni.navigateTo({
  98. url: `${route}`
  99. })
  100. },
  101. // 提交保存
  102. onSubmit() {
  103. const that = this;
  104. let data = that.form;
  105. data = {
  106. ...data,
  107. check: that.check
  108. }
  109. console.log(data);
  110. // this.$refs.form.validate().then(async (res) => {
  111. // let arr;
  112. // if (data._id) {
  113. // arr = await that.$api(``, 'POST', data)
  114. // } else {
  115. // arr = await that.$api(``, 'POST', data)
  116. // }
  117. // if (arr.errcode == '0') {
  118. // uni.showToast({
  119. // title: `维护信息成功`,
  120. // icon: 'success',
  121. // duration: 2000
  122. // });
  123. // that.back()
  124. // } else {
  125. // uni.showToast({
  126. // title: arr.errmsg,
  127. // icon: 'error',
  128. // duration: 2000
  129. // })
  130. // }
  131. // })
  132. },
  133. }
  134. }
  135. </script>
  136. <style lang="scss">
  137. .main {
  138. display: flex;
  139. flex-direction: column;
  140. width: 100vw;
  141. height: 100vh;
  142. .one {
  143. padding: 2vw;
  144. .uni-input {
  145. border: #f1f1ff 1px solid;
  146. padding: 2vw 2vw;
  147. border-radius: 1vw;
  148. }
  149. .btn {
  150. text-align: center;
  151. button {
  152. margin: 0 2vw 2vw 2vw;
  153. background-color: var(--f35BColor);
  154. color: var(--fffColor);
  155. }
  156. }
  157. }
  158. }
  159. .uni-forms-item {
  160. margin-bottom: 6vw !important;
  161. display: flex;
  162. flex-direction: row;
  163. }
  164. .local {
  165. .uni-data-tree {
  166. width: 60vw;
  167. }
  168. }
  169. .localicon {
  170. position: absolute;
  171. right: 0;
  172. top: 5px;
  173. }
  174. </style>