index.vue 4.3 KB

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