expressBill.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询和其他操作 -->
  4. <div class="filter-container">
  5. <el-button v-permission="['expressBill:expressbill:list']" class="filter-item" type="primary" size="mini" icon="el-icon-search" @click="handleFilter">查找</el-button>
  6. <el-button v-permission="['expressBill:expressbill:create']" class="filter-item" type="primary" size="mini" icon="el-icon-edit" @click="handleCreate">添加</el-button>
  7. </div>
  8. <!-- 查询结果 -->
  9. <el-table
  10. v-loading="listLoading"
  11. :data="list"
  12. size="small"
  13. element-loading-text="正在查询中。。。"
  14. border
  15. fit
  16. highlight-current-row
  17. >
  18. <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
  19. <template slot-scope="scope">
  20. <el-button v-permission="['expressBill:expressbill:edit']" type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
  21. <el-button v-permission="['expressBill:expressbill:delete']" type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
  22. </template>
  23. </el-table-column>
  24. </el-table>
  25. <pagination
  26. v-show="total>0"
  27. :total="total"
  28. :page.sync="listQuery.page"
  29. :limit.sync="listQuery.limit"
  30. @pagination="getList"
  31. />
  32. <!-- 添加或修改对话框 -->
  33. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
  34. <el-form
  35. ref="dataForm"
  36. :rules="rules"
  37. :model="dataForm"
  38. status-icon
  39. label-position="left"
  40. label-width="100px"
  41. style="width: 400px; margin-left:50px;"
  42. >
  43. <el-form-item label="id" prop="id" hidden>
  44. <el-input v-model="dataForm.id" />
  45. </el-form-item>
  46. </el-form>
  47. <div slot="footer" class="dialog-footer">
  48. <el-button @click="dialogFormVisible = false">取消</el-button>
  49. <el-button v-if="dialogStatus=='create'" :loading="submiting" type="primary" @click="createData">确定</el-button>
  50. <el-button v-else type="primary" :loading="submiting" @click="updateData">确定</el-button>
  51. </div>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script>
  56. import {
  57. listExpressBill,
  58. createExpressBill,
  59. updateExpressBill,
  60. deleteExpressBill
  61. } from '@/api/expressBill'
  62. import Pagination from '@/components/Pagination'
  63. export default {
  64. name: 'ExpressBill',
  65. components: { Pagination },
  66. data() {
  67. return {
  68. list: null,
  69. total: 0,
  70. listLoading: true,
  71. listQuery: {
  72. page: 1,
  73. limit: 20
  74. },
  75. dataForm: {
  76. id: undefined
  77. },
  78. dialogFormVisible: false,
  79. submiting: false,
  80. dialogStatus: '',
  81. textMap: {
  82. update: '编辑',
  83. create: '创建'
  84. },
  85. rules: {
  86. }
  87. }
  88. },
  89. created() {
  90. this.getList()
  91. },
  92. methods: {
  93. getList() {
  94. this.listLoading = true
  95. listExpressBill(this.listQuery).then(response => {
  96. this.list = response.data.data.items
  97. this.total = response.data.data.total
  98. this.listLoading = false
  99. })
  100. .catch(() => {
  101. this.list = []
  102. this.total = 0
  103. this.listLoading = false
  104. })
  105. },
  106. handleFilter() {
  107. this.listQuery.page = 1
  108. this.getList()
  109. },
  110. resetForm() {
  111. this.dataForm = {
  112. id: undefined
  113. }
  114. },
  115. handleCreate() {
  116. this.resetForm()
  117. this.dialogStatus = 'create'
  118. this.dialogFormVisible = true
  119. this.$nextTick(() => {
  120. this.$refs['dataForm'].clearValidate()
  121. })
  122. },
  123. createData() {
  124. this.$refs['dataForm'].validate(valid => {
  125. if (valid) {
  126. this.submiting = true
  127. createExpressBill(this.dataForm).then(response => {
  128. this.list.unshift(response.data.data)
  129. this.dialogFormVisible = false
  130. this.$notify.success({
  131. title: '成功',
  132. message: '添加成功'
  133. })
  134. this.submiting = false
  135. })
  136. .catch(response => {
  137. this.$notify.error({
  138. title: '失败',
  139. message: response.data.errmsg
  140. })
  141. this.submiting = false
  142. })
  143. }
  144. })
  145. },
  146. handleUpdate(row) {
  147. this.dataForm = Object.assign({}, row)
  148. this.dialogStatus = 'update'
  149. this.dialogFormVisible = true
  150. this.$nextTick(() => {
  151. this.$refs['dataForm'].clearValidate()
  152. })
  153. },
  154. updateData() {
  155. this.$refs['dataForm'].validate(valid => {
  156. if (valid) {
  157. this.submiting = true
  158. updateExpressBill(this.dataForm).then(() => {
  159. for (const v of this.list) {
  160. if (v.id === this.dataForm.id) {
  161. const index = this.list.indexOf(v)
  162. this.list.splice(index, 1, this.dataForm)
  163. break
  164. }
  165. }
  166. this.dialogFormVisible = false
  167. this.submiting = false
  168. this.$notify.success({
  169. title: '成功',
  170. message: '更新成功'
  171. })
  172. })
  173. .catch(response => {
  174. this.$notify.error({
  175. title: '失败',
  176. message: response.data.errmsg
  177. })
  178. this.submiting = false
  179. })
  180. }
  181. })
  182. },
  183. handleDelete(row) {
  184. this.$confirm('此操作将永久删除该记录---' + row.id + '---, 是否继续?', '提示', {
  185. confirmButtonText: '确定',
  186. cancelButtonText: '取消',
  187. type: 'warning'
  188. }).then(() => {
  189. deleteExpressBill(row.id).then(response => {
  190. this.$notify.success({
  191. title: '成功',
  192. message: '删除成功'
  193. })
  194. const index = this.list.indexOf(row)
  195. this.list.splice(index, 1)
  196. })
  197. .catch(response => {
  198. this.$notify.error({
  199. title: '失败',
  200. message: response.data.errmsg
  201. })
  202. })
  203. }).catch(() => {
  204. return false
  205. })
  206. }
  207. }
  208. }
  209. </script>