index.vue 5.0 KB

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