index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view>
  3. <div class="wrapper">
  4. <u-swipe-action
  5. v-for="(item, index) in list"
  6. :key="item.id"
  7. :index="index"
  8. :show="item.show"
  9. @click="clickDeleteCar(index)"
  10. @open="open(index)"
  11. :options="options"
  12. :bg-color="$bg-color"
  13. >
  14. <view class="view-item-content" @click="navigateTo(`/pages/mine/car/detail?id=${item.id}`)">
  15. <view class="view-item-detail">
  16. <view class="-title">{{ item.plateNo }}</view>
  17. <!-- <view class="-number">{{getCarVinText(item)}}</view> -->
  18. </view>
  19. </view>
  20. </u-swipe-action>
  21. <u-empty style="margin-top:20%;" text="还没有车辆记录" v-if="list.length == 0"></u-empty>
  22. <!-- 底部 -->
  23. <div class="bottom-bar mp-iphonex-bottom">
  24. <view class="button">
  25. <u-button type="success" :ripple="true" shape="circle" @click="navigateTo('/pages/mine/car/detail')">添加车辆</u-button>
  26. </view>
  27. </div>
  28. </div>
  29. <view>
  30. <u-modal
  31. v-model="showDeleteCar"
  32. :title="modalTitle"
  33. :content="modalContent"
  34. @confirm="handleDeleteCar"
  35. :showCancelButton="true"
  36. @cancel="handleCancel"
  37. ></u-modal>
  38. </view>
  39. <u-top-tips ref="uTips"></u-top-tips>
  40. </view>
  41. </template>
  42. <script>
  43. import { getCarList, deleteCar } from "@/api/car";
  44. export default {
  45. computed: {
  46. modalContent() {
  47. let plateNo = ""
  48. if (this.selectedCarIndex != -1) {
  49. let selectedCar = this.list[this.selectedCarIndex];
  50. if (selectedCar) {
  51. plateNo = selectedCar.plateNo;
  52. }
  53. }
  54. return `是否确认删除车辆[${plateNo}]?`;
  55. }
  56. },
  57. data() {
  58. return {
  59. keyword: "",
  60. params: {
  61. },
  62. list: [],
  63. options: [{
  64. text: '删除',
  65. style: {
  66. backgroundColor: '#dd524d'
  67. }
  68. }],
  69. modalTitle: '删除车辆',
  70. showDeleteCar: false,
  71. selectedCarIndex: -1,
  72. };
  73. },
  74. onReachBottom() {
  75. },
  76. onPullDownRefresh() {
  77. this.list = []
  78. this.init();
  79. },
  80. mounted() {
  81. },
  82. onShow() {
  83. this.reload()
  84. },
  85. methods: {
  86. getCarVinText(item) {
  87. let text = '';
  88. switch (item.checkState) {
  89. case 0:
  90. text = '认证中'
  91. break
  92. case 1:
  93. text = item.carVin || '已认证'
  94. break
  95. case 2:
  96. text = '认证未通过'
  97. break
  98. case 3:
  99. text = '未认证'
  100. break
  101. default:
  102. text = '未认证'
  103. break
  104. }
  105. return text
  106. },
  107. navigateTo(url) {
  108. uni.navigateTo({
  109. url,
  110. });
  111. },
  112. search() {
  113. this.init();
  114. },
  115. async init() {
  116. uni.stopPullDownRefresh()
  117. let res = await getCarList(this.params);
  118. if (res.data.code == 200) {
  119. let data = res.data.data;
  120. this.list = data;
  121. }
  122. },
  123. reload() {
  124. this.init();
  125. },
  126. clickDeleteCar(index) {
  127. this.selectedCarIndex = index;
  128. this.showDeleteCar = true;
  129. },
  130. // 如果打开一个的时候,不需要关闭其他,则无需实现本方法
  131. open(carIndex) {
  132. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  133. // 原本为'false',再次设置为'false'会无效
  134. let car = this.list[carIndex];
  135. car.show = true;
  136. this.list.map((car, idx) => {
  137. if (carIndex != idx) {
  138. this.list[idx].show = false;
  139. }
  140. })
  141. this.$set(this.list, carIndex, car)
  142. },
  143. async handleDeleteCar() {
  144. let selectedCar = this.list[this.selectedCarIndex];
  145. const response = await deleteCar(selectedCar.id)
  146. if (response.data.code == 200) {
  147. uni.showToast({
  148. icon: "success",
  149. title: "删除成功!",
  150. });
  151. this.reload();
  152. } else if (response.data.msg != null) {
  153. this.$refs.uTips.show({ title: response.data.msg, type: "error" });
  154. }
  155. selectedCar.show = false;
  156. this.$set(this.list, this.selectedCarIndex, selectedCar)
  157. this.selectedCarIndex = -1;
  158. },
  159. handleCancel() {
  160. let selectedCar = this.list[this.selectedCarIndex];
  161. selectedCar.show = false;
  162. this.$set(this.list, this.selectedCarIndex, selectedCar)
  163. }
  164. },
  165. };
  166. </script>
  167. <style lang="scss" scoped>
  168. .wrapper {
  169. padding: 0 0 100rpx;
  170. height: calc(100vh - 170rpx);
  171. overflow-y: auto;
  172. }
  173. .bottom-bar {
  174. position: fixed;
  175. bottom: 0;
  176. left: 0;
  177. width: 100%;
  178. height: 100rpx;
  179. overflow: hidden;
  180. line-height: 100rpx;
  181. margin-bottom: 0px !important;
  182. background: #ffffff;
  183. display: flex;
  184. justify-content: space-between;
  185. > .button {
  186. margin: 0 30rpx;
  187. flex: 1;
  188. }
  189. }
  190. /* DarkMode 下的样式 start */
  191. @media (prefers-color-scheme: dark) {
  192. .bottom-bar {
  193. background: #121425;
  194. }
  195. }
  196. .view-item {
  197. padding: 32rpx;
  198. display: flex;
  199. justify-content: space-between;
  200. align-items: center;
  201. box-shadow: 0px 0px 2px 1px #b7b7b740;
  202. border-radius: 10px;
  203. margin: 30rpx;
  204. }
  205. .view-item-content {
  206. padding: 30rpx;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. background: url(/static/mine/car-list-bg.png) right -30rpx bottom no-repeat;
  211. background-size: auto 80%;
  212. box-shadow: 0px 0px 2px 1px #b7b7b740;
  213. border-radius: 10px;
  214. margin: 15rpx 30rpx;
  215. }
  216. .view-item-detail {
  217. line-height: 1.75;
  218. flex: 1;
  219. > .-title {
  220. font-size: 32rpx;
  221. font-weight: 500;
  222. }
  223. > .-number {
  224. font-size: 24rpx;
  225. color: #bdbfc0;
  226. }
  227. }
  228. </style>