index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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/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. }
  108. });
  109. }
  110. });
  111. } else {
  112. this.http.request({
  113. url: '/app/relate/remove',
  114. data: { companyId: item.companyId },
  115. method: 'POST',
  116. success: (res) => {
  117. uni.showToast({ title: '解除成功' });
  118. this.list.splice(this.list.indexOf(item), 1);
  119. }
  120. });
  121. }
  122. }
  123. }
  124. });
  125. },
  126. //刷新数据
  127. refresh() {
  128. this.loadMore = true;
  129. this.param.pageNum = 1;
  130. this.list = [];
  131. this.getData();
  132. }
  133. },
  134. //下拉刷新
  135. onPullDownRefresh() {
  136. setTimeout(() => {
  137. this.refresh();
  138. uni.stopPullDownRefresh();
  139. }, 1000);
  140. },
  141. //上拉加载
  142. onReachBottom() {
  143. if (this.loadMore) {
  144. this.param.pageNum++;
  145. this.getData();
  146. }
  147. }
  148. };
  149. </script>
  150. <style lang="scss">
  151. .list {
  152. padding: 10px 10px 90px 10px;
  153. .item {
  154. background-color: white;
  155. padding: 15px;
  156. border-radius: 5px;
  157. margin-bottom: 10px;
  158. .title {
  159. padding-bottom: 10px;
  160. }
  161. .op {
  162. border-top: 1px solid $line;
  163. padding-top: 10px;
  164. color: #676767;
  165. font-size: 14px;
  166. .del {
  167. float: right;
  168. color: #f44336;
  169. }
  170. .add {
  171. float: right;
  172. color: $main-color;
  173. }
  174. }
  175. }
  176. }
  177. .footer {
  178. position: fixed;
  179. width: 100%;
  180. bottom: 0px;
  181. padding-bottom: 13px;
  182. background-color: white;
  183. border-top: 1px solid $line;
  184. .db {
  185. padding: 15px 35px 10px 35px;
  186. }
  187. }
  188. </style>