whiteList.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="app-container ">
  3. <div class="margin_top">
  4. <!-- 搜索向 -->
  5. <div class="flex">
  6. <div class="w_input">
  7. <span class="textSpan">手机号:</span>
  8. <el-input v-model="body.phoneNo" style="width:200px" placeholder="请输入手机号" size="small" clearable />
  9. <el-button class="filter-item" icon="el-icon-search" type="primary" plain @click="Search">搜索</el-button>
  10. <el-button class="classitem" style="marginRight:30px" type="primary" plain icon="el-icon-plus" @click="dataFormAdd">新增</el-button>
  11. <el-button icon="el-icon-delete" type="danger" plain @click="ModifyDelete">删除</el-button>
  12. </div>
  13. </div>
  14. <div >
  15. </div>
  16. <!-- 表格数据 -->
  17. <el-table v-loading="loading" :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
  18. <el-table-column
  19. type="selection"
  20. align="center"
  21. width="55">
  22. </el-table-column>
  23. <el-table-column label="手机号" align="center" width="300" show-overflow-tooltip>
  24. <template slot-scope="scope">
  25. <span>{{ scope.row.phoneNo }}</span>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="备注" align="center" show-overflow-tooltip>
  29. <template slot-scope="scope">
  30. <span type="text" >{{ scope.row.note }}</span>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <!-- 分页 -->
  35. <div class="pagination">
  36. <el-pagination
  37. current-page.sync="body.current"
  38. :current-page="body.current"
  39. :page-sizes="[10, 20, 30, 50]"
  40. :page-size="body.size"
  41. layout="total, sizes, prev, pager, next, jumper"
  42. background
  43. :total="total"
  44. @size-change="handleSizeChange"
  45. @current-change="handleCurrentChange"
  46. />
  47. </div>
  48. </div>
  49. <!-- 新增与修改 -->
  50. <el-dialog :title="operation?'新增黑名单':'编辑黑名单'" :visible.sync="dialogFormVisible" width="55%" center>
  51. <el-form ref="dataForm" :model="dataForm" :rules="rules2" label-width="80px" size="small" label-position="right">
  52. <el-form-item label="手机号" prop="phoneNo" :label-width="formLabelWidth" style="width:420px;margin:15px auto">
  53. <el-input v-model="dataForm.phoneNo" placeholder="请输入手机号" />
  54. </el-form-item>
  55. <el-form-item label="备注" prop="groupName" :label-width="formLabelWidth" style="width:420px;margin:15px auto">
  56. <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="dataForm.note" placeholder="请输入备注" />
  57. </el-form-item>
  58. </el-form>
  59. <div slot="footer" class="dialog-footer">
  60. <el-button @click="dialogFormVisible = false">取 消</el-button>
  61. <el-button type="primary" @click="submitForm">确 定</el-button>
  62. </div>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script>
  67. import api from '@/api/blackList.js'
  68. export default {
  69. data(){
  70. return{
  71. loading:false, //表格数据加载
  72. tableData:[], //表格数据
  73. body:{
  74. size:10,
  75. current:1,
  76. phoneNo:"" //名称搜索
  77. },
  78. total:0,
  79. dataForm:{},
  80. rules2:{
  81. phoneNo: [{ required: true, message: '请输入手机', trigger: 'blur' } ],
  82. },
  83. phone:[],
  84. operation:false,
  85. dialogFormVisible:false,
  86. formLabelWidth:"120px"
  87. }
  88. },
  89. created(){
  90. this.reLoad()
  91. },
  92. methods:{
  93. // 重载数据
  94. reLoad(){
  95. this.loading = true
  96. api.Search(this.body).then((res) => {
  97. this.loading = false
  98. console.log(res)
  99. let list = res.data.data.records
  100. // console.log(data)
  101. this.tableData = list
  102. this.total = res.data.data.total
  103. })
  104. },
  105. //搜索数据
  106. Search(){
  107. this.body.current = 1
  108. this.reLoad()
  109. },
  110. //新增和修改API
  111. submitForm(){
  112. this.$refs['dataForm'].validate((valid) => {
  113. if (valid) {
  114. if (!this.operation) {
  115. } else {
  116. console.log(this.dataForm)
  117. // // 添加
  118. let dataForm = this.dataForm
  119. let list = []
  120. list.push(dataForm)
  121. api.add(list).then(response => {
  122. if (response.status === 200) {
  123. this.$message({
  124. type: 'success',
  125. message: '操作成功'
  126. })
  127. this.dialogFormVisible = false
  128. this.reLoad()
  129. } else {
  130. this.$message({
  131. type: 'error',
  132. message: response.data.msg
  133. })
  134. }
  135. })
  136. }
  137. }
  138. })
  139. },
  140. //新增弹框
  141. dataFormAdd(){
  142. this.operation = true // true:新增, false:编辑
  143. this.dialogFormVisible = true // 控制弹出框
  144. this.dataForm = {}
  145. if(this.$refs['dataForm']){
  146. this.$refs['dataForm'].resetFields();
  147. }
  148. },
  149. //编辑弹框
  150. handleEdit(row){
  151. this.operation = false // true:新增, false:编辑
  152. this.dialogFormVisible = true // 控制弹出框
  153. this.dataForm = JSON.parse(JSON.stringify(row))
  154. if(this.$refs['dataForm']){
  155. this.$refs['dataForm'].resetFields();
  156. }
  157. },
  158. //删除API
  159. ModifyDelete(){
  160. const that = this
  161. if(this.phone.length > 0){
  162. that.$confirm('此操作将删除该手机号', '提示', {
  163. confirmButtonText: '确定',
  164. cancelButtonText: '取消',
  165. type: 'warning'
  166. })
  167. .then(() => {
  168. api.del(this.phone).then((res)=>{
  169. if (res.status === 200) {
  170. that.$message({
  171. type: 'success',
  172. message: '删除成功'
  173. })
  174. that.reLoad()
  175. } else {
  176. that.$message({
  177. type: 'error',
  178. message: res.msg
  179. })
  180. }
  181. })
  182. })
  183. }else{
  184. that.$message({
  185. type: 'error',
  186. message: "请至少选择一项"
  187. })
  188. }
  189. },
  190. //多选
  191. handleSelectionChange(row){
  192. let arryList = []
  193. row.map(res=>{
  194. let phoneNo = res.phoneNo
  195. arryList.push(phoneNo)
  196. })
  197. this.phone = arryList
  198. },
  199. ///分页
  200. handleSizeChange: function(val) {
  201. this.body.size = val
  202. this.reLoad()
  203. },
  204. handleCurrentChange: function(val) {
  205. this.body.current = val
  206. console.log(val)
  207. this.reLoad()
  208. }
  209. }
  210. }
  211. </script>
  212. <style scoped>
  213. .flex{
  214. width: 90%;
  215. display: flex;
  216. flex-direction: row;
  217. margin-bottom: 10px;
  218. /* flex-wrap: wrap; */
  219. justify-content: flex-start;
  220. /* margin: 20px auto; */
  221. }
  222. .flexend{
  223. display: flex;
  224. justify-content: flex-end;
  225. /* padding-right: 2rem; */
  226. width: 100%;
  227. /* margin: 0 auto; */
  228. padding-bottom: 20px;
  229. }
  230. </style>