add.vue 11KB

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