index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="page-wrap">
  3. <view class="title">
  4. <uni-list-item :show-switch="true" title="按周排班">
  5. <template v-slot:footer>
  6. <view class="tip">
  7. <text>第</text>
  8. <view class="week">
  9. <uni-tag :text="`${week}`" size="mini" type="primary"></uni-tag>
  10. </view>
  11. <text>周</text>
  12. <text class="time">{{startDate}}至{{endDate}}</text>
  13. </view>
  14. </template>
  15. </uni-list-item>
  16. </view>
  17. <view class="selectbox">
  18. <uni-data-select class="item-select year" v-model="year" :localdata="years" :clear="false" @change="getData"></uni-data-select>
  19. <uni-data-select class="item-select" v-model="week" :localdata="weeks" :clear="false" @change="getData"></uni-data-select>
  20. </view>
  21. <uni-list>
  22. <uni-swipe-action ref="itemSwipe">
  23. <uni-swipe-action-item :auto-close="true" v-for="(item,idx) in items" :key="item.id">
  24. <template v-slot:right>
  25. <view class="slot-button">
  26. <view class="bt edit" @click="swipeHandle({type:1,item})"><text class="slot-button-text">编辑</text></view>
  27. <view class="bt del" @click="swipeHandle({type:2,item})"><text class="slot-button-text">删除</text></view>
  28. </view>
  29. </template>
  30. <uni-list-item
  31. :title="item.accountName"
  32. :note="item.remark"
  33. thumb="/static/images/avatar.png"
  34. :rightText="item.posName" >
  35. <template v-slot:footer>
  36. <div class="rtbox">
  37. <view class="rt">
  38. <view class="positionName">
  39. <uni-tag :text="item.positionName" size="mini" type="primary"></uni-tag>
  40. </view>
  41. <view class="posName">
  42. <uni-tag :text="item.posName" size="mini" type="success"></uni-tag>
  43. </view>
  44. </view>
  45. </div>
  46. </template>
  47. </uni-list-item>
  48. </uni-swipe-action-item>
  49. </uni-swipe-action>
  50. </uni-list>
  51. <div class="addbt" @click="onAdd">+</div>
  52. <AddForm ref="add" @success='getData' />
  53. </view>
  54. </template>
  55. <script>
  56. import AddForm from './components/AddForm.vue'
  57. import {getNumberOfWeeks,currentWeek,getDateByWeek,parseTime} from '@/libs/index.js'
  58. import dutyApi from '@/api/duty.js'
  59. export default {
  60. components:{
  61. AddForm
  62. },
  63. computed:{
  64. weeks(){
  65. return Array.from({length:getNumberOfWeeks(this.year)},(_,i)=>{return{value:i+1,text:`${this.year}年第${i+1}周`}})
  66. },
  67. years(){
  68. let year=this.year;
  69. return Array.from({ length: 101 }, (_, i) => {return {value:year+i - 20,text:`${year+i - 20}年`}})
  70. },
  71. startDate(){
  72. let day=getDateByWeek(this.week-1)
  73. return parseTime(day,'{y}-{m}-{d}')
  74. },
  75. endDate(){
  76. let day=new Date(getDateByWeek(this.week-1))
  77. let endDate=day.setDate(day.getDate()+6)
  78. return parseTime(endDate,'{y}-{m}-{d}')
  79. }
  80. },
  81. data() {
  82. return {
  83. keywords:"",
  84. year:new Date().getFullYear(),
  85. dutyDate:'',
  86. week: currentWeek(),
  87. changeIndx:-1,
  88. items:[]
  89. }
  90. },
  91. onShow() {
  92. this.getData()
  93. },
  94. methods: {
  95. getData(){
  96. dutyApi.getWeekRecordByList({
  97. year:this.year,
  98. week:this.week
  99. }).then((res)=>{
  100. this.items=res.data.map((item,idx)=>{return{...item,id:`${item.accountId}-${idx+1}`}})
  101. })
  102. },
  103. swipeHandle({type,item}){
  104. const self=this;
  105. let week=this.week;let year=this.year;
  106. if(type===1){
  107. this.$refs.add.show({type:'edit',params:{week,year,...item}})
  108. }else{
  109. uni.showModal({
  110. title: '提示',
  111. content: '是否确定删除',
  112. success: function (res) {
  113. if (res.confirm) {
  114. dutyApi.deleteWeekRecordById(year, week, item.accountId).then(()=>{
  115. uni.showToast({
  116. title:'删除成功!',
  117. icon:'none'
  118. })
  119. self.getData()
  120. })
  121. }
  122. }
  123. });
  124. }
  125. },
  126. onAdd(){
  127. this.$refs.add.show({type:'add',params:{week:this.week,year:this.year}})
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .page-wrap{
  134. width: 710rpx;
  135. background-color: #fff;
  136. margin: 20rpx auto;
  137. box-shadow: 0 0 4px rgba(0,0,0,0.46);
  138. padding: 20rpx;
  139. box-sizing: border-box;
  140. border-radius: 4px;
  141. }
  142. .tip{
  143. font-size: 28rpx;
  144. color: #666;
  145. .week{
  146. padding: 0 10rpx;
  147. display: inline-block;
  148. }
  149. .time{
  150. padding-left: 10rpx;
  151. font-size: 26rpx;
  152. }
  153. }
  154. .selectbox{
  155. display: flex;
  156. justify-content: space-between;
  157. align-items: center;
  158. padding: 20rpx;
  159. .item-select{
  160. width: 300rpx;
  161. &.year{
  162. width: 200rpx;
  163. }
  164. }
  165. }
  166. .addbt{
  167. width: 80rpx;
  168. height: 80rpx;
  169. border-radius: 50%;
  170. background-color: #409eff;
  171. color: #fff;
  172. line-height: 80rpx;
  173. text-align: center;
  174. box-shadow:0 2px 10rpx rgba(64,158,255,0.30);
  175. position: fixed;
  176. right: 10rpx;
  177. top: 50%;
  178. z-index: 99;
  179. font-size: 60rpx;
  180. }
  181. .slot-button{
  182. width: 260rpx;
  183. height: 80%;
  184. display: flex;
  185. flex-direction: row;
  186. justify-content: center;
  187. align-items: center;
  188. color: #fff;
  189. margin-top: 7%;
  190. .bt{
  191. width: 50%;
  192. height: 100%;
  193. font-size: 30rpx;
  194. box-sizing: border-box;
  195. display: flex;
  196. justify-content: center;
  197. align-items: center;
  198. &.edit{
  199. background-color:#007aff;
  200. }
  201. &.del{
  202. background-color:#F56C6C;
  203. }
  204. }
  205. }
  206. .rtbox{
  207. display: flex;
  208. align-items: center;
  209. justify-content: space-between;
  210. .rt{
  211. text-align: right;
  212. }
  213. }
  214. .delbt{
  215. padding: 20rpx;
  216. image{
  217. display: block;
  218. width: 30rpx;
  219. height: 30rpx;
  220. }
  221. }
  222. </style>