business.vue 9.8 KB

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