123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>课程主图:</span>
  7. <div class="flex-item">
  8. <div>
  9. <el-upload
  10. class="avatar-uploader"
  11. action='string'
  12. :http-request="toolClass.upload"
  13. :show-file-list="false"
  14. :on-success="handleAvatarSuccess">
  15. <img v-if="detail.CourseImg" :src="detail.CourseImg" class="avatar">
  16. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  17. </el-upload>
  18. </div>
  19. </div>
  20. </li>
  21. <li class="flex-h">
  22. <span>课程名称:</span>
  23. <div class="flex-item">
  24. <div style="width: 50%;">
  25. <el-input
  26. placeholder="请输入课程名称"
  27. v-model="detail.CourseName"
  28. clearable
  29. >
  30. </el-input>
  31. </div>
  32. </div>
  33. </li>
  34. <li class="flex-h">
  35. <span>课程类型:</span>
  36. <div class="flex-item">
  37. <div style="width: 50%;">
  38. <el-select v-model="detail.LocationId" placeholder="请选择">
  39. <el-option
  40. v-for="item in location"
  41. :key="item.LocationId"
  42. :label="item.LocationName"
  43. :value="item.LocationId">
  44. </el-option>
  45. </el-select>
  46. </div>
  47. </div>
  48. </li>
  49. <li class="flex-h">
  50. <span>课程价格:</span>
  51. <div class="flex-item">
  52. <div style="width: 200px;">
  53. <el-input
  54. placeholder="请输入课程价格"
  55. v-model="detail.Price"
  56. clearable
  57. >
  58. </el-input>
  59. </div>
  60. </div>
  61. </li>
  62. <li class="flex-h">
  63. <span>案场:</span>
  64. <div class="flex-item">
  65. <div style="width: 50%;">
  66. <el-select v-model="CaseId" placeholder="请选择">
  67. <el-option
  68. v-for="item in cases"
  69. :key="item.CaseId"
  70. :label="item.CaseName"
  71. :value="item.CaseId">
  72. </el-option>
  73. </el-select>
  74. </div>
  75. </div>
  76. </li>
  77. <li class="flex-h">
  78. <span>开课人数:</span>
  79. <div class="flex-item">
  80. <div style="width: 200px;">
  81. <el-input
  82. placeholder="请输入开课人数"
  83. v-model="detail.MaxNum"
  84. clearable
  85. >
  86. </el-input>
  87. </div>
  88. </div>
  89. </li>
  90. <li class="flex-h">
  91. <span>最小开课人数:</span>
  92. <div class="flex-item">
  93. <div style="width: 200px;">
  94. <el-input
  95. placeholder="请输入开课人数"
  96. v-model="detail.MinNum"
  97. clearable
  98. >
  99. </el-input>
  100. </div>
  101. </div>
  102. </li>
  103. <li class="flex-h">
  104. <span>课时数:</span>
  105. <div class="flex-item">
  106. <div style="width: 200px;">
  107. <el-input
  108. placeholder="请输入课时数"
  109. v-model="detail.CourseNum"
  110. clearable
  111. >
  112. </el-input>
  113. </div>
  114. </div>
  115. </li>
  116. <li class="flex-h">
  117. <span>课程时间:</span>
  118. <div class="flex-item">
  119. <div>
  120. <el-date-picker
  121. v-model="courseDate"
  122. type="daterange"
  123. align="right"
  124. unlink-panels
  125. range-separator="至"
  126. start-placeholder="开始日期"
  127. end-placeholder="结束日期"
  128. value-format="yyyy-MM-ddTHH:mm:ss"
  129. :picker-options="pickerOptions">
  130. </el-date-picker>
  131. </div>
  132. </div>
  133. </li>
  134. <li class="flex-h">
  135. <span>课程计划备注:</span>
  136. <div class="flex-item">
  137. <div style="width: 50%;">
  138. <el-input
  139. type="textarea"
  140. autosize
  141. placeholder="请输入备注"
  142. v-model="detail.Remark"
  143. clearable
  144. >
  145. </el-input>
  146. </div>
  147. </div>
  148. </li>
  149. <li class="flex-h">
  150. <span>课程标签:</span>
  151. <div class="flex-item">
  152. <div style="width: 50%;">
  153. <el-select
  154. style="width:100%"
  155. v-model="tags"
  156. multiple
  157. filterable
  158. allow-create
  159. default-first-option
  160. placeholder="请选择课程标签">
  161. <el-option
  162. v-for="item in tagList.list"
  163. :key="item.TagId"
  164. :label="item.TagName"
  165. :value="item.TagId"
  166. :value-key="item.TagId"
  167. >
  168. </el-option>
  169. </el-select>
  170. </div>
  171. </div>
  172. </li>
  173. <li class="flex-h">
  174. <span>课程简介:</span>
  175. <div class="flex-item">
  176. <div style="width: 50%;">
  177. <el-input
  178. type="textarea"
  179. autosize
  180. placeholder="请输入课程简介"
  181. v-model="detail.CourseDesc"
  182. clearable
  183. >
  184. </el-input>
  185. </div>
  186. </div>
  187. </li>
  188. <li class="flex-h">
  189. <span>是否精选课程:</span>
  190. <div class="flex-item">
  191. <div>
  192. <el-radio v-model="detail.IsSelect" :label="1">是</el-radio>
  193. <el-radio v-model="detail.IsSelect" :label="0">否</el-radio>
  194. </div>
  195. </div>
  196. </li>
  197. <li style="text-align:center">
  198. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  199. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  200. </li>
  201. </ul>
  202. </form>
  203. </div>
  204. </template>
  205. <script>
  206. import { createNamespacedHelpers, mapState } from 'vuex'
  207. const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')
  208. const { mapState: mapLocationState, mapActions: mapLocationActions } = createNamespacedHelpers('cms')
  209. const { mapState: mapTagState, mapActions: mapTagActions } = createNamespacedHelpers('coursetag')
  210. export default {
  211. name: '',
  212. data () {
  213. return {
  214. pickerOptions: {
  215. shortcuts: [{
  216. text: '最近一周',
  217. onClick (picker) {
  218. const end = new Date()
  219. const start = new Date()
  220. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  221. picker.$emit('pick', [start, end])
  222. }
  223. }, {
  224. text: '最近一个月',
  225. onClick (picker) {
  226. const end = new Date()
  227. const start = new Date()
  228. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  229. picker.$emit('pick', [start, end])
  230. }
  231. }, {
  232. text: '最近三个月',
  233. onClick (picker) {
  234. const end = new Date()
  235. const start = new Date()
  236. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  237. picker.$emit('pick', [start, end])
  238. }
  239. }]
  240. },
  241. }
  242. },
  243. computed: {
  244. ...mapLocationState({
  245. location: x => x.location
  246. }),
  247. ...mapCourseState({
  248. detail: x => x.courseInfo
  249. }),
  250. ...mapState({
  251. cases: x => x.app.cases.list,
  252. caseid: x => x.app.cases.default,
  253. orgid: x => x.app.user.OrgId,
  254. }),
  255. ...mapTagState({
  256. tagList: x => x.tagList
  257. }),
  258. CaseId: {
  259. get () {
  260. return this.detail.CaseId || this.caseid
  261. },
  262. set (val) {
  263. this.UpdateInfo({ ...this.detail, CaseId: val })
  264. }
  265. },
  266. courseDate: {
  267. get () {
  268. return this.detail.BeginDate && this.detail.EndDate ? [this.detail.BeginDate, this.detail.EndDate] : []
  269. },
  270. set (val) {
  271. this.UpdateInfo({ ...this.detail, BeginDate: val[0], EndDate: val[1] })
  272. },
  273. },
  274. tags: {
  275. get () {
  276. return (this.detail.CourseTags || []).map(x => x.TagId)
  277. },
  278. set (val) {
  279. let v = val.map(x => {
  280. return {
  281. TagId: x,
  282. }
  283. })
  284. this.UpdateInfo({ ...this.detail, CourseTags: v })
  285. }
  286. },
  287. },
  288. components: {},
  289. methods: {
  290. ...mapCourseActions([
  291. 'GetCourseByID',
  292. 'AddCourse',
  293. 'UpdateCourse',
  294. 'UpdateInfo',
  295. ]),
  296. ...mapLocationActions([
  297. 'updateLocationInfo',
  298. ]),
  299. ...mapTagActions([
  300. 'GetCourseTagList',
  301. ]),
  302. handleAvatarSuccess (res, file) {
  303. this.UpdateInfo({ ...this.detail, CourseImg: res.result.url })
  304. },
  305. upLoad (item) {
  306. this.toolClass.upload(item).then((res) => { this.handleAvatarSuccess(res, item.file) })
  307. },
  308. submit () { // 提交数据
  309. const { id } = this.$route.query
  310. if (!id || id === '') {
  311. this.UpdateInfo({ ...this.detail, CourseId: '' })
  312. }
  313. const _that = this
  314. this.detail.tagids = this.tags.map(x => {
  315. let tagfilter = (_that.tagList.list || []).filter(tag => tag.TagId === x)
  316. if (tagfilter.length > 0) {
  317. return tagfilter[0].TagName + ':' + tagfilter[0].TagId
  318. } else {
  319. return x
  320. }
  321. }).join(',')
  322. if ((this.detail.CourseId || '') === '') {
  323. this.detail.OrgId = this.orgid
  324. if (!this.detail.CaseId || this.detail.CaseId === '') {
  325. this.detail.CaseId = this.caseid
  326. }
  327. this.AddCourse({ ...this.detail, callback: _that.afterSave })
  328. } else {
  329. this.UpdateCourse({ ...this.detail, callback: _that.afterSave })
  330. }
  331. },
  332. afterSave () {
  333. this.$message({
  334. type: 'success',
  335. message: '操作成功'
  336. })
  337. this.$router.push({ name: 'courseList' })
  338. },
  339. cancel () {
  340. this.$router.push({ name: 'courseList' })
  341. }
  342. },
  343. mounted () {
  344. this.updateLocationInfo(false)
  345. this.GetCourseTagList({ pagesize: 100 })
  346. const { id } = this.$route.query
  347. if (id && id !== '') {
  348. this.GetCourseByID({ id: id })
  349. } else {
  350. // this.SetNull()
  351. }
  352. }
  353. }
  354. </script>
  355. <!-- Add "scoped" attribute to limit CSS to this component only -->
  356. <style lang="scss" scoped>
  357. </style>