index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. that.dizhi.name=res.data.data.name;
  194. that.dizhi.mobile=res.data.data.mobile;
  195. that.dizhi.region=res.data.data.region;
  196. that.dizhi.address=res.data.data.address;
  197. that.dizhi.label=res.data.data.label;
  198. that.dizhi.isdefault=res.data.data.default_address;
  199. this.tags.forEach((item, index) => {
  200. if (that.dizhi.label == item.name) {
  201. that.sel = index;
  202. }
  203. })
  204. if (res.data.data.default_address == 1) {
  205. that.on = true;
  206. }
  207. } else {
  208. that.$refs.toast.show({
  209. model: 'error',
  210. label: res.data.msg
  211. })
  212. }
  213. })
  214. },
  215. redact() {
  216. let that = this;
  217. myRequest({
  218. url: '/api/Address/updateAddress',
  219. method: 'post',
  220. data: {
  221. id: that.dizhi.id,
  222. name: that.dizhi.name,
  223. mobile: that.dizhi.mobile,
  224. region: that.dizhi.region,
  225. address: that.dizhi.address,
  226. label: that.dizhi.label,
  227. default_address: that.dizhi.isdefault
  228. }
  229. }).then(res => {
  230. console.log(res.data);
  231. if (res.data.code == 200) {
  232. uni.showToast({
  233. title: res.data.msg,
  234. icon: 'success'
  235. })
  236. setTimeout(() => {
  237. uni.navigateTo({
  238. url: '/pages/dizhi/index'
  239. })
  240. }, 800)
  241. } else {
  242. that.$refs.toast.show({
  243. model: 'error',
  244. label: res.data.msg
  245. })
  246. }
  247. })
  248. }
  249. },
  250. }
  251. </script>
  252. <style lang="scss">
  253. /deep/ .tm-menubars .body {
  254. background-color: #1b1b1b !important;
  255. }
  256. /deep/ .kuang {
  257. margin: 0 !important;
  258. padding: 0px !important;
  259. margin-top: 10px !important;
  260. }
  261. /deep/ .border-grey-darken-4-b-1 {
  262. border-bottom: solid 1px #303030 !important;
  263. }
  264. /deep/.tm-button .tm-button-btn uni-button.wn[data-v-dae977ca] {
  265. padding-left: 0px !important;
  266. }
  267. .sao {
  268. width: 88%;
  269. margin: 0 auto;
  270. margin-top: 30px;
  271. }
  272. /deep/ .tm-button-label {
  273. color: white;
  274. }
  275. /deep/ .tm-listitem {
  276. border-top: 1px solid #303030;
  277. margin-top: 15px;
  278. }
  279. </style>