index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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,this.year)
  77. return parseTime(day,'{y}-{m}-{d}')
  78. },
  79. endDate(){
  80. let day=new Date(getDateByWeek(this.week-1,this.year))
  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. .tip{
  146. font-size: 28rpx;
  147. color: #666;
  148. .week{
  149. padding: 0 10rpx;
  150. display: inline-block;
  151. }
  152. .time{
  153. padding-left: 10rpx;
  154. font-size: 26rpx;
  155. }
  156. }
  157. .selectbox{
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: center;
  161. padding: 20rpx;
  162. .item-select{
  163. width: 300rpx;
  164. &.year{
  165. width: 200rpx;
  166. }
  167. }
  168. }
  169. .addbt{
  170. width: 100rpx;
  171. height: 100rpx;
  172. border-radius: 50%;
  173. color: #fff;
  174. background-color: rgba(64,158,255,0.6);
  175. box-shadow:0 0 10rpx rgba(0,0,0,0.6);
  176. position: fixed;
  177. right: 10rpx;
  178. bottom: 20%;
  179. z-index: 99;
  180. text-align: center;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. .word{
  185. width: 80rpx;
  186. height: 80rpx;
  187. border-radius: 50%;
  188. margin: 5rpx auto;
  189. font-size: 28rpx;
  190. letter-spacing: 2px;
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. }
  195. }
  196. .slot-button{
  197. width: 260rpx;
  198. height: 80%;
  199. display: flex;
  200. flex-direction: row;
  201. justify-content: center;
  202. align-items: center;
  203. color: #fff;
  204. margin-top: 7%;
  205. .bt{
  206. width: 50%;
  207. height: 100%;
  208. font-size: 30rpx;
  209. box-sizing: border-box;
  210. display: flex;
  211. justify-content: center;
  212. align-items: center;
  213. &.edit{
  214. background-color:#007aff;
  215. }
  216. &.del{
  217. background-color:#F56C6C;
  218. }
  219. }
  220. }
  221. .rtbox{
  222. display: flex;
  223. align-items: center;
  224. justify-content: space-between;
  225. .rt{
  226. text-align: right;
  227. }
  228. }
  229. .delbt{
  230. padding: 20rpx;
  231. image{
  232. display: block;
  233. width: 30rpx;
  234. height: 30rpx;
  235. }
  236. }
  237. }
  238. </style>