756333ccd9a7c6236adbf5bf59fc7ea9018d1776.svn-base 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. did: ''
  79. }
  80. },
  81. created() {
  82. console.log('this.$route.params.id', this.$route.params.id)
  83. const isEdit = this.$route.params.isEdit
  84. this.isEdit = isEdit
  85. this.did = window.location.href.split('~')[1]
  86. this.getList()
  87. },
  88. methods: {
  89. // getList() {
  90. // this.loading = true
  91. // dashboardList().then(resp => {
  92. // this.loading = false
  93. // this.dashboardList = []
  94. // resp.data.order.forEach((id, index) => {
  95. // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
  96. // if (itemIndex >= 0) {
  97. // this.dashboardList.push(resp.data.dashboards[itemIndex])
  98. // resp.data.dashboards.splice(itemIndex, 1)
  99. // } else {
  100. // console.log(id, index)
  101. // }
  102. // })
  103. // this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
  104. // const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
  105. // if (dashboard) {
  106. // this.currentDashboard = dashboard
  107. // } else {
  108. // this.currentDashboard = this.dashboardList[0]
  109. // }
  110. // if (this.currentDashboard) {
  111. // this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`).catch(_ => { })
  112. // }
  113. // })
  114. // },
  115. getList() {
  116. this.loading = true
  117. if (this.$route.params.id) {
  118. this.did = this.$route.params.id
  119. } else {
  120. this.did = this.did
  121. }
  122. var send_data = {
  123. name: 'getdashboards',
  124. parammaps: {
  125. pastureid: Cookies.get('pastureid'),
  126. empid: Cookies.get('employeid'),
  127. did: this.did
  128. }
  129. }
  130. console.log('进入大页面=================')
  131. dashboardListJiade(send_data).then(resp => {
  132. this.loading = false
  133. this.dashboardList = []
  134. console.log('看板列表数据:', resp)
  135. console.log('看板列表优化数据list:', resp.data.list)
  136. console.log('看板列表优化数据dashboards:', resp.data.dashboards)
  137. // resp.data.order.forEach((id, index) => {
  138. // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
  139. // if (itemIndex >= 0) {
  140. // this.dashboardList.push(resp.data.dashboards[itemIndex])
  141. // resp.data.dashboards.splice(itemIndex, 1)
  142. // } else {
  143. // console.log(id, index)
  144. // }
  145. // })
  146. this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
  147. const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
  148. if (dashboard) {
  149. this.currentDashboard = dashboard
  150. } else {
  151. this.currentDashboard = this.dashboardList[0]
  152. }
  153. console.log('this.currentDashboard', this.currentDashboard)
  154. console.log('this.dashboardList', this.dashboardList)
  155. if (this.currentDashboard) {
  156. // this.$router.push({ path: '/customboard/addboard', query: { id: this.currentDashboard.dashboard_id }}).catch(_ => { })
  157. }
  158. })
  159. },
  160. switchDb(db) {
  161. if (db.dashboard_id === this.currentDashboard.dashboard_id) {
  162. this.getList()
  163. return
  164. }
  165. this.currentDashboard = db
  166. this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`)
  167. },
  168. addDashboard() {
  169. this.dbObj = {}
  170. this.editDialogVisible = true
  171. },
  172. editDashboard(db) {
  173. this.dbObj = Object.assign({}, db)
  174. this.editDialogVisible = true
  175. },
  176. handleCommand(cmd) {
  177. if (cmd.type === 'edit') {
  178. this.editDashboard(cmd.target)
  179. } else {
  180. this.deleteDashboard(cmd.target)
  181. }
  182. },
  183. // handleSubmit() {
  184. // if (this.dbObj.dashboard_id) {
  185. // updateDashboard(this.dbObj).then(resp => {
  186. // this.getList()
  187. // this.editDialogVisible = false
  188. // })
  189. // } else {
  190. // addDashboard(this.dbObj).then(resp => {
  191. // this.getList()
  192. // this.editDialogVisible = false
  193. // })
  194. // }
  195. // },
  196. handleSubmit() {
  197. if (this.dbObj.dashboard_id) {
  198. updateDashboard(this.dbObj).then(resp => {
  199. this.getList()
  200. this.editDialogVisible = false
  201. })
  202. } else {
  203. console.log('this.dbObj', this.dbObj)
  204. var data = {
  205. name: 'insertDashboard',
  206. parammaps: {
  207. dname: this.dbObj.name,
  208. display: this.dbObj.desc,
  209. pastureid: Cookies.get('pastureid'),
  210. empid: Cookies.get('employeid'),
  211. emp: Cookies.get('employename')
  212. }
  213. }
  214. PostDataByName(data).then(response => {
  215. console.log('新增保存发送参数', data)
  216. this.$message({
  217. type: 'success',
  218. message: this.$t('common.saveSuccess')
  219. })
  220. this.getList()
  221. this.editDialogVisible = false
  222. })
  223. // addDashboard(this.dbObj).then(resp => {
  224. // this.getList()
  225. // this.editDialogVisible = false
  226. // })
  227. }
  228. },
  229. handleOrderChange(evt) {
  230. const data = {
  231. order: this.dashboardList.map(item => item.dashboard_id)
  232. }
  233. dbOrder(data)
  234. },
  235. deleteDashboard(db) {
  236. this.$confirm(this.$t('dashboard.deleteConfirm', db.name), this.$t('common.confirm')).then(() => {
  237. deleteDashboard({ dashboard_id: db.dashboard_id }).then(() => {
  238. this.getList()
  239. this.$message({
  240. type: 'success',
  241. message: this.$t('common.deleteSuccess')
  242. })
  243. })
  244. })
  245. }
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .container {
  251. display: flex;
  252. min-height: calc(100vh - 62px);
  253. align-items: stretch;
  254. .dashboard-list {
  255. width: 250px;
  256. min-height: 100%;
  257. padding: 20px 10px;
  258. /deep/ .el-card__header {
  259. div {
  260. display: flex;
  261. justify-content: space-between;
  262. font-size: 14px;
  263. color: #606266;
  264. i {
  265. cursor: pointer;
  266. }
  267. }
  268. padding: 5px 0px;
  269. }
  270. .dashboard-list-item {
  271. display: flex;
  272. justify-content: space-between;
  273. line-height: 35px;
  274. font-size: 14px;
  275. cursor: pointer;
  276. color: #606266;
  277. i {
  278. margin-right: 10px;
  279. line-height: 35px;
  280. }
  281. }
  282. .high-light-dashboard {
  283. color: #205cd8;
  284. }
  285. }
  286. .dashboard-wrapper {
  287. width: 100%;
  288. }
  289. }
  290. </style>