图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
5.6 KiB

1 month ago
  1. <template>
  2. <view class="reader-card">
  3. <image class="card-top-bg" src="@/static/images/card-img1.png" mode="widthFix" />
  4. <view class="card-list">
  5. <!-- 点击选择要解绑的读者证 -->
  6. <view
  7. class="card-list-item"
  8. v-for="(item, index) in cardList"
  9. :key="item.id"
  10. @click="handleSelectItem(item.bindValue)"
  11. :class="{ active: selectedValue === item.bindValue }"
  12. >
  13. <image class="card-left-img" src="@/static/images/card-img2.png" mode="widthFix" />
  14. <view class="card-right-info">
  15. <text class="info-title">读者证号</text>
  16. <text class="info-num">{{ item.bindValue }}</text>
  17. </view>
  18. <uni-icons
  19. type="checkmark"
  20. size="24"
  21. color="#01a4fe"
  22. v-if="selectedValue === item.bindValue"
  23. ></uni-icons>
  24. </view>
  25. <!-- <view class="add-card-btn" @click="toAddReaderCard">
  26. <uni-icons type="plus" size="20" color="#01a4fe"></uni-icons>
  27. <text>新增读者证</text>
  28. </view> -->
  29. </view>
  30. <!-- 底部解绑按钮 -->
  31. <button
  32. class="unbind-btn"
  33. :disabled="!selectedValue"
  34. :class="{disabled: !selectedValue}"
  35. @click="handleUnbind"
  36. >
  37. 确认解绑
  38. </button>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. FetchFindAllReaderBindByOpenId,
  44. FetchUnbindReadCard
  45. } from '@/api/user';
  46. const READLIST = 'reader-card-list';
  47. export default {
  48. data() {
  49. return {
  50. selectedValue: '', // 选中要解绑的证号
  51. cardList: [],
  52. }
  53. },
  54. onLoad() {},
  55. onShow() {
  56. this.getBindReaderCardList();
  57. },
  58. methods: {
  59. // 获取列表
  60. async getBindReaderCardList() {
  61. try {
  62. const openId = uni.getStorageSync('wx_login_code');
  63. if (!openId) return;
  64. const res = await FetchFindAllReaderBindByOpenId({
  65. libcode: '1201',
  66. openId: openId
  67. });
  68. if (res.code === 200) {
  69. this.cardList = res.data;
  70. uni.setStorageSync(READLIST, res.data);
  71. } else {
  72. this.cardList = [];
  73. uni.setStorageSync(READLIST, []);
  74. }
  75. } catch (err) {
  76. this.cardList = uni.getStorageSync(READLIST) || [];
  77. }
  78. },
  79. // 点击选择
  80. handleSelectItem(value) {
  81. // 重复点击取消选择
  82. if (this.selectedValue === value) {
  83. this.selectedValue = '';
  84. } else {
  85. this.selectedValue = value;
  86. }
  87. },
  88. // 确认解绑
  89. handleUnbind() {
  90. if (!this.selectedValue) {
  91. uni.showToast({ title: '请选择要解绑的读者证', icon: 'none' });
  92. return;
  93. }
  94. const openId = uni.getStorageSync('wx_login_code');
  95. if (!openId) return;
  96. uni.showModal({
  97. title: '提示',
  98. content: `确定要解绑【${this.selectedValue}】吗?`,
  99. success: async (res) => {
  100. if (res.confirm) {
  101. try {
  102. // 解绑接口参数 完全按你要求
  103. const result = await FetchUnbindReadCard({
  104. bindType: "rdid",
  105. bindValue: this.selectedValue,
  106. libcode: "1201",
  107. openid: openId
  108. });
  109. if (result.code === 200) {
  110. uni.showToast({ title: '解绑成功', icon: 'success' });
  111. this.selectedValue = '';
  112. this.getBindReaderCardList(); // 刷新列表
  113. } else {
  114. uni.showToast({ title: result.msg || '解绑失败', icon: 'none' });
  115. }
  116. } catch (err) {
  117. uni.showToast({ title: '解绑失败', icon: 'none' });
  118. }
  119. }
  120. }
  121. });
  122. },
  123. toAddReaderCard() {
  124. uni.navigateTo({ url: "/pages/login/login" });
  125. },
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .reader-card{
  131. position: relative;
  132. min-height: 100vh;
  133. background-color: #f5f5f5;
  134. .card-top-bg{
  135. position: absolute;
  136. left: 0;
  137. top: 0;
  138. width: 100%;
  139. display: block;
  140. }
  141. .card-list{
  142. position: absolute;
  143. left: 0;
  144. top: 60px;
  145. width: calc(100% - 24px);
  146. height: calc(100vh - 195px);
  147. overflow-y: auto;
  148. padding: 12px;
  149. z-index: 999;
  150. .card-list-item{
  151. display: flex;
  152. justify-content: space-between;
  153. align-items: center;
  154. padding: 10px;
  155. margin-bottom: 12px;
  156. border: 2px solid #C6C6E2;
  157. border-radius: 8px;
  158. background: rgba(241,241,249,0.4);
  159. cursor: pointer;
  160. transition: all 0.2s;
  161. &.active{
  162. border-color: #01a4fe;
  163. background: rgba(1, 164, 254, 0.1);
  164. }
  165. .card-left-img{
  166. width: 80px;
  167. margin-right: 12px;
  168. display: block;
  169. }
  170. .card-right-info{
  171. flex: 1;
  172. display: flex;
  173. flex-direction: column;
  174. .info-title{
  175. font-size: 16px;
  176. color: #333;
  177. font-weight: bold;
  178. padding-bottom: 12px;
  179. }
  180. .info-num{
  181. font-size: 14px;
  182. color: #999;
  183. }
  184. }
  185. }
  186. }
  187. .add-card-btn {
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. margin-top: 15px;
  192. height: 44px;
  193. border: 1px dashed #01a4fe;
  194. border-radius: 8px;
  195. color: #01a4fe;
  196. font-size: 15px;
  197. uni-icons {
  198. margin-right: 6px;
  199. }
  200. }
  201. .unbind-btn{
  202. position: fixed;
  203. bottom: 40px;
  204. left: 0;
  205. right: 0;
  206. width: calc(100% - 40px);
  207. margin: 0 auto;
  208. padding: 4px 0;
  209. color: #fff;
  210. background-color: #01a4fe;
  211. border-radius: 23px;
  212. font-size: 16px;
  213. border: none;
  214. &.disabled{
  215. background-color: #ccc;
  216. }
  217. }
  218. }
  219. </style>