| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 | <template>  <el-row :gutter="5" style="margin-top:5px;margin-left:5px;">    <el-col :span="5">      <el-card class="box-card">        <div slot="header" class="clearfix" style="text-align: right; ">          <el-row :gutter="2" style="margin-top:5px; margin-left:5px;">            <el-col :span="12" style="text-align: left; vertical-align:middle; font-size: 20px">  <span>字典分类 </span></el-col>            <el-col :span="6"> <el-col :span="6">  <el-button type="warning" icon="el-icon-edit-outline" size="mini" @click="jump" /></el-col>            </el-col>            <el-col :span="6">  <el-button type="primary" icon="el-icon-refresh" size="mini" /></el-col>          </el-row>        </div>        <div class="component-item">          <el-tree            ref="tree"            class="filter-tree"            :data="parent"            :props="defaultProps"            default-expand-all            @node-click="handleNodeClick"          />        </div>      </el-card>    </el-col>    <el-col :span="19">      <div class="app-container">        <div class="filter-container">          <el-button class="success" style="margin-left: 10px;" icon="el-icon-plus" @click="handleCreate"> 新增 </el-button>        </div>        <el-table          v-loading="listLoading"          element-loading-text="给我一点时间"          :data="list"          border          fit          highlight-current-row          style="width: 100%;"          :row-style="rowStyle"          :cell-style="cellStyle"          class="elTable"          row-key="id"          default-expand-all          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"        >          <el-table-column label="名称" header-align="center" width="150px" align="center">            <template slot-scope="scope">              <span>{{ scope.row.label }}</span>            </template>          </el-table-column>          <el-table-column label="值" min-width="150px" header-align="center" align="center">            <template slot-scope="scope">              <span>{{ scope.row.value }}</span>            </template>          </el-table-column>          <el-table-column label="顺序" min-width="150px" header-align="center" align="center">            <template slot-scope="scope">              <span>{{ scope.row.orderby }}</span>            </template>          </el-table-column>          <!--           <el-table-column label="是否牧场" min-width="150px" header-align="center" align="center">            <template slot-scope="scope">              <el-switch                v-model="scope.row.isPasture"                :active-value="1"                :inactive-value="0"                @change="handleEnableChange(scope.$index, scope.row)"              />            </template>          </el-table-column> -->          <el-table-column label="启用" min-width="150px" header-align="center" align="center">            <template slot-scope="scope">              <el-switch                v-model="scope.row.enable"                active-color="#13ce66"                inactive-color="#ff4949"                :active-value="1"                :inactive-value="0"                @change="handleEnableChange(scope.$index, scope.row)"              />            </template>          </el-table-column>          <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">            <template slot-scope="{row}">              <el-button type="primary" size="mini" @click="handleUpdate(row)">                编辑              </el-button>              <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)">                删除              </el-button>            </template>          </el-table-column>        </el-table>        <pagination v-show="total>=0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">          <el-form            ref="dataForm"            v-enterToNext="true"            :rules="rules"            :model="deptform"            label-position="left"            label-width="100px"            style="width: 600px; margin-left:50px;"          >            <el-form-item label="名称" prop="label">              <el-input                ref="label"                v-model="deptform.label"              />            </el-form-item>            <el-form-item label="值" prop="value">              <el-input                ref="value"                v-model="deptform.value"              />            </el-form-item>            <el-form-item label="顺序" prop="orderby">              <el-input                ref="orderby"                v-model="deptform.orderby"              />            </el-form-item>            <!--   <el-form-item label="是否牧场" prop="isPasture">              <el-input                ref="isPasture"                v-model="deptform.isPasture"              />            </el-form-item> -->            <el-form-item label="启用" prop="enable">              <el-switch                ref="enable"                v-model="deptform.enable"                active-color="#13ce66"                inactive-color="#ff4949"                :active-value="1"                :inactive-value="0"              />            </el-form-item>          </el-form>          <div slot="footer" class="dialog-footer">            <el-button              v-if="dialogStatus==='create'"              ref="createb"              type="success"              @click="createData_again()"            >              确认新增            </el-button>            <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">              确认            </el-button>            <el-button @click="dialogFormVisible = false">              关闭            </el-button>          </div>        </el-dialog>      </div>    </el-col>  </el-row></template><script>import waves from '@/directive/waves' // waves directiveimport enterToNext from '@/directive/enterToNext' // enterToNext directiveimport { PostDataByName, GetDataByName, getRecuData } from '@/api/common'import { isIntegerZero } from '@/utils/validate'import Pagination from '@/components/Pagination' // secondary package based on el-paginationimport { MessageBox } from 'element-ui'export default {  name: 'Dict',  components: { Pagination },  directives: { waves, enterToNext },  data() {    return {      defaultProps: {        children: 'children',        label: 'name'      },      dictid: 0,      list: [],      total: 0,      listLoading: true,      requestParam: {        name: '',        params: []      },      deptform: {        label: '',        value: '',        orderby: '',        enable: '',        pid: ''      },      getdataListParm: { name: 'getDictList',        offset: 1,        pagecount: 8,        params: [] },      getRecuListParm: { name: 'getDictclass',        idname: 'id',        params: [-1] },      rules: {        label: [{ type: 'string', required: true, message: '名称必填', trigger: 'change' }],        value: [{ type: 'string', required: true, message: '只必填', trigger: 'change' }],        orderby: [{ validator: isIntegerZero, trigger: 'blur' }]      },      dialogFormVisible: false,      parentDeptVisible: true,      dialogStatus: '',      textMap: {        update: '编辑',        create: '新增'      },      parent: [],      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },      cellStyle: { padding: 0 + 'px' }    }  },  created() {    this.getList()  },  methods: {    jump() {      this.$router.push('/console/menu')    // 传递的参数用{{ $route.query.goodsId }}获取    //  this.$router.push({ path: '/cart?goodsId=12' })    // this.$router.go(-2)    // 后退两步    },    handleNodeClick(data) {      if (data.children.length === 0) {        this.listLoading = true        this.dictid = data.id        this.getdataListParm.params = [data.id, data.id]        GetDataByName(this.getdataListParm).then(response => {          this.list = response.data.list          this.total = response.data.total          // Just to simulate the time of the request          setTimeout(() => {            this.listLoading = false          }, 100)        })      }    },    getDownList() {      getRecuData(this.getRecuListParm).then(response => {        this.parent = response.data      })    },    getList() {      this.listLoading = true      this.getDownList()      GetDataByName(this.getdataListParm).then(response => {        this.list = response.data.list        this.total = response.data.total        setTimeout(() => {          this.listLoading = false        }, 100)      })    },    resetRequestParam() {      this.deptform.id = ''      this.deptform.pid = ''      this.deptform.label = ''      this.deptform.value = ''      this.deptform.orderby = '0'      this.deptform.enable = '1'    },    handleCreate() {      this.resetRequestParam()      this.dialogStatus = 'create'      this.deptform.orderby = '0'      this.deptform.enable = 1      this.dialogFormVisible = true      this.$nextTick(() => {        this.$refs['dataForm'].clearValidate()        this.$refs['label'].focus()      })    },    createData() {      this.$refs['dataForm'].validate((valid) => {        if (valid) {          this.requestParam.name = 'insertDictList'          this.requestParam.params = []          this.requestParam.params[0] = this.deptform.label          this.requestParam.params[1] = this.deptform.value          this.requestParam.params[2] = this.deptform.orderby          this.requestParam.params[3] = this.deptform.enable          this.requestParam.params[4] = this.dictid          PostDataByName(this.requestParam).then(() => {            this.getList()            this.dialogFormVisible = false            this.$notify({              title: '成功',              message: '新增成功',              type: 'success',              duration: 2000            })          })        }      })    },    createData_again() {      this.$refs['dataForm'].validate((valid) => {        if (valid) {          this.requestParam.name = 'insertDictList'          this.requestParam.params = []          this.requestParam.params[0] = this.deptform.label          this.requestParam.params[1] = this.deptform.value          this.requestParam.params[2] = this.deptform.orderby          this.requestParam.params[3] = this.deptform.enable          this.requestParam.params[4] = this.dictid          PostDataByName(this.requestParam).then(() => {            this.$nextTick(() => {              this.$refs['label'].focus()            })            this.getList()            this.resetRequestParam()            this.deptform.orderby = '0'            this.deptform.enable = 1            this.$notify({              title: '成功',              message: '新增成功',              type: 'success',              duration: 2000            })          })        }      })    },    handleUpdate(row) {      this.deptform.id = row.id      this.deptform.label = row.label      this.deptform.value = row.value      this.deptform.orderby = row.orderby      this.deptform.enable = row.enable      this.deptform.pid = row.pid      this.dialogStatus = 'update'      this.dialogFormVisible = true      this.$nextTick(() => {        this.$refs['dataForm'].clearValidate()        this.$refs['label'].focus()      })    },    updateData() {      this.$refs['dataForm'].validate((valid) => {        if (valid) {          this.requestParam.name = 'updateDictList'          this.requestParam.params = []          this.requestParam.params[0] = this.deptform.label          this.requestParam.params[1] = this.deptform.value          this.requestParam.params[2] = this.deptform.orderby          this.requestParam.params[3] = this.deptform.enable          this.requestParam.params[4] = this.dictid          this.requestParam.params[5] = this.deptform.id          PostDataByName(this.requestParam).then(() => {            this.getList()            this.resetRequestParam()            this.dialogFormVisible = false            this.$notify({              title: '成功',              message: '修改成功',              type: 'success',              duration: 2000            })          })        }      })    },    handleEnableChange(index, row) {      this.requestParam.name = 'updateDictList'      this.requestParam.params = []      this.requestParam.params[0] = row.label      this.requestParam.params[1] = row.value      this.requestParam.params[2] = row.orderby      this.requestParam.params[3] = row.enable      this.requestParam.params[4] = this.dictid      this.requestParam.params[5] = row.id      PostDataByName(this.requestParam).then(() => {        this.$notify({          title: '成功',          message: '修改成功',          type: 'success',          duration: 2000        })      })    },    handleDelete(row) {      MessageBox.confirm('名称:' + row.label, '确认删除?', {        confirmButtonText: '确认',        cancelButtonText: '取消',        type: 'warning'      }).then(() => {        this.requestParam.name = 'deleteDictList'        this.requestParam.params = []        this.requestParam.params[0] = row.id        PostDataByName(this.requestParam).then(() => {          this.getList()          this.resetRequestParam()          this.dialogFormVisible = false          this.$notify({            title: '成功',            message: '删除成功',            type: 'success',            duration: 2000          })        })      }).catch(() => {        this.$message({          type: 'info',          message: '已取消删除'        })      })    }  }}</script>
 |