index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div>
  3. <el-button type="primary" size="small" class="inline-16" @click="allProduct" v-if="type=='upload'">一 键 选 择</el-button>
  4. <el-button type="primary" size="small" class="inline-16" @click="allProduct" v-else>一 键 删 除</el-button>
  5. <el-dialog
  6. title=""
  7. :visible.sync="progressVisible"
  8. :show-close="false"
  9. append-to-body
  10. width="500px">
  11. <el-progress v-if="totalPage" :percentage="Math.floor(progress / totalPage * 100)"></el-progress>
  12. </el-dialog>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: '',
  18. data() {
  19. return {
  20. totalPage:0,
  21. progress:0,
  22. progressVisible:false,
  23. deleteIds:[]
  24. };
  25. },
  26. props: {
  27. dataSize: {
  28. type:[Number,String],
  29. default:() => 200
  30. },
  31. total: {
  32. type:[Number,String],
  33. default:() => 0
  34. },
  35. type: {
  36. type:String,
  37. default:() => 'upload'
  38. },
  39. idName: {
  40. type: [Number,String]
  41. }
  42. },
  43. computed:{
  44. },
  45. watch:{
  46. },
  47. methods: {
  48. /* 一键选择所有商品 */
  49. allProduct () {
  50. if (this.total > this.dataSize) {
  51. this.$confirm(`总共有${this.total}个商品,提交时间较长,是否继续`,'提示',{
  52. confirmButtonText:'确定',
  53. cancelButtonText:'取消',
  54. type:'warning'
  55. }).then(async () => {
  56. this.progressVisible = true
  57. this.type == 'upload' ? this.totalPage = Math.ceil(this.total / this.dataSize) * 2 : this.totalPage = Math.ceil(this.total / this.dataSize)
  58. let totalPage = Math.ceil(this.total / this.dataSize)
  59. for (let index = 1; index <= totalPage; index++) {
  60. this.pullData(index)
  61. }
  62. })
  63. } else {
  64. this.$confirm(`总共有${this.total}个商品,是否继续`,'提示',{
  65. confirmButtonText:'确定',
  66. cancelButtonText:'取消',
  67. type:'warning'
  68. }).then(async () => {
  69. if (!this.total) return
  70. let pullApi = {}
  71. /**
  72. * 暴露出去操作 修改拉取请求
  73. * @param pullApi - 拉取数据的请求接口
  74. */
  75. this.$emit('handlePullApi',pullApi)
  76. pullApi.content.pageNumber = 1
  77. pullApi.content.pageSize = this.dataSize
  78. const res = await this.$api.requested(pullApi)
  79. if (this.type == 'upload') {
  80. let uploadApi = {}
  81. /**
  82. * 暴露出去操作 修改上传请求
  83. * @param1 uploadApi - 上传接口
  84. * @param2 res.data - 拉取的上传数据
  85. */
  86. this.$emit('handleUploadApi',uploadApi,res.data)
  87. const res2 = await this.$api.requested(uploadApi)
  88. this.tool.showMessage(res2,() => {
  89. this.$emit('onSuccess',res2.data)
  90. })
  91. } else {
  92. this.deleteIds.push(...res.data.map(item => item[this.idName]))
  93. this.deleteOrderProduct(this.deleteIds)
  94. }
  95. })
  96. }
  97. },
  98. /* 拉取数据 */
  99. async pullData (page) {
  100. let pullApi = {}
  101. /**
  102. * 暴露出去操作 修改拉取请求
  103. * @param pullApi - 拉取数据的请求接口
  104. */
  105. this.$emit('handlePullApi',pullApi)
  106. pullApi.content.pageNumber = page
  107. pullApi.content.pageSize = this.dataSize
  108. const res = await this.$api.requested(pullApi)
  109. this.progress++
  110. if (this.type == 'upload') {
  111. this.uploadData(res.data)
  112. if (this.progress >= this.totalPage) {
  113. this.$emit('onSuccess')
  114. this.progressVisible = false
  115. this.progress = 0
  116. }
  117. } else {
  118. this.deleteIds.push(...res.data.map(item => item[this.idName]))
  119. if (this.progress >= this.totalPage) {
  120. this.deleteOrderProduct(this.deleteIds)
  121. this.progressVisible = false
  122. }
  123. }
  124. },
  125. /* 添加数据 */
  126. async uploadData (data) {
  127. let uploadApi = {}
  128. /**
  129. * 暴露出去操作 修改上传请求
  130. * @param1 uploadApi - 上传接口
  131. * @param2 res.data - 拉取的上传数据
  132. */
  133. this.$emit('handleUploadApi',uploadApi,data)
  134. const res = await this.$api.requested(uploadApi)
  135. this.progress++
  136. if (this.progress >= this.totalPage) {
  137. this.$emit('onSuccess')
  138. this.progressVisible = false
  139. this.progress = 0
  140. }
  141. },
  142. /* 删除数据 */
  143. async deleteOrderProduct (row) {
  144. let delApi = {}
  145. this.$emit('handleDelApi',delApi,row)
  146. const res = await this.$api.requested(delApi)
  147. this.tool.showMessage(res,()=>{
  148. this.$emit('onSuccess')
  149. this.deleteIds = []
  150. })
  151. },
  152. },
  153. };
  154. </script>
  155. <style scoped>
  156. </style>