index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <c-table
  9. :curr="options"
  10. @pagination="getList"
  11. >
  12. <template #header>
  13. <div class="l-flex__auto c-sibling-item">
  14. <button
  15. class="o-button"
  16. @click="onAdd"
  17. >
  18. <i class="o-button__icon el-icon-circle-plus-outline" />
  19. 新增
  20. </button>
  21. </div>
  22. <el-select
  23. v-model="options.params.resolutionRatio"
  24. class="l-flex__none c-sibling-item o-select"
  25. placeholder="请选择分辨率"
  26. :loading="fetching"
  27. @change="search"
  28. @visible-change="getRatios"
  29. >
  30. <el-option
  31. v-for="item in resolutionRatios"
  32. :key="item.label"
  33. :label="item.label"
  34. :value="item.value"
  35. />
  36. </el-select>
  37. <el-select
  38. v-model="options.params.status"
  39. class="l-flex__none c-sibling-item o-select"
  40. placeholder="请选择状态"
  41. @change="search"
  42. >
  43. <el-option
  44. v-for="item in statusOptions"
  45. :key="item.label"
  46. :label="item.label"
  47. :value="item.value"
  48. />
  49. </el-select>
  50. <search-input
  51. v-model.trim="options.params.name"
  52. class="l-flex__none c-sibling-item"
  53. placeholder="名称"
  54. @search="search"
  55. />
  56. <button
  57. class="l-flex__none c-sibling-item o-button"
  58. @click="search"
  59. >
  60. 搜索
  61. </button>
  62. </template>
  63. <el-table-column
  64. prop="name"
  65. label="名称"
  66. align="center"
  67. show-overflow-tooltip
  68. />
  69. <el-table-column
  70. prop="resolutionRatio"
  71. label="分辨率"
  72. align="center"
  73. show-overflow-tooltip
  74. />
  75. <el-table-column
  76. label="审核状态"
  77. align="center"
  78. min-width="100"
  79. >
  80. <template v-slot="scope">
  81. <el-tag
  82. v-if="scope.row.status === 1"
  83. class="o-tag u-readonly"
  84. type="warning"
  85. size="medium"
  86. >
  87. 未审核
  88. </el-tag>
  89. <el-tag
  90. v-else-if="scope.row.status === 2"
  91. class="o-tag u-readonly"
  92. type="success"
  93. size="medium"
  94. >
  95. 已审核
  96. </el-tag>
  97. <el-tag
  98. v-else
  99. class="o-tag u-readonly"
  100. size="medium"
  101. >
  102. 待提交
  103. </el-tag>
  104. </template>
  105. </el-table-column>
  106. <el-table-column
  107. prop="createTime"
  108. label="创建时间"
  109. align="center"
  110. show-overflow-tooltip
  111. />
  112. <el-table-column
  113. label="操作"
  114. align="center"
  115. width="180"
  116. >
  117. <template v-slot="scope">
  118. <template v-if="scope.row.status === 0">
  119. <div
  120. class="c-table__btn u-pointer"
  121. @click="onDesign(scope.row.id)"
  122. >
  123. 编辑
  124. </div>
  125. <div
  126. class="c-table__btn u-pointer"
  127. @click="onSubmit(scope.row)"
  128. >
  129. 提交
  130. </div>
  131. </template>
  132. <template v-else>
  133. <div
  134. class="c-table__btn u-pointer"
  135. @click="onView(scope.row.id)"
  136. >
  137. 预览
  138. </div>
  139. <div
  140. class="c-table__btn u-pointer"
  141. @click="onCopy(scope.row)"
  142. >
  143. 复制
  144. </div>
  145. </template>
  146. <permission
  147. :skip="scope.row.status === 0"
  148. :access="Access.DELETE_FORCE"
  149. >
  150. <div
  151. class="c-table__btn u-pointer"
  152. @click="onDel(scope.row)"
  153. >
  154. 删除
  155. </div>
  156. </permission>
  157. </template>
  158. </el-table-column>
  159. </c-table>
  160. <el-dialog
  161. title="新增"
  162. :visible.sync="adding"
  163. custom-class="c-dialog"
  164. :close-on-click-modal="false"
  165. >
  166. <div class="c-form">
  167. <div class="c-form__section">
  168. <span class="c-form__label">名称:</span>
  169. <el-input
  170. v-model.trim="schedule.name"
  171. class="c-form__item"
  172. placeholder="请输入名称"
  173. maxlength="50"
  174. show-word-limit
  175. />
  176. </div>
  177. <div class="c-form__section">
  178. <span class="c-form__label">分辨率:</span>
  179. <el-select
  180. v-model="schedule.resolutionRatio"
  181. class="c-form__item"
  182. placeholder="请选择"
  183. popper-class="o-select-option"
  184. :loading="fetching"
  185. >
  186. <el-option
  187. v-for="ratio in ratios"
  188. :key="ratio.value"
  189. :label="ratio.label"
  190. :value="ratio.value"
  191. />
  192. </el-select>
  193. </div>
  194. </div>
  195. <template #footer>
  196. <button
  197. class="o-button"
  198. @click="add"
  199. >
  200. 确定
  201. </button>
  202. <button
  203. class="o-button cancel"
  204. @click="onCloseAddDialog"
  205. >
  206. 取消
  207. </button>
  208. </template>
  209. </el-dialog>
  210. <el-dialog
  211. :visible.sync="isPreviewing"
  212. custom-class="c-preview schedule"
  213. :before-close="onCloseScheduleDialog"
  214. >
  215. <schedule
  216. v-if="scheduleId"
  217. class="l-flex__auto has-padding"
  218. :schedule="scheduleId"
  219. />
  220. </el-dialog>
  221. <el-dialog
  222. title="复制"
  223. :visible.sync="copying"
  224. custom-class="c-dialog mini"
  225. :close-on-click-modal="false"
  226. :before-close="onCloseCopyDialog"
  227. >
  228. <div class="c-form">
  229. <div class="c-form__section">
  230. <span class="c-form__label auto">名称:</span>
  231. <el-input
  232. v-model.trim="copySchedule.name"
  233. class="c-form__item"
  234. placeholder="请输入名称"
  235. maxlength="50"
  236. show-word-limit
  237. />
  238. </div>
  239. </div>
  240. <template #footer>
  241. <button
  242. class="o-button"
  243. @click="copy"
  244. >
  245. 确定
  246. </button>
  247. <button
  248. class="o-button cancel"
  249. @click="onCloseCopyDialog"
  250. >
  251. 取消
  252. </button>
  253. </template>
  254. </el-dialog>
  255. </wrapper>
  256. </template>
  257. <script>
  258. import { getRatios } from '@/api/device'
  259. import {
  260. getSchedules,
  261. addSchedule,
  262. deleteSchedule,
  263. submitSchedule,
  264. copySchedule
  265. } from '@/api/calendar'
  266. import { State } from '@/constant'
  267. import { createListOptions } from '@/utils'
  268. export default {
  269. name: 'ScheduleList',
  270. data () {
  271. return {
  272. statusOptions: [
  273. { value: void 0, label: '全部状态' },
  274. { value: State.READY, label: '待提交' },
  275. { value: State.SUBMITTED, label: '未审核' },
  276. { value: State.RESOLVED, label: '已审核' }
  277. ],
  278. options: createListOptions({
  279. type: this.$route.meta.info.type,
  280. status: void 0,
  281. resolutionRatio: void 0,
  282. name: ''
  283. }),
  284. adding: false,
  285. schedule: {},
  286. scheduleId: null,
  287. fetching: false,
  288. ratios: [],
  289. isPreviewing: false,
  290. copying: false,
  291. copySchedule: {
  292. id: null,
  293. name: ''
  294. }
  295. }
  296. },
  297. computed: {
  298. resolutionRatios () {
  299. return [{ value: void 0, label: '全部分辨率' }].concat(this.ratios.map(({ value }) => {
  300. return { value, label: value }
  301. }))
  302. }
  303. },
  304. created () {
  305. this.getList()
  306. },
  307. activated () {
  308. if (this.$route.params.refresh) {
  309. const status = this.options.params.status
  310. if (status !== void 0) {
  311. this.options.params.status = void 0
  312. }
  313. this.search()
  314. }
  315. },
  316. methods: {
  317. search () {
  318. const options = this.options
  319. options.list = []
  320. options.totalCount = 0
  321. options.params.pageNum = 1
  322. this.getList()
  323. },
  324. getList () {
  325. const options = this.options
  326. if (!options.loading) {
  327. options.error = false
  328. options.loading = true
  329. getSchedules(options.params).then(({ data, totalCount }) => {
  330. options.list = data
  331. options.totalCount = totalCount
  332. }, () => {
  333. options.error = true
  334. options.list = []
  335. }).finally(() => {
  336. options.loading = false
  337. })
  338. }
  339. },
  340. getRatios () {
  341. if (!this.fetching && this.ratios.length === 0) {
  342. this.fetching = true
  343. getRatios().then(ratios => {
  344. this.ratios = ratios
  345. }).finally(() => {
  346. this.fetching = false
  347. })
  348. }
  349. },
  350. onAdd () {
  351. this.schedule = {
  352. type: this.$route.meta.info.type,
  353. name: '',
  354. resolutionRatio: ''
  355. }
  356. this.adding = true
  357. this.getRatios()
  358. },
  359. onCloseAddDialog () {
  360. this.adding = false
  361. },
  362. add () {
  363. if (!this.schedule.name) {
  364. this.$message({
  365. type: 'warning',
  366. message: '名称不能为空'
  367. })
  368. return
  369. }
  370. if (!this.schedule.resolutionRatio) {
  371. this.$message({
  372. type: 'warning',
  373. message: '请选择分辨率'
  374. })
  375. return
  376. }
  377. addSchedule(this.schedule).then(({ data: id }) => {
  378. this.onCloseAddDialog()
  379. const params = this.options.params
  380. if (params.status && params.status !== State.READY) {
  381. params.status = void 0
  382. }
  383. if (params.name && !(new RegExp(params.name).test(this.schedule.name))) {
  384. params.name = ''
  385. }
  386. this.search()
  387. this.onDesign(id)
  388. })
  389. },
  390. onView (id) {
  391. this.scheduleId = id
  392. this.isPreviewing = true
  393. },
  394. onCloseScheduleDialog () {
  395. this.scheduleId = null
  396. this.isPreviewing = false
  397. },
  398. onDesign (id) {
  399. this.$router.push({
  400. name: this.$route.meta.info.design,
  401. params: { id: `${id}` }
  402. })
  403. },
  404. onSubmit (item) {
  405. submitSchedule(item).then(() => {
  406. this.search()
  407. })
  408. },
  409. onDel (item) {
  410. deleteSchedule(item).then(() => {
  411. const options = this.options
  412. if (options.list.length === 1 && options.params.pageNum > 1) {
  413. options.params.pageNum -= 1
  414. }
  415. this.getList()
  416. })
  417. },
  418. onCopy ({ id, name }) {
  419. this.copySchedule = { id, name }
  420. this.copying = true
  421. },
  422. copy () {
  423. const { id, name } = this.copySchedule
  424. copySchedule({ id }, name).then(() => {
  425. this.onCloseCopyDialog()
  426. const params = this.options.params
  427. if (params.status !== void 0 && params.status !== State.READY) {
  428. params.status = void 0
  429. }
  430. if (params.name && !(new RegExp(params.name).test(name))) {
  431. params.name = ''
  432. }
  433. this.search()
  434. })
  435. },
  436. onCloseCopyDialog () {
  437. this.copying = false
  438. }
  439. }
  440. }
  441. </script>