178 行
5.8 KiB
JavaScript
可执行文件
178 行
5.8 KiB
JavaScript
可执行文件
Vue.component('select-goods-customer-unit', {
|
|
template: `<el-select v-model="choose_unit"
|
|
placeholder="选择单位"
|
|
:disabled="isDisabled"
|
|
allow-create
|
|
default-first-option
|
|
size="small"
|
|
ref="unitLabel"
|
|
@change="changeUnit"
|
|
clearable filterable>
|
|
<el-option v-for="item in dataList"
|
|
:key="item.id"
|
|
:label="item.name"
|
|
:value="item.name">
|
|
</el-option>
|
|
</el-select>`,
|
|
props: {
|
|
'unit': {
|
|
type: String,
|
|
default: '',
|
|
},//选择的单位ID
|
|
'userType': {
|
|
type: Number,
|
|
default: 1,
|
|
},//1商户 2门店
|
|
'isDisabled': {
|
|
type: Boolean,
|
|
default: false,
|
|
},//是否禁止修改
|
|
},
|
|
data() {
|
|
return {
|
|
choose_unit: '',//已选中的单位名称
|
|
dataList: [],// 数据
|
|
};
|
|
},
|
|
methods: {
|
|
//切换单位
|
|
changeUnit(val) {
|
|
this.$nextTick(() => {
|
|
if (this.$refs.unitLabel.createdLabel === null) {
|
|
this.$emit('update:unit', val ? val : '');
|
|
} else {
|
|
this.$confirm("确认添加到单位库吗?", "温馨提示", {
|
|
confirmButtonText: '添加',
|
|
cancelButtonText: '取消',
|
|
type: 'info'
|
|
}).then(() => {
|
|
this.sendRequest('Retail/UnitLibrary/' + (this.userType == 1 ? 'addMerchantUnit' : 'addStoreUnit'), {
|
|
data: {
|
|
name: val,
|
|
},
|
|
type: 'post',
|
|
success: (res) => {
|
|
this.$refs.unitLabel.createdLabel = null;
|
|
if (res.status == 1) {
|
|
this.$message.success(res.message);
|
|
let obj = {
|
|
id: res.data.id,
|
|
name: val,
|
|
};
|
|
this.dataList.unshift(obj);
|
|
this.choose_unit = obj.name;
|
|
this.$nextTick(() => {
|
|
this.$emit('update:unit', obj.name);
|
|
})
|
|
} else {
|
|
this.$message.error(res.message);
|
|
}
|
|
}
|
|
})
|
|
}).catch(() => {
|
|
this.$refs.unitLabel.createdLabel = null;
|
|
this.choose_unit = '';
|
|
this.$emit('update:unit', '');
|
|
})
|
|
}
|
|
})
|
|
},
|
|
//获取单位列表
|
|
getUnitList(fn) {
|
|
this.dataList = [];
|
|
$.ajax({
|
|
url: '/index.php/Retail/UnitLibrary/getUnitSelect',
|
|
type: "post",
|
|
data: {
|
|
type: this.userType,
|
|
},
|
|
success: (res) => {
|
|
if (res.status == 1) {
|
|
this.dataList = res.data.list;
|
|
typeof fn == "function" && fn();
|
|
}
|
|
},
|
|
})
|
|
},
|
|
handleUnit() {
|
|
let flag = false;
|
|
for (let i in this.dataList) {
|
|
if (this.dataList[i].name == this.unit) {
|
|
this.choose_unit = this.dataList[i].name;
|
|
flag = true;
|
|
continue;
|
|
}
|
|
}
|
|
if (!flag) {
|
|
this.choose_unit = '';
|
|
}
|
|
},
|
|
},
|
|
created() {
|
|
this.getUnitList(() => {
|
|
if (this.unit) {
|
|
this.handleUnit()
|
|
}
|
|
});
|
|
},
|
|
watch: {
|
|
unit(n, o) {
|
|
if (n != this.choose_unit) this.handleUnit();
|
|
}
|
|
}
|
|
});
|
|
Vue.component('select-goods-weight-unit', {
|
|
template: `<el-select v-model="choose_unit"
|
|
placeholder="选择单位"
|
|
:disabled="isDisabled"
|
|
size="small"
|
|
@change="changeUnit"
|
|
clearable filterable>
|
|
<el-option v-for="item in dataList"
|
|
:value-key="item.name"
|
|
:key="item.name"
|
|
:label="item.name"
|
|
:value="item.name">
|
|
</el-option>
|
|
</el-select>`,
|
|
props: {
|
|
'unit': {
|
|
type: String,
|
|
default: '',
|
|
},//选择的单位ID
|
|
'isDisabled': {
|
|
type: Boolean,
|
|
default: false,
|
|
},//是否禁止修改
|
|
},
|
|
data() {
|
|
return {
|
|
choose_unit: '',//已选中的单位名称
|
|
dataList: [
|
|
{name: 'kg'},
|
|
{name: 'KG'},
|
|
{name: '斤'},
|
|
{name: '公斤'},
|
|
{name: '市斤'},
|
|
{name: '千克'},
|
|
{name: 'g'},
|
|
{name: 'G'},
|
|
{name: '克'},
|
|
],
|
|
}
|
|
},
|
|
methods: {
|
|
//切换单位
|
|
changeUnit(val) {
|
|
this.$emit('update:unit', val);
|
|
},
|
|
},
|
|
created() {
|
|
this.choose_unit = this.unit;
|
|
},
|
|
watch: {
|
|
unit(n) {
|
|
this.choose_unit = n;
|
|
}
|
|
}
|
|
}); |