index.vue 8.8 KB

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