123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <template>
- <div>
- <en-table-layout
- toolbar
- @selection-change="selectFun"
- pagination
- :tableData="tableData"
- :height="600"
- :loading="loading"
- :default-sort="{prop: 'id', order: 'ascending'}"
- >
- <!--工具栏-->
- <div slot="toolbar" class="inner-toolbar">
- <div class="toolbar-search">
- <en-table-search @search="handlerSearch" :placeholder="this.$t('action.keywords')"/>
- </div>
- <div class="toolbar-btns">
- <el-button type="primary" @click="handleAdd">添加亲属</el-button>
- <el-button type="danger" :disabled="multipleSelection.length === 0" @click="batchDelete">批量删除</el-button>
- </div>
- </div>
- <!--表头-->
- <template slot="table-columns">
- <el-table-column type="selection" width="55" align="center"></el-table-column>
- <el-table-column prop="nickname" label="姓名" align="center"></el-table-column>
- <el-table-column prop="relative_name" label="亲属称呼" align="center"></el-table-column>
- <el-table-column prop="sex" label="性别" align="center" :formatter="formatterSex"></el-table-column>
- <el-table-column prop="mobile" label="手机" align="center"></el-table-column>
- <el-table-column label="操作" width="120">
- <template slot-scope="scope">
- <el-button type="danger" size="mini" @click="handlerDelete(scope.row.member_id)">
- 删除
- </el-button>
- </template>
- </el-table-column>
- </template>
- <!--翻页-->
- <el-pagination
- slot="pagination"
- v-if="pageData"
- :current-page="pageData.page_no"
- :page-sizes="[20, 30, 50, 100]"
- :page-size="pageData.page_size"
- @size-change="handlePageSizeChange"
- @current-change="handlePageCurrentChange"
- layout="total, sizes, prev, pager, next, jumper"
- :total="pageData.data_total">
- </el-pagination>
- </en-table-layout>
- <el-dialog title="添加用户亲属" :visible.sync="dialogAddVisible" :append-to-body="true" width="80%">
- <el-form :model="formmodel" :rules="rules" ref="editForm" label-width="140px">
- <el-row>
- <el-col :span="12">
- <el-form-item label="姓名" prop="nickname">
- <el-input v-model="formmodel.nickname" clearable placeholder="请输入姓名" :maxlength="20"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="亲属称呼" prop="relative_name">
- <el-input v-model="formmodel.relative_name" clearable placeholder="请输入亲属称呼" :maxlength="20"></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="12">
- <el-form-item label="性别" class="form-item-sex">
- <el-radio v-model="formmodel.sex" :label="1">男</el-radio>
- <el-radio v-model="formmodel.sex" :label="0">女</el-radio>
- <el-radio v-model="formmodel.sex" :label="3">未知</el-radio>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="手机号码">
- <el-input v-model="formmodel.mobile" clearable placeholder="请输入手机号码" :maxlength="20"></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <el-form-item>
- <el-button type="primary" @click="addMember">立即添加</el-button>
- <el-button @click="quxiao">取消</el-button>
- </el-form-item>
- </el-form>
- </el-dialog>
- </div>
- </template>
- <script>
- import * as API_user from '@/api/user'
- import * as RegExp from "@/utils/RegExp";
- export default {
- name: 'customer_relative',
- props: {
- memberId: {
- type: Number,
- default: 0
- }
- },
- data: function() {
- return {
- /** 列表loading状态 */
- loading: false,
- /** 列表参数 */
- params: {
- page_size: 10,
- page_no: 1,
- sort: 'create_time',
- dir: 'desc',
- fixedCondition: ''
- },
- currentRow: {},
- /** 列表数据 */
- tableData: [],
- pageData: [],
- dialogAddVisible: false,
- /** 选中行数据 */
- multipleSelection: [],
- lookForm: {},
- formshow: false,
- formmodel: {
- sex: 1
- },
- rules: {
- nickname: [
- this.MixinRequired('请输入亲属姓名!'),
- { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' },
- {
- validator: (rule, value, callback) => {
- if (!RegExp.userName.test(value)) {
- callback(new Error('只支持汉字、字母、数字、“-”、“_”的组合!'))
- } else {
- callback()
- }
- }
- }
- ],
- relative_name: [
- this.MixinRequired('请输入亲属称呼!'),
- { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' },
- {
- validator: (rule, value, callback) => {
- if (!RegExp.userName.test(value)) {
- callback(new Error('只支持汉字、字母、数字、“-”、“_”的组合!'))
- } else {
- callback()
- }
- }
- }
- ],
- },
- }
- },
- mounted() {
- // if (this.memberId) {
- // this.GET_List()
- // }
- },
- watch: {
- memberId: function() {
- if (this.memberId) {
- this.GET_List()
- }
- }
- },
- methods: {
- /** 选择行变化时,记录选中的行数据 */
- selectFun(val) {
- this.multipleSelection = val
- },
- /** 加载设备信息列表 */
- GET_List() {
- this.loading = true
- this.params.fixedCondition = ' relative_id=' + this.memberId
- API_user.getList(this.params).then(res => {
- this.loading = false
- this.tableData = res.data
- this.pageData = {
- page_no: res.page_no,
- page_size: res.page_size,
- data_total: res.data_total
- }
- }).catch(() => {
- this.loading = false
- })
- },
- /** 处理搜索 **/
- handlerSearch(keywords) {
- this.params.query = keywords
- this.GET_List()
- },
- /** 单条数据删除处理 */
- handlerDelete(ids) {
- let test = '你确定要删除此用户亲属信息?'
- let _this = this
- this.$confirm(test, this.$t('action.waring'), {
- confirmButtonText: this.$t('action.yes'),
- cancelButtonText: this.$t('action.cancel'),
- type: 'warning'
- }).then(() => {
- API_user.remove(ids).then(
- response => {
- _this.GET_List()
- }
- ).catch(response => {
- _this.$message({
- type: 'info',
- message: response.message
- })
- })
- })
- },
- /** 批量数据删除处理(删除选中的行) */
- batchDelete: function() {
- const ids = []
- this.multipleSelection.forEach(function(item) {
- ids.push(item.member_id)
- })
- this.handlerDelete(ids.join(','), 'del')
- },
- /** 添加设备信息 */
- handleAdd() {
- this.dialogAddVisible = true
- },
- /** 编辑设备信息 */
- handlerEdit(index, row) {
- this.lookForm = Object.assign({}, row);
- this.formshow = true
- },
- /** 分页大小发生改变 */
- handlePageSizeChange(size) {
- this.params.page_size = size
- this.GET_List()
- },
- /** 分页页数发生改变 */
- handlePageCurrentChange(page) {
- this.params.page_no = page
- this.GET_List()
- },
- addMember() {
- this.formmodel.relative_id = this.memberId
- let _this = this
- API_user.add(this.formmodel).then(res=> {
- _this.GET_List()
- _this.quxiao()
- })
- },
- quxiao() {
- this.dialogAddVisible = false
- this.formmodel = {
- sex: 1
- }
- },
- formatterSex(row, column, cellValue) {
- if (row.sex === 1) {
- return '男'
- } else if (row.sex === 0) {
- return '女'
- } else {
- return '未知'
- }
- }
- }
- }
- </script>
- <style type="text/scss" scoped>
- /deep/ div.toolbar {
- height: 70px;
- padding: 20px 0;
- }
- /deep/ .el-table {
- width: 100%;
- overflow-x: scroll;
- & td:not(.is-left) {
- text-align: center;
- }
- }
- </style>
|