yangfeng
2023-08-26 7da8d51d212f96b2d419d4f22617827ea4df9e3d
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
<template>
  <div class="rightContent">
    <div class="top">
      <div class="supplier-search">
        <SearchCommonView
          ref="searchCommonView"
          :search-options="searchOptions"
          @searchClick="searchClick"
          @resetClick="resetClick"
        />
        <div class="add-view">
          <el-button type="primary" size="mini" @click="addBtnClick">新建</el-button>
        </div>
      </div>
      <template>
        <TableCommonView ref="tableListRef" :table-list="tableList" @selCommonClick="selCommonClick">
          <template slot="tableButton">
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
                <el-button @click="delClick(scope.row.id)" type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </template>
        </TableCommonView>
        <div class="btn-pager">
          <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
        </div>
      </template>
    </div>
    <!-- 新建/编辑产品 -->
    <AddProduct v-if="editConfig.visible" :add-common-config="editConfig" />
    <!-- 详情 -->
    <DetailProduct v-if="commonDetail.visible" :common-detail="commonDetail" />
  </div>
</template>
 
<script>
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import { getProductList, deleteProduct } from "@/api/productManage/product"
import DetailProduct from "@/views/productManage/product/DetailProduct"
import AddProduct from "@/views/productManage/product/AddProduct"
 
export default {
  name: "PruductManage",
  props: {},
  components: { DetailProduct, AddProduct },
  mixins: [pageMixin],
  computed: {},
  data() {
    return {
      tableList: {},
      searchOptions: [],
      commonDetail: {
        visible: false,
        title: "新建",
        infomation: {}
      },
      editConfig: {
        visible: false,
        title: "新建",
        infomation: {}
      }
    }
  },
  created() {
    this.setTable()
    this.getData()
  },
  methods: {
    setTable() {
      this.tableList = {
        tableInfomation: [],
        selectIndex: true,
        tableColumn: [
          { label: "产品编码", prop: "number", min: 190, isCommonClick: true },
          { label: "产品名称", prop: "name", min: 130 },
          { label: "供应商", prop: "id", min: 130 },
          { label: "产品类别", prop: "productType", min: 130 },
          { label: "规格", prop: "sales_resources", min: 130 },
          { label: "型号", prop: "province", min: 130 },
          { label: "单位", prop: "unit", min: 60 },
          { label: "价格", prop: "contact_phone1", min: 130 },
          { label: "最低库存", prop: "desc", min: 80 },
          { label: "最高库存", prop: "member_name", min: 80 }
        ]
      }
      this.searchOptions = []
      for (let i = 0; i < this.tableList.tableColumn.length; i++) {
        const label = this.tableList.tableColumn[i].label
        const value = this.tableList.tableColumn[i].prop
        this.searchOptions.push({ value: value, label: label })
      }
    },
    // 请求数据
    async getData(val, content) {
      await getProductList({
        val,
        content,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      }).then((res) => {
        if (res.data.code === 200) {
          const list = res.data.data.list.map((item) => {
            return {
              ...item
            }
          })
          this.tableList.tableInfomation = list || []
          this.pagerOptions.totalCount = res.data.data.total
        }
      })
    },
    // 搜索
    searchClick(val, content) {
      console.log(val, content)
      this.getData(val, content)
    },
    resetClick() {
      this.getData()
    },
    // 新建
    addBtnClick() {
      this.editConfig.visible = true
      this.editConfig.title = "新建"
    },
    // 编辑
    handleClick(row) {
      console.log(row)
      this.editConfig.visible = true
      this.editConfig.title = "编辑"
      this.editConfig.infomation = { ...row }
    },
    // 删除
    delClick(val) {
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteProduct({ id: val }).then((response) => {
            if (response.code === 200) {
              this.$message.success("删除成功")
              this.getData()
            } else {
              this.$message.warning("删除失败")
            }
          })
        })
        .catch(() => {})
    },
    // 详情
    selCommonClick(row) {
      console.log(row)
      this.commonDetail.visible = true
      this.commonDetail.infomation = { ...row }
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.rightContent {
  .top {
    margin-bottom: 20px;
    .supplier-search {
      display: flex;
      align-items: center;
      .add-view {
        margin-left: auto;
        margin-right: 20px;
      }
    }
    .btn-pager {
      display: flex;
      .page {
        margin-left: auto;
      }
    }
  }
}
</style>