08fe193744de28f4d5877ccd59bb65bcdac61955.svn-base 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div v-loading="loading" class="container">
  3. <el-card v-show="false" body-style="padding: 0px;" class="dashboard-list" shadow="never">
  4. <div slot="header">
  5. <span>看板</span>
  6. <i class="el-icon-plus" @click="addDashboard" />
  7. </div>
  8. <ul>
  9. <draggable v-model="dashboardList" :group="{name: 'dashboard',pull: true}" class="draggable-wrapper" @change="handleOrderChange">
  10. <li v-for="item in dashboardList" :key="item.dashboard_id" :class="{'dashboard-list-item': true, 'high-light-dashboard': currentDashboard.dashboard_id === item.dashboard_id}">
  11. <span @click="switchDb(item)">
  12. <i class="el-icon-document" />
  13. <span>{{ item.name }}</span>
  14. </span>
  15. <el-dropdown szie="mini" trigger="click" @command="handleCommand">
  16. <span class="el-dropdown-link">
  17. <i class="el-icon-more" />
  18. </span>
  19. <el-dropdown-menu slot="dropdown">
  20. <el-dropdown-item
  21. :command="{
  22. type: 'edit',
  23. target: item
  24. }"
  25. >
  26. {{ $t('common.edit') }}
  27. </el-dropdown-item>
  28. <el-dropdown-item
  29. :command="{
  30. type: 'delete',
  31. target: item
  32. }"
  33. >
  34. {{ $t('common.delete') }}
  35. </el-dropdown-item>
  36. </el-dropdown-menu>
  37. </el-dropdown>
  38. </li>
  39. </draggable>
  40. </ul>
  41. </el-card>
  42. <dashboardItem :dashboard="currentDashboard" :mode="isEdit" @fatherMethod="getList" />
  43. <el-dialog :title="$t('dashboard.addOrEditDashboard')" width="750px" :visible.sync="editDialogVisible">
  44. <el-form label-width="160px">
  45. <el-form-item :label="$t('dashboard.dashboardName')">
  46. <el-input v-model="dbObj.name" size="small" style="width: 450px;" :placeholder="$t('dashboard.dashboardNamePlaceholder')" />
  47. </el-form-item>
  48. <el-form-item :label="$t('dashboard.dashboardDesc')">
  49. <el-input v-model="dbObj.desc" type="textarea" :rows="5" size="small" style="width: 450px;" :placeholder="$t('dashboard.dashboardDescPlaceholder')" />
  50. </el-form-item>
  51. </el-form>
  52. <span slot="footer" class="dialog-footer">
  53. <el-button type="primary" size="small" @click="editDialogVisible = false"> {{ $t('common.cancel') }}</el-button>
  54. <el-button type="primary" size="small" @click="handleSubmit"> {{ $t('common.confirm') }}</el-button>
  55. </span>
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script>
  60. import draggable from 'vuedraggable'
  61. import dashboardItem from './dashboardItem'
  62. import { GetDataByName, ExeSqlJiade, PostDataByName, dashboardListJiade } from '@/api/common'
  63. import Cookies from 'js-cookie'
  64. // import { addDashboard, updateDashboard, dashboardList, deleteDashboard, dbOrder } from '@/api/dashboard'
  65. import { addDashboard, updateDashboard, deleteDashboard, dbOrder } from '@/api/dashboard'
  66. export default {
  67. name: 'Addboard',
  68. components: { dashboardItem, draggable },
  69. data() {
  70. return {
  71. isEdit: 'edit',
  72. dashboardList: [],
  73. currentDashboard: undefined,
  74. editDialogVisible: false,
  75. dbObj: {},
  76. loading: false,
  77. isCollapse: false
  78. }
  79. },
  80. created() {
  81. console.log('this.$route.params.id', this.$route.params.id)
  82. const isEdit = this.$route.params.isEdit
  83. this.isEdit = isEdit
  84. this.getList()
  85. },
  86. methods: {
  87. // getList() {
  88. // this.loading = true
  89. // dashboardList().then(resp => {
  90. // this.loading = false
  91. // this.dashboardList = []
  92. // resp.data.order.forEach((id, index) => {
  93. // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
  94. // if (itemIndex >= 0) {
  95. // this.dashboardList.push(resp.data.dashboards[itemIndex])
  96. // resp.data.dashboards.splice(itemIndex, 1)
  97. // } else {
  98. // console.log(id, index)
  99. // }
  100. // })
  101. // this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
  102. // const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
  103. // if (dashboard) {
  104. // this.currentDashboard = dashboard
  105. // } else {
  106. // this.currentDashboard = this.dashboardList[0]
  107. // }
  108. // if (this.currentDashboard) {
  109. // this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`).catch(_ => { })
  110. // }
  111. // })
  112. // },
  113. getList() {
  114. this.loading = true
  115. var send_data = {
  116. name: 'getdashboards',
  117. parammaps: {
  118. pastureid: Cookies.get('pastureid'),
  119. empid: Cookies.get('employeid'),
  120. did: this.$route.params.id
  121. }
  122. }
  123. console.log('进入大页面=================')
  124. dashboardListJiade(send_data).then(resp => {
  125. this.loading = false
  126. this.dashboardList = []
  127. console.log('看板列表数据:', resp)
  128. console.log('看板列表优化数据list:', resp.data.list)
  129. console.log('看板列表优化数据dashboards:', resp.data.dashboards)
  130. // resp.data.order.forEach((id, index) => {
  131. // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
  132. // if (itemIndex >= 0) {
  133. // this.dashboardList.push(resp.data.dashboards[itemIndex])
  134. // resp.data.dashboards.splice(itemIndex, 1)
  135. // } else {
  136. // console.log(id, index)
  137. // }
  138. // })
  139. this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
  140. const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
  141. if (dashboard) {
  142. this.currentDashboard = dashboard
  143. } else {
  144. this.currentDashboard = this.dashboardList[0]
  145. }
  146. console.log('this.currentDashboard', this.currentDashboard)
  147. console.log('this.dashboardList', this.dashboardList)
  148. if (this.currentDashboard) {
  149. this.$router.push({ path: '/customboard/Addboard', query: { id: this.currentDashboard.dashboard_id }}).catch(_ => { })
  150. }
  151. })
  152. },
  153. switchDb(db) {
  154. if (db.dashboard_id === this.currentDashboard.dashboard_id) {
  155. this.getList()
  156. return
  157. }
  158. this.currentDashboard = db
  159. this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`)
  160. },
  161. addDashboard() {
  162. this.dbObj = {}
  163. this.editDialogVisible = true
  164. },
  165. editDashboard(db) {
  166. this.dbObj = Object.assign({}, db)
  167. this.editDialogVisible = true
  168. },
  169. handleCommand(cmd) {
  170. if (cmd.type === 'edit') {
  171. this.editDashboard(cmd.target)
  172. } else {
  173. this.deleteDashboard(cmd.target)
  174. }
  175. },
  176. // handleSubmit() {
  177. // if (this.dbObj.dashboard_id) {
  178. // updateDashboard(this.dbObj).then(resp => {
  179. // this.getList()
  180. // this.editDialogVisible = false
  181. // })
  182. // } else {
  183. // addDashboard(this.dbObj).then(resp => {
  184. // this.getList()
  185. // this.editDialogVisible = false
  186. // })
  187. // }
  188. // },
  189. handleSubmit() {
  190. if (this.dbObj.dashboard_id) {
  191. updateDashboard(this.dbObj).then(resp => {
  192. this.getList()
  193. this.editDialogVisible = false
  194. })
  195. } else {
  196. console.log('this.dbObj', this.dbObj)
  197. var data = {
  198. name: 'insertDashboard',
  199. parammaps: {
  200. dname: this.dbObj.name,
  201. display: this.dbObj.desc,
  202. pastureid: Cookies.get('pastureid'),
  203. empid: Cookies.get('employeid'),
  204. emp: Cookies.get('employename')
  205. }
  206. }
  207. PostDataByName(data).then(response => {
  208. console.log('新增保存发送参数', data)
  209. this.$message({
  210. type: 'success',
  211. message: this.$t('common.saveSuccess')
  212. })
  213. this.getList()
  214. this.editDialogVisible = false
  215. })
  216. // addDashboard(this.dbObj).then(resp => {
  217. // this.getList()
  218. // this.editDialogVisible = false
  219. // })
  220. }
  221. },
  222. handleOrderChange(evt) {
  223. const data = {
  224. order: this.dashboardList.map(item => item.dashboard_id)
  225. }
  226. dbOrder(data)
  227. },
  228. deleteDashboard(db) {
  229. this.$confirm(this.$t('dashboard.deleteConfirm', db.name), this.$t('common.confirm')).then(() => {
  230. deleteDashboard({ dashboard_id: db.dashboard_id }).then(() => {
  231. this.getList()
  232. this.$message({
  233. type: 'success',
  234. message: this.$t('common.deleteSuccess')
  235. })
  236. })
  237. })
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .container {
  244. display: flex;
  245. min-height: calc(100vh - 62px);
  246. align-items: stretch;
  247. .dashboard-list {
  248. width: 250px;
  249. min-height: 100%;
  250. padding: 20px 10px;
  251. /deep/ .el-card__header {
  252. div {
  253. display: flex;
  254. justify-content: space-between;
  255. font-size: 14px;
  256. color: #606266;
  257. i {
  258. cursor: pointer;
  259. }
  260. }
  261. padding: 5px 0px;
  262. }
  263. .dashboard-list-item {
  264. display: flex;
  265. justify-content: space-between;
  266. line-height: 35px;
  267. font-size: 14px;
  268. cursor: pointer;
  269. color: #606266;
  270. i {
  271. margin-right: 10px;
  272. line-height: 35px;
  273. }
  274. }
  275. .high-light-dashboard {
  276. color: #205cd8;
  277. }
  278. }
  279. .dashboard-wrapper {
  280. width: 100%;
  281. }
  282. }
  283. </style>