list.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view>
  3. <scroll-view :scroll-y="true">
  4. <view class="cu-bar bg-white solid-bottom">
  5. <view class="action">
  6. <text class="cuIcon-title text-orange "></text> 车间列表
  7. </view>
  8. <view class="action">
  9. <button class="cu-btn bg-blue shadow" @click="addClick">新增</button>
  10. </view>
  11. </view>
  12. <view class="cu-list menu card-menu margin-top">
  13. <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''" @touchstart="ListTouchStart"
  14. @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index"
  15. style="margin-top: 10rpx;" v-for="(item,index) in workshopList" :key="index">
  16. <view class="content" @click="editWorkshop(item)">
  17. <view class="cu-form-group">
  18. <view class="title" style="min-width: calc(6em + 15px);">制衣生产车间</view>
  19. <text class="text-grey" style="flex: 1;">{{item.zyProductWorkshop}}</text>
  20. </view>
  21. <view class="cu-form-group">
  22. <view class="title" style="min-width: calc(6em + 15px);" >状态</view>
  23. <text v-if="item.status" class="text-grey" style="flex: 1;">正常</text>
  24. <text v-else="item.status" class="text-grey" style="flex: 1;">禁用</text>
  25. </view>
  26. </view>
  27. <view class="move">
  28. <view class="bg-grey" @click="editWorkshop(item)">修改</view>
  29. <view class="bg-red" @click="deleteWorkshop(item)">删除</view>
  30. </view>
  31. </view>
  32. </view>
  33. <u-toast ref="uToast" />
  34. </scroll-view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. list,
  40. deleteWorkshop
  41. } from '@/api/biz/workshop.js'
  42. export default {
  43. data() {
  44. return {
  45. workshopList: [],
  46. modalName: null,
  47. }
  48. },
  49. methods: {
  50. addClick() {
  51. uni.navigateTo({
  52. url: '/pages/workshop/add'
  53. })
  54. },
  55. loadData() {
  56. list().then(res => {
  57. if (res.success) {
  58. this.workshopList = res.data
  59. } else {}
  60. })
  61. },
  62. editWorkshop(item) {
  63. uni.navigateTo({
  64. url: '/pages/workshop/edit?workshopInfo=' + encodeURIComponent(JSON.stringify(item))
  65. })
  66. },
  67. // ListTouch触摸开始
  68. ListTouchStart(e) {
  69. this.listTouchStart = e.touches[0].pageX
  70. },
  71. // ListTouch计算方向
  72. ListTouchMove(e) {
  73. this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
  74. },
  75. // ListTouch计算滚动
  76. ListTouchEnd(e) {
  77. if (this.listTouchDirection == 'left') {
  78. this.modalName = e.currentTarget.dataset.target
  79. } else {
  80. this.modalName = null
  81. }
  82. this.listTouchDirection = null
  83. },
  84. deleteWorkshop(item) {
  85. const arr = []
  86. arr.push(item)
  87. deleteWorkshop(arr).then(res => {
  88. if (res.success) {
  89. this.$refs.uToast.show({
  90. type: 'success',
  91. message: "删除成功",
  92. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  93. })
  94. this.removeWorkshopInfo(item)
  95. }else{
  96. this.$refs.uToast.show({
  97. type: 'error',
  98. message: res.message,
  99. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  100. })
  101. }
  102. })
  103. },
  104. removeWorkshopInfo(item) {
  105. const index = this.workshopList.findIndex(ele => {
  106. return ele.id == item.id
  107. })
  108. this.workshopList.splice(index, 1)
  109. }
  110. },
  111. onLoad() {
  112. this.loadData()
  113. uni.$on('loadData', () => {
  114. this.loadData();
  115. })
  116. }
  117. }
  118. </script>
  119. <style>
  120. .cu-form-group {
  121. min-height: 0;
  122. border: none;
  123. }
  124. </style>