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. onShow: 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. } else {
  179. uni.showToast({
  180. title: arr.errmsg,
  181. icon: 'none'
  182. })
  183. }
  184. },
  185. fail: function(err) {
  186. console.log(err);
  187. that.clearPage()
  188. }
  189. })
  190. }
  191. }
  192. })
  193. },
  194. // 设置默认
  195. toDefa(e) {
  196. const that = this;
  197. uni.showModal({
  198. title: '提示',
  199. content: '确定设置该地址为默认地址吗?',
  200. success: async function(res) {
  201. if (res.confirm) {
  202. const arr = await that.$api(`/address/toDefault/${e._id}`, `POST`);
  203. if (arr.errcode == '0') {
  204. uni.showToast({
  205. title: '添加默认成功',
  206. icon: 'none'
  207. })
  208. that.clearPage();
  209. that.search();
  210. } else {
  211. uni.showToast({
  212. title: arr.errmsg,
  213. icon: 'none'
  214. })
  215. }
  216. }
  217. }
  218. });
  219. },
  220. // 编辑
  221. toCommon(e) {
  222. const that = this;
  223. that.clearPage();
  224. uni.navigateTo({
  225. url: `/pagesMy/address/add?id=${e&&e.id?e.id:''}`
  226. })
  227. },
  228. // 删除
  229. toDel(e) {
  230. const that = this;
  231. uni.showModal({
  232. title: '提示',
  233. content: '确定删除该地址吗?',
  234. success: async function(res) {
  235. if (res.confirm) {
  236. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  237. if (arr.errcode == '0') {
  238. uni.showToast({
  239. title: '删除信息成功',
  240. icon: 'none'
  241. })
  242. that.clearPage();
  243. that.search();
  244. } else {
  245. uni.showToast({
  246. title: arr.errmsg,
  247. icon: 'none'
  248. })
  249. }
  250. }
  251. }
  252. });
  253. },
  254. // 清空列表
  255. clearPage() {
  256. const that = this;
  257. that.$set(that, `list`, [])
  258. that.$set(that, `skip`, 0)
  259. that.$set(that, `limit`, 5)
  260. that.$set(that, `page`, 0)
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss">
  266. .main {
  267. display: flex;
  268. flex-direction: column;
  269. width: 100vw;
  270. height: 100vh;
  271. .one {
  272. position: relative;
  273. flex-grow: 1;
  274. background-color: var(--f5Color);
  275. .list {
  276. position: relative;
  277. background: var(--fffColor);
  278. padding: 2vw;
  279. width: 92vw;
  280. margin: 2vw 2vw 0 2vw;
  281. border-radius: 5px;
  282. .name {
  283. font-size: var(--font16Size);
  284. margin: 0 0 2vw 0;
  285. text {
  286. padding: 0 2vw 0 0;
  287. }
  288. }
  289. .address {
  290. font-size: var(--font14Size);
  291. margin: 0 0 1vw 0;
  292. text {
  293. padding: 0 2vw 0 0;
  294. }
  295. }
  296. .btn {
  297. display: flex;
  298. flex-direction: row;
  299. justify-content: space-around;
  300. border-top: 1px solid var(--font16Size);
  301. padding: 2vw 0 0 0;
  302. .btn_1 {
  303. button {
  304. width: 100%;
  305. color: var(--fffColor);
  306. background-color: var(--f35BColor);
  307. }
  308. }
  309. .btn_1:nth-child(2) {
  310. button {
  311. background-color: var(--f0fColor);
  312. }
  313. }
  314. .btn_1:last-child {
  315. button {
  316. background-color: var(--fFB1Color);
  317. }
  318. }
  319. }
  320. .default {
  321. position: absolute;
  322. top: 0;
  323. right: 0;
  324. text {
  325. background: var(--ff0Color);
  326. color: var(--fffColor);
  327. font-size: var(--font12Size);
  328. padding: 1vw;
  329. border-radius: 5px;
  330. }
  331. }
  332. }
  333. }
  334. .two {
  335. display: flex;
  336. flex-direction: row;
  337. justify-content: space-between;
  338. .two_1 {
  339. width: 50vw;
  340. button {
  341. width: 100%;
  342. color: var(--fffColor);
  343. background-color: var(--f08Color);
  344. border-radius: 0;
  345. }
  346. }
  347. .two_1:nth-child(2) {
  348. button {
  349. background-color: var(--fFB1Color);
  350. }
  351. }
  352. }
  353. }
  354. .scroll-view {
  355. position: absolute;
  356. top: 0;
  357. left: 0;
  358. right: 0;
  359. bottom: 0;
  360. .list-scroll-view {
  361. display: flex;
  362. flex-direction: column;
  363. }
  364. }
  365. .is_bottom {
  366. text-align: center;
  367. text {
  368. padding: 2vw 0;
  369. display: inline-block;
  370. color: #858585;
  371. font-size: 14px;
  372. }
  373. }
  374. </style>