quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <!--
    作者:luoyiming
    时间:2020-06-04
    描述:插件中心-积分商城-商品设置-添加商品
  -->
  <div class="pb50">
    <el-form size="small" ref="form" :model="form" label-width="150px" v-if="!loading">
      <!--商品信息-->
      <Info></Info>
 
      <!--规格-->
      <Spec></Spec>
 
      <!--其它-->
      <Other></Other>
 
       <!--审核-->
    <Audit v-if="old_audit == 0 || old_audit == 20"></Audit>
 
     <!--提交-->
    </el-form>
    <div class="common-button-wrapper">
      <el-button size="small" type="info" @click="cancelFunc">取消</el-button>
      <el-button size="small" type="primary" @click="onSubmit" :loading="loading">提交</el-button>
    </div>
  </div>
</template>
<script>
import AssembleApi from '@/api/assemble';
import Info from './part/Info.vue';
import Spec from './part/Spec.vue';
import Other from './part/Other.vue';
import Audit from './part/Audit.vue';
import { formatModel } from '@/utils/base.js';
export default {
  components: {
    /*产品基本信息*/
    Info,
    /*规格*/
    Spec,
    /*其它*/
    Other,
    /* 审核 */
    Audit
  },
  data() {
    return {
      /*是否正在加载*/
      loading: true,
      old_audit:0,
      /*表单*/
      form: {
        /*商品ID*/
        assemble_product_id: 0,
        /*商品状态*/
        status: 10,
        /* 审核备注*/
        remark:"",
        /*商品名称*/
        product_name: '',
        /*图片*/
        product_image:'',
        /*排序*/
        sort: 100,
        /*规格*/
        product_sku_id: 0,
        /*限购数量*/
        limit_num: 1,
        /*商品表格*/
        tableData: [],
        /*活动名称*/
        active_name:'',
      }
    };
  },
  provide: function() {
    return {
      form: this.form,
      type: 'add'
    };
  },
  created() {
    this.form.assemble_product_id = this.$route.query.assemble_product_id;
    this.form.assemble_activity_id = this.$route.query.assemble_activity_id;
    this.getData();
  },
  methods: {
    /*获取商品*/
    getData() {
      let self = this;
      AssembleApi.getAssembleedit(
        {
          assemble_product_id: self.form.assemble_product_id
        },
        true
      ).then(res => {
        self.form.product_name=res.data.detail.product.product_name;
        self.form.product_image=res.data.detail.product.image[0].file_path;
        self.form.product_id=res.data.detail.product.product_id;
        self.form.limit_num=res.data.detail.limit_num;
        self.form.assemble_num=res.data.detail.assemble_num;
        self.form.stock=res.data.detail.stock;
        self.form.active_name = res.data.detail.active.title;
        self.old_audit=res.data.detail.status;
        res.data.detail.assembleSku.forEach(item=>{
          item.product_name= self.form.product_name;
          item.spec_name=item.product_attr;
          item.spec_type=res.data.detail.product.spec_type;
        });
        self.form.tableData=res.data.detail.assembleSku;
        self.loading = false;
      });
    },
 
    /*提交表单*/
    onSubmit() {
      let self = this;
      self.$refs.form.validate(valid => {
        if (valid) {
          let params = {
            product: {}
          };
          params.product_id = self.form.product_id;
          params.status = self.form.status;
          params.remark = self.form.remark;
          params.sort = self.form.sort;
          params.limit_num = self.form.limit_num;
          params.assemble_product_id=self.form.assemble_product_id;
          params.product_id=self.form.product_id;
          params.product.spec_list = self.tableFormet(self.form.tableData);
          self.loading = true;
          AssembleApi.postAssembleedit(params, true)
            .then(data => {
              self.loading = false;
              self.$message({
                message: '审核成功',
                type: 'success'
              });
              self.cancelFunc();
            })
            .catch(error => {
              self.loading = false;
            });
        }
      });
    },
 
    /*表格数据格式化*/
    tableFormet(list) {
      list.forEach(item=>{
        item.product_attr=item.spec_name;
      });
      return list;
    },
 
    /*取消*/
    cancelFunc() {
      this.$router.back(-1);
    }
  }
};
</script>
<style>
.edit_container {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
 
.ql-editor {
  height: 400px;
}
</style>