haoxuan
2023-08-25 641ce71b7b29c32105c82619fa7abfb9b2f38e3b
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<template>
  <div class="add-common">
    <el-dialog
      :title="addCommonConfig.title + '提供的产品'"
      :visible.sync="editConfig.visible"
      :width="dialogWidth"
      :before-close="handleClose"
      :close-on-click-modal="false"
      append-to-body
      custom-class="iframe-dialog"
    >
      <div class="basic-info">
        <!-- 产品信息 -->
        <div class="basic-info-title">产品信息</div>
        <div class="basic-info-view">
          <CommonFormTableView
            :product-table-list="productTableList"
            @inputContent="inputContent"
            @addProductClick="addProductClick"
            @emptyProductClick="emptyProductClick"
            @clearupProduct="clearupProduct"
          />
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="saveClick">保 存</el-button>
        <el-button size="small" @click="editConfig.visible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { getAddContact, getUpdateContact } from "@/api/client/contacts"
import CommonFormTableView from "@/components/makepager/CommonFormTableView"
export default {
  name: "AddNewProduct",
  props: {
    addCommonConfig: {
      type: Object,
      default: () => {
        return {
          visible: false,
          title: "添加",
          infomation: {}
        }
      }
    }
  },
  components: { CommonFormTableView },
  computed: {},
  data() {
    return {
      dialogWidth: "80%",
      editConfig: this.addCommonConfig,
      productTableList: {},
      tableData: [],
      productId: 1,
      isNoProduct: true
    }
  },
  created() {
    // if (this.editConfig.title !== "添加" && this.editConfig.infomation.province_id !== 0) {
    //   this.getCityList(this.editConfig.infomation.province_id, "edit")
    // }
    this.setTableForm()
  },
  methods: {
    handleClose() {
      this.editConfig.visible = false
    },
    // 保存
    saveClick() {
      console.log(this.editConfig.infomation)
      const params = this.saveParams()
      console.log(params)
      if (this.editConfig.title === "添加") {
        getAddContact(params).then((res) => {
          console.log(res)
          this.editConfig.visible = false
          if (res.code === 200) {
            this.$message.success("添加成功")
            this.$parent.getData()
          }
        })
      } else {
        getUpdateContact(params).then((res) => {
          console.log(res)
          this.editConfig.visible = false
          if (res.code === 200) {
            this.$message.success("编辑成功")
            this.$parent.getData()
          }
        })
      }
    },
    saveParams() {
      let data = this.editConfig.infomation
      let params = {
        id: this.editConfig.title === "添加" ? 0 : data.id,
        birthday: data.birthday || "",
        city_id: data.city_id || 0,
        client_id: this.clientId || 0,
        country_id: data.country_id || 0,
        desc: data.desc || "",
        email: data.email || "",
        is_first: data.is_first || false,
        member_id: data.member_id || 0,
        name: data.name || "",
        number: data.number || "",
        phone: data.phone || "",
        position: data.position || "",
        province_id: data.province_id || 0,
        region_id: data.region_id || 0,
        wechat: data.wechat || ""
      }
      return params
    },
    setTableForm() {
      if (this.editConfig.title === "添加" || this.editConfig.infomation.products.length === 0) {
        this.tableData = [
          {
            productId: this.productId,
            id: 0,
            amount: 0,
            desc: "",
            name: "",
            number: "",
            price: 0,
            total: 0
          }
        ]
      } else {
        this.tableData = this.editConfig.infomation.products
        this.tableData.map((item, index) => {
          item.productId = index + 1
        })
      }
      this.productTableList = {
        tableData: this.tableData,
        tableColumn: [
          { label: "产品名称", prop: "name", productName: true, isRequird: true },
          { label: "产品编码", prop: "number" },
          { label: "计量单位", prop: "number" },
          { label: "规格型号", prop: "number" },
          { label: "采购价格", prop: "amount", inputFloat: true, isRequird: true },
          { label: "供货时长", prop: "price", inputNumber: true, isRequird: true },
          { label: "物流时长", prop: "total", inputNumber: true, isRequird: true }
        ]
      }
    },
    // 产品列表输入
    inputContent(val, prop, row) {
      this.productId = row.productId
      this.tableData.map((item) => {
        if (item.productId === row.productId) {
          item[prop] = val
        }
      })
    },
    // 产品新增
    addProductClick() {
      this.productId++
      this.tableData.push({
        productId: this.productId,
        id: 0,
        amount: 0,
        desc: "",
        name: "",
        number: "",
        price: 0,
        total: 0
      })
    },
    //  产品清空
    emptyProductClick() {
      this.productId = 1
      this.tableData = [
        {
          productId: this.productId,
          id: 0,
          amount: 0,
          desc: "",
          name: "",
          number: "",
          price: 0,
          total: 0
        }
      ]
      this.productTableList.tableData = this.tableData
    },
    // 产品清除
    clearupProduct(data) {
      this.tableData = data
      this.productTableList.tableData = this.tableData
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
::v-deep {
  .iframe-dialog .el-dialog__body {
    .basic-info {
      .basic-info-title {
        background-color: #f4f8fe;
        padding-left: 10px;
        font-size: 15px;
        font-weight: bold;
        color: #666;
        height: 42px;
        line-height: 42px;
      }
      .basic-info-view {
        margin-top: 10px;
      }
    }
    .dialog-footer {
      background-color: #f5f5f5;
      height: 55px;
      line-height: 55px;
    }
  }
}
</style>