info.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view>
  3. <view class="alter_info">请选择您药店/诊所所在城市,选择后不可更改,请谨慎选择</view>
  4. <view class="form">
  5. <!-- 地区代表表单 -->
  6. <form class="info_form">
  7. <view class="form_group">
  8. <view class="group_title">所在城市:</view>
  9. <view class="group_box">
  10. <picker mode="multiSelector" class="form_ctrl" :range="cityArray" @columnchange="cityChange" @change="cityFinish">
  11. <view class="area_text">
  12. <text v-if="requestParam.province"> {{ requestParam.province }} </text>
  13. <text v-if="requestParam.city"> / {{ requestParam.city }} </text>
  14. </view>
  15. </picker>
  16. </view>
  17. </view>
  18. <button @click="toApply" class="submit_btn">提交</button>
  19. </form>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { getProvinces, getMyCity } from '../../utils/city';
  25. export default {
  26. data() {
  27. return {
  28. requestParam: {
  29. province: '',
  30. city: '',
  31. },
  32. cityArray: [[], []],
  33. cityValue: [0, 0],
  34. };
  35. },
  36. onLoad() {
  37. // 替换对应的数据
  38. this.cityArray.splice(0, 1, getProvinces());
  39. this.cityArray.splice(1, 1, getMyCity(this.cityValue[0]));
  40. // 默认地址
  41. // this.requestParam.province = this.cityArray[0][this.cityValue[0]]
  42. // this.requestParam.city = this.cityArray[1][this.cityValue[1]];
  43. },
  44. onShow() {
  45. // 登录信息
  46. if (!this.$checkAccess.alterLogin()) return;
  47. // 授权成功以后,调用绑定
  48. this.$http.request('api/custom/get_city', {}, 'get').then((re) => {
  49. // 成功的话
  50. if (re.code != 'success') {
  51. // 跳转
  52. uni.showToast({ title: re.msg, icon: 'none' });
  53. return;
  54. }
  55. this.requestParam.province = re.data.province;
  56. this.requestParam.city = re.data.city;
  57. });
  58. },
  59. methods: {
  60. toApply() {
  61. // 登录信息
  62. if (!this.$checkAccess.alterLogin()) return;
  63. // 提示信息
  64. if (!this.requestParam.province) {
  65. uni.showToast({
  66. title: '请选择所在城市',
  67. icon: 'none',
  68. });
  69. return;
  70. }
  71. // 提示信息
  72. if (!this.requestParam.city) {
  73. uni.showToast({
  74. title: '请选择所在城市',
  75. icon: 'none',
  76. });
  77. return;
  78. }
  79. // 请求状态
  80. uni.showLoading({ mask: true });
  81. // 授权成功以后,调用绑定
  82. this.$http.request('api/custom/set_city', this.requestParam, 'post').then((re) => {
  83. // 关闭
  84. uni.hideLoading();
  85. // 成功的话
  86. if (re.code != 'success') {
  87. // 跳转
  88. uni.showToast({ title: re.msg, icon: 'none' });
  89. return;
  90. }
  91. uni.switchTab({ url: '/pages/user/index' });
  92. });
  93. },
  94. cityChange(e) {
  95. // 替换三个选项
  96. this.cityValue.splice(e.detail.column, 1, e.detail.value);
  97. // 下一级设置为0
  98. if (e.detail.column == 0) {
  99. this.cityValue.splice(1, 1, 0);
  100. this.cityValue.splice(2, 1, 0);
  101. }
  102. if (e.detail.column == 1) {
  103. this.cityValue.splice(2, 1, 0);
  104. }
  105. // 替换对应的数据
  106. this.cityArray.splice(0, 1, getProvinces());
  107. this.cityArray.splice(1, 1, getMyCity(this.cityValue[0]));
  108. },
  109. cityFinish(e) {
  110. this.requestParam.province = this.cityArray[0][this.cityValue[0]];
  111. this.requestParam.city = this.cityArray[1][this.cityValue[1]];
  112. },
  113. },
  114. };
  115. </script>
  116. <style lang="less">
  117. .alter_info {
  118. display: block;
  119. color: #f89c33;
  120. font-size: 20rpx;
  121. overflow: hidden;
  122. margin: 20rpx auto;
  123. background: #ffffff;
  124. line-height: 40rpx;
  125. padding: 35rpx 35rpx;
  126. text-align: center;
  127. }
  128. .info_form {
  129. display: block;
  130. overflow: hidden;
  131. padding: 20rpx 0rpx;
  132. background: #ffffff;
  133. .form_group {
  134. display: block;
  135. overflow: hidden;
  136. line-height: 60rpx;
  137. padding: 20rpx 35rpx;
  138. .group_title {
  139. float: left;
  140. width: 160rpx;
  141. display: block;
  142. overflow: hidden;
  143. font-size: 30rpx;
  144. margin-right: 20rpx;
  145. }
  146. .group_box {
  147. width: 480rpx;
  148. float: left;
  149. display: block;
  150. .form_ctrl {
  151. height: 56rpx;
  152. font-size: 24rpx;
  153. padding: 0rpx 20rpx;
  154. line-height: 56rpx;
  155. border: 2rpx solid #dddddd;
  156. .area_text {
  157. width: 446rpx;
  158. height: 56rpx;
  159. font-size: 20rpx;
  160. overflow: hidden;
  161. white-space: nowrap;
  162. line-height: 56rpx;
  163. text-overflow: ellipsis;
  164. }
  165. }
  166. .group_image {
  167. width: 200rpx;
  168. height: 200rpx;
  169. }
  170. .choose_image {
  171. display: block;
  172. width: 200rpx;
  173. height: 200rpx;
  174. font-size: 38rpx;
  175. text-align: center;
  176. line-height: 200rpx;
  177. border: 2rpx solid #dddddd;
  178. }
  179. }
  180. }
  181. .submit_btn {
  182. color: #ffffff;
  183. width: 220rpx;
  184. height: 80rpx;
  185. display: block;
  186. font-size: 30rpx;
  187. padding: 0rpx 0rpx;
  188. line-height: 80rpx;
  189. margin: 50rpx auto;
  190. background-color: forestgreen;
  191. }
  192. }
  193. </style>