guest.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询表单区域 -->
  4. <el-form :model="listQuery" size="small" :inline="true" label-position="top">
  5. <el-row :gutter="20">
  6. <el-col :span="6">
  7. <el-form-item label="散客编号">
  8. <el-input v-model="listQuery.customerCode" placeholder="请输入散客编号" style="width: 100%" clearable></el-input>
  9. </el-form-item>
  10. </el-col>
  11. <el-col :span="6">
  12. <el-form-item label="散客姓名">
  13. <el-input v-model="listQuery.customerName" placeholder="请输入散客姓名" style="width: 100%" clearable></el-input>
  14. </el-form-item>
  15. </el-col>
  16. <el-col :span="6">
  17. <el-form-item label="性别">
  18. <el-select v-model="listQuery.sex" clearable placeholder="请选择性别" style="width: 100%">
  19. <el-option :key="item.type" v-for="item in sexList" :label="item.name" :value="item.type">
  20. </el-option>
  21. </el-select>
  22. </el-form-item>
  23. </el-col>
  24. </el-row>
  25. <el-row :gutter="20">
  26. <el-col :span="6">
  27. <el-form-item label="搜索">
  28. <el-button style="width: 100%;" type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="6">
  32. <el-form-item label="重置">
  33. <el-button style="width: 100%;" icon="el-icon-refresh" type="primary" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-col>
  36. </el-row>
  37. </el-form>
  38. <!-- 操作按钮区域 -->
  39. <el-row :gutter="10" class="mb8">
  40. <el-col :span="1.5">
  41. <el-button type="primary" class="editButton" size="small" icon="el-icon-plus" @click="handleCreate">添加</el-button>
  42. </el-col>
  43. <el-col :span="1.5">
  44. <el-button type="warning" icon="el-icon-download" size="small" @click="handleDownload">导出</el-button>
  45. </el-col>
  46. </el-row>
  47. <!-- 表格区域 -->
  48. <div class="border-card">
  49. <el-table height="450" size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit highlight-current-row>
  50. <el-table-column type="index" label="序号" header-align="center" align="center" width="55"></el-table-column>
  51. <el-table-column align="center" min-width="80px" label="散客编号" prop="customerCode"></el-table-column>
  52. <el-table-column align="center" min-width="100px" label="散客姓名" prop="customerName"></el-table-column>
  53. <el-table-column align="center" min-width="80px" label="性别" prop="sexStr"></el-table-column>
  54. <el-table-column align="center" min-width="100px" label="联系方式" prop="customerPhone"></el-table-column>
  55. <el-table-column align="center" min-width="150px" label="备注" prop="remarks"></el-table-column>
  56. <el-table-column align="center" label="操作" width="240px" class-name="small-padding fixed-width">
  57. <template slot-scope="scope">
  58. <el-button type="text" icon="el-icon-edit" class="editText" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
  59. <el-button type="text" icon="el-icon-delete" class="deleteText" size="small" @click="handleDelete(scope.row)">删除</el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <!-- 分页 -->
  64. <div class="pagination-container">
  65. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  66. :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
  67. layout="total, sizes, prev, pager, next, jumper" :total="total">
  68. </el-pagination>
  69. </div>
  70. </div>
  71. <!-- 添加或修改对话框 -->
  72. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="40%">
  73. <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="110px">
  74. <el-form-item label="散客编号" prop="customerCode">
  75. <el-input v-model="dataForm.customerCode" placeholder="请输入散客编号"></el-input>
  76. </el-form-item>
  77. <el-form-item label="散客名称" prop="customerName">
  78. <el-input v-model="dataForm.customerName" placeholder="请输入散客名称"></el-input>
  79. </el-form-item>
  80. <el-form-item label="性别" prop="sex">
  81. <el-radio-group v-model="dataForm.sex">
  82. <el-radio :key="item.type" v-for="item in sexList" :label="item.type">{{ item.name }}</el-radio>
  83. </el-radio-group>
  84. </el-form-item>
  85. <el-form-item label="联系方式" prop="customerPhone">
  86. <el-input v-model="dataForm.customerPhone" placeholder="请输入联系方式"></el-input>
  87. </el-form-item>
  88. <el-form-item label="备注" prop="remarks">
  89. <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" placeholder="请输入备注" v-model="dataForm.remarks"></el-input>
  90. </el-form-item>
  91. </el-form>
  92. <div slot="footer" class="dialog-footer">
  93. <el-button @click="dialogFormVisible = false">取消</el-button>
  94. <el-button v-if="dialogStatus == 'create'" type="primary" @click="createData">确定</el-button>
  95. <el-button v-else type="primary" @click="updateData">确定</el-button>
  96. </div>
  97. </el-dialog>
  98. </div>
  99. </template>
  100. <script>
  101. import { listGuest, createGuest, updateGuest, deleteGuest, setState } from '@/api/guest'
  102. import waves from '@/directive/waves' // 水波纹指令
  103. export default {
  104. directives: { waves },
  105. data() {
  106. return {
  107. list: undefined,
  108. total: undefined,
  109. listLoading: true,
  110. sexList: [
  111. {
  112. type: 0,
  113. name: '男'
  114. },
  115. {
  116. type: 1,
  117. name: '女'
  118. }
  119. ],
  120. listQuery: {
  121. page: 1,
  122. limit: 10,
  123. customerCode: undefined,
  124. customerName: undefined,
  125. sex: undefined
  126. },
  127. dataForm: {
  128. customerCode: undefined,
  129. customerName: undefined,
  130. sex: undefined,
  131. customerPhone: undefined,
  132. remarks: undefined
  133. },
  134. dialogFormVisible: false,
  135. dialogStatus: '',
  136. textMap: {
  137. update: '编辑散客',
  138. create: '添加散客'
  139. },
  140. rules: {
  141. customerCode: [
  142. { required: true, message: '散客编号不能为空', trigger: 'blur' }
  143. // { min: 6, max: 6, message: "散客编号必须为7位", trigger: "blur" },
  144. // { pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/, message: "散客编号必须为6位字母加数字", trigger: "blur" }
  145. ],
  146. customerName: [{ required: true, message: '散客姓名不能为空', trigger: 'blur' }]
  147. }
  148. }
  149. },
  150. created() {
  151. this.getList()
  152. },
  153. methods: {
  154. /** 重置按钮操作 */
  155. resetQuery() {
  156. this.listQuery = {
  157. page: 1,
  158. limit: 10,
  159. customerCode: undefined,
  160. customerName: undefined,
  161. sex: undefined
  162. }
  163. this.handleQuery()
  164. },
  165. getList() {
  166. this.listLoading = true
  167. listGuest(this.listQuery).then(response => {
  168. this.list = response.data.data.items
  169. this.total = response.data.data.total
  170. this.listLoading = false
  171. }).catch(() => {
  172. this.list = []
  173. this.total = 0
  174. this.listLoading = false
  175. })
  176. },
  177. handleQuery() {
  178. this.listQuery.page = 1
  179. this.getList()
  180. },
  181. handleSizeChange(val) {
  182. this.listQuery.limit = val
  183. this.getList()
  184. },
  185. handleCurrentChange(val) {
  186. this.listQuery.page = val
  187. this.getList()
  188. },
  189. resetForm() {
  190. this.dataForm = {
  191. customerCode: undefined,
  192. customerName: undefined,
  193. sex: undefined,
  194. customerPhone: undefined,
  195. remarks: undefined
  196. }
  197. },
  198. handleCreate() {
  199. this.resetForm()
  200. this.dialogStatus = 'create'
  201. this.dialogFormVisible = true
  202. this.$nextTick(() => {
  203. this.$refs['dataForm'].clearValidate()
  204. })
  205. },
  206. createData() {
  207. this.$refs['dataForm'].validate((valid) => {
  208. if (valid) {
  209. createGuest(this.dataForm).then(response => {
  210. this.list.unshift(response.data.data)
  211. this.dialogFormVisible = false
  212. this.$notify({
  213. title: '成功',
  214. message: '创建成功',
  215. type: 'success',
  216. duration: 2000
  217. })
  218. this.getList()
  219. })
  220. }
  221. })
  222. },
  223. handleUpdate(row) {
  224. this.dataForm = Object.assign({}, row)
  225. this.dialogStatus = 'update'
  226. this.dialogFormVisible = true
  227. this.$nextTick(() => {
  228. this.$refs['dataForm'].clearValidate()
  229. })
  230. },
  231. updateData() {
  232. this.$refs['dataForm'].validate((valid) => {
  233. if (valid) {
  234. updateGuest(this.dataForm).then(() => {
  235. for (const v of this.list) {
  236. if (v.id === this.dataForm.id) {
  237. const index = this.list.indexOf(v)
  238. this.list.splice(index, 1, this.dataForm)
  239. break
  240. }
  241. }
  242. this.dialogFormVisible = false
  243. this.$notify({
  244. title: '成功',
  245. message: '更新成功',
  246. type: 'success',
  247. duration: 2000
  248. })
  249. this.getList()
  250. })
  251. }
  252. })
  253. },
  254. handleDelete(row) {
  255. this.$confirm('确认删除吗?', '提示', {
  256. confirmButtonText: '确定',
  257. cancelButtonText: '取消',
  258. type: 'warning'
  259. }).then(() => {
  260. deleteGuest({ id: row.id }).then(response => {
  261. this.$notify({
  262. title: '成功',
  263. message: '删除成功',
  264. type: 'success',
  265. duration: 2000
  266. })
  267. this.getList()
  268. })
  269. }).catch(() => {
  270. })
  271. },
  272. handleDownload() {
  273. window.location.href = process.env.BASE_API + '/customer-guest/export'
  274. },
  275. changeState(id, status) {
  276. setState({ id: id, status: status }).then(response => {
  277. this.$notify({
  278. title: '成功',
  279. message: '状态修改成功',
  280. type: 'success',
  281. duration: 2000
  282. })
  283. this.getList()
  284. })
  285. }
  286. }
  287. }
  288. </script>