index.vue 7.4 KB

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