index.vue 7.5 KB

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