No Description

index.vue 8.2KB

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