index.vue 7.5 KB

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