edit.vue 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>对应案场:<em>*</em></span>
  7. <div class="flex-item">
  8. <div style="width:50%">
  9. <el-select :disabled="id && id !== ''" v-model="CaseId" placeholder="请选择" @change="caseChange">
  10. <el-option
  11. key="all"
  12. label="全部案场"
  13. value="all">
  14. </el-option>
  15. <el-option
  16. v-for="item in caseList"
  17. :key="item.CaseId"
  18. :label="item.CaseName"
  19. :value="item.CaseId">
  20. </el-option>
  21. </el-select>
  22. </div>
  23. </div>
  24. </li>
  25. <li class="flex-h">
  26. <span>名称:<em>*</em></span>
  27. <div class="flex-item">
  28. <div style="width:50%">
  29. <el-input
  30. placeholder="请输入名称"
  31. v-model="detail.Name"
  32. clearable>
  33. </el-input>
  34. </div>
  35. </div>
  36. </li>
  37. <li class="flex-h">
  38. <span>标题:</span>
  39. <div class="flex-item">
  40. <div style="width:50%">
  41. <el-input
  42. placeholder="请输入标题"
  43. v-model="detail.Title"
  44. clearable>
  45. </el-input>
  46. </div>
  47. </div>
  48. </li>
  49. <li class="flex-h">
  50. <span>图片:<em>*</em></span>
  51. <div class="flex-item">
  52. <el-upload
  53. class="avatar-uploader"
  54. action='string'
  55. :http-request="toolClass.upload"
  56. :show-file-list="false"
  57. :on-success="handleImgSuccess">
  58. <img v-if="imgShow" :src="imgShow" class="avatar">
  59. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  60. </el-upload>
  61. </div>
  62. </li>
  63. <li class="flex-h">
  64. <span>详细图片:<em>*</em></span>
  65. <div class="flex-item">
  66. <el-upload
  67. class="avatar-uploader"
  68. action='string'
  69. :http-request="toolClass.upload"
  70. :show-file-list="false"
  71. :on-success="handleDetailImgSuccess">
  72. <img v-if="detailImgShow" :src="detailImgShow" class="avatar">
  73. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  74. </el-upload>
  75. </div>
  76. </li>
  77. <li class="flex-h">
  78. <span>专题简介:<em>*</em></span>
  79. <div class="flex-item">
  80. <div style="width:50%">
  81. <el-input
  82. placeholder="请输入专题简介"
  83. v-model="detail.DetailContent"
  84. type='textarea'
  85. :autosize="{ minRows: 3, maxRows: 5}"
  86. clearable>
  87. </el-input>
  88. </div>
  89. </div>
  90. </li>
  91. <li class="flex-h">
  92. <span>展示课程:<em>*</em></span>
  93. <div class="flex-item">
  94. <div style="width:50%" class="radio">
  95. <el-radio v-model="detail.IsAllCourse" :label='1' >全部课程</el-radio>
  96. <el-radio v-model="detail.IsAllCourse" :label='0' >指定课程</el-radio>
  97. </div>
  98. </div>
  99. </li>
  100. <li class="flex-h" v-if="detail.IsAllCourse === 0">
  101. <el-table
  102. :data="detail.Courses"
  103. stripe
  104. style="width: 100%">
  105. <el-table-column
  106. prop="CourseName"
  107. label="课程名称">
  108. </el-table-column>
  109. <el-table-column
  110. prop="BeginDate"
  111. label="课程开始时间">
  112. <template slot-scope="scope">
  113. <label v-if="scope.row.BeginDate !== '0001-01-01T00:00:00Z'">{{toolClass.dateFormat(scope.row.BeginDate,'yyyy-MM-dd')}}</label>
  114. <label v-else>-</label>
  115. </template>
  116. </el-table-column>
  117. <el-table-column
  118. prop="EndDate"
  119. label="课程结束时间">
  120. <template slot-scope="scope">
  121. <label v-if="scope.row.EndDate !== '0001-01-01T00:00:00Z'">{{toolClass.dateFormat(scope.row.EndDate,'yyyy-MM-dd')}}</label>
  122. <label v-else>-</label>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="操作" width="450">
  126. <template slot-scope="scope">
  127. <el-button
  128. size="mini"
  129. type="danger"
  130. @click="deleteItem(scope.row)">删除</el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <el-button type="primary" size="mini" @click="coursesShow">新增</el-button>
  135. </li>
  136. <li class="flex-h">
  137. <span>是否前台展示:<em>*</em></span>
  138. <div class="flex-item">
  139. <div style="width:50%" class="radio">
  140. <el-radio v-model="detail.Status" :label='1' >是</el-radio>
  141. <el-radio v-model="detail.Status" :label='0' >否</el-radio>
  142. </div>
  143. </div>
  144. </li>
  145. <li style="text-align:center">
  146. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  147. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  148. </li>
  149. </ul>
  150. </form>
  151. <el-dialog
  152. title="选择课程"
  153. :visible.sync="selCourseVisible"
  154. width="500px"
  155. center>
  156. <div>
  157. <el-table
  158. ref="courseTable"
  159. :data="coursesList"
  160. tooltip-effect="dark"
  161. stripe
  162. @selection-change="handleSelectionChange"
  163. style="width: 100%">
  164. <el-table-column
  165. type="selection"
  166. width="55">
  167. </el-table-column>
  168. <el-table-column
  169. prop="CourseName"
  170. label="课程名称">
  171. </el-table-column>
  172. <el-table-column
  173. prop="BeginDate"
  174. label="课程开始时间">
  175. <template slot-scope="scope">
  176. <label v-if="scope.row.BeginDate !== '0001-01-01T00:00:00Z'">{{toolClass.dateFormat(scope.row.BeginDate,'yyyy-MM-dd')}}</label>
  177. <label v-else>-</label>
  178. </template>
  179. </el-table-column>
  180. <el-table-column
  181. prop="EndDate"
  182. label="课程结束时间">
  183. <template slot-scope="scope">
  184. <label v-if="scope.row.EndDate !== '0001-01-01T00:00:00Z'">{{toolClass.dateFormat(scope.row.EndDate,'yyyy-MM-dd')}}</label>
  185. <label v-else>-</label>
  186. </template>
  187. </el-table-column>
  188. </el-table>
  189. </div>
  190. <el-pagination
  191. @current-change="handleCurrentChange"
  192. :current-page.sync="postData.page"
  193. :page-size="postData.pagesize"
  194. layout="prev, pager, next, jumper"
  195. :total="total">
  196. </el-pagination>
  197. <span slot="footer" class="dialog-footer">
  198. <el-button @click="selCourseVisible = false">取 消</el-button>
  199. <el-button type="primary" @click="addCourseOk">确 定</el-button>
  200. </span>
  201. </el-dialog>
  202. </div>
  203. </template>
  204. <script>
  205. import { createNamespacedHelpers, mapState } from 'vuex'
  206. const { mapState: mapCaseState, mapActions: mapCaseActions } = createNamespacedHelpers('cmscase')
  207. const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')
  208. export default {
  209. name: '',
  210. data () {
  211. return {
  212. id: '',
  213. limit: 1,
  214. // imgs: null,
  215. // detailimgs: null,
  216. img: '',
  217. detailimg: '',
  218. selCourseVisible: false,
  219. selCourseList: [],
  220. postData: {
  221. page: 1,
  222. pagesize: 6
  223. },
  224. total: 0,
  225. }
  226. },
  227. components: {},
  228. computed: {
  229. ...mapState({
  230. caseList: x => x.app.cases.list,
  231. defaultCaseId: x => x.app.cases.default,
  232. OrgId: x => x.app.user.OrgId
  233. }),
  234. ...mapCaseState({
  235. detail: x => x.caseInfo,
  236. }),
  237. ...mapCourseState({
  238. courses: x => x.courseList,
  239. }),
  240. CaseId: {
  241. get () {
  242. return this.detail.CaseId || this.caseid
  243. },
  244. set (val) {
  245. this.UpdateInfo({ ...this.detail, CaseId: val })
  246. this.getCourse()
  247. }
  248. },
  249. imgShow () {
  250. return this.img || ((this.detail.CmsCaseImgs || []).filter(x => x.ImageType === 'cover')[0] || {}).CaseImageUrl
  251. },
  252. detailImgShow () {
  253. return this.detailimg || ((this.detail.CmsCaseImgs || []).filter(x => x.ImageType === 'detail')[0] || {}).CaseImageUrl
  254. },
  255. coursesList () {
  256. return (this.courses.list || []).map(x => {
  257. return {
  258. CourseId: x.CourseId,
  259. CourseName: x.CourseName,
  260. BeginDate: x.BeginDate,
  261. EndDate: x.BeginDate
  262. }
  263. })
  264. },
  265. },
  266. methods: {
  267. ...mapCaseActions([
  268. 'GetCaseInfo',
  269. 'AddCaseInfo',
  270. 'SetNull',
  271. 'UpdateInfo',
  272. ]),
  273. ...mapCourseActions([
  274. 'GetCourseList',
  275. ]),
  276. caseChange () {
  277. this.selCourseList = []
  278. this.detail.Courses = []
  279. },
  280. checkFn (arr) {
  281. for (var n = 0; n < arr.length; n++) {
  282. if (arr[n].type === 'isNull' && !arr[n].target) {
  283. this.$message({
  284. message: arr[n].errorMsg,
  285. type: 'error'
  286. })
  287. return false
  288. }
  289. }
  290. return true
  291. },
  292. handleCurrentChange (val) {
  293. this.postData.page = val
  294. this.getCourse()
  295. },
  296. submit () {
  297. var checkOff = this.checkFn([{
  298. target: Boolean(this.CaseId || ''),
  299. errorMsg: '对应案场不能为空',
  300. type: 'isNull'
  301. }, {
  302. target: Boolean(this.detail.Name || ''),
  303. errorMsg: '名称不能为空',
  304. type: 'isNull'
  305. }, {
  306. target: Boolean(this.imgShow || ''),
  307. errorMsg: '图片不能为空',
  308. type: 'isNull'
  309. }, {
  310. target: Boolean(this.detailImgShow || ''),
  311. errorMsg: '详细图片不能为空',
  312. type: 'isNull'
  313. }, {
  314. target: Boolean(this.detail.DetailContent || ''),
  315. errorMsg: '专题简介不能为空',
  316. type: 'isNull'
  317. }, {
  318. target: Boolean(String(this.detail.IsAllCourse) || ''),
  319. errorMsg: '展示课程不能为空',
  320. type: 'isNull'
  321. }, {
  322. target: Boolean(String(this.detail.Status) || ''),
  323. errorMsg: '是否前台展示不能为空',
  324. type: 'isNull'
  325. }])
  326. if (!checkOff) {
  327. return false
  328. }
  329. if (this.detail.IsAllCourse === 0 && !this.detail.Courses.length) {
  330. this.$message({
  331. message: '选择指定课程不能为空',
  332. type: 'error'
  333. })
  334. return false
  335. }
  336. const courseids = (this.detail.Courses || []).map(x => x.CourseId).join(',')
  337. if (this.id === '') {
  338. this.detail.OrgId = this.OrgId
  339. // console.log(JSON.stringify({ ...this.detail, OrgId: this.OrgId, imgs: this.imgShow, detailimgs: this.detailImgShow, courseids }))
  340. this.AddCaseInfo({ ...this.detail, OrgId: this.OrgId, imgs: this.imgShow, detailimgs: this.detailImgShow, courseids }).then((res) => {
  341. this.afterSave()
  342. })
  343. } else {
  344. // console.log(JSON.stringify({ ...this.detail, OrgId: this.OrgId, imgs: this.imgShow, detailimgs: this.detailImgShow, courseids }))
  345. this.AddCaseInfo({ ...this.detail, imgs: this.imgShow, detailimgs: this.detailImgShow, courseids }).then((res) => {
  346. this.afterSave()
  347. })
  348. }
  349. },
  350. afterSave () {
  351. this.$message({
  352. message: '保存成功',
  353. type: 'success',
  354. duration: 1000
  355. })
  356. this.$router.push({ name: 'indexCase' })
  357. },
  358. cancel () {
  359. this.$router.go(-1)
  360. },
  361. getDetail () {
  362. this.GetCaseInfo({ id: this.id })
  363. },
  364. getCourse () {
  365. this.GetCourseList({ caseid: this.CaseId === 'all' ? '' : this.CaseId, ...this.postData }).then((res) => {
  366. this.postData.page = res.page
  367. this.total = res.pagenum
  368. })
  369. },
  370. toggleSelection (rows) {
  371. if (rows) {
  372. rows.forEach(row => {
  373. this.$refs.courseTable.toggleRowSelection(row)
  374. })
  375. } else {
  376. this.$refs.courseTable.clearSelection()
  377. }
  378. },
  379. addCourse () {
  380. this.GetCourseList({ caseid: this.CaseId === 'all' ? '' : this.CaseId, page: 1, pagesize: 100, callback: this.coursesShow })
  381. },
  382. coursesShow () {
  383. this.selCourseList = this.detail.Courses || []
  384. this.selCourseVisible = true
  385. setTimeout(() => {
  386. this.toggleSelection(this.coursesList.filter(x => (this.selCourseList || []).filter(y => y.CourseId === x.CourseId).length > 0))
  387. }, 30)
  388. },
  389. handleSelectionChange (val) {
  390. this.selCourseList = val
  391. },
  392. addCourseOk () {
  393. this.UpdateInfo({ ...this.detail, Courses: this.selCourseList })
  394. this.selCourseVisible = false
  395. },
  396. deleteItem (row) {
  397. this.UpdateInfo({ ...this.detail, Courses: this.detail.Courses.filter(x => x.CourseId !== row.CourseId) })
  398. },
  399. handleImgSuccess (res, file) {
  400. this.img = res.result.url
  401. },
  402. handleDetailImgSuccess (res, file) {
  403. this.detailimg = res.result.url
  404. }
  405. },
  406. mounted () {
  407. this.getCourse()
  408. const { id } = this.$route.query
  409. this.id = id
  410. if (id && id !== '') {
  411. this.getDetail()
  412. } else {
  413. this.SetNull()
  414. }
  415. }
  416. }
  417. </script>
  418. <!-- Add "scoped" attribute to limit CSS to this component only -->
  419. <style lang="scss" scoped>
  420. </style>