index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  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 class="is_bottom" v-if="is_bottom">
  35. <text>{{config.bottom_title}}</text>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. <view class="two">
  41. <view class="two_1">
  42. <button type="default" @click="toWxaddress()">获取微信地址</button>
  43. </view>
  44. <view class="two_1">
  45. <button type="default" @click="toCommon()">新增收货地址</button>
  46. </view>
  47. </view>
  48. </view>
  49. </mobile-frame>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. // 系统设置
  56. config: {},
  57. user: {},
  58. list: [],
  59. total: 0,
  60. skip: 0,
  61. limit: 5,
  62. page: 0,
  63. // 数据是否触底
  64. is_bottom: false,
  65. scrollTop: 0,
  66. };
  67. },
  68. onLoad: function() {
  69. const that = this;
  70. that.searchConfig();
  71. that.watchLogin();
  72. },
  73. methods: {
  74. // 查询基本设置
  75. searchConfig() {
  76. const that = this;
  77. uni.getStorage({
  78. key: 'config',
  79. success: function(res) {
  80. if (res.data) that.$set(that, `config`, res.data)
  81. },
  82. fail: function(err) {
  83. console.log(err);
  84. }
  85. })
  86. },
  87. // 监听用户是否登录
  88. watchLogin() {
  89. const that = this;
  90. uni.getStorage({
  91. key: 'token',
  92. success: function(res) {
  93. let user = that.$jwt(res.data);
  94. that.$set(that, `user`, user);
  95. that.search()
  96. },
  97. fail: function(err) {
  98. uni.reLaunch({
  99. url: `/pages/login/index`
  100. })
  101. }
  102. })
  103. },
  104. // 查询列表
  105. async search() {
  106. const that = this;
  107. let user = that.user;
  108. let info = {
  109. skip: that.skip,
  110. limit: that.limit,
  111. customer: user._id
  112. }
  113. const res = await that.$api(`/address`, 'GET', {
  114. ...info
  115. })
  116. if (res.errcode == '0') {
  117. let list = [...that.list, ...res.data];
  118. that.$set(that, `list`, list);
  119. that.$set(that, `total`, res.total)
  120. }
  121. },
  122. // 分页
  123. toPage() {
  124. const that = this;
  125. let list = that.list;
  126. let limit = that.limit;
  127. if (that.total > list.length) {
  128. uni.showLoading({
  129. title: '加载中',
  130. mask: true
  131. })
  132. let page = that.page + 1;
  133. that.$set(that, `page`, page)
  134. let skip = page * limit;
  135. that.$set(that, `skip`, skip)
  136. that.search();
  137. uni.hideLoading();
  138. } else that.$set(that, `is_bottom`, true)
  139. },
  140. toScroll(e) {
  141. const that = this;
  142. let up = that.scrollTop;
  143. that.$set(that, `scrollTop`, e.detail.scrollTop);
  144. let num = Math.sign(up - e.detail.scrollTop);
  145. if (num == 1) that.$set(that, `is_bottom`, false);
  146. },
  147. // 获取微信地址
  148. toWxaddress() {
  149. const that = this;
  150. let user = that.user;
  151. uni.getStorage({
  152. key: 'system',
  153. success: function(res) {
  154. if (res.data.uniPlatform == 'app') {
  155. uni.showToast({
  156. title: '请进入微信小程序进行获取微信地址',
  157. icon: 'none'
  158. })
  159. } else if (res.data.uniPlatform == 'mp-weixin') {
  160. uni.chooseAddress({
  161. success: async function(add) {
  162. let params = {
  163. customer: user._id,
  164. name: add.userName,
  165. phone: add.telNumber,
  166. province: add.provinceName,
  167. city: add.cityName,
  168. area: add.countyName,
  169. address: add.detailInfo
  170. }
  171. const arr = await that.$api(`/address`, 'POST', params);
  172. if (arr.errcode == '0') {
  173. uni.showToast({
  174. title: '添加收货地址成功',
  175. icon: 'none'
  176. })
  177. that.clearPage();
  178. that.search();
  179. } else {
  180. uni.showToast({
  181. title: arr.errmsg,
  182. icon: 'none'
  183. })
  184. }
  185. },
  186. fail: function(err) {
  187. that.clearPage();
  188. that.search();
  189. }
  190. })
  191. }
  192. }
  193. })
  194. },
  195. // 设置默认
  196. toDefa(e) {
  197. const that = this;
  198. uni.showModal({
  199. title: '提示',
  200. content: '确定设置该地址为默认地址吗?',
  201. success: async function(res) {
  202. if (res.confirm) {
  203. const arr = await that.$api(`/address/toDefault/${e._id}`, `POST`);
  204. if (arr.errcode == '0') {
  205. uni.showToast({
  206. title: '添加默认成功',
  207. icon: 'none'
  208. })
  209. that.clearPage();
  210. that.search();
  211. } else {
  212. uni.showToast({
  213. title: arr.errmsg,
  214. icon: 'none'
  215. })
  216. }
  217. }
  218. }
  219. });
  220. },
  221. // 编辑
  222. toCommon(e) {
  223. const that = this;
  224. that.clearPage();
  225. uni.navigateTo({
  226. url: `/pagesMy/address/add?id=${e&&e.id?e.id:''}`
  227. })
  228. },
  229. // 删除
  230. toDel(e) {
  231. const that = this;
  232. uni.showModal({
  233. title: '提示',
  234. content: '确定删除该地址吗?',
  235. success: async function(res) {
  236. if (res.confirm) {
  237. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  238. if (arr.errcode == '0') {
  239. uni.showToast({
  240. title: '删除信息成功',
  241. icon: 'none'
  242. })
  243. that.clearPage();
  244. that.search();
  245. } else {
  246. uni.showToast({
  247. title: arr.errmsg,
  248. icon: 'none'
  249. })
  250. }
  251. }
  252. }
  253. });
  254. },
  255. // 清空列表
  256. clearPage() {
  257. const that = this;
  258. that.$set(that, `list`, [])
  259. that.$set(that, `skip`, 0)
  260. that.$set(that, `limit`, 5)
  261. that.$set(that, `page`, 0)
  262. }
  263. }
  264. }
  265. </script>
  266. <style lang="scss">
  267. .main {
  268. display: flex;
  269. flex-direction: column;
  270. width: 100vw;
  271. height: 100vh;
  272. .one {
  273. position: relative;
  274. flex-grow: 1;
  275. background-color: var(--f5Color);
  276. .list {
  277. position: relative;
  278. background: var(--fffColor);
  279. padding: 2vw;
  280. width: 92vw;
  281. margin: 2vw 2vw 0 2vw;
  282. border-radius: 5px;
  283. .name {
  284. font-size: var(--font16Size);
  285. margin: 0 0 2vw 0;
  286. text {
  287. padding: 0 2vw 0 0;
  288. }
  289. }
  290. .address {
  291. font-size: var(--font14Size);
  292. margin: 0 0 1vw 0;
  293. text {
  294. padding: 0 2vw 0 0;
  295. }
  296. }
  297. .btn {
  298. display: flex;
  299. flex-direction: row;
  300. justify-content: space-around;
  301. border-top: 1px solid var(--font16Size);
  302. padding: 2vw 0 0 0;
  303. .btn_1 {
  304. button {
  305. width: 100%;
  306. color: var(--fffColor);
  307. background-color: var(--f35BColor);
  308. }
  309. }
  310. .btn_1:nth-child(2) {
  311. button {
  312. background-color: var(--f0fColor);
  313. }
  314. }
  315. .btn_1:last-child {
  316. button {
  317. background-color: var(--fFB1Color);
  318. }
  319. }
  320. }
  321. .default {
  322. position: absolute;
  323. top: 0;
  324. right: 0;
  325. text {
  326. background: var(--ff0Color);
  327. color: var(--fffColor);
  328. font-size: var(--font12Size);
  329. padding: 1vw;
  330. border-radius: 5px;
  331. }
  332. }
  333. }
  334. }
  335. .two {
  336. display: flex;
  337. flex-direction: row;
  338. justify-content: space-between;
  339. .two_1 {
  340. width: 50vw;
  341. button {
  342. width: 100%;
  343. color: var(--fffColor);
  344. background-color: var(--f08Color);
  345. border-radius: 0;
  346. }
  347. }
  348. .two_1:nth-child(2) {
  349. button {
  350. background-color: var(--fFB1Color);
  351. }
  352. }
  353. }
  354. }
  355. .scroll-view {
  356. position: absolute;
  357. top: 0;
  358. left: 0;
  359. right: 0;
  360. bottom: 0;
  361. .list-scroll-view {
  362. display: flex;
  363. flex-direction: column;
  364. }
  365. }
  366. .is_bottom {
  367. text-align: center;
  368. text {
  369. padding: 2vw 0;
  370. display: inline-block;
  371. color: #858585;
  372. font-size: 14px;
  373. }
  374. }
  375. </style>