index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  6. <view class="list-scroll-view">
  7. <view class="list" v-for="(item,index) in list" :key="index">
  8. <view class="name">
  9. <text>{{item.name}}</text>
  10. <text>{{item.phone}}</text>
  11. </view>
  12. <view class="address">
  13. <text>{{item.province}}</text>
  14. <text>{{item.city}}</text>
  15. <text>{{item.area}}</text>
  16. <text>{{item.address}}</text>
  17. <text>{{item.number}}</text>
  18. </view>
  19. <view class="btn">
  20. <view class="btn_1" v-if="item.is_default==false">
  21. <button type="default" size="mini" @click="toDefa(item)">设为默认</button>
  22. </view>
  23. <view class="btn_1">
  24. <button type="default" size="mini" @click="toCommon(item)">编辑</button>
  25. </view>
  26. <view class="btn_1">
  27. <button type="default" size="mini" @click="toDel(item)">删除</button>
  28. </view>
  29. </view>
  30. <view class="default" v-if="item.is_default==true">
  31. <text>默认</text>
  32. </view>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. <view class="two">
  38. <view class="two_1">
  39. <button type="default" @click="toWxaddress()">获取微信地址</button>
  40. </view>
  41. <view class="two_1">
  42. <button type="default" @click="toCommon()">新增收货地址</button>
  43. </view>
  44. </view>
  45. </view>
  46. </mobile-frame>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. user: {},
  53. list: [],
  54. total: 0,
  55. skip: 0,
  56. limit: 5,
  57. page: 0
  58. };
  59. },
  60. onShow: function() {
  61. const that = this;
  62. that.watchLogin()
  63. },
  64. methods: {
  65. // 监听用户是否登录
  66. watchLogin() {
  67. const that = this;
  68. uni.getStorage({
  69. key: 'token',
  70. success: function(res) {
  71. let user = that.$jwt(res.data);
  72. that.$set(that, `user`, user);
  73. that.search()
  74. },
  75. fail: function(err) {
  76. uni.reLaunch({
  77. url: `/pages/login/index`
  78. })
  79. }
  80. })
  81. },
  82. // 查询列表
  83. async search() {
  84. const that = this;
  85. let user = that.user;
  86. let info = {
  87. skip: that.skip,
  88. limit: that.limit,
  89. customer: user._id
  90. }
  91. const res = await that.$api(`/address`, 'GET', {
  92. ...info
  93. })
  94. if (res.errcode == '0') {
  95. let list = [...that.list, ...res.data];
  96. that.$set(that, `list`, list);
  97. that.$set(that, `total`, res.total)
  98. }
  99. },
  100. // 分页
  101. toPage() {
  102. const that = this;
  103. let list = that.list;
  104. let limit = that.limit;
  105. if (that.total > list.length) {
  106. uni.showLoading({
  107. title: '加载中',
  108. mask: true
  109. })
  110. let page = that.page + 1;
  111. that.$set(that, `page`, page)
  112. let skip = page * limit;
  113. that.$set(that, `skip`, skip)
  114. that.search();
  115. uni.hideLoading();
  116. } else uni.showToast({
  117. title: '没有更多数据了'
  118. });
  119. },
  120. // 获取微信地址
  121. toWxaddress() {
  122. const that = this;
  123. let user = that.user;
  124. uni.getStorage({
  125. key: 'system',
  126. success: function(res) {
  127. if (res.data.uniPlatform == 'app') {
  128. uni.showToast({
  129. title: '请进入微信小程序进行获取微信地址',
  130. icon: 'none'
  131. })
  132. } else if (res.data.uniPlatform == 'mp-weixin') {
  133. uni.chooseAddress({
  134. success: async function(add) {
  135. let params = {
  136. customer: user._id,
  137. name: add.userName,
  138. phone: add.telNumber,
  139. province: add.provinceName,
  140. city: add.cityName,
  141. area: add.countyName,
  142. address: add.detailInfo
  143. }
  144. const arr = await that.$api(`/address`, 'POST', params);
  145. if (arr.errcode == '0') {
  146. uni.showToast({
  147. title: '添加收货地址成功',
  148. icon: 'none'
  149. })
  150. that.search()
  151. } else {
  152. uni.showToast({
  153. title: arr.errmsg,
  154. icon: 'none'
  155. })
  156. }
  157. },
  158. fail: function(err) {
  159. console.log(err);
  160. }
  161. })
  162. }
  163. }
  164. })
  165. },
  166. // 设置默认
  167. toDefa(e) {
  168. uni.showModal({
  169. title: '提示',
  170. content: '确定设置该地址为默认地址吗?',
  171. success: function(res) {
  172. if (res.confirm) {
  173. console.log('用户点击确定');
  174. }
  175. }
  176. });
  177. },
  178. // 编辑
  179. toCommon(e) {
  180. uni.navigateTo({
  181. url: `/pagesMy/address/add?id=${e&&e.id?e.id:''}`
  182. })
  183. },
  184. // 删除
  185. toDel(e) {
  186. uni.showModal({
  187. title: '提示',
  188. content: '确定删除该地址吗?',
  189. success: function(res) {
  190. if (res.confirm) {
  191. console.log('用户点击确定');
  192. }
  193. }
  194. });
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss">
  200. .main {
  201. display: flex;
  202. flex-direction: column;
  203. width: 100vw;
  204. height: 100vh;
  205. .one {
  206. position: relative;
  207. flex-grow: 1;
  208. background-color: var(--f5Color);
  209. .list {
  210. position: relative;
  211. background: var(--fffColor);
  212. padding: 2vw;
  213. width: 92vw;
  214. margin: 2vw 2vw 0 2vw;
  215. border-radius: 5px;
  216. .name {
  217. font-size: var(--font16Size);
  218. margin: 0 0 1vw 0;
  219. text {
  220. padding: 0 2vw 0 0;
  221. }
  222. }
  223. .address {
  224. font-size: var(--font14Size);
  225. margin: 0 0 1vw 0;
  226. text {
  227. padding: 0 2vw 0 0;
  228. }
  229. }
  230. .btn {
  231. display: flex;
  232. flex-direction: row;
  233. justify-content: space-around;
  234. border-top: 1px solid var(--font16Size);
  235. padding: 2vw 0 0 0;
  236. .btn_1 {
  237. button {
  238. width: 100%;
  239. color: var(--fffColor);
  240. background-color: var(--f35BColor);
  241. }
  242. }
  243. .btn_1:nth-child(2) {
  244. button {
  245. background-color: var(--f0fColor);
  246. }
  247. }
  248. .btn_1:last-child {
  249. button {
  250. background-color: var(--fFB1Color);
  251. }
  252. }
  253. }
  254. .default {
  255. position: absolute;
  256. top: 0;
  257. right: 0;
  258. text {
  259. background: var(--ff0Color);
  260. color: var(--fffColor);
  261. font-size: var(--font12Size);
  262. padding: 1vw;
  263. border-radius: 5px;
  264. }
  265. }
  266. }
  267. }
  268. .two {
  269. display: flex;
  270. flex-direction: row;
  271. justify-content: space-between;
  272. .two_1 {
  273. width: 50vw;
  274. button {
  275. width: 100%;
  276. color: var(--fffColor);
  277. background-color: var(--f08Color);
  278. }
  279. }
  280. .two_1:nth-child(2) {
  281. button {
  282. background-color: var(--fFB1Color);
  283. }
  284. }
  285. }
  286. }
  287. .scroll-view {
  288. position: absolute;
  289. top: 0;
  290. left: 0;
  291. right: 0;
  292. bottom: 0;
  293. .list-scroll-view {
  294. display: flex;
  295. flex-direction: column;
  296. }
  297. }
  298. </style>