123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <template>
- <el-dialog
- v-loading="loading"
- :title="title"
- :center="true"
- align="left"
- top="5vh"
- width="1040px"
- :close-on-click-modal="false"
- :visible.sync="showModelThis"
- element-loading-text="拼命加载中"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- @close="showModelThis = false"
- append-to-body
- >
- <el-card style="margin: -20px 0 0 0">
- <el-row :gutter="10">
- <el-col :span="24">
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- status-icon
- :size="'small'"
- :rules="rulesThis"
- label-width="80px"
- class="demo-ruleForm"
- >
- <el-form-item label="规格类型" prop="specid">
- <search-spec
- :value="ruleForm.specid"
- :disabled="sitem.isMust"
- :size="'mini'"
- :isDetail="false"
- :placeholder="'规格类型'"
- @searchChange="specidsearchChange"
- />
- </el-form-item>
- <el-form-item label="规格值" prop="spec_value_id">
- <div v-if="specVlist.length > 0">
- <el-select
- v-model="ruleForm.spec_value_id"
- placeholder="请选择规格值"
- @change="spec_value_id_change"
- style="width: 100%"
- filterable
- >
- <el-option
- v-for="item in specVlist"
- :key="item.id + item.spec_value"
- :label="item.spec_value"
- :value="item.id"
- >{{ item.spec_value }}</el-option
- >
- </el-select>
- </div>
- <div class="no-data" v-else>暂无规格值,请添加!</div>
- </el-form-item>
- </el-form>
- </el-col>
- <el-col :span="24" style="text-align: right">
- <el-input
- style="width: 209px"
- v-model="sinput"
- class="fl"
- :disabled="id == 'edit'"
- :size="'small'"
- placeholder="规格值名称,如红色"
- maxlength="20"
- />
- <el-button
- style="margin: 0 0 0 10px"
- icon="el-icon-plus"
- :size="'small'"
- @click="add_spec"
- class="fl"
- >新增规格值</el-button
- >
- <el-button
- v-if="id !== 'edit'"
- :size="'small'"
- type="primary"
- @click="submitForm"
- >保 存
- </el-button>
- <el-button @click="showModelThis = false" :size="'small'">{{
- id == "edit" ? "关 闭" : "取 消"
- }}</el-button>
- </el-col>
- </el-row>
- </el-card>
- </el-dialog>
- </template>
- <script>
- import asyncRequest from "@/apis/service/goodStore/goodsCost";
- import resToken from "@/mixins/resToken";
- export default {
- name: "brand",
- props: ["showModel", "index", "sitem"],
- mixins: [resToken],
- data() {
- return {
- loading: false,
- title: "商品规格",
- sinput: "",
- showModelThis: this.showModel,
- specVlist: [],
- ruleForm: {},
- rulesThis: this.rules,
- rules: {
- specid: [
- {
- required: true,
- message: "规格类型不能为空",
- trigger: "change",
- },
- ],
- spec_value_id: [{ required: true, message: "请选择规格值", trigger: "change" }],
- },
- };
- },
- watch: {
- showModel: function (val) {
- this.showModelThis = val;
- if (val) {
- this.initForm();
- }
- },
- showModelThis(val) {
- if (!val) {
- this.$emit("cancel");
- }
- },
- },
- methods: {
- async initForm() {
- this.loading = true;
- this.resetFormData();
- this.rulesThis = this.rules;
- if (this.index + "" === "-1") {
- this.title = "添加商品规格值";
- } else {
- this.title = "修改商品规格值";
- }
- await this.resetForm();
- this.loading = false;
- },
- async resetForm() {
- // 重置
- await this.$nextTick(async () => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- if (this.index + "" !== "-1") {
- this.specVlist = [];
- const { specid, spec_name, spec_value_id, spec_value_name } = this.sitem;
- console.log(this.sitem);
- this.ruleForm = {
- index: this.index,
- specid: specid || "",
- spec_name: spec_name || "",
- spec_value_id: spec_value_id || "",
- spec_value_name: spec_value_name || "",
- };
- await this.getlist();
- console.log(this.ruleForm);
- }
- }
- });
- },
- resetFormData() {
- this.specVlist = [];
- this.ruleForm = {
- index: "-1",
- specid: "",
- spec_name: "",
- spec_value_id: "",
- spec_value_name: "",
- };
- },
- async add_spec() {
- const { specid } = this.ruleForm;
- if (specid) {
- if (this.sinput) {
- const { code, data, message } = await asyncRequest.valueadd({
- spec_id: specid,
- spec_value: this.sinput,
- });
- if (code === 0) {
- await this.getlist();
- } else if (code >= 100 && code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(message);
- }
- } else {
- this.$message.warning("请输入规格值!");
- }
- } else {
- this.$message.warning("请选择规格类型!");
- }
- },
- async specidsearchChange(e) {
- const { id, spec_name } = e;
- this.ruleForm.specid = id || "";
- this.ruleForm.spec_name = spec_name || "";
- this.$refs.ruleForm.validateField("specid");
- await this.getlist();
- },
- spec_value_id_change(e) {
- if (e) {
- const { id, spec_value } = this.specVlist.find((i) => i.id === e);
- this.ruleForm.spec_value_id = id || "";
- this.ruleForm.spec_value_name = spec_value || "";
- } else {
- this.ruleForm.spec_value_id = "";
- this.ruleForm.spec_value_name = "";
- }
- this.$refs.ruleForm.validateField("spec_value_id");
- },
- async getlist() {
- const { specid } = this.ruleForm;
- if (specid) {
- const { code, data, message } = await asyncRequest.valueall({
- spec_id: specid,
- });
- if (code === 0) {
- this.specVlist = data;
- } else if (code >= 100 && code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(message);
- }
- } else {
- this.specVlist = [];
- }
- },
- async submitForm() {
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- this.showModelThis = false;
- console.log(this.ruleForm);
- this.$emit("refresh", this.ruleForm);
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .goodsCostAdd {
- .no-data {
- text-align: center;
- line-height: 32px;
- color: #8492a6;
- // border: 1px solid #ccc;
- border-radius: 6px;
- }
- }
- </style>
|