石广澎
2023-12-13 db5f18c8d02881bbf8b8b43d45236bc59bd2f958
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
<template>
  <win-md title="规格型号" @close="close" :width="'800px'">
    <!--列表-->
    <my-table-v2 ref="myTable" :filter="{goodsTemplatesId: setting.goodsTemplatesId}" :table="table"/>
    <div slot="footer" align="center" class="dialog-footer">
      <my-button name="取消" site="form" @click="close"/>
    </div>
    <specsAdd v-if="specsSetting.show" :setting="specsSetting" @close="specsSetting.show = false" @search="search"/>
  </win-md>
</template>
 
<script>
import winMd from '@/components/win/win-md'
import myButton from '@/components/myButton/myButton'
import {delSpecs, updSpecsStatus} from "@/api/foudation/material";
import specsAdd from "@/views/foundation/material/specs/specsAdd.vue";
import {mapGetters} from 'vuex'
import MyTableV2 from "@/components/myTable/myTableV2.vue";
import SettingIplatform from "@/utils/settingIplatform";
 
export default {
  name: 'specs',
  components: {MyTableV2, winMd, myButton, specsAdd},
  props: {
    setting: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      specsSetting: {
        title: '',
        id: '',
        show: false,
      },
      // 表格数据
      table: {
        autoLoad: false,
        showIndex: true, // 是否显示序号
        expand: false, // 是否显示详情数据
        dataIndex: 'goodsTemplatesId',
        url: SettingIplatform.apiBaseURL + '/pc/base/goods/models/query/goodsModel', // 请求地址
        // 工具条
        tools: {
          columnsCtrl: {// 列控制按钮
            show: false
          },
          generalExport: {// 通用导出按钮
            show: false
          },
          // 自定义工具条按钮
          custom: [
            {
              name: '新增',
              click: () => {
                this.showAdd(null);
              },
            },
          ]
        },
        // 列信息
        columns: [
          {title: '规格型号', field: 'modelName', align: 'left', minWidth: 120},
          {title: '单位', field: 'unit', align: 'center', width: 100},
          {
            field: 'states',
            title: '状态',
            align: 'center',
            width: 100,
            switch: row => {
              const result = {}
              if (row.states == 1) {
                Object.assign(result, {
                  value: true, // 开
                  label: '是', // 开的描述
                  click: () => { // 点击事件
                    this.updState(row)
                  }
                })
              } else {
                Object.assign(result, {
                  value: false, // 关
                  label: '否', // 关的描述
                  click: () => {
                    this.updState(row)
                  }
                })
              }
              return result
            }
          }
        ],
        // 操作信息
        operation: {
          show: true, // 显示操作列
          width: 100, // 列宽
          attr: [
            {
              title: '删除',
              events: (row) => {
                this.del(row);
              },
            },
          ],
        },
        paging: {
          show: false, // 显示分页
          // 分页信息
          page: {
            small: false,
            pageNum: 1,
            pageSize: 10,
            total: 0
          }
        }
      },
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  mounted() {
    this.$nextTick(() => {
      this.search()
    })
 
  },
  methods: {
    showAdd() {
      this.specsSetting.goodsTemplatesId = this.setting.goodsTemplatesId;//物品ID
      this.specsSetting.show = true;
    },
    updState(row) {
      let vm = this
      let text = row.states == 0 ? "启用" : "禁用";
      vm.$modal.confirm('确认要' + text + '"' + row.modelName + '"规格吗?').then(function () {
        let params = Object.assign({}, row)
        params.states = row.states == 1 ? 0 : 1
        updSpecsStatus(params).then(res => {
          if (res) {
            row.states = row.states === 1 ? 0 : 1
            vm.$modal.msgSuccess(text + "成功");
            vm.search()
          }
        })
      })
    },
    del(row) {
      this.$modal
        .confirm('是否确认删除名称为"' + row.modelName + '"的规格吗?')
        .then(function () {
          delSpecs({id: row.id}).then((res) => {
          });
        })
        .then((res) => {
          this.$message.success('删除成功!');
          this.$refs.myTable.search();
        })
        .catch(() => {
        });
    },
    close() {
      this.$emit('close')
    },
    // 查询table列表
    search() {
      this.$refs.myTable.search()
    },
 
  }
}
</script>