score.vue 8.3 KB

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