food/src/components/SelectionShopId.vue
air f7a52217a0 【类 型】:feat
【原  因】:根据学校要求 如站点改为地块管理 商铺改为单位
【过  程】:
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2025-06-25 12:16:44 +08:00

79 lines
1.9 KiB
Vue

<template>
<el-select v-model="form.shop_id" :filterable="isMobile" :placeholder="allSel === true ? '所有单位' : '请选择,也可输入搜索'"
@input="updateShopId">
<el-option v-if="allSel === true && shopList.length > 1" label="所有单位" value="">
<el-avatar class="vm f-s-12" shape="square" :size="25"> all </el-avatar>
<span class="rspan">所有单位</span>
</el-option>
<el-option v-for="item in shopList" :key="item.id" :label="item.name" :value="item.shop_id">
<el-avatar v-if="item.logo != ''" class="vm" shape="square" :size="25" :src="item.logo[0]">
</el-avatar>
<el-avatar v-else :size="25" class="vm" icon="iconfont icon-tuxiang"></el-avatar>
<span class="rspan">{{ item.name }}</span>
</el-option>
</el-select>
</template>
<script>
export default {
name: 'SelectionShopId',
props: {
value: String, // 接收父级的值作为 prop
allSel: { // 是否显示 所有单位选项
type: Boolean,
default: false
}
},
data () {
return {
form: {
shop_id: this.$store.state.user.shop_id
}
}
},
computed: {
// 获取单位列表
shopList () {
return this.$store.state.shopList
},
/**
* @description: 终端平台是否是pc
*/
isMobile () {
return this.$store.state.app.isMobile
}
},
watch: {
shopList (val) {
this.form.shop_id = this.$store.state.user.shop_id
this.updateShopId()
}
},
created () {
if (this.shopList.length > 0) {
this.form.shop_id = this.$store.state.user.shop_id
this.updateShopId()
}
},
methods: {
updateShopId () {
this.$emit('input', this.form.shop_id) // 发送 input 事件给父级
}
}
}
</script>
<style lang="scss" scoped>
.centered-avatar {
display: flex;
align-items: center;
justify-content: center;
}
.rspan {
float: right;
color: #8492a6;
font-size: 13px
}
</style>