index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="address-page">
  3. <view class="address-section">
  4. <pub-list-scroll @next="onScrollTolower" :loaded="loaded" :text="loadText" :status="status">
  5. <view class="no-data" v-if="(!list || list.length == 0)&&!loaded">
  6. <image mode="heightFix" src="/static/image/no-data.png" />
  7. 暂无数据
  8. </view>
  9. <view class="address-list" v-else>
  10. <view v-for="(item,index) in list" :key="'cf'+index" class="address-item" @click="onClickItem(item.shrxxid)"
  11. :class="item.shrxxid==curAddressId?'is-active':''">
  12. <view class="row address-item-top">
  13. <view>{{item.shrxm}}</view>
  14. <view>{{item.shrsjh}}</view>
  15. </view>
  16. <view class="">{{ formattedAddress(item) }}</view>
  17. <view class="address-item-bottom">
  18. <view class="row" @click.stop="updateDefault(item)">
  19. <text class="iconfont checkbox is-active" v-if="item.isDefaulted">&#xe63b;</text>
  20. <text class="iconfont checkbox" v-else>&#xe8bb;</text>
  21. 默认收件地址
  22. </view>
  23. <view class="row">
  24. <view class="row" @click.stop="openDetails('edit',item)"><text class="iconfont">&#xe6ae;</text>编辑</view>
  25. <view class="row next-btn" @click.stop="openDeletePopup('center',item.shrxxid)"><text
  26. class="iconfont">&#xe626;</text>删除
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </pub-list-scroll>
  33. </view>
  34. <view class="pub-button is-bg large" @click="openDetails('add')">新增地址</view>
  35. <!-- 选择弹窗 -->
  36. <uni-popup ref="confirmPopup" type="dialog">
  37. <uni-popup-dialog type="info" cancelText="取消" confirmText="确定" content="确定使用快递配送?" @confirm="onApply"
  38. @close="onCancel"></uni-popup-dialog>
  39. </uni-popup>
  40. <!-- 删除弹窗 注意这里取消按钮的位置 -->
  41. <uni-popup ref="delPopup" type="dialog">
  42. <uni-popup-dialog type="info" cancelText="确定" confirmText="取消" content="确定删除该地址?" @confirm="onDelApply"
  43. @close="onDelCancel"></uni-popup-dialog>
  44. </uni-popup>
  45. </view>
  46. </template>
  47. <script lang="ts" setup>
  48. import { ref, onMounted } from 'vue'
  49. import dlg from '@/lib/dlg'
  50. import { onLoad } from "@dcloudio/uni-app";
  51. import rest from '@/stores/rest'
  52. import * as link from '@/lib/link'
  53. import { BasicInfoVO } from '../../lib/type';
  54. const loaded = ref(false)
  55. const loadText = ref('数据加载中...')
  56. const status = ref('loading')
  57. const list = ref() //处方列表
  58. const queryParams = ref({
  59. pageNo: 1,
  60. pageSize: 10,
  61. hzid: '',
  62. })
  63. const ptwybh = ref()
  64. const total = ref(0)
  65. const confirmPopup = ref() // 弹出层
  66. const delPopup = ref() // 删除弹出层
  67. const deleteId = ref() // 删除的id
  68. const curAddressId = ref() // 选中项
  69. const selAddressId = ref() // 点击项
  70. // 拼接地址
  71. const formattedAddress = (item) => {
  72. const { province, city, area, shrdzxxdz } = item
  73. return `${province || ''}${city || ''}${area || ''}${shrdzxxdz || ''}`
  74. }
  75. const openDeletePopup = (position, id) => {
  76. deleteId.value = id
  77. delPopup.value.open(position)
  78. }
  79. const onClickItem = (id : string) => {
  80. selAddressId.value = id
  81. confirmPopup.value.open('center')
  82. }
  83. const onDelCancel = async () => {
  84. // 从 list 中找到该项的位置
  85. const index = list.value.findIndex(item => item.shrxxid === deleteId.value);
  86. if (index !== -1) {
  87. const [removedItem] = list.value.splice(index, 1);
  88. // 执行删除接口
  89. try {
  90. await rest.del('/default/consignee-info/delete?id=' + deleteId.value, {});
  91. } catch (error) {
  92. list.value.splice(index, 0, removedItem);
  93. }
  94. } else {
  95. console.warn("未找到要删除的项");
  96. }
  97. }
  98. const onDelApply = () => {
  99. // 删除取消
  100. }
  101. const onCancel = () => {
  102. }
  103. const onApply = async () => {
  104. if (ptwybh.value) {
  105. curAddressId.value = selAddressId.value
  106. const data = {
  107. ptwybh: ptwybh.value,
  108. shrxxid: curAddressId.value,
  109. kd: true
  110. }
  111. await rest.put('/default/consignee-info/bindShrxxid', data);
  112. dlg.success('操作成功')
  113. }
  114. }
  115. // 修改默认
  116. const updateDefault = async (item) => {
  117. if (item.isDefaulted === null) {
  118. item.isDefaulted = true;
  119. const index = list.value.findIndex(i => i.shrxxid === item.shrxxid);
  120. if (index !== -1) {
  121. const [movedItem] = list.value.splice(index, 1);
  122. list.value.unshift(movedItem);
  123. if (list.value.length > 1) {
  124. list.value[1].isDefaulted = null;
  125. }
  126. }
  127. await rest.put('/default/consignee-info/update', item)
  128. }
  129. }
  130. const getList = async () => {
  131. try {
  132. loaded.value = true;
  133. let res = await rest.get('/default/consignee-info/list', queryParams.value) as BasicInfoVO
  134. let _list = res.list
  135. if (!list.value) {
  136. list.value = _list;
  137. } else {
  138. list.value = list.value.concat(_list);
  139. }
  140. total.value = res.total
  141. if (res.total && queryParams.value.pageNo >= total.value / queryParams.value.pageSize) {
  142. status.value = "noMore"
  143. }
  144. } catch (e) {
  145. dlg.error(e)
  146. } finally {
  147. loaded.value = false;
  148. }
  149. }
  150. //下一页
  151. const onScrollTolower = async () => {
  152. if (!list.value || queryParams.value.pageNo > (total.value / queryParams.value.pageSize)) {
  153. return false;
  154. }
  155. if (queryParams.value.pageNo < total.value / queryParams.value.pageSize) {
  156. status.value = "loading";
  157. } else {
  158. status.value = "noMore"
  159. return;
  160. }
  161. queryParams.value.pageNo++;
  162. getList();
  163. }
  164. const openDetails = (action, item = null) => {
  165. if (item) {
  166. let row = JSON.stringify(item)
  167. uni.setStorageSync('addressItemInfo', row)
  168. }
  169. link.addAddress(queryParams.value.hzid)
  170. }
  171. onLoad((data) => {
  172. queryParams.value.hzid = data.hzid
  173. ptwybh.value = data.ptwybh
  174. })
  175. onMounted(() => {
  176. getList()
  177. })
  178. </script>
  179. <style lang="scss" scoped>
  180. .address-page {
  181. display: flex;
  182. flex-direction: column;
  183. height: 100%;
  184. .address-section {
  185. flex: 1;
  186. overflow-y: auto;
  187. margin-top: 16rpx;
  188. .address-list {
  189. .address-item {
  190. background: #fff;
  191. margin-bottom: 24rpx;
  192. padding: 24rpx 32rpx 16rpx;
  193. color: $uni-text-color-grey;
  194. border: 1px solid #fff;
  195. .row {
  196. @include flex;
  197. }
  198. .address-item-top {
  199. font-size: $uni-font-size-lg;
  200. line-height: $uni-line-height-lg;
  201. color: $uni-text-color;
  202. margin-bottom: 24rpx;
  203. >view+view {
  204. margin-left: 32rpx;
  205. }
  206. }
  207. .address-item-bottom {
  208. border-top: 1px solid $uni-border-color;
  209. margin-top: 24rpx;
  210. padding-top: 16rpx;
  211. @include flex-between;
  212. font-size: $uni-font-size-sm;
  213. line-height: $uni-line-height-sm;
  214. .iconfont {
  215. font-size: 36rpx;
  216. margin-right: 8rpx;
  217. &.checkbox {
  218. margin-right: 16rpx;
  219. color: $uni-text-color-disable;
  220. }
  221. &.is-active {
  222. color: $uni-color-primary;
  223. }
  224. }
  225. .next-btn {
  226. margin-left: 32rpx;
  227. }
  228. }
  229. &.is-active {
  230. border: 1px solid $uni-color-primary;
  231. box-sizing: border-box;
  232. }
  233. }
  234. }
  235. ::v-deep .scroll-view {
  236. height: calc(100%);
  237. }
  238. }
  239. .pub-button {
  240. margin-left: 32rpx;
  241. margin-right: 32rpx;
  242. }
  243. }
  244. </style>