index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. },
  103. // 获取微信地址
  104. toWxaddress() {
  105. const that = this;
  106. let user = that.user;
  107. uni.getStorage({
  108. key: 'system',
  109. success: function(res) {
  110. if (res.data.uniPlatform == 'app') {
  111. uni.showToast({
  112. title: '请进入微信小程序进行获取微信地址',
  113. icon: 'none'
  114. })
  115. } else if (res.data.uniPlatform == 'mp-weixin') {
  116. uni.chooseAddress({
  117. success: async function(add) {
  118. let params = {
  119. customer: user._id,
  120. name: add.userName,
  121. phone: add.telNumber,
  122. province: add.provinceName,
  123. city: add.cityName,
  124. area: add.countyName,
  125. address: add.detailInfo
  126. }
  127. const arr = await that.$api(`/address`, 'POST', params);
  128. if (arr.errcode == '0') {
  129. uni.showToast({
  130. title: '添加收货地址成功',
  131. icon: 'none'
  132. })
  133. that.search()
  134. } else {
  135. uni.showToast({
  136. title: arr.errmsg,
  137. icon: 'none'
  138. })
  139. }
  140. },
  141. fail: function(err) {
  142. console.log(err);
  143. }
  144. })
  145. }
  146. }
  147. })
  148. },
  149. // 设置默认
  150. toDefa(e) {
  151. uni.showModal({
  152. title: '提示',
  153. content: '确定设置该地址为默认地址吗?',
  154. success: function(res) {
  155. if (res.confirm) {
  156. console.log('用户点击确定');
  157. }
  158. }
  159. });
  160. },
  161. // 编辑
  162. toCommon(e) {
  163. uni.navigateTo({
  164. url: `/pagesMy/address/add?id=${e&&e.id?e.id:''}`
  165. })
  166. },
  167. // 删除
  168. toDel(e) {
  169. uni.showModal({
  170. title: '提示',
  171. content: '确定删除该地址吗?',
  172. success: function(res) {
  173. if (res.confirm) {
  174. console.log('用户点击确定');
  175. }
  176. }
  177. });
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss">
  183. .main {
  184. display: flex;
  185. flex-direction: column;
  186. width: 100vw;
  187. height: 100vh;
  188. .one {
  189. position: relative;
  190. flex-grow: 1;
  191. background-color: var(--f5Color);
  192. .list {
  193. position: relative;
  194. background: var(--fffColor);
  195. padding: 2vw;
  196. width: 92vw;
  197. margin: 2vw 2vw 0 2vw;
  198. border-radius: 5px;
  199. .name {
  200. font-size: var(--font16Size);
  201. margin: 0 0 1vw 0;
  202. text {
  203. padding: 0 2vw 0 0;
  204. }
  205. }
  206. .address {
  207. font-size: var(--font14Size);
  208. margin: 0 0 1vw 0;
  209. text {
  210. padding: 0 2vw 0 0;
  211. }
  212. }
  213. .btn {
  214. display: flex;
  215. flex-direction: row;
  216. justify-content: space-around;
  217. border-top: 1px solid var(--font16Size);
  218. padding: 2vw 0 0 0;
  219. .btn_1 {
  220. button {
  221. width: 100%;
  222. color: var(--fffColor);
  223. background-color: var(--f35BColor);
  224. }
  225. }
  226. .btn_1:nth-child(2) {
  227. button {
  228. background-color: var(--f0fColor);
  229. }
  230. }
  231. .btn_1:last-child {
  232. button {
  233. background-color: var(--fFB1Color);
  234. }
  235. }
  236. }
  237. .default {
  238. position: absolute;
  239. top: 0;
  240. right: 0;
  241. text {
  242. background: var(--ff0Color);
  243. color: var(--fffColor);
  244. font-size: var(--font12Size);
  245. padding: 1vw;
  246. border-radius: 5px;
  247. }
  248. }
  249. }
  250. }
  251. .two {
  252. display: flex;
  253. flex-direction: row;
  254. justify-content: space-between;
  255. .two_1 {
  256. width: 50vw;
  257. button {
  258. width: 100%;
  259. color: var(--fffColor);
  260. background-color: var(--f08Color);
  261. }
  262. }
  263. .two_1:nth-child(2) {
  264. button {
  265. background-color: var(--fFB1Color);
  266. }
  267. }
  268. }
  269. }
  270. .scroll-view {
  271. position: absolute;
  272. top: 0;
  273. left: 0;
  274. right: 0;
  275. bottom: 0;
  276. .list-scroll-view {
  277. display: flex;
  278. flex-direction: column;
  279. }
  280. }
  281. </style>