score.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <view class="container main">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="searchInfo.name" placeholder="请输入名称" @blur="toInput">
  6. </view>
  7. <view class="one_2">
  8. <button size="mini" class="button" type="primary" @click="toAdd">添加</button>
  9. </view>
  10. </view>
  11. <view class="two">
  12. <tabs :tabs="tabs" @tabsChange="tabsChange">
  13. <view class="tabsList">
  14. <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-view" @scrolltolower="toPage"
  15. @scroll="toScroll" v-if="total>0">
  16. <view class="list-scroll-view">
  17. <view class="list" v-for="(item, index) in list" :key="index">
  18. <view class="value">
  19. <view class="title">流程名称:</view>
  20. <view class="label">{{item.matchPath_name||'暂无'}}</view>
  21. </view>
  22. <view class="value">
  23. <view class="title">选手名称:</view>
  24. <view class="label">{{item.sign_name||'暂无'}}</view>
  25. </view>
  26. <view class="value">
  27. <view class="title">分数:</view>
  28. <view class="label">{{item.score||'暂无'}}</view>
  29. </view>
  30. <view class="value">
  31. <view class="title">时间:</view>
  32. <view class="label">{{item.time||'暂无'}}</view>
  33. </view>
  34. <view class="bottom">
  35. <button class="button button_1" type="default" size="mini"
  36. @tap.stop="toEdit(item)">修改</button>
  37. <button class="button button_2" type="default" size="mini"
  38. @tap.stop="toDelete(item)">删除</button>
  39. </view>
  40. </view>
  41. <view class="is_bottom" v-if="is_bottom">
  42. <text>{{config.bottom_title||'到底了!'}}</text>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. <o-empty v-else />
  47. </view>
  48. </tabs>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import tabs from '../../components/tabs/index.vue';
  54. export default {
  55. components: {
  56. tabs
  57. },
  58. data() {
  59. return {
  60. id: '',
  61. user: {},
  62. tabs: {
  63. active: '',
  64. bgColor: '#ffffff',
  65. menu: []
  66. },
  67. config: {},
  68. searchInfo: {},
  69. list: [],
  70. total: 0,
  71. skip: 0,
  72. limit: 5,
  73. page: 0,
  74. // 数据是否触底
  75. is_bottom: false,
  76. scrollTop: 0,
  77. }
  78. },
  79. onLoad: async function(e) {
  80. const that = this;
  81. that.$set(that, `id`, e && e.id || '');
  82. await that.searchToken();
  83. await that.searchConfig();
  84. },
  85. onShow: async function() {
  86. const that = this;
  87. that.clearPage();
  88. await that.searchOther();
  89. await that.search();
  90. },
  91. onPullDownRefresh: async function() {
  92. const that = this;
  93. that.clearPage();
  94. await that.searchOther();
  95. await that.search();
  96. uni.stopPullDownRefresh();
  97. },
  98. methods: {
  99. // 用户信息
  100. searchToken() {
  101. const that = this;
  102. try {
  103. const res = uni.getStorageSync('token');
  104. if (res) {
  105. const user = that.$jwt(res);
  106. that.$set(that, `user`, user);
  107. }
  108. } catch (e) {}
  109. },
  110. async searchOther() {
  111. const that = this;
  112. const res = await that.$api(`/matchPath`, 'GET', {
  113. match: that.id
  114. })
  115. if (res.errcode == '0' && res.total > 0) {
  116. that.$set(that.tabs, `active`, res.data[0].id)
  117. const menu = []
  118. for (let val of res.data) {
  119. menu.push({
  120. title: val.name,
  121. active: val.id
  122. })
  123. }
  124. that.$set(that.tabs, `menu`, menu)
  125. }
  126. },
  127. searchConfig() {
  128. const that = this;
  129. try {
  130. const res = uni.getStorageSync('config');
  131. if (res) that.$set(that, `config`, res);
  132. } catch (e) {}
  133. },
  134. // 查询
  135. async search() {
  136. const that = this;
  137. let info = {
  138. skip: that.skip,
  139. limit: that.limit,
  140. match: that.id,
  141. matchPath: that.tabs.active
  142. }
  143. const res = await that.$api(`/score/list`, 'GET', {
  144. ...info,
  145. ...that.searchInfo
  146. })
  147. if (res.errcode == '0') {
  148. let list = [...that.list, ...res.data];
  149. that.$set(that, `list`, list)
  150. that.$set(that, `total`, res.total)
  151. } else {
  152. uni.showToast({
  153. title: res.errmsg,
  154. icon: 'none'
  155. });
  156. }
  157. },
  158. // 输入框
  159. toInput() {
  160. const that = this;
  161. if (!that.searchInfo.name) that.$set(that, `searchInfo`, {})
  162. that.clearPage();
  163. that.search();
  164. },
  165. // 添加
  166. toAdd() {
  167. const that = this;
  168. uni.navigateTo({
  169. url: `/pagesMy/match/add?match=${that.id}&matchPath=${that.tabs.active}`
  170. })
  171. },
  172. // 选择选项卡
  173. tabsChange(e) {
  174. const that = this;
  175. that.$set(that.tabs, `active`, e.active)
  176. that.clearPage();
  177. that.search()
  178. },
  179. // 修改
  180. toEdit(item) {
  181. const that = this;
  182. uni.navigateTo({
  183. url: `/pagesMy/match/add?id=${item.id || item._id}&match=${that.id}`
  184. })
  185. },
  186. // 删除
  187. async toDelete(item) {
  188. const that = this;
  189. uni.showModal({
  190. title: '提示',
  191. content: '确定删除该打分吗?',
  192. success: async function(res) {
  193. if (res.confirm) {
  194. const arr = await that.$api(`/score/${item.id}`, 'DELETE');
  195. if (arr.errcode == '0') {
  196. uni.showToast({
  197. title: '删除信息成功',
  198. icon: 'none'
  199. })
  200. await that.clearPage()
  201. await that.search()
  202. } else {
  203. uni.showToast({
  204. title: arr.errmsg,
  205. icon: 'none'
  206. })
  207. }
  208. }
  209. }
  210. });
  211. },
  212. // 分页
  213. toPage(e) {
  214. const that = this;
  215. let list = that.list;
  216. let limit = that.limit;
  217. if (that.total > list.length) {
  218. uni.showLoading({
  219. title: '加载中',
  220. mask: true
  221. })
  222. let page = that.page + 1;
  223. that.$set(that, `page`, page)
  224. let skip = page * limit;
  225. that.$set(that, `skip`, skip)
  226. that.search();
  227. uni.hideLoading();
  228. } else that.$set(that, `is_bottom`, true)
  229. },
  230. toScroll(e) {
  231. const that = this;
  232. let up = that.scrollTop;
  233. let num = Math.sign(up - e.detail.scrollTop);
  234. if (num == 1) that.$set(that, `is_bottom`, false);
  235. // 检查滚动位置是否达到div显示的条件
  236. if (e.detail.scrollTop >= 300 && !that.showDiv) {
  237. that.showDiv = true;
  238. } else if (e.detail.scrollTop < 300 && that.showDiv) {
  239. that.showDiv = false;
  240. }
  241. },
  242. // 清空列表
  243. clearPage() {
  244. const that = this;
  245. that.$set(that, `list`, [])
  246. that.$set(that, `skip`, 0)
  247. that.$set(that, `limit`, 5)
  248. that.$set(that, `page`, 0)
  249. }
  250. }
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. .main {
  255. .one {
  256. display: flex;
  257. justify-content: center;
  258. align-items: center;
  259. padding: 2vw;
  260. background-color: var(--mainColor);
  261. .one_1 {
  262. padding: 0 2vw;
  263. width: 75vw;
  264. input {
  265. padding: 2vw;
  266. background-color: var(--f1Color);
  267. font-size: var(--font14Size);
  268. border-radius: 5px;
  269. }
  270. }
  271. .one_2 {
  272. .button {
  273. background-color: var(--f3CColor);
  274. color: var(--mainColor);
  275. }
  276. }
  277. }
  278. .two {
  279. background-color: var(--f1Color);
  280. .tabsList {
  281. position: relative;
  282. flex-grow: 1;
  283. width: 100vw;
  284. height: 82vh;
  285. margin: 10px 0 0 0;
  286. .list {
  287. background-color: var(--mainColor);
  288. border-bottom: 1px solid var(--f5Color);
  289. margin: 2vw 2vw 0 2vw;
  290. border-radius: 4px;
  291. padding: 3vw;
  292. .value {
  293. display: flex;
  294. align-items: center;
  295. .title {
  296. font-size: var(--font14Size);
  297. font-weight: bold;
  298. }
  299. .label {
  300. font-size: var(--font12Size);
  301. color: var(--f85Color);
  302. }
  303. }
  304. .bottom {
  305. margin: 2vw 0 0 0;
  306. text-align: center;
  307. .button {
  308. color: var(--mainColor);
  309. font-size: var(--font14Size);
  310. border-radius: 2vw;
  311. }
  312. .button_1 {
  313. margin: 0 2vw 0 0;
  314. background-color: var(--f3CColor);
  315. }
  316. .button_2 {
  317. background-color: var(--fF0Color);
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. .scroll-view {
  325. position: absolute;
  326. top: 0;
  327. left: 0;
  328. right: 0;
  329. bottom: 0;
  330. .list-scroll-view {
  331. display: flex;
  332. flex-direction: column;
  333. }
  334. }
  335. .is_bottom {
  336. width: 100%;
  337. text-align: center;
  338. text {
  339. padding: 2vw 0;
  340. display: inline-block;
  341. color: var(--f85Color);
  342. font-size: var(--font14Size);
  343. }
  344. }
  345. </style>