|
|
@@ -0,0 +1,342 @@
|
|
|
+<template>
|
|
|
+ <div class="app-container">
|
|
|
+ <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
|
|
+ <el-form-item label="一级原因" prop="reasonName">
|
|
|
+ <el-input
|
|
|
+ v-model="queryParams.reasonName"
|
|
|
+ placeholder="请输入一级原因名称"
|
|
|
+ clearable
|
|
|
+ size="small"
|
|
|
+ @keyup.enter.native="handleQuery"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
|
+ <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <el-row :gutter="10" class="mb8">
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ plain
|
|
|
+ icon="el-icon-plus"
|
|
|
+ size="mini"
|
|
|
+ @click="handleAdd"
|
|
|
+ v-hasPermi="['store:refundReason:add']"
|
|
|
+ >新增一级原因</el-button>
|
|
|
+ </el-col>
|
|
|
+ <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-table
|
|
|
+ v-loading="loading"
|
|
|
+ :data="refundReasonList"
|
|
|
+ row-key="id"
|
|
|
+ @expand-change="handleExpandChange"
|
|
|
+ >
|
|
|
+ <el-table-column type="expand">
|
|
|
+ <template slot-scope="props">
|
|
|
+ <el-table
|
|
|
+ :data="props.row.children"
|
|
|
+ style="margin-left: 50px; width: calc(100% - 50px)"
|
|
|
+ v-loading="props.row.loading"
|
|
|
+ >
|
|
|
+ <el-table-column label="序号" type="index" width="80" align="center" />
|
|
|
+ <el-table-column label="二级原因" prop="reasonName" />
|
|
|
+ <el-table-column label="状态" align="center" prop="status" width="100">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-tag v-if="scope.row.status === 1" type="success">正常</el-tag>
|
|
|
+ <el-tag v-else type="danger">禁用</el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" align="center" width="200">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-edit"
|
|
|
+ @click="handleUpdateChild(scope.row, props.row)"
|
|
|
+ v-hasPermi="['store:refundReason:edit']"
|
|
|
+ >修改</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-delete"
|
|
|
+ @click="handleDeleteChild(scope.row, props.row)"
|
|
|
+ v-hasPermi="['store:refundReason:remove']"
|
|
|
+ >删除</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="序号" type="index" width="80" align="center" />
|
|
|
+ <el-table-column label="一级原因" prop="reasonName" />
|
|
|
+ <el-table-column label="二级原因数量" align="center" width="120">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ scope.row.childrenCount || 0 }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="状态" align="center" prop="status" width="100">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-tag v-if="scope.row.status === 1" type="success">正常</el-tag>
|
|
|
+ <el-tag v-else type="danger">禁用</el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="280">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-edit"
|
|
|
+ @click="handleUpdate(scope.row)"
|
|
|
+ v-hasPermi="['store:refundReason:edit']"
|
|
|
+ >编辑</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-plus"
|
|
|
+ @click="handleAddChild(scope.row)"
|
|
|
+ v-hasPermi="['store:refundReason:add']"
|
|
|
+ >新增二级原因</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-delete"
|
|
|
+ @click="handleDelete(scope.row)"
|
|
|
+ v-hasPermi="['store:refundReason:remove']"
|
|
|
+ >删除</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+
|
|
|
+ <pagination
|
|
|
+ v-show="total > 0"
|
|
|
+ :total="total"
|
|
|
+ :page.sync="queryParams.pageNum"
|
|
|
+ :limit.sync="queryParams.pageSize"
|
|
|
+ @pagination="getList"
|
|
|
+ />
|
|
|
+
|
|
|
+ <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
|
|
|
+ <el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
|
|
+ <el-form-item label="原因名称" prop="reasonName">
|
|
|
+ <el-input v-model="form.reasonName" placeholder="请输入原因名称" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="状态" prop="status">
|
|
|
+ <el-select v-model="form.status" placeholder="请选择状态">
|
|
|
+ <el-option label="正常" :value="1" />
|
|
|
+ <el-option label="禁用" :value="0" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="二级原因" v-if="form.typeLevel === 1 && form.id == null">
|
|
|
+ <el-button type="primary" size="mini" @click="addChildReason">添加二级原因</el-button>
|
|
|
+ <div v-for="(item, index) in form.childrenReasons" :key="index" style="margin-top: 10px;">
|
|
|
+ <el-input v-model="item.reasonName" placeholder="请输入二级原因名称" style="width: 400px;" />
|
|
|
+ <el-button type="danger" size="mini" @click="removeChildReason(index)" style="margin-left: 10px;">删除</el-button>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
+ <el-button @click="cancel">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { listRefundReason, getChildrenByParentId, getRefundReason, addRefundReason, updateRefundReason, delRefundReason } from "@/api/hisStore/refundReason";
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: "RefundReason",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ loading: true,
|
|
|
+ showSearch: true,
|
|
|
+ total: 0,
|
|
|
+ refundReasonList: [],
|
|
|
+ title: "",
|
|
|
+ open: false,
|
|
|
+ queryParams: {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ reasonName: null,
|
|
|
+ typeLevel: 1
|
|
|
+ },
|
|
|
+ form: {},
|
|
|
+ rules: {
|
|
|
+ reasonName: [
|
|
|
+ { required: true, message: "原因名称不能为空", trigger: "blur" }
|
|
|
+ ],
|
|
|
+ status: [
|
|
|
+ { required: true, message: "请选择状态", trigger: "change" }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getList();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getList() {
|
|
|
+ this.loading = true;
|
|
|
+ listRefundReason(this.queryParams).then(response => {
|
|
|
+ this.refundReasonList = response.rows.map(item => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ children: [],
|
|
|
+ loading: false
|
|
|
+ };
|
|
|
+ });
|
|
|
+ this.total = response.total;
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handleExpandChange(row, expandedRows) {
|
|
|
+ if (expandedRows.find(item => item.id === row.id)) {
|
|
|
+ row.loading = true;
|
|
|
+ getChildrenByParentId(row.id).then(response => {
|
|
|
+ row.children = response.data;
|
|
|
+ row.childrenCount = response.data.length;
|
|
|
+ row.loading = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cancel() {
|
|
|
+ this.open = false;
|
|
|
+ this.reset();
|
|
|
+ },
|
|
|
+ reset() {
|
|
|
+ this.form = {
|
|
|
+ id: null,
|
|
|
+ parentId: 0,
|
|
|
+ reasonName: null,
|
|
|
+ typeLevel: 1,
|
|
|
+ status: 1,
|
|
|
+ childrenReasons: []
|
|
|
+ };
|
|
|
+ this.resetForm("form");
|
|
|
+ },
|
|
|
+ handleQuery() {
|
|
|
+ this.queryParams.pageNum = 1;
|
|
|
+ this.getList();
|
|
|
+ },
|
|
|
+ resetQuery() {
|
|
|
+ this.resetForm("queryForm");
|
|
|
+ this.handleQuery();
|
|
|
+ },
|
|
|
+ handleAdd() {
|
|
|
+ this.reset();
|
|
|
+ this.form.childrenReasons = [];
|
|
|
+ this.open = true;
|
|
|
+ this.title = "新增一级原因";
|
|
|
+ },
|
|
|
+ handleAddChild(row) {
|
|
|
+ this.reset();
|
|
|
+ this.form.parentId = row.id;
|
|
|
+ this.form.typeLevel = 2;
|
|
|
+ this.open = true;
|
|
|
+ this.title = "新增二级原因";
|
|
|
+ },
|
|
|
+ addChildReason() {
|
|
|
+ this.form.childrenReasons.push({
|
|
|
+ reasonName: '',
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ },
|
|
|
+ removeChildReason(index) {
|
|
|
+ this.form.childrenReasons.splice(index, 1);
|
|
|
+ },
|
|
|
+ handleUpdate(row) {
|
|
|
+ this.reset();
|
|
|
+ getRefundReason(row.id).then(response => {
|
|
|
+ this.form = response.data;
|
|
|
+ this.open = true;
|
|
|
+ this.title = "编辑一级原因";
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handleUpdateChild(row, parent) {
|
|
|
+ this.reset();
|
|
|
+ getRefundReason(row.id).then(response => {
|
|
|
+ this.form = response.data;
|
|
|
+ this.open = true;
|
|
|
+ this.title = "编辑二级原因";
|
|
|
+ });
|
|
|
+ },
|
|
|
+ submitForm() {
|
|
|
+ this.$refs["form"].validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ if (this.form.id != null) {
|
|
|
+ updateRefundReason(this.form).then(response => {
|
|
|
+ this.msgSuccess("修改成功");
|
|
|
+ this.open = false;
|
|
|
+ this.getList();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ addRefundReason(this.form).then(response => {
|
|
|
+ if (this.form.typeLevel === 1 && this.form.childrenReasons && this.form.childrenReasons.length > 0) {
|
|
|
+ const parentId = response.data;
|
|
|
+ const promises = this.form.childrenReasons
|
|
|
+ .filter(item => item.reasonName && item.reasonName.trim() !== '')
|
|
|
+ .map(item => {
|
|
|
+ return addRefundReason({
|
|
|
+ parentId: parentId,
|
|
|
+ reasonName: item.reasonName,
|
|
|
+ typeLevel: 2,
|
|
|
+ status: item.status
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (promises.length > 0) {
|
|
|
+ Promise.all(promises).then(() => {
|
|
|
+ this.msgSuccess("新增成功");
|
|
|
+ this.open = false;
|
|
|
+ this.getList();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.msgSuccess("新增成功");
|
|
|
+ this.open = false;
|
|
|
+ this.getList();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.msgSuccess("新增成功");
|
|
|
+ this.open = false;
|
|
|
+ this.getList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handleDelete(row) {
|
|
|
+ this.$confirm('确定删除该一级原因吗,删除将影响其下属二级原因都被同步删除,请谨慎操作。', "警告", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning"
|
|
|
+ }).then(() => {
|
|
|
+ return delRefundReason(row.id);
|
|
|
+ }).then(() => {
|
|
|
+ this.getList();
|
|
|
+ this.msgSuccess("删除成功");
|
|
|
+ }).catch(() => {});
|
|
|
+ },
|
|
|
+ handleDeleteChild(row, parent) {
|
|
|
+ this.$confirm('是否确认删除该二级原因?', "警告", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning"
|
|
|
+ }).then(() => {
|
|
|
+ return delRefundReason(row.id);
|
|
|
+ }).then(() => {
|
|
|
+ getChildrenByParentId(parent.id).then(response => {
|
|
|
+ parent.children = response.data;
|
|
|
+ parent.childrenCount = response.data.length;
|
|
|
+ });
|
|
|
+ this.msgSuccess("删除成功");
|
|
|
+ }).catch(() => {});
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|