chooseWarehouse.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <u-picker
  3. :show="showPick"
  4. :closeOnClickOverlay="true"
  5. ref="uPicker"
  6. title="选择仓库仓位"
  7. :columns="pickItem"
  8. :defaultIndex="defaultIndex"
  9. keyName="name"
  10. @confirm="confirmWarehouse"
  11. @close="showPick=false"
  12. @cancel="showPick=false"
  13. @change="changePick"></u-picker>
  14. </template>
  15. <script>
  16. export default{
  17. props:{
  18. value: {
  19. type: Array,
  20. default: function(){
  21. return [null,null]
  22. }
  23. },
  24. openPick: {
  25. type: Boolean,
  26. default: false
  27. }
  28. },
  29. data(){
  30. return {
  31. showPick: this.openPick,
  32. pickItem: [],
  33. defaultIndex: [],
  34. defaultName: []
  35. }
  36. },
  37. watch: {
  38. openPick (a,b){
  39. console.log(a)
  40. this.showPick = a
  41. if(a){
  42. // 仓库列表
  43. this.getWarehousePick()
  44. if(this.value&&this.value[0]&&this.value[1]){
  45. const list = this.$store.state.vuex_warehouseList
  46. const w = list.findIndex(item => item.warehouseSn == this.value[0])
  47. const sc = list[w].warehouseLocationList
  48. if(w>=0 && sc){
  49. const s = sc.findIndex(item => item.warehouseLocationSn == this.value[1])
  50. this.defaultIndex = [w||0,s||0]
  51. this.defaultName = [list[w||0].name,sc[s||0].name]
  52. }
  53. }else{
  54. this.defaultIndex = [0,0]
  55. }
  56. }
  57. },
  58. showPick(a,b){
  59. if(!a){
  60. this.$emit('close')
  61. }
  62. }
  63. },
  64. methods:{
  65. getDefName(){
  66. return this.defaultName
  67. },
  68. getWarehousePick(){
  69. const col1 = []
  70. const col2 = []
  71. const list = this.$store.state.vuex_warehouseList
  72. const s = this.value && this.value[0] ? list.findIndex(item => item.warehouseSn == this.value[0]) : 0
  73. list.map((item,index) => {
  74. col1.push(item)
  75. if(index == s && item.warehouseLocationList){
  76. item.warehouseLocationList.map(k => {
  77. col2.push(k)
  78. })
  79. }
  80. })
  81. this.pickItem = [col1,col2]
  82. },
  83. // 选择仓库
  84. changePick(e){
  85. const {
  86. columnIndex,
  87. index,
  88. // 微信小程序无法将picker实例传出来,只能通过ref操作
  89. picker = this.$refs.uPicker
  90. } = e
  91. console.log(columnIndex,index)
  92. if (columnIndex === 0) {
  93. const currow = this.pickItem[0][index]
  94. const col2 = []
  95. currow&&currow.warehouseLocationList.map(item => {
  96. col2.push(item)
  97. })
  98. picker.setColumnValues(1, col2)
  99. }
  100. },
  101. // 确定选择仓库
  102. confirmWarehouse(e){
  103. console.log(e.indexs)
  104. const indexs = e.indexs
  105. const currow = this.pickItem[0][indexs[0]]
  106. if(currow){
  107. const warehouseSn = currow.warehouseSn
  108. const curcol = currow.warehouseLocationList[indexs[1]]
  109. if(curcol){
  110. const warehouseLocationSn = curcol.warehouseLocationSn
  111. this.$emit("change", [warehouseSn,warehouseLocationSn])
  112. }
  113. }
  114. },
  115. }
  116. }
  117. </script>
  118. <style>
  119. </style>