add.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <uni-forms ref="form" v-model="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="number" v-model="form.phone" placeholder="请输入联系电话" />
  11. </uni-forms-item>
  12. <uni-forms-item label="地图选点">
  13. <button type="default" size="mini" class="toLoacl" @click="toLocaltion()">地图选点</button>
  14. </uni-forms-item>
  15. <uni-forms-item label="所在省份">
  16. <picker class="picker" mode="selector" :range="provinceList" @change="proChange" range-key="value">
  17. <view>{{form.province||'请选择所在省份'}}</view>
  18. </picker>
  19. </uni-forms-item>
  20. <uni-forms-item label="所在市">
  21. <picker class="picker" mode="selector" :range="cityList" @change="cityChange" range-key="value">
  22. <view>{{form.city||'请选择所在市'}}</view>
  23. </picker>
  24. </uni-forms-item>
  25. <uni-forms-item label="所在区">
  26. <picker class="picker" mode="selector" :range="areaList" @change="areaChange" range-key="value">
  27. <view>{{form.area||'请选择所在区'}}</view>
  28. </picker>
  29. </uni-forms-item>
  30. <uni-forms-item label="详细地址" name="address">
  31. <uni-easyinput type="textarea" v-model="form.address" placeholder="请输入所在小区/大厦/学校" />
  32. </uni-forms-item>
  33. </uni-forms>
  34. <view class="btn">
  35. <button type="primary" @click="onSubmit('form')" size="small">提交保存</button>
  36. </view>
  37. </view>
  38. </view>
  39. </mobile-frame>
  40. </template>
  41. <script>
  42. const chooseLocation = requirePlugin('chooseLocation');
  43. export default {
  44. data() {
  45. return {
  46. id: '',
  47. form: {},
  48. rules: {
  49. // name: {
  50. // rules: [{
  51. // required: true,
  52. // errorMessage: '请输入收货人',
  53. // }]
  54. // },
  55. // phone: {
  56. // rules: [{
  57. // required: true,
  58. // errorMessage: '请输入联系电话',
  59. // tel: true
  60. // }]
  61. // },
  62. // deptname: {
  63. // rules: [{
  64. // required: true,
  65. // errorMessage: '请输入机构名称'
  66. // }]
  67. // },
  68. // address: {
  69. // rules: [{
  70. // required: true,
  71. // errorMessage: '请输入详细地址'
  72. // }]
  73. // },
  74. },
  75. provinceList: [ //所在省份
  76. {
  77. code: '1',
  78. value: '吉林省',
  79. },
  80. {
  81. code: '2',
  82. value: '辽宁省',
  83. },
  84. {
  85. code: '3',
  86. value: '黑龙江省',
  87. },
  88. ],
  89. cityList: [ //所在市
  90. {
  91. code: '1-1',
  92. value: '长春市',
  93. },
  94. {
  95. code: '2-1',
  96. value: '大连市',
  97. },
  98. {
  99. code: '3-1',
  100. value: '哈尔滨市',
  101. },
  102. ],
  103. areaList: [ //所在区
  104. {
  105. code: '1-1-1',
  106. value: '朝阳区'
  107. },
  108. {
  109. code: '2-1-1',
  110. value: '开发区'
  111. },
  112. {
  113. code: '3-1-1',
  114. value: '发展区'
  115. },
  116. ]
  117. };
  118. },
  119. onLoad: function(e) {
  120. const that = this;
  121. that.$set(that, `id`, e && e.id || '');
  122. that.search()
  123. },
  124. onShow: function() {
  125. const that = this;
  126. that.searchLocal()
  127. },
  128. onUnload: function() {
  129. chooseLocation.setLocation(null);
  130. },
  131. methods: {
  132. // 查询详细信息
  133. async search() {
  134. const that = this;
  135. if (that.id) {
  136. let res = await that.$api(`/address/${that.id}`, 'GET')
  137. if (res.errcode == '0') {
  138. console.log(res.data);
  139. that.$set(that, `form`, res.data)
  140. }
  141. }
  142. },
  143. // 定位
  144. toLocaltion() {
  145. const that = this;
  146. const key = that.$config.txlocalKey;
  147. const referer = that.$config.txlocalReferer;
  148. uni.navigateTo({
  149. url: `plugin://chooseLocation/index?key=${key}&referer=${referer}`
  150. });
  151. },
  152. searchLocal() {
  153. const location = chooseLocation.getLocation();
  154. console.log(location);
  155. },
  156. // 选择省份
  157. proChange(e) {
  158. const that = this;
  159. let data = that.provinceList[e.detail.value];
  160. if (data) {
  161. that.$set(that.form, `province`, data.value)
  162. }
  163. },
  164. // 选择区
  165. areaChange(e) {
  166. const that = this;
  167. let data = that.areaList[e.detail.value];
  168. if (data) {
  169. that.$set(that.form, `area`, data.value)
  170. }
  171. },
  172. // 选择市
  173. cityChange(e) {
  174. const that = this;
  175. let data = that.cityList[e.detail.value];
  176. if (data) {
  177. that.$set(that.form, `city`, data.value)
  178. }
  179. },
  180. // 提交保存
  181. onSubmit() {
  182. const that = this;
  183. let data = that.form;
  184. data = {
  185. ...data,
  186. check: that.check
  187. }
  188. },
  189. }
  190. }
  191. </script>
  192. <style lang="scss">
  193. .main {
  194. display: flex;
  195. flex-direction: column;
  196. width: 100vw;
  197. height: 100vh;
  198. .one {
  199. padding: 2vw;
  200. .toLoacl {
  201. margin: 1vw 0 0 0;
  202. }
  203. .picker {
  204. border: 1px solid #3333;
  205. border-radius: 5px;
  206. padding: 2vw;
  207. }
  208. }
  209. }
  210. // .uni-forms-item {
  211. // margin-bottom: 6vw !important;
  212. // display: flex;
  213. // flex-direction: row;
  214. // }
  215. // .local {
  216. // .uni-data-tree {
  217. // width: 60vw;
  218. // }
  219. // }
  220. // .localicon {
  221. // position: absolute;
  222. // right: 0;
  223. // top: 5px;
  224. // }
  225. </style>