hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
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
<template>
  <div>
    <v-header
      title="便民服务分类"
      search
      :bar="bar"
      @on-search="onSearch"
    ></v-header>
    <div class="but">
      <el-button @click="add()" size="small" type="primary">新增</el-button>
    </div>
    <div>
      <v-tool-table :trs="trs" :tds="tds">
        <template v-slot:btn="{ scope }">
          <el-button type="text" @click="edit(scope)">编辑</el-button>
          <el-button type="text" @click="clear(scope.id)">删除</el-button>
        </template>
      </v-tool-table>
    </div>
    <v-tool-page :item="paged" @on-page="onPage"></v-tool-page>
    <!---->
    <el-dialog
      :title="title"
      :modal="false"
      destroy-on-close
      :close-on-click-modal="false"
      :visible.sync="centerDialogVisible"
      width="600px"
      center
    >
      <div class="dialog-box">
        <el-form ref="form" label-width="100px">
          <el-form-item label="服务名称">
            <el-input v-model="os.serviceName" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="价格">
            <el-input v-model="os.servicePrice" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="分类">
            <el-select v-model="os.categoryId" placeholder="请选择">
              <el-option
                v-for="item in options"
                :label="item.name"
                :key="'a-' + item.id"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="服务描述">
            <el-input v-model="os.serviceDesc" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="所属商家">
            <el-select v-model="os.businessId" placeholder="请选择">
              <el-option
                v-for="item in options1"
                :label="item.name"
                :key="'b-' + item.id"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input
              v-model="os.remark"
              type="textarea"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sub()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: [],
  components: {},
  data() {
    return {
      Authorization: "",
      title: "新增",
      editType: 1, //1新增 2 编辑
      centerDialogVisible: false,
      bar: [{ title: "服务名称", name: "serviceName", value: "" }],
      ba: {},
      os: {
        serviceName: "",
        servicePrice: "",
        categoryId: "",
        serviceDesc: "",
        businessId: "",
        remark: ""
      },
      trs: [
        { text: "服务名称", val: "serviceName" },
        { text: "服务价格(元)", val: "servicePrice", width: "" },
        { text: "服务分类", val: "categoryName" },
        { text: "服务描述", val: "serviceDesc" },
        { text: "商家名称", val: "businessName" },
        { text: "创建时间", val: "createAt" },
        { text: "操作", val: "btn" }
      ],
      options: [], //分类
      options1: [], //商家
      tds: [],
      paged: { page: 0, total: 10, r: 0, limit: 10 }
    };
  },
  created() {
    this.init();
    this.categoryAll();
    this.businessPage();
  },
  mounted() {
    this.Authorization = "Bearer " + demo.$session.get("token") || "";
  },
  methods: {
    clear(id) {
      //删除
      let t = this;
      t.$js.model("删除便民服务", "是否删除便民服务", res => {
        if (res) {
          t.$api.del("convenient/serve/delete?id=" + id, {}, e => {
            demo.toast("删除成功");
            t.init();
          });
        }
      });
    },
    add() {
      //新增弹出层
 
      this.editType = 1;
      for (let i in this.os) {
        this.os[i] = "";
      }
      this.centerDialogVisible = true;
    },
    edit(scope) {
      //编辑
      console.log(scope);
      this.editType = 2;
      this.os.id = scope.id;
      this.os.serviceName = scope.serviceName;
      this.os.servicePrice = scope.servicePrice;
      this.os.categoryId = scope.categoryId;
      this.os.serviceDesc = scope.serviceDesc;
      this.os.businessId = scope.businessId;
      this.os.remark = scope.remark;
 
      this.centerDialogVisible = true;
    },
    sub() {
      //新增
      if (this.editType == 1) {
        //新增
        this.$api.post("convenient/serve/add", this.os, e => {
          this.init();
          this.centerDialogVisible = false;
        });
      } else {
        //编辑
        this.$api.put("convenient/serve/put", this.os, e => {
          this.init();
          this.centerDialogVisible = false;
        });
      }
    },
    businessPage() {
      // 分页查询便民分类
      // this.$api.post('convenient/category/pagee',{},e=>{
      //   console.log(e)
      //   this.options1 = e.records
      // })
    },
    categoryAll() {
      // 查询便民服务所有分类,下拉框
      this.$api.post("convenient/category/all", "", e => {
        this.options = e;
      });
    },
    init() {
      Object.assign(this.paged, this.ba);
      this.$api.post("convenient/category/page", this.paged, e => {
        console.log(e);
        this.tds = e.records;
        this.paged.total = e.total;
      });
    },
    onSearch(e) {
      // console.log(e)
      this.ba = e;
      this.init();
    },
    onPage(v) {
      //分页
      if (v.page === this.paged.page && v.page && !v.reset) {
        return 0;
      }
      this.paged.page = v.page;
      this.paged.limit = v.limit;
      this.init();
    },
    success() {},
    error() {}
  },
  watch: {},
  computed: {}
};
</script>
<style scoped>
.but {
  padding-bottom: 20px;
  display: flex;
}
.upload-box {
  margin: 0 16px;
}
</style>