index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <el-container>
  3. <el-main class="page-main">
  4. <el-card>
  5. <el-container>
  6. <el-header height="120">
  7. <query ref="searchForm" :form-config="query" @onSubmit="search" />
  8. </el-header>
  9. <el-main>
  10. <sheet ref="qtable" :api="this.$api.sysOptionset.page" :columns="tableColumns" :data-query="dataQuery" :operates="operates" :float-type="'right'" :select-type="'selection'" />
  11. </el-main>
  12. </el-container>
  13. </el-card>
  14. </el-main>
  15. <el-dialog :title="dialogStatus==='create'? $t('common.create'):$t('common.update')" :visible.sync="dialogVisible" width="40%" @close="dialogClose">
  16. <el-form ref="temp" :size="size" :rules="rules" :model="temp" label-width="120px">
  17. <el-form-item label="Name:" prop="name">
  18. <el-input v-model="temp.name" :size="size" placeholder="Please input Name" />
  19. </el-form-item>
  20. <el-form-item label="Code:" prop="code">
  21. <el-input v-model="temp.code" :size="size" placeholder="Please input Code" />
  22. </el-form-item>
  23. <el-form-item label="Remark:" prop="remark">
  24. <el-input v-model="temp.remark" :size="size" placeholder="Please input Remark" />
  25. </el-form-item>
  26. <el-form-item label="Key&Value:" label-position="right" label-width="120px" class="notice-input" prop="maps">
  27. <div v-for="(item, index) in maps" :key="index" style="width: 100%; float: left; margin-bottom: 5px;" type="flex">
  28. <div style="width: 15%; float: left">
  29. <el-input v-model="item.value" placeholder="value" />
  30. </div>
  31. <div style="width: 35%; float: left;">
  32. <el-input v-model="item.text" type="textarea" :rows="2" placeholder="text" clearable style="border-left: 0px;margin-left: 11px;" />
  33. </div>
  34. <div style="width: 35%; float: left;margin-left:20px">
  35. <el-input v-model="item.label" type="textarea" :rows="2" placeholder="请输入说明文字" clearable style="border-left: 0px;margin-left: 11px;" />
  36. </div>
  37. <div style="width: 5%; float: left;padding-left: 23px; ">
  38. <el-button icon="el-icon-minus" circle :size="size" style="padding: 5px;" @click="delItem(index)" />
  39. </div>
  40. </div>
  41. <div type="flex" class="row-bg repair-item" style="float: left; width: 95%; ">
  42. <div class="button" @click="addItem">+ {{ $t('common.create') }}</div>
  43. </div>
  44. </el-form-item>
  45. </el-form>
  46. <footer slot="footer" class="dialog-footer">
  47. <el-button :size="size" @click="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
  48. <el-button :size="size" type="primary" @click="dialogStatus==='create'?createData():updateData()">{{ $t('common.confirm') }}</el-button>
  49. </footer>
  50. </el-dialog>
  51. </el-container>
  52. </template>
  53. <script>
  54. import { mapGetters } from 'vuex'
  55. import Sheet from '@/components/Sheet/index'
  56. import Query from '@/components/Query'
  57. import { optionset } from './query'
  58. export default {
  59. name: 'Optionset',
  60. components: {
  61. Sheet,
  62. Query
  63. },
  64. mixins: [optionset],
  65. data() {
  66. return {
  67. maps: [{ value: '', text: '' }],
  68. tableColumns: [
  69. {
  70. prop: 'name',
  71. label: 'Name',
  72. align: 'center',
  73. minWidth: 180,
  74. maxWidth: 220
  75. },
  76. {
  77. prop: 'code',
  78. label: 'Code',
  79. align: 'center',
  80. minWidth: 150,
  81. maxWidth: 180
  82. },
  83. {
  84. prop: 'remark',
  85. label: 'Remark',
  86. align: 'center',
  87. minWidth: 150,
  88. maxWidth: 180
  89. }
  90. ],
  91. operates: {
  92. list: [
  93. {
  94. label: 'Edit',
  95. show: true,
  96. type: 'primary',
  97. method: row => {
  98. this.edit(row)
  99. }
  100. },
  101. {
  102. label: 'Del',
  103. show: true,
  104. type: 'danger',
  105. method: row => {
  106. this.deleteData(row)
  107. }
  108. }
  109. ],
  110. width: 150
  111. },
  112. dataQuery: {
  113. page: 1,
  114. size: 10,
  115. name: '',
  116. code: ''
  117. },
  118. rules: {
  119. name: [{ required: true, message: 'Please input Name', trigger: 'blur' }],
  120. code: [{ required: true, message: 'Please input Code', trigger: 'blur' }]
  121. },
  122. temp: {
  123. id: undefined,
  124. name: '',
  125. code: '',
  126. value: ''
  127. },
  128. dataLoading: false,
  129. dialogStatus: '',
  130. dialogVisible: false
  131. }
  132. },
  133. computed: {
  134. ...mapGetters(['size', 'minMainHeight'])
  135. },
  136. watch: {
  137. maps(val) {
  138. this.temp.value = JSON.stringify(val)
  139. }
  140. },
  141. created() {},
  142. methods: {
  143. createData() {
  144. this.$refs['temp'].validate(valid => {
  145. if (valid) {
  146. this.temp.value = JSON.stringify(this.maps)
  147. this.$api.system.AddOptionset(this.temp).then(res => {
  148. this.dialogVisible = false
  149. this.$message({
  150. message: 'Created successfully',
  151. type: 'success'
  152. })
  153. this.$refs.qtable.getData()
  154. })
  155. }
  156. })
  157. },
  158. updateData() {
  159. this.$refs['temp'].validate(valid => {
  160. if (valid) {
  161. this.temp.value = JSON.stringify(this.maps)
  162. this.$api.sysOptionset.update(this.temp).then(res => {
  163. this.dialogVisible = false
  164. this.$message({
  165. message: 'modified successful',
  166. type: 'success'
  167. })
  168. this.$refs.qtable.getData()
  169. })
  170. }
  171. })
  172. },
  173. deleteData(row) {
  174. this.$confirm('Confirm deletion?', 'Tips', {
  175. type: 'warning'
  176. }).then(() => {
  177. this.$api.system.DelOptionset([{ id: row.id }]).then(res => {
  178. this.$refs.qtable.getData()
  179. this.$message({
  180. message: 'Removal successful',
  181. type: 'success'
  182. })
  183. })
  184. }).catch(() => {})
  185. },
  186. deleteBatch() {
  187. const ids = this.$refs.qtable.multipleSelection.map(row => ({ id: row.id }))
  188. this.$confirm('Do you confirm bulk deletion of selected data?', 'Tips', {
  189. type: 'warning'
  190. }).then(() => {
  191. this.$api.system.DelOptionset(ids).then(res => {
  192. this.$refs.qtable.getData()
  193. this.$message({
  194. message: 'Removal successful',
  195. type: 'success'
  196. })
  197. })
  198. })
  199. },
  200. delItem(index) {
  201. this.maps.splice(index, 1)
  202. },
  203. addItem() {
  204. this.maps.push({ value: '', text: '' })
  205. },
  206. search(obj) {
  207. return this.$refs.qtable.getData(obj)
  208. },
  209. resetFields() {
  210. this.$refs['searchForm'].resetFields()
  211. this.$refs.qtable.getData()
  212. },
  213. dialogClose() {
  214. this.$refs['temp'].resetFields()
  215. this.maps = [{ value: '', text: '' }]
  216. },
  217. create() {
  218. this.dialogStatus = 'create'
  219. this.dialogVisible = true
  220. this.$nextTick(() => {
  221. this.$refs['temp'].clearValidate()
  222. })
  223. },
  224. edit(row) {
  225. this.dialogStatus = 'update'
  226. this.dialogVisible = true
  227. this.$nextTick(() => {
  228. this.$refs['temp'].clearValidate()
  229. this.temp = Object.assign({}, row)
  230. this.maps = JSON.parse(this.temp.value)
  231. })
  232. }
  233. }
  234. }
  235. </script>
  236. <style>
  237. .repair-item .oprate {
  238. color: #409eff;
  239. }
  240. .repair-item .button {
  241. width: 100%;
  242. height: 30px;
  243. line-height: 30px;
  244. text-align: center;
  245. border: 2px dotted #eee;
  246. background-color: white;
  247. }
  248. </style>