3d5c2ea73c784ad35d19b67fd6e0c0d0ed6ffe8e.svn-base 9.6 KB

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