index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view :style="{ minHeight: sys.windowHeight + 'px' }" :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
  3. <tm-menubars title="消息列表" :shadow="0" :showback="true"></tm-menubars>
  4. <div>
  5. <tm-sheet class="kuang" style="padding-bottom: 40px !important;">
  6. <view style="width: 94%;margin:0 auto;">
  7. <tm-input title="收货人" placeholder="请填写收货人姓名" v-model="name"></tm-input>
  8. <tm-input title="手机号码" placeholder="填写收件人手机号码" v-model="mobile"></tm-input>
  9. <tm-input title="所在地区" placeholder="省市区县、乡镇等" v-model="region" @click="dateSe_3"></tm-input>
  10. <tm-input title="详细地址" placeholder="街道、楼牌号等" v-model="address"></tm-input>
  11. </view>
  12. </tm-sheet>
  13. <tm-sheet class="kuang" style="padding-bottom: 20px !important;">
  14. <view style="width: 94%;margin:0 auto;padding-top:15px;">
  15. <view class="fl text-white mt-10" style="width: 15%;">标签</view>
  16. <view class="fl" style="width: 80%;">
  17. <tm-button class="ml-20" :round="10" theme="gray" size="s">{{label}}</tm-button>
  18. <!-- <tm-button class="ml-20" :round="10" theme="gray" size="s">学校</tm-button>
  19. <tm-button class="ml-20" :round="10" theme="gray" size="s">学校</tm-button>
  20. <tm-button class="ml-20" :round="10" theme="gray" size="s">学校</tm-button>
  21. <tm-button class="ml-20" :round="10" theme="gray" size="s">学校</tm-button> -->
  22. <tm-button class="ml-20" :round="10" theme="gray" size="s">+</tm-button>
  23. </view>
  24. <view style="clear: both;"></view>
  25. <tm-listitem title="设置为默认地址" @click="btnClick">
  26. <template v-slot:rightIcon="">
  27. <tm-switch offBgcolor="yellow text-black" :text="['','']" color="primary" v-model="on">
  28. </tm-switch>
  29. </template>
  30. </tm-listitem>
  31. </view>
  32. </tm-sheet>
  33. <tm-button :round="24" class="sao mb-40 mt-40" block @click="saveAdd">保存</tm-button>
  34. </div>
  35. <!-- 弹出层消息 -->
  36. <tm-message ref="toast"></tm-message>
  37. <!-- 地区选择 -->
  38. <tm-pickersCity @confirm="dateSe_3" btn-color="bg-gradient-deep-purple-accent" v-model="isAdd">
  39. <!-- <tm-button theme="bg-gradient-deep-purple-accent">地区选择</tm-button> -->
  40. </tm-pickersCity>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. myRequest
  46. } from '@/api/request.js'
  47. export default {
  48. data() {
  49. return {
  50. isAdd: false,
  51. on: false,
  52. name: '',
  53. mobile: '',
  54. region: '',
  55. address: '',
  56. label: '学校',
  57. isdefault: 0,
  58. d_3: [],
  59. };
  60. },
  61. onLoad() {
  62. },
  63. created() {
  64. var that = this;
  65. setTimeout(function() {
  66. if (uni.getStorageSync("token") == "") {
  67. uni.redirectTo({
  68. url: "/pages/login/index"
  69. })
  70. }
  71. }, 1000)
  72. this.sys = uni.getSystemInfoSync();
  73. },
  74. methods: {
  75. dateSe_3(e) {
  76. this.isAdd = true;
  77. if (this.d_3 != null) {
  78. this.d_3 = e;
  79. this.region = this.d_3.join('');
  80. console.log(this.d_3, this.region, '地区');
  81. }
  82. },
  83. // 设置默认地址
  84. btnClick() {
  85. if (this.on) {
  86. this.isdefault = 1;
  87. } else {
  88. this.isdefault = 0;
  89. }
  90. },
  91. // 保存地址
  92. saveAdd() {
  93. let that = this;
  94. let phone = /^1[3456789]\d{9}$/;
  95. let reg = phone.test(that.mobile);
  96. if (that.name == '') {
  97. uni.showToast({
  98. title: '姓名不能为空',
  99. icon: 'none'
  100. })
  101. } else if (that.mobile == '' || reg == false) {
  102. uni.showToast({
  103. title: '手机号格式不正确',
  104. icon: 'none'
  105. })
  106. } else if (that.region == '') {
  107. uni.showToast({
  108. title: '地区不能为空',
  109. icon: 'none'
  110. })
  111. } else if (that.address == '') {
  112. uni.showToast({
  113. title: '详细地址不能为空',
  114. icon: 'none'
  115. })
  116. } else {
  117. myRequest({
  118. url: '/api/Address/addAddress',
  119. method: 'post',
  120. data: {
  121. name: that.name,
  122. mobile: that.mobile,
  123. region: that.region,
  124. address: that.address,
  125. label: that.label,
  126. default_address: that.isdefault
  127. }
  128. }).then(res => {
  129. console.log(res.data);
  130. if (res.data.code == 200) {
  131. that.$refs.toast.show({
  132. model: 'successs',
  133. label: res.data.msg
  134. })
  135. setTimeout(()=>{
  136. uni.navigateTo({
  137. url:'/pages/dizhi/index'
  138. })
  139. },800)
  140. } else {
  141. that.$refs.toast.show({
  142. model: 'error',
  143. label: res.data.msg
  144. })
  145. }
  146. })
  147. }
  148. },
  149. },
  150. }
  151. </script>
  152. <style lang="scss">
  153. /deep/ .tm-menubars .body {
  154. background-color: #1b1b1b !important;
  155. }
  156. /deep/ .kuang {
  157. margin: 0 !important;
  158. padding: 0px !important;
  159. margin-top: 10px !important;
  160. }
  161. /deep/ .border-grey-darken-4-b-1 {
  162. border-bottom: solid 1px #303030;
  163. }
  164. .sao {
  165. width: 88%;
  166. margin: 0 auto;
  167. margin-top: 30px;
  168. }
  169. /deep/ .tm-button-label {
  170. color: white;
  171. }
  172. /deep/ .tm-listitem {
  173. border-top: 1px solid #303030;
  174. margin-top: 15px;
  175. }
  176. </style>