index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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.sysAttachment.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 { attachment } from './query'
  58. export default {
  59. name: 'Attachment',
  60. components: {
  61. Sheet,
  62. Query
  63. },
  64. mixins: [attachment],
  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: 'type',
  78. label: 'Type',
  79. align: 'center',
  80. minWidth: 150,
  81. maxWidth: 180
  82. },
  83. {
  84. prop: 'Size',
  85. label: 'size',
  86. align: 'center',
  87. minWidth: 150,
  88. maxWidth: 180
  89. },
  90. {
  91. prop: 'Remark',
  92. label: 'remark',
  93. align: 'center',
  94. minWidth: 150,
  95. maxWidth: 180
  96. }
  97. ],
  98. operates: {
  99. list: [
  100. {
  101. label: 'Edit',
  102. show: true,
  103. type: 'primary',
  104. method: row => {
  105. this.edit(row)
  106. }
  107. },
  108. {
  109. label: 'Del',
  110. show: true,
  111. type: 'danger',
  112. method: row => {
  113. this.deleteData(row)
  114. }
  115. }
  116. ],
  117. width: 150
  118. },
  119. dataQuery: {
  120. page: 1,
  121. size: 10,
  122. name: '',
  123. code: ''
  124. },
  125. rules: {
  126. name: [{ required: true, message: 'Please input Name', trigger: 'blur' }],
  127. code: [{ required: true, message: 'Please input Code', trigger: 'blur' }]
  128. },
  129. temp: {
  130. id: undefined,
  131. name: '',
  132. code: '',
  133. value: ''
  134. },
  135. dataLoading: false,
  136. dialogStatus: '',
  137. dialogVisible: false
  138. }
  139. },
  140. computed: {
  141. ...mapGetters(['size', 'minMainHeight'])
  142. },
  143. watch: {
  144. maps(val) {
  145. this.temp.value = JSON.stringify(val)
  146. }
  147. },
  148. created() {},
  149. methods: {
  150. createData() {
  151. this.$refs['temp'].validate(valid => {
  152. if (valid) {
  153. this.temp.value = JSON.stringify(this.maps)
  154. this.$api.system.AddOptionset(this.temp).then(res => {
  155. this.dialogVisible = false
  156. this.$message({
  157. message: 'Created successfully',
  158. type: 'success'
  159. })
  160. this.$refs.qtable.getData()
  161. })
  162. }
  163. })
  164. },
  165. updateData() {
  166. this.$refs['temp'].validate(valid => {
  167. if (valid) {
  168. this.temp.value = JSON.stringify(this.maps)
  169. this.$api.sysOptionset.update(this.temp).then(res => {
  170. this.dialogVisible = false
  171. this.$message({
  172. message: 'modified successful',
  173. type: 'success'
  174. })
  175. this.$refs.qtable.getData()
  176. })
  177. }
  178. })
  179. },
  180. deleteData(row) {
  181. this.$confirm('Confirm deletion?', 'Tips', {
  182. type: 'warning'
  183. }).then(() => {
  184. this.$api.system.DelOptionset([{ id: row.id }]).then(res => {
  185. this.$refs.qtable.getData()
  186. this.$message({
  187. message: 'Removal successful',
  188. type: 'success'
  189. })
  190. })
  191. }).catch(() => {})
  192. },
  193. deleteBatch() {
  194. const ids = this.$refs.qtable.multipleSelection.map(row => ({ id: row.id }))
  195. this.$confirm('Do you confirm bulk deletion of selected data?', 'Tips', {
  196. type: 'warning'
  197. }).then(() => {
  198. this.$api.system.DelOptionset(ids).then(res => {
  199. this.$refs.qtable.getData()
  200. this.$message({
  201. message: 'Removal successful',
  202. type: 'success'
  203. })
  204. })
  205. })
  206. },
  207. delItem(index) {
  208. this.maps.splice(index, 1)
  209. },
  210. addItem() {
  211. this.maps.push({ value: '', text: '' })
  212. },
  213. search(obj) {
  214. return this.$refs.qtable.getData(obj)
  215. },
  216. resetFields() {
  217. this.$refs['searchForm'].resetFields()
  218. this.$refs.qtable.getData()
  219. },
  220. dialogClose() {
  221. this.$refs['temp'].resetFields()
  222. this.maps = [{ value: '', text: '' }]
  223. },
  224. create() {
  225. this.dialogStatus = 'create'
  226. this.dialogVisible = true
  227. this.$nextTick(() => {
  228. this.$refs['temp'].clearValidate()
  229. })
  230. },
  231. edit(row) {
  232. this.dialogStatus = 'update'
  233. this.dialogVisible = true
  234. this.$nextTick(() => {
  235. this.$refs['temp'].clearValidate()
  236. this.temp = Object.assign({}, row)
  237. this.maps = JSON.parse(this.temp.value)
  238. })
  239. }
  240. }
  241. }
  242. </script>
  243. <style>
  244. .repair-item .oprate {
  245. color: #409eff;
  246. }
  247. .repair-item .button {
  248. width: 100%;
  249. height: 30px;
  250. line-height: 30px;
  251. text-align: center;
  252. border: 2px dotted #eee;
  253. background-color: white;
  254. }
  255. </style>