zhibananpai.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view style="width: 100vw;height:100vh;">
  3. <view style="height: calc(100% - 104rpx);">
  4. <view style="padding: 20rpx;background-color: #fff;">
  5. <view style="display: flex;" class="">
  6. <!-- <u-search v-model="dateChange" disabled placeholder="请选择月份" :showAction="true" actionText="搜索"
  7. :animation="false" @custom="confirmSearch"
  8. @clear="clearSearch"></u-search> -->
  9. <view shape="round" @click="openDatePicker"
  10. style="background-color: #f2f2f2;width: 600rpx;height:60rpx;display: flex;border-radius: 2%;"
  11. class="">
  12. <u-icon style="margin-left: 10rpx;" size="23" name="search"></u-icon>
  13. <span style="display: inline-block;margin-top: 12rpx;">{{dateChange}}</span>
  14. </view>
  15. <view @click="confirmSearch(dateChange)"
  16. style="font-size: 30rpx; line-height: 60rpx;margin-left: 30rpx;" class="">
  17. 搜索
  18. </view>
  19. </view>
  20. <uni-table style="margin-top: 15rpx;overflow-x: auto;" ref="table" :loading="loading" border
  21. emptyText="暂无更多数据">
  22. <uni-tr>
  23. <uni-th style="position: sticky;left: 0;background-color: #fff;" width="70"
  24. align="center">日期</uni-th>
  25. <uni-th width="50" align="center">星期</uni-th>
  26. <uni-th width="120" align="center">白天</uni-th>
  27. <uni-th width="120" align="center">夜晚</uni-th>
  28. <uni-th width="120" align="center">应急值班</uni-th>
  29. <uni-th width="120" align="center">带班干部</uni-th>
  30. <uni-th width="120" align="center">值班司机</uni-th>
  31. </uni-tr>
  32. <uni-tr v-for="(item, index) in tableData" :key="index">
  33. <uni-td style="position: sticky;left: 0;background-color: #fff;" :style="getRowStyle(item)"
  34. align="center">{{ item.dateForApp }}</uni-td>
  35. <uni-td :style="getRowStyle(item)" align="center">
  36. <view class="weekForApp">{{ item.weekForApp }}</view>
  37. </uni-td>
  38. <uni-td :style="getRowStyle(item)" align="center">{{ item.dutyDay }}</uni-td>
  39. <uni-td :style="getRowStyle(item)" align="center">{{ item.dutyNight }}</uni-td>
  40. <uni-td :style="getRowStyle(item)" align="center">
  41. <view class="dutyEmergency">{{ item.dutyEmergency }}</view>
  42. </uni-td>
  43. <uni-td :style="getRowStyle(item)" align="center">{{ item.dutyLeader }}</uni-td>
  44. <uni-td :style="getRowStyle(item)" align="center">{{ item.dutyDriver }}</uni-td>
  45. </uni-tr>
  46. </uni-table>
  47. </view>
  48. <u-datetime-picker :formatter="formatter" :show="showDatePicker" v-model="selectedDate" mode="year-month"
  49. @confirm="handleDateConfirm" @cancel="showDatePicker = false"></u-datetime-picker>
  50. </view>
  51. <!-- <u-action-sheet :actions="morelist" :closeOnClickOverlay="true" :closeOnClickAction="true" cancelText="取消" title="申请" :show="show" @select="selectClick" @close="show = false"></u-action-sheet> -->
  52. </view>
  53. </template>
  54. <script>
  55. import dayjs from 'dayjs';
  56. export default {
  57. data() {
  58. return {
  59. loading: false,
  60. tableData: [],
  61. dateChange: '', // 绑定到搜索框的值
  62. showDatePicker: false, // 控制日期选择器的显示
  63. selectedDate: Number(new Date()), // 选择的日期
  64. }
  65. },
  66. onLoad() {
  67. const date = new Date();
  68. const year = date.getFullYear();
  69. const month = date.getMonth() + 1; // getMonth() 返回的月份是从0开始的
  70. const formattedDate = `${year}-${month.toString().padStart(2, '0')}`;
  71. this.dateChange = formattedDate; // 确认日期后,更新搜索框的显示值
  72. this.confirmSearch(this.dateChange)
  73. },
  74. onNavigationBarButtonTap(e) {},
  75. onShow() {
  76. },
  77. methods: {
  78. getRowStyle(row) {
  79. console.log('row', row)
  80. if (row.selfDuty == 1) { // 根据条件设置背景色
  81. return {
  82. backgroundColor: '#fae018'
  83. };
  84. } else {
  85. return {};
  86. }
  87. },
  88. openDatePicker() {
  89. this.showDatePicker = true; // 点击搜索框时打开日期选择器
  90. },
  91. handleDateConfirm(value) {
  92. console.log('value', value)
  93. const date = new Date(value.value);
  94. const year = date.getFullYear();
  95. const month = date.getMonth() + 1; // getMonth() 返回的月份是从0开始的
  96. const formattedDate = `${year}-${month.toString().padStart(2, '0')}`;
  97. this.dateChange = formattedDate; // 确认日期后,更新搜索框的显示值
  98. this.showDatePicker = false; // 关闭日期选择器
  99. },
  100. confirmSearch(value) {
  101. // 处理搜索逻辑
  102. console.log('搜索月份:', value);
  103. uni.$u.http.get('/duty/duty/app/selectList', {
  104. params: {
  105. month: value + '-01'
  106. }
  107. }).then((res) => {
  108. console.log('res', res)
  109. this.tableData = res.rows
  110. })
  111. },
  112. clearSearch() {
  113. // 清除搜索框内容
  114. this.dateChange = '';
  115. },
  116. formatter(type, value) {
  117. if (type === 'year') {
  118. return `${value}年`
  119. }
  120. if (type === 'month') {
  121. return `${value}月`
  122. }
  123. if (type === 'day') {
  124. return `${value}日`
  125. }
  126. return value
  127. },
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .grid-text {
  133. height: 100rpx;
  134. line-height: 100rpx;
  135. font-size: 36rpx;
  136. color: #606266;
  137. /* #ifndef APP-PLUS */
  138. box-sizing: border-box;
  139. /* #endif */
  140. }
  141. .choose {
  142. color: #409EFF
  143. }
  144. .uni-table thead {
  145. position: sticky;
  146. top: 0;
  147. z-index: 10;
  148. background-color: #fff;
  149. }
  150. .uni-table th:first-child,
  151. .uni-table td:first-child {
  152. position: sticky;
  153. left: 0;
  154. background-color: #fff;
  155. z-index: 5;
  156. }
  157. </style>