urgentSetting.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div>
  3. <Toptitle :title="title">
  4. <slot name="titleButton">
  5. <!-- <Button @click="back"
  6. type='primary'
  7. ghost
  8. style="margin-right:10px;">返回</Button> -->
  9. <Button type="primary"
  10. style="margin-right:10px;"
  11. @click="handleRowClick({},null,1)"
  12. ghost>新增</Button>
  13. </slot>
  14. </Toptitle>
  15. <div style="padding-top:20px">
  16. <Form inline>
  17. <FormItem>
  18. <Input style="width:150px"
  19. clearable
  20. v-model="search_title"
  21. size="small"
  22. placeholder="请输入紧急程度名称" />
  23. </FormItem>
  24. <FormItem>
  25. <Button type="primary"
  26. size="small"
  27. @click="init">搜索</Button>
  28. </FormItem>
  29. </Form>
  30. </div>
  31. <div style="padding:20px 0px">
  32. <Table border
  33. ref="refTableData"
  34. draggable
  35. :columns="columns"
  36. :data="tableData"
  37. @on-drag-drop="onDragDrop">
  38. <template slot="colorStyle"
  39. slot-scope="{row}">
  40. <div :style="row.style">
  41. 颜色展示
  42. </div>
  43. </template>
  44. <template slot="op"
  45. slot-scope="{row,index}">
  46. <a @click="handleRowClick(row,index,2)"
  47. style="margin-right:10px">编辑</a>
  48. <a @click="handleRowClick(row,index,3)">删除</a>
  49. </template>
  50. </Table>
  51. </div>
  52. <Modal class="modal"
  53. title='请选择'
  54. v-model='showModal'
  55. :mask-closable="false"
  56. :width="400">
  57. <div>
  58. <span>ID:</span>
  59. <span>
  60. <Input style="width:150px"
  61. v-model="currencyRow.id"
  62. disabled
  63. placeholder="自动生成" />
  64. </span>
  65. </div>
  66. <div>
  67. <span>紧急程度名称:</span>
  68. <span>
  69. <Input style="width:150px"
  70. v-model="currencyRow.title"
  71. placeholder="请输入紧急程度名称" />
  72. </span>
  73. </div>
  74. <div>
  75. <span>字体颜色: </span>
  76. <span>
  77. <ColorPicker v-model="currencyRow.color" />
  78. </span>
  79. </div>
  80. <div class="modal-footer"
  81. slot="footer">
  82. <Button @click="showModal = false">取消</Button>
  83. <Button type="primary"
  84. @click="handleColorConfirm">确认</Button>
  85. </div>
  86. </Modal>
  87. </div>
  88. </template>
  89. <script>
  90. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  91. // 例如:import 《组件名称》 from '《组件路径》';
  92. export default {
  93. name: 'colorSetting',
  94. components: {
  95. },
  96. props: {},
  97. // import引入的组件需要注入到对象中才能使用
  98. data () {
  99. // 这里存放数据
  100. return {
  101. title: '紧急程度',
  102. columns: [
  103. { type: 'index', key: '', align: 'center' },
  104. { title: '紧急程度名称', key: 'title', align: 'center', },
  105. { title: '字体颜色', key: 'color', align: 'center', slot: 'colorStyle' },
  106. { title: '操作', key: 'operation', align: 'center', slot: 'op' }
  107. ],
  108. tableData: [],
  109. maxSort: 0,
  110. showModal: false,
  111. //1新增2编辑
  112. addState: 0,
  113. currencyRow: {
  114. color: ''
  115. },
  116. currencyIndex: 0
  117. }
  118. },
  119. // 生命周期 - 创建完成(可以访问当前this实例)
  120. created () {
  121. // this.initData()
  122. this.init()
  123. },
  124. // 生命周期 - 挂载完成(可以访问DOM元素)
  125. mounted () {
  126. },
  127. methods: {
  128. init () {
  129. this.axios.get('/api/warning_list', {
  130. params: {
  131. title: this.search_title
  132. }
  133. }).then(res => {
  134. if (res.code == 200) {
  135. this.tableData = res.data.data
  136. this.tableData.forEach(element => {
  137. element.style = {
  138. backgroundColor: element.color,
  139. color: element.color,
  140. }
  141. });
  142. }
  143. }).catch(err => { console.error(err); })
  144. },
  145. back () {
  146. this.$router.go(-1)
  147. },
  148. handleRowClick (row, index, type) {
  149. this.currencyRow = JSON.parse(JSON.stringify(row))
  150. this.currencyIndex = index
  151. this.addState = type
  152. switch (type) {
  153. case 1:
  154. case 2:
  155. this.showModal = true
  156. break;
  157. case 3:
  158. this.$Modal.confirm({
  159. title: '确认删除?',
  160. content: '此操作无法恢复,请确认!',
  161. onOk: () => {
  162. this.axios({
  163. method: 'post',
  164. url: '/api/warning_del',
  165. data: {
  166. id: row.id
  167. }
  168. }).then((res) => {
  169. this.$Message.success(res.msg)
  170. this.init()
  171. }).catch((err) => { });
  172. },
  173. onCancel: () => { }
  174. })
  175. break;
  176. }
  177. },
  178. handleColorChange (row, index, type) {
  179. this.addState = type
  180. this.showModal = true
  181. },
  182. handleColorConfirm () {
  183. this.axios({
  184. method: 'post',
  185. url: '/api/warning_edit',
  186. data: {
  187. ...this.currencyRow
  188. }
  189. }).then((res) => {
  190. this.$Message.success(res.msg)
  191. this.showModal = false
  192. this.init()
  193. }).catch((err) => { });
  194. },
  195. handleSave () {
  196. this.tableData.forEach((el, index) => {
  197. el.sort = index + 1
  198. });
  199. this.axios({
  200. method: 'post',
  201. url: '/api/basics_color_edit',
  202. data: {
  203. ...this.tableData
  204. }
  205. }).then((res) => {
  206. this.$Message.success(res.msg)
  207. this.showModal = false
  208. // this.init()
  209. }).catch((err) => { });
  210. },
  211. onDragDrop (a, b) {
  212. this.tableData.splice(b, 0, ...this.tableData.splice(a, 1))
  213. }
  214. },
  215. // 监听属性 类似于data概念
  216. computed: {},
  217. // 监控data中的数据变化
  218. watch: {},
  219. beforeCreate () { }, // 生命周期 - 创建之前
  220. beforeMount () { }, // 生命周期 - 挂载之前
  221. beforeUpdate () { }, // 生命周期 - 更新之前
  222. updated () { }, // 生命周期 - 更新之后
  223. beforeDestroy () { }, // 生命周期 - 销毁之前
  224. destroyed () { }, // 生命周期 - 销毁完成
  225. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  226. }
  227. </script>
  228. <style lang='scss' scoped>
  229. .modal {
  230. div {
  231. display: flex;
  232. justify-content: space-around;
  233. align-items: center;
  234. padding: 10px 0;
  235. span {
  236. width: 150px;
  237. }
  238. }
  239. }
  240. </style>