index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view>
  3. <view class="tab">
  4. <u-tabs :list="tab" :current="0"></u-tabs>
  5. </view>
  6. <view class="list">
  7. <view class="item" v-for="(item, index) in list" :key="index">
  8. <view class="title">{{ item.companyName }}</view>
  9. <view class="op">
  10. <text>{{ item.createTime }}</text>
  11. <text class="del" @click="del(item)">解除</text>
  12. </view>
  13. </view>
  14. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  15. <u-empty v-if="!loadMore && list.length == 0" text="尚未关联公司"></u-empty>
  16. </view>
  17. <view class="footer">
  18. <view class="db"><button class="btn" @click="show = true">关联企业</button></view>
  19. </view>
  20. <u-action-sheet round="20" :actions="actions" @select="selectClick" cancelText="取消" :show="show" @close="show = false"></u-action-sheet>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. tab: [{ name: '全部' }],
  28. show: false,
  29. actions: [{ name: '扫码关联' }, { name: '手动关联' }],
  30. list: [],
  31. param: { pageNum: 1, pageSize: 10, orderByColumn: 'createTime', isAsc: 'desc' },
  32. loadMore: true
  33. };
  34. },
  35. onLoad(e) {
  36. this.getData();
  37. uni.$on('company', (res) => {
  38. this.refresh();
  39. });
  40. },
  41. methods: {
  42. getData() {
  43. this.http.request({
  44. url: '/app/relate/list',
  45. data: this.param,
  46. loading: 'false',
  47. success: (res) => {
  48. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  49. res.data.rows.forEach((item) => {
  50. item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
  51. this.list.push(item);
  52. });
  53. }
  54. });
  55. },
  56. selectClick(e) {
  57. if (e.name == '手动关联') {
  58. uni.navigateTo({ url: '/pages/company/search' });
  59. } else {
  60. uni.scanCode({
  61. success: (res) => {
  62. this.http.request({
  63. url: '/app/relate/add',
  64. data: { companyId: res.result,way:'扫码关联' },
  65. method: 'POST',
  66. success: (res) => {
  67. uni.showModal({
  68. title: '提示',
  69. content: '关联成功',
  70. showCancel: false,
  71. success: (res) => {
  72. this.refresh();
  73. }
  74. });
  75. }
  76. });
  77. },
  78. fail: (res) => {}
  79. });
  80. }
  81. },
  82. del(item) {
  83. uni.showModal({
  84. title: '提示',
  85. content: '确定解除该企业关联?',
  86. success: (res) => {
  87. if (res.confirm) {
  88. this.http.request({
  89. url: '/app/relate/remove',
  90. data: { companyId: item.companyId },
  91. method: 'POST',
  92. success: (res) => {
  93. uni.showToast({ title: '解除成功' });
  94. this.list.splice(this.list.indexOf(item), 1);
  95. }
  96. });
  97. }
  98. }
  99. });
  100. },
  101. //刷新数据
  102. refresh() {
  103. this.loadMore = true;
  104. this.param.pageNum = 1;
  105. this.list = [];
  106. this.getData();
  107. }
  108. },
  109. //下拉刷新
  110. onPullDownRefresh() {
  111. setTimeout(() => {
  112. this.refresh();
  113. uni.stopPullDownRefresh();
  114. }, 1000);
  115. },
  116. //上拉加载
  117. onReachBottom() {
  118. if (this.loadMore) {
  119. this.param.pageNum++;
  120. this.getData();
  121. }
  122. }
  123. };
  124. </script>
  125. <style lang="scss">
  126. .list {
  127. padding: 10px 10px 90px 10px;
  128. .item {
  129. background-color: white;
  130. padding: 15px;
  131. border-radius: 5px;
  132. margin-bottom: 10px;
  133. .title {
  134. padding-bottom: 10px;
  135. }
  136. .op {
  137. border-top: 1px solid $line;
  138. padding-top: 10px;
  139. color: #676767;
  140. font-size: 14px;
  141. .del {
  142. float: right;
  143. color: #f44336;
  144. }
  145. }
  146. }
  147. }
  148. .footer {
  149. position: fixed;
  150. width: 100%;
  151. bottom: 0px;
  152. padding-bottom: 13px;
  153. background-color: white;
  154. border-top: 1px solid $line;
  155. .db {
  156. padding: 15px 35px 10px 35px;
  157. }
  158. }
  159. </style>