123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <template>
- <u-picker
- :show="showPick"
- :closeOnClickOverlay="true"
- ref="uPicker"
- title="选择仓库仓位"
- :columns="pickItem"
- :defaultIndex="defaultIndex"
- keyName="name"
- @confirm="confirmWarehouse"
- @close="showPick=false"
- @cancel="showPick=false"
- @change="changePick"></u-picker>
- </template>
- <script>
- export default{
- props:{
- value: {
- type: Array,
- default: function(){
- return [null,null]
- }
- },
- openPick: {
- type: Boolean,
- default: false
- }
- },
- data(){
- return {
- showPick: this.openPick,
- pickItem: [],
- defaultIndex: [],
- defaultName: []
- }
- },
- watch: {
- openPick (a,b){
- console.log(a)
- this.showPick = a
- if(a){
- // 仓库列表
- this.getWarehousePick()
- if(this.value&&this.value[0]&&this.value[1]){
- const list = this.$store.state.vuex_warehouseList
- const w = list.findIndex(item => item.warehouseSn == this.value[0])
- const sc = list[w].warehouseLocationList
- if(w>=0 && sc){
- const s = sc.findIndex(item => item.warehouseLocationSn == this.value[1])
- this.defaultIndex = [w||0,s||0]
- this.defaultName = [list[w||0].name,sc[s||0].name]
- }
- }else{
- this.defaultIndex = [0,0]
- }
- }
- },
- showPick(a,b){
- if(!a){
- this.$emit('close')
- }
- }
- },
- methods:{
- getDefName(){
- return this.defaultName
- },
- getWarehousePick(){
- const col1 = []
- const col2 = []
- const list = this.$store.state.vuex_warehouseList
- const s = this.value && this.value[0] ? list.findIndex(item => item.warehouseSn == this.value[0]) : 0
- list.map((item,index) => {
- col1.push(item)
- if(index == s && item.warehouseLocationList){
- item.warehouseLocationList.map(k => {
- col2.push(k)
- })
- }
- })
- this.pickItem = [col1,col2]
- },
- // 选择仓库
- changePick(e){
- const {
- columnIndex,
- index,
- // 微信小程序无法将picker实例传出来,只能通过ref操作
- picker = this.$refs.uPicker
- } = e
- console.log(columnIndex,index)
- if (columnIndex === 0) {
- const currow = this.pickItem[0][index]
- const col2 = []
- currow&&currow.warehouseLocationList.map(item => {
- col2.push(item)
- })
- picker.setColumnValues(1, col2)
- }
- },
- // 确定选择仓库
- confirmWarehouse(e){
- console.log(e.indexs)
- const indexs = e.indexs
- const currow = this.pickItem[0][indexs[0]]
- if(currow){
- const warehouseSn = currow.warehouseSn
- const curcol = currow.warehouseLocationList[indexs[1]]
- if(curcol){
- const warehouseLocationSn = curcol.warehouseLocationSn
- this.$emit("change", [warehouseSn,warehouseLocationSn])
- }
- }
- },
- }
- }
- </script>
- <style>
- </style>
|