index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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="dizhi.name"></tm-input>
  8. <tm-input title="手机号码" placeholder="填写收件人手机号码" v-model="dizhi.mobile"></tm-input>
  9. <tm-pickersCity @confirm="dateSe_3" :default-value="d_3" btn-color="bg-gradient-deep-purple-accent"
  10. style="margin:0 16px 0px;box-sizing: border-box;">
  11. <tm-button class="xuanze" theme="bg-gradient-deep-purple-accent"
  12. style="padding-left: 0px!important;margin-left:0px;border-bottom: 1px solid #303030!important;">
  13. <tm-input style="padding: 0px 60px 0px 0px!important;margin-left: 0!important;" title="所在地区"
  14. placeholder="省市区县、乡镇等" v-model="dizhi.region" @click="dateSe_3">
  15. </tm-input>
  16. </tm-button>
  17. </tm-pickersCity>
  18. <tm-input title="详细地址" placeholder="街道、楼牌号等" v-model="dizhi.address"></tm-input>
  19. </view>
  20. </tm-sheet>
  21. <tm-sheet class="kuang" style="padding-bottom: 20px !important;">
  22. <view style="width: 94%;margin:0 auto;padding-top:15px;">
  23. <view class="fl text-white mt-10" style="width: 15%;">标签</view>
  24. <view class="fl" style="width: 80%;">
  25. <!-- <tm-button class="ml-20" :round="10" theme="gray" size="s">{{dizhi.label}}</tm-button> -->
  26. <tm-button class="ml-20" :round="10" v-model="sel" :theme="sel==index?'blue':'gray'" size="s"
  27. v-for="(item,index) in tags" @click="selectTag(index)">{{item.name}}</tm-button>
  28. <tm-button class="ml-20" :round="10" theme="gray" size="s" @click="addTag">+</tm-button>
  29. </view>
  30. <view style="clear: both;"></view>
  31. <tm-listitem title="设置为默认地址" @click="btnClick">
  32. <template v-slot:rightIcon="">
  33. <tm-switch offBgcolor="yellow text-black" :text="['','']" color="primary" v-model="on">
  34. </tm-switch>
  35. </template>
  36. </tm-listitem>
  37. </view>
  38. </tm-sheet>
  39. <tm-button :round="24" class="sao mb-40 mt-40" block @click="redact" v-if="isSave">修改</tm-button>
  40. <tm-button :round="24" class="sao mb-40 mt-40" block @click="saveAdd" v-else>保存</tm-button>
  41. </div>
  42. <!-- 弹出层消息 -->
  43. <tm-message ref="toast"></tm-message>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. myRequest
  49. } from '@/api/request.js'
  50. export default {
  51. data() {
  52. return {
  53. tags: [{
  54. name: '家庭'
  55. }, {
  56. name: '学校'
  57. }, {
  58. name: '公司'
  59. }],
  60. isAdd: false,
  61. isSave: false,
  62. on: false,
  63. sel: -1,
  64. dizhi: {
  65. name: '',
  66. mobile: '',
  67. region: '',
  68. address: '',
  69. label: '',
  70. isdefault: 0,
  71. },
  72. d_3: [],
  73. };
  74. },
  75. onLoad(op) {
  76. if (Object.keys(op).length != 0) {
  77. this.isSave = true;
  78. this.dizhi.id = op.id;
  79. }
  80. },
  81. created() {
  82. var that = this;
  83. setTimeout(function() {
  84. if (uni.getStorageSync("token") == "") {
  85. uni.redirectTo({
  86. url: "/pages/login/index"
  87. })
  88. }
  89. }, 1000)
  90. this.sys = uni.getSystemInfoSync();
  91. if (that.dizhi.id) {
  92. this.getAddDetail()
  93. }
  94. },
  95. methods: {
  96. // 选择标签
  97. selectTag(index) {
  98. this.sel = index;
  99. this.dizhi.label = this.tags[index].name;
  100. console.log(this.dizhi.label, '33');
  101. },
  102. // 新增标签
  103. addTag() {
  104. },
  105. // 选择地址
  106. dateSe_3(e) {
  107. this.d_3 = e;
  108. this.dizhi.region = this.d_3.join('');
  109. },
  110. // 设置默认地址
  111. btnClick() {
  112. if (this.on) {
  113. this.dizhi.isdefault = 1;
  114. } else {
  115. this.dizhi.isdefault = 0;
  116. }
  117. },
  118. // 保存地址
  119. saveAdd() {
  120. let that = this;
  121. let phone = /^1[3456789]\d{9}$/;
  122. let reg = phone.test(that.dizhi.mobile);
  123. if (that.dizhi.name == '') {
  124. uni.showToast({
  125. title: '姓名不能为空',
  126. icon: 'none'
  127. })
  128. } else if (that.dizhi.mobile == '' || reg == false) {
  129. uni.showToast({
  130. title: '手机号格式不正确',
  131. icon: 'none'
  132. })
  133. } else if (that.dizhi.region == '') {
  134. uni.showToast({
  135. title: '地区不能为空',
  136. icon: 'none'
  137. })
  138. } else if (that.dizhi.address == '') {
  139. uni.showToast({
  140. title: '详细地址不能为空',
  141. icon: 'none'
  142. })
  143. } else {
  144. myRequest({
  145. url: '/api/Address/addAddress',
  146. method: 'post',
  147. data: {
  148. name: that.dizhi.name,
  149. mobile: that.dizhi.mobile,
  150. region: that.dizhi.region,
  151. address: that.dizhi.address,
  152. label: that.dizhi.label,
  153. default_address: that.dizhi.isdefault
  154. }
  155. }).then(res => {
  156. console.log(res.data);
  157. if (res.data.code == 200) {
  158. that.$refs.toast.show({
  159. model: 'successs',
  160. label: res.data.msg
  161. })
  162. // uni.showToast({
  163. // title: res.data.msg,
  164. // icon: 'success'
  165. // })
  166. setTimeout(() => {
  167. uni.navigateTo({
  168. url: '/pages/dizhi/index'
  169. })
  170. }, 800)
  171. } else {
  172. that.$refs.toast.show({
  173. model: 'error',
  174. label: res.data.msg
  175. })
  176. }
  177. })
  178. }
  179. },
  180. // 获取地址详情
  181. getAddDetail() {
  182. let that = this;
  183. myRequest({
  184. url: '/api/Address/getAddressDetails',
  185. method: 'post',
  186. data: {
  187. id: that.dizhi.id,
  188. }
  189. }).then(res => {
  190. console.log(res.data);
  191. if (res.data.code == 200) {
  192. that.dizhi = res.data.data;
  193. this.tags.forEach((item, index) => {
  194. if (that.dizhi.label == item.name) {
  195. that.sel = index;
  196. }
  197. })
  198. if (res.data.data.default_address == 1) {
  199. that.on = true;
  200. }
  201. } else {
  202. that.$refs.toast.show({
  203. model: 'error',
  204. label: res.data.msg
  205. })
  206. }
  207. })
  208. },
  209. redact() {
  210. let that = this;
  211. myRequest({
  212. url: '/api/Address/updateAddress',
  213. method: 'post',
  214. data: {
  215. id: that.dizhi.id,
  216. name: that.dizhi.name,
  217. mobile: that.dizhi.mobile,
  218. region: that.dizhi.region,
  219. address: that.dizhi.address,
  220. label: that.dizhi.label,
  221. default_address: that.dizhi.isdefault
  222. }
  223. }).then(res => {
  224. console.log(res.data);
  225. if (res.data.code == 200) {
  226. uni.showToast({
  227. title: res.data.msg,
  228. icon: 'success'
  229. })
  230. setTimeout(() => {
  231. uni.navigateTo({
  232. url: '/pages/dizhi/index'
  233. })
  234. }, 800)
  235. } else {
  236. that.$refs.toast.show({
  237. model: 'error',
  238. label: res.data.msg
  239. })
  240. }
  241. })
  242. }
  243. },
  244. }
  245. </script>
  246. <style lang="scss">
  247. /deep/ .tm-menubars .body {
  248. background-color: #1b1b1b !important;
  249. }
  250. /deep/ .kuang {
  251. margin: 0 !important;
  252. padding: 0px !important;
  253. margin-top: 10px !important;
  254. }
  255. /deep/ .border-grey-darken-4-b-1 {
  256. border-bottom: solid 1px #303030 !important;
  257. }
  258. /deep/.tm-button .tm-button-btn uni-button.wn[data-v-dae977ca] {
  259. padding-left: 0px !important;
  260. }
  261. .sao {
  262. width: 88%;
  263. margin: 0 auto;
  264. margin-top: 30px;
  265. }
  266. /deep/ .tm-button-label {
  267. color: white;
  268. }
  269. /deep/ .tm-listitem {
  270. border-top: 1px solid #303030;
  271. margin-top: 15px;
  272. }
  273. </style>