customer_relative.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div>
  3. <en-table-layout
  4. toolbar
  5. @selection-change="selectFun"
  6. pagination
  7. :tableData="tableData"
  8. :height="600"
  9. :loading="loading"
  10. :default-sort="{prop: 'id', order: 'ascending'}"
  11. >
  12. <!--工具栏-->
  13. <div slot="toolbar" class="inner-toolbar">
  14. <div class="toolbar-search">
  15. <en-table-search @search="handlerSearch" :placeholder="this.$t('action.keywords')"/>
  16. </div>
  17. <div class="toolbar-btns">
  18. <el-button type="primary" @click="handleAdd">添加亲属</el-button>
  19. <el-button type="danger" :disabled="multipleSelection.length === 0" @click="batchDelete">批量删除</el-button>
  20. </div>
  21. </div>
  22. <!--表头-->
  23. <template slot="table-columns">
  24. <el-table-column type="selection" width="55" align="center"></el-table-column>
  25. <el-table-column prop="nickname" label="姓名" align="center"></el-table-column>
  26. <el-table-column prop="relative_name" label="亲属称呼" align="center"></el-table-column>
  27. <el-table-column prop="sex" label="性别" align="center" :formatter="formatterSex"></el-table-column>
  28. <el-table-column prop="mobile" label="手机" align="center"></el-table-column>
  29. <el-table-column label="操作" width="120">
  30. <template slot-scope="scope">
  31. <el-button type="danger" size="mini" @click="handlerDelete(scope.row.member_id)">
  32. 删除
  33. </el-button>
  34. </template>
  35. </el-table-column>
  36. </template>
  37. <!--翻页-->
  38. <el-pagination
  39. slot="pagination"
  40. v-if="pageData"
  41. :current-page="pageData.page_no"
  42. :page-sizes="[20, 30, 50, 100]"
  43. :page-size="pageData.page_size"
  44. @size-change="handlePageSizeChange"
  45. @current-change="handlePageCurrentChange"
  46. layout="total, sizes, prev, pager, next, jumper"
  47. :total="pageData.data_total">
  48. </el-pagination>
  49. </en-table-layout>
  50. <el-dialog title="添加用户亲属" :visible.sync="dialogAddVisible" :append-to-body="true" width="80%">
  51. <el-form :model="formmodel" :rules="rules" ref="editForm" label-width="140px">
  52. <el-row>
  53. <el-col :span="12">
  54. <el-form-item label="姓名" prop="nickname">
  55. <el-input v-model="formmodel.nickname" clearable placeholder="请输入姓名" :maxlength="20"></el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item label="亲属称呼" prop="relative_name">
  60. <el-input v-model="formmodel.relative_name" clearable placeholder="请输入亲属称呼" :maxlength="20"></el-input>
  61. </el-form-item>
  62. </el-col>
  63. </el-row>
  64. <el-row>
  65. <el-col :span="12">
  66. <el-form-item label="性别" class="form-item-sex">
  67. <el-radio v-model="formmodel.sex" :label="1">男</el-radio>
  68. <el-radio v-model="formmodel.sex" :label="0">女</el-radio>
  69. <el-radio v-model="formmodel.sex" :label="3">未知</el-radio>
  70. </el-form-item>
  71. </el-col>
  72. <el-col :span="12">
  73. <el-form-item label="手机号码">
  74. <el-input v-model="formmodel.mobile" clearable placeholder="请输入手机号码" :maxlength="20"></el-input>
  75. </el-form-item>
  76. </el-col>
  77. </el-row>
  78. <el-form-item>
  79. <el-button type="primary" @click="addMember">立即添加</el-button>
  80. <el-button @click="quxiao">取消</el-button>
  81. </el-form-item>
  82. </el-form>
  83. </el-dialog>
  84. </div>
  85. </template>
  86. <script>
  87. import * as API_user from '@/api/user'
  88. import * as RegExp from "@/utils/RegExp";
  89. export default {
  90. name: 'customer_relative',
  91. props: {
  92. memberId: {
  93. type: Number,
  94. default: 0
  95. }
  96. },
  97. data: function() {
  98. return {
  99. /** 列表loading状态 */
  100. loading: false,
  101. /** 列表参数 */
  102. params: {
  103. page_size: 10,
  104. page_no: 1,
  105. sort: 'create_time',
  106. dir: 'desc',
  107. fixedCondition: ''
  108. },
  109. currentRow: {},
  110. /** 列表数据 */
  111. tableData: [],
  112. pageData: [],
  113. dialogAddVisible: false,
  114. /** 选中行数据 */
  115. multipleSelection: [],
  116. lookForm: {},
  117. formshow: false,
  118. formmodel: {
  119. sex: 1
  120. },
  121. rules: {
  122. nickname: [
  123. this.MixinRequired('请输入亲属姓名!'),
  124. { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' },
  125. {
  126. validator: (rule, value, callback) => {
  127. if (!RegExp.userName.test(value)) {
  128. callback(new Error('只支持汉字、字母、数字、“-”、“_”的组合!'))
  129. } else {
  130. callback()
  131. }
  132. }
  133. }
  134. ],
  135. relative_name: [
  136. this.MixinRequired('请输入亲属称呼!'),
  137. { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' },
  138. {
  139. validator: (rule, value, callback) => {
  140. if (!RegExp.userName.test(value)) {
  141. callback(new Error('只支持汉字、字母、数字、“-”、“_”的组合!'))
  142. } else {
  143. callback()
  144. }
  145. }
  146. }
  147. ],
  148. },
  149. }
  150. },
  151. mounted() {
  152. // if (this.memberId) {
  153. // this.GET_List()
  154. // }
  155. },
  156. watch: {
  157. memberId: function() {
  158. if (this.memberId) {
  159. this.GET_List()
  160. }
  161. }
  162. },
  163. methods: {
  164. /** 选择行变化时,记录选中的行数据 */
  165. selectFun(val) {
  166. this.multipleSelection = val
  167. },
  168. /** 加载设备信息列表 */
  169. GET_List() {
  170. this.loading = true
  171. this.params.fixedCondition = ' relative_id=' + this.memberId
  172. API_user.getList(this.params).then(res => {
  173. this.loading = false
  174. this.tableData = res.data
  175. this.pageData = {
  176. page_no: res.page_no,
  177. page_size: res.page_size,
  178. data_total: res.data_total
  179. }
  180. }).catch(() => {
  181. this.loading = false
  182. })
  183. },
  184. /** 处理搜索 **/
  185. handlerSearch(keywords) {
  186. this.params.query = keywords
  187. this.GET_List()
  188. },
  189. /** 单条数据删除处理 */
  190. handlerDelete(ids) {
  191. let test = '你确定要删除此用户亲属信息?'
  192. let _this = this
  193. this.$confirm(test, this.$t('action.waring'), {
  194. confirmButtonText: this.$t('action.yes'),
  195. cancelButtonText: this.$t('action.cancel'),
  196. type: 'warning'
  197. }).then(() => {
  198. API_user.remove(ids).then(
  199. response => {
  200. _this.GET_List()
  201. }
  202. ).catch(response => {
  203. _this.$message({
  204. type: 'info',
  205. message: response.message
  206. })
  207. })
  208. })
  209. },
  210. /** 批量数据删除处理(删除选中的行) */
  211. batchDelete: function() {
  212. const ids = []
  213. this.multipleSelection.forEach(function(item) {
  214. ids.push(item.member_id)
  215. })
  216. this.handlerDelete(ids.join(','), 'del')
  217. },
  218. /** 添加设备信息 */
  219. handleAdd() {
  220. this.dialogAddVisible = true
  221. },
  222. /** 编辑设备信息 */
  223. handlerEdit(index, row) {
  224. this.lookForm = Object.assign({}, row);
  225. this.formshow = true
  226. },
  227. /** 分页大小发生改变 */
  228. handlePageSizeChange(size) {
  229. this.params.page_size = size
  230. this.GET_List()
  231. },
  232. /** 分页页数发生改变 */
  233. handlePageCurrentChange(page) {
  234. this.params.page_no = page
  235. this.GET_List()
  236. },
  237. addMember() {
  238. this.formmodel.relative_id = this.memberId
  239. let _this = this
  240. API_user.add(this.formmodel).then(res=> {
  241. _this.GET_List()
  242. _this.quxiao()
  243. })
  244. },
  245. quxiao() {
  246. this.dialogAddVisible = false
  247. this.formmodel = {
  248. sex: 1
  249. }
  250. },
  251. formatterSex(row, column, cellValue) {
  252. if (row.sex === 1) {
  253. return '男'
  254. } else if (row.sex === 0) {
  255. return '女'
  256. } else {
  257. return '未知'
  258. }
  259. }
  260. }
  261. }
  262. </script>
  263. <style type="text/scss" scoped>
  264. /deep/ div.toolbar {
  265. height: 70px;
  266. padding: 20px 0;
  267. }
  268. /deep/ .el-table {
  269. width: 100%;
  270. overflow-x: scroll;
  271. & td:not(.is-left) {
  272. text-align: center;
  273. }
  274. }
  275. </style>