Nenhuma Descrição

index.vue 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="app-container calendar-list-container">
  3. <div class="app-container">
  4. <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="名稱" v-model="listQuery.name">
  5. </el-input>
  6. <el-select clearable @change='handleFilter' style="width: 120px" class="filter-item" v-model="listQuery.chipsSort" placeholder="點數">
  7. <el-option v-for="item in chipsSortOptions" :key="item.label" :label="item.label" :value="item.key">
  8. </el-option>
  9. </el-select>
  10. <el-select clearable @change='handleFilter' style="width: 120px" class="filter-item" v-model="listQuery.updatedSort" placeholder="更新時間">
  11. <el-option v-for="item in updatedSortOptions" :key="item.label" :label="item.label" :value="item.key">
  12. </el-option>
  13. </el-select>
  14. <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜尋</el-button>
  15. <el-button class="filter-item" @click="handleCreate" type="primary" icon="el-icon-edit">創建</el-button>
  16. </div>
  17. <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row
  18. style="width: 100%">
  19. <el-table-column align="center" label='ID' >
  20. <template slot-scope="scope">
  21. {{scope.row.id}}
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="名稱" align="center" width="200">
  25. <template slot-scope="scope">
  26. {{scope.row.name}}
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="點數" width="150" align="center">
  30. <template slot-scope="scope">
  31. <span>{{scope.row.chips}}</span>
  32. </template>
  33. </el-table-column>
  34. <el-table-column align="center" label="操作">
  35. <template slot-scope="scope">
  36. <el-button type="primary" size="mini" @click="handleDeposit(scope.row)">儲值</el-button>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <div v-show="!listLoading" class="pagination-container">
  41. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page"
  42. :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
  43. </el-pagination>
  44. </div>
  45. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
  46. <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="100px" style='width: 400px; margin-left:50px;'>
  47. <el-form-item v-if="dialogStatus=='deposit'" label="ID" prop="id">
  48. <el-input v-model="temp.id" :disabled="true"></el-input>
  49. </el-form-item>
  50. <el-form-item label="名稱" prop="name">
  51. <el-input v-if="dialogStatus=='deposit'" v-model="temp.name" :disabled="true"></el-input>
  52. <el-input v-if="dialogStatus=='create'" v-model="temp.name"></el-input>
  53. </el-form-item>
  54. <el-form-item label="點數" prop="chips">
  55. <el-input v-if="dialogStatus=='deposit'" v-model="temp.chips" :disabled="true"></el-input>
  56. <el-input v-if="dialogStatus=='create'" v-model="temp.chips"></el-input>
  57. </el-form-item>
  58. <el-form-item v-if="dialogStatus=='deposit'" label="加值點數" prop="depositChips">
  59. <el-input placeholder="請輸入加值金額" v-model="temp.depositChips">
  60. </el-input>
  61. </el-form-item>
  62. </el-form>
  63. <div slot="footer" class="dialog-footer">
  64. <el-button @click="dialogFormVisible = false">取 消</el-button>
  65. <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">確 定</el-button>
  66. <el-button v-if="dialogStatus=='deposit'" type="primary" @click="depositChips">確 定</el-button>
  67. </div>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script>
  72. import { fetchList, updateChips, createGambleMember } from '@/api/gambleMember'
  73. import waves from '@/directive/waves' // 水波纹指令
  74. export default {
  75. name: 'gambleMemberTable',
  76. directives: {
  77. waves
  78. },
  79. data() {
  80. return {
  81. list: null,
  82. total: null,
  83. listLoading: true,
  84. listQuery: {
  85. page: 1,
  86. limit: 20,
  87. importance: '',
  88. title: '',
  89. type: '',
  90. chipsSort: '',
  91. updatedSort: ''
  92. },
  93. temp: {
  94. id: '',
  95. importance: 1,
  96. name: '',
  97. chips: '',
  98. depositChips: ''
  99. },
  100. dialogFormVisible: false,
  101. dialogStatus: '',
  102. textMap: {
  103. deposit: '儲值',
  104. create: '新增'
  105. },
  106. chipsSortOptions: [{ label: '多 -> 少', key: 'DESC' }, { label: '少 -> 多', key: 'ASC' }],
  107. updatedSortOptions: [{ label: '新 -> 舊', key: 'DESC' }, { label: '舊 -> 新', key: 'ASC' }],
  108. rules: {
  109. depositChips: [{ pattern: /^\+?[1-9][0-9]*$/, required: true, message: '請輸入整數', trigger: 'change' }],
  110. chips: [{ pattern: /^\+?[1-9][0-9]*$/, required: true, message: '請輸入整數', trigger: 'change' }],
  111. name: [{ type: 'string', required: true, message: '必填', trigger: 'change' }]
  112. }
  113. }
  114. },
  115. created() {
  116. this.getList()
  117. },
  118. methods: {
  119. getList() {
  120. this.listLoading = true
  121. fetchList(this.listQuery).then(response => {
  122. this.list = response.data.rows
  123. this.total = response.data.count
  124. this.listLoading = false
  125. })
  126. },
  127. handleDeposit(row) {
  128. this.temp = Object.assign({}, row) // copy obj
  129. this.temp.timestamp = new Date(this.temp.timestamp)
  130. this.dialogStatus = 'deposit'
  131. this.dialogFormVisible = true
  132. this.$nextTick(() => {
  133. this.$refs['dataForm'].clearValidate()
  134. })
  135. },
  136. depositChips() {
  137. this.$refs['dataForm'].validate((valid) => {
  138. if (valid) {
  139. const tempData = Object.assign({}, this.temp)
  140. updateChips(tempData).then(() => {
  141. for (const v of this.list) {
  142. if (v.id === this.temp.id) {
  143. const index = this.list.indexOf(v)
  144. this.list.splice(index, 1, this.temp)
  145. break
  146. }
  147. }
  148. this.dialogFormVisible = false
  149. this.$notify({
  150. title: '成功',
  151. message: '儲值成功',
  152. type: 'success',
  153. duration: 2000
  154. })
  155. this.getList()
  156. })
  157. }
  158. })
  159. },
  160. resetTemp() {
  161. this.temp = {
  162. id: undefined,
  163. name: '',
  164. chips: '',
  165. depositChips: ''
  166. }
  167. },
  168. handleCreate() {
  169. this.resetTemp()
  170. this.dialogStatus = 'create'
  171. this.dialogFormVisible = true
  172. this.$nextTick(() => {
  173. this.$refs['dataForm'].clearValidate()
  174. })
  175. },
  176. createData() {
  177. this.$refs['dataForm'].validate((valid) => {
  178. if (valid) {
  179. createGambleMember(this.temp).then((response) => {
  180. this.list.unshift(response.data)
  181. this.dialogFormVisible = false
  182. this.$notify({
  183. title: '成功',
  184. message: '創建成功',
  185. type: 'success',
  186. duration: 2000
  187. })
  188. })
  189. }
  190. })
  191. },
  192. handleFilter() {
  193. this.listQuery.page = 1
  194. this.getList()
  195. },
  196. handleSizeChange(val) {
  197. this.listQuery.limit = val
  198. this.getList()
  199. },
  200. handleCurrentChange(val) {
  201. this.listQuery.page = val
  202. this.getList()
  203. }
  204. }
  205. }
  206. </script>