index.vue 5.3 KB

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