worker.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <view class="container" style="margin-bottom: 100rpx;">
  4. <template v-for="(item,index) in list">
  5. <view v-if="wids.includes(item.id)" :key="index" class="worker-box1 cur" @click="selectWorker(item)">
  6. <image class="worker-box-img" :src="item.img" mode="aspectFit"></image>
  7. <view class="worker-box-name">{{item.name}}</view>
  8. <view v-if="item.count > 0" class="worker-box-desc">当前有{{item.count}}单</view>
  9. <view v-if="item.count == 0" class="worker-box-desc">当前空闲</view>
  10. <image class="worker-box-cur" src="../../images/select-worker.png" mode="aspectFit"></image>
  11. </view>
  12. <view v-if="!wids.includes(item.id)" class="worker-box1" @click="selectWorker(item)">
  13. <image class="worker-box-img" :src="item.img" mode="aspectFit"></image>
  14. <view class="worker-box-name">{{item.name}}</view>
  15. <view v-if="item.count > 0" class="worker-box-desc">当前有{{item.count}}单</view>
  16. <view v-if="item.count == 0" class="worker-box-desc">当前空闲</view>
  17. <image class="worker-box-cur" src="../../images/select-worker.png" mode="aspectFit"></image>
  18. </view>
  19. </template>
  20. </view>
  21. <view class="confirmBtn" @click="confirmBtn">确认选择</view>
  22. </view>
  23. </template>
  24. <script>
  25. var app = getApp();
  26. export default {
  27. data() {
  28. return {
  29. list: [],
  30. workers: [],
  31. wids: []
  32. }
  33. },
  34. onLoad() {
  35. var that = this;
  36. const eventChannel = this.getOpenerEventChannel()
  37. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  38. eventChannel.on('acceptDataFromOpenerPage', function(data) {
  39. that.workers = data.workers;
  40. that.wids = [];
  41. that.workers.forEach((item) => {
  42. that.wids.push(item.id);
  43. });
  44. })
  45. },
  46. onShow() {
  47. var that = this;
  48. app.ajaxReadyCallback = res => { //各个接口统一回调方法
  49. var apiname = res.data.apiname;
  50. console.log(res);
  51. if(apiname == 'worker'){
  52. that.list = res.data.data;
  53. }
  54. }
  55. this.getWorkerAll();
  56. },
  57. methods: {
  58. selectWorker(obj){
  59. if(this.wids.includes(obj.id)){ // 去除
  60. this.wids = this.wids.filter((item) => {
  61. return item != obj.id;
  62. });
  63. this.workers = this.workers.filter((item) => {
  64. return item.id != obj.id;
  65. })
  66. }else{ // 添加
  67. this.wids.push(obj.id);
  68. this.workers.push(obj);
  69. }
  70. },
  71. confirmBtn(){
  72. const eventChannel = this.getOpenerEventChannel()
  73. eventChannel.emit('acceptDataFromOpenedPage', this.workers);
  74. uni.navigateBack({
  75. delta: 1
  76. });
  77. },
  78. getWorkerAll(){
  79. if(this.flag == 1){
  80. return;
  81. }
  82. app.ajax({
  83. url: app.globalData.serverUrl + 'order/getWorkerAll',
  84. type: 'POST',
  85. apiname: 'worker',
  86. });
  87. },
  88. getUrlCode (name) {
  89. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
  90. },
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .confirmBtn{
  96. position: fixed;
  97. z-index: 99;
  98. bottom: 0;
  99. left: 0;
  100. width: 100%;
  101. height: 90rpx;
  102. line-height: 90rpx;
  103. text-align: center;
  104. color: #FFFFFF;
  105. background-color: var(--themeColor);
  106. font-size: 34rpx;
  107. font-weight: bold;
  108. }
  109. .worker-box1{
  110. position: relative;
  111. width: 218rpx;
  112. height: 280rpx;
  113. margin-right: 15rpx;
  114. background-color: #FFFFFF;
  115. border-radius: 10rpx;
  116. text-align: center;
  117. border: 2rpx solid #FFFFFF;
  118. float: left;
  119. margin-bottom: 15rpx;
  120. }
  121. .worker-box1.cur{
  122. border: 2rpx solid #FF7576;
  123. }
  124. .worker-box1 .worker-box-cur{
  125. display: none;
  126. position: absolute;
  127. width: 66rpx;
  128. height: 68rpx;
  129. z-index: 100;
  130. top: -1rpx;
  131. right: -1rpx;
  132. }
  133. .worker-box1.cur .worker-box-cur{
  134. display: block;
  135. }
  136. .worker-box1 .worker-box-img{
  137. width: 130rpx;
  138. height: 130rpx;
  139. border-radius: 50%;
  140. margin-top: 25rpx;
  141. margin-bottom: 10rpx;
  142. }
  143. .worker-box1 .worker-box-name{
  144. width: 100%;
  145. height: auto;
  146. font-size: 30rpx;
  147. font-weight: bold;
  148. color: #333333;
  149. }
  150. .worker-box1 .worker-box-desc{
  151. width: 100%;
  152. height: auto;
  153. font-size: 28rpx;
  154. color: #808080;
  155. }
  156. </style>