splitModal.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <vxe-modal v-model="value" id="splitModel" title="拆分订单" width="70%" height="80%" min-width="460" min-height="320" show-zoom resize transfer :show-footer="!hideBtn" v-loading="load">
  3. <by-table :propConfig="config" ref="table" id="split-table">
  4. <template v-slot:num="{row}">
  5. <vxe-input v-model="row.num" v-if="row.splitNum > 0" placeholder="请输入" type="integer" @input="onChangeRow(row)"></vxe-input>
  6. </template>
  7. </by-table>
  8. <template #footer>
  9. <div class="btn">
  10. <el-button plain size="small" @click="value = false">取消</el-button>
  11. <el-button type="primary" size="small" @click="btn">确定</el-button>
  12. </div>
  13. </template>
  14. </vxe-modal>
  15. </template>
  16. <script lang="ts">
  17. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  18. import { splitQtyQuery,split } from '@/api/omsOrder'
  19. @Component({components:{}})
  20. export default class SplitModel extends Vue {
  21. value=false;
  22. load=false;
  23. billData:any=null;
  24. hideBtn=false;
  25. data:Array<any>=[]
  26. config:any={
  27. attr:{
  28. size:'small',
  29. seq:true
  30. },
  31. columns:[{
  32. title:'名称',
  33. field:'name',
  34. width:300
  35. },{
  36. title:'价格',
  37. field:'price',
  38. width:130
  39. },{
  40. title:'商品数量',
  41. field:'qty',
  42. width:130
  43. },{
  44. title:'可拆分数量',
  45. field:'splitNum',
  46. width:130
  47. },{
  48. title:'拆分数量',
  49. field:'num',
  50. slot:true,
  51. // component:'by-input',
  52. // compConfig:{
  53. // attr:{
  54. // size:'mini',
  55. // type:'integer'
  56. // }
  57. // }
  58. }]
  59. }
  60. setShow(v:boolean){
  61. this.hideBtn = false;
  62. this.value = v;
  63. }
  64. setData(data:any){
  65. if(data){
  66. this.billData = data;
  67. this.data = [];
  68. if(data.items) {
  69. for(const item of data.items){
  70. item.splitNum = item.qty - item.splitQty
  71. this.data.push(item)
  72. }
  73. }
  74. // this.getSplitNum(data);
  75. }else{
  76. this.billData = null;
  77. this.data = [];
  78. }
  79. this.$nextTick(()=>{
  80. let height = (document.getElementById('split-table') as any).parentNode.offsetHeight;
  81. this.config.attr.height=height - 36;
  82. if(this.$refs.table){
  83. (this.$refs.table as any).setConfig(this.config);
  84. (this.$refs.table as any).setValue(this.data);
  85. }
  86. })
  87. }
  88. //获取可拆分数量
  89. getSplitNum(v:any){
  90. if(!v) return;
  91. let data = v.items?v.items:[];
  92. if(data.length == 0) return;
  93. this.load = true;
  94. splitQtyQuery({id:v.id}).then((res:any) => {
  95. this.load = false;
  96. if(res.data){
  97. let j = 0;
  98. for(const item of data){
  99. let n = Number(res.data[item.id]);
  100. if(n){
  101. item.splitNum = item.qty - n;
  102. }else{
  103. item.splitNum = item.qty;
  104. }
  105. this.data.push(item)
  106. if(item.splitNum == 0){
  107. j++
  108. }
  109. }
  110. if(j == this.data.length){
  111. this.hideBtn = true
  112. }
  113. (this.$refs.table as any).setValue(this.data);
  114. }
  115. }).catch((err:any) => {
  116. this.load = false
  117. })
  118. }
  119. btn(){
  120. let data = (this.$refs.table as any).getValue();
  121. let info:Array<any>=[];
  122. if(data.length == 0){
  123. this.$message('未有数据不能执行此操作!')
  124. return
  125. }
  126. for(const item of data){
  127. if(Number(item.num) > 0){
  128. info.push({
  129. qty:Number(item.num),
  130. orderItemId:item.id
  131. })
  132. }
  133. }
  134. if(info.length == 0){
  135. this.$message('请设置拆分数量!')
  136. return
  137. }
  138. this.load = true;
  139. split({
  140. id:this.billData.id,
  141. splitInfos:info
  142. }).then((res:any) => {
  143. this.load = false;
  144. this.$message({
  145. message:'拆分成功!',
  146. type:'success'
  147. })
  148. this.$emit('handleSuccess');
  149. this.value = false;
  150. }).catch(() => {
  151. this.load = false
  152. })
  153. }
  154. onChangeRow(row:any){
  155. if(Number(row.splitNum) < Number(row.num)){
  156. this.$message('拆分数量不能大于可拆分数量!');
  157. row.num = 0;
  158. this.$forceUpdate()
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. </style>