index.vue 7.5 KB

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