edit.vue 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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 v-model="cardInfo.CaseId" placeholder="请选择" @change="caseChange">
  10. <el-option
  11. v-for="item in cases"
  12. :key="item.CaseId"
  13. :label="item.CaseName"
  14. :value="item.CaseId">
  15. </el-option>
  16. </el-select>
  17. </div>
  18. </div>
  19. </li>
  20. <li class="flex-h">
  21. <span>卡图片:<em>*</em></span>
  22. <div class="flex-item">
  23. <div>
  24. <el-upload
  25. class="avatar-uploader"
  26. action='string'
  27. :http-request="toolClass.upload"
  28. :show-file-list="false"
  29. :on-success="handleAvatarSuccess">
  30. <img v-if="cardInfo.Images" :src="cardInfo.Images[0].CardImageUrl" class="avatar">
  31. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  32. </el-upload>
  33. </div>
  34. </div>
  35. </li>
  36. <li class="flex-h">
  37. <span>卡名称:<em>*</em></span>
  38. <div class="flex-item">
  39. <div style="width:200px;">
  40. <el-input
  41. placeholder="请输入"
  42. v-model="cardInfo.CardName"
  43. clearable>
  44. </el-input>
  45. </div>
  46. </div>
  47. </li>
  48. <li class="flex-h">
  49. <span>卡价格:<em>*</em></span>
  50. <div class="flex-item">
  51. <div style="width:200px;">
  52. <el-input
  53. placeholder="请输入"
  54. v-model="cardInfo.Price"
  55. clearable>
  56. </el-input>
  57. </div>
  58. </div>
  59. </li>
  60. <li class="flex-h">
  61. <span>总张数:<em>*</em></span>
  62. <div class="flex-item">
  63. <div style="width:200px;">
  64. <el-input
  65. placeholder="请输入"
  66. v-model="cardInfo.TotalCount"
  67. clearable>
  68. </el-input>
  69. </div>
  70. </div>
  71. </li>
  72. <li class="flex-h">
  73. <span>发送类型:<em>*</em></span>
  74. <div class="flex-item">
  75. <div>
  76. <el-radio v-model="cardInfo.SendType" label="channel">渠道</el-radio>
  77. <el-radio v-model="cardInfo.SendType" label="case">案场</el-radio>
  78. <el-radio v-model="cardInfo.SendType" label="system">系统</el-radio>
  79. </div>
  80. </div>
  81. </li>
  82. <li class="flex-h" v-if="cardInfo.SendType === 'channel'">
  83. <span>选择渠道:<em>*</em></span>
  84. <div class="flex-item">
  85. <div style="width:50%">
  86. <el-select v-model="cardInfo.ChannelId" placeholder="请选择">
  87. <el-option
  88. v-for="item in channelList"
  89. :key="item.ChannelId"
  90. :label="item.ChannelName"
  91. :value="item.ChannelId">
  92. </el-option>
  93. </el-select>
  94. </div>
  95. </div>
  96. </li>
  97. <li class="flex-h">
  98. <span>目标课程:<em>*</em></span>
  99. <div class="flex-item">
  100. <div>
  101. <el-select v-model="cardInfo.Targets[0].TargetId" placeholder="请选择">
  102. <el-option
  103. v-for="item in courseList"
  104. :key="item.CourseId"
  105. :label="item.CourseName"
  106. :value="item.CourseId"
  107. :disabled="item.Status !== 1">
  108. </el-option>
  109. </el-select>
  110. </div>
  111. </div>
  112. </li>
  113. <li class="flex-h">
  114. <span>卡有效时间:<em>*</em></span>
  115. <div class="flex-item">
  116. <div>
  117. <div class="addLine flex-h" style="align-item:center;margin-bottom:20px;">
  118. <el-date-picker
  119. v-model="date"
  120. type="daterange"
  121. range-separator="至"
  122. start-placeholder="开始日期"
  123. end-placeholder="结束日期"
  124. :picker-options="pickerOptions">
  125. </el-date-picker>
  126. </div>
  127. </div>
  128. </div>
  129. </li>
  130. <li class="flex-h" v-if="cardInfo.SendType !== 'case' && cardInfo.SendType !== 'system'">
  131. <span>视频:<em>*</em></span>
  132. <div class="flex-item">
  133. <div style="vertical-align: middle;">
  134. <a style="line-height: 40px;" v-if="videoOff" :href="cardInfo.VideoUrl" target="blank">{{cardInfo.VideoUrl}}</a>
  135. <el-upload
  136. class="avatar-uploader"
  137. action='string'
  138. :http-request="toolClass.upload"
  139. :show-file-list="false"
  140. :on-success="videoSuccess">
  141. <a style="line-height: 40px;padding: 0 10px;">{{videoOff ? '更换' : '添加'}}视频</a>
  142. </el-upload>
  143. <el-button v-if="videoOff" type="danger" @click="deleteVideo">删除视频</el-button>
  144. </div>
  145. </div>
  146. </li>
  147. <li class="flex-h">
  148. <span>分享描述:<em>*</em></span>
  149. <div class="flex-item">
  150. <div>
  151. <el-input
  152. type="textarea"
  153. :rows="2"
  154. placeholder="请输入"
  155. v-model="cardInfo.Share.CardShareInfo">
  156. </el-input>
  157. </div>
  158. </div>
  159. </li>
  160. <li class="flex-h">
  161. <span>规则描述:<em>*</em></span>
  162. <div class="flex-item">
  163. <div>
  164. <el-input
  165. type="textarea"
  166. :rows="2"
  167. placeholder="请输入"
  168. v-model="cardInfo.Share.CardUseRule">
  169. </el-input>
  170. </div>
  171. </div>
  172. </li>
  173. <li class="flex-h">
  174. <span>使用说明:<em>*</em></span>
  175. <div class="flex-item">
  176. <div>
  177. <el-input
  178. type="textarea"
  179. :rows="2"
  180. placeholder="请输入"
  181. v-model="cardInfo.Share.CardUseInstruction">
  182. </el-input>
  183. </div>
  184. </div>
  185. </li>
  186. <li style="text-align:center">
  187. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  188. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  189. </li>
  190. </ul>
  191. </form>
  192. </div>
  193. </template>
  194. <script>
  195. import { mapState, createNamespacedHelpers } from 'vuex'
  196. const { mapActions: mapCardActions } = createNamespacedHelpers('card')
  197. const { mapState: mapChannelState, mapActions: mapChannelActions } = createNamespacedHelpers('channel')
  198. const { mapActions: mapCourseActions } = createNamespacedHelpers('course')
  199. export default {
  200. name: '',
  201. data () {
  202. return {
  203. date: '',
  204. courseList: [],
  205. videoOff: false,
  206. total: 0,
  207. type: this.$route.query.type,
  208. isEdit: this.$route.query.id === undefined ? 0 : 1,
  209. ChannelList: [], // 渠道列表
  210. TypeList: [], // 类型列表
  211. GoodsList: [], // 商品列表
  212. currentList: [{
  213. Name: 'ccc',
  214. Type: 'xxx'
  215. }], // 指定商品数据
  216. cardInfo: {
  217. CardName: '',
  218. SendType: '',
  219. VideoUrl: '',
  220. Price: ' ',
  221. StartDate: '',
  222. EndDate: '',
  223. TotalCount: '',
  224. CaseId: '',
  225. OrgId: '',
  226. Share: {
  227. CardShareInfo: '',
  228. CardUseRule: '',
  229. CardUseInstruction: '',
  230. },
  231. Images: null,
  232. Targets: [{}],
  233. ChannelId: ''
  234. },
  235. postData: {
  236. page: 1,
  237. pagesize: 10,
  238. },
  239. }
  240. },
  241. mounted () {
  242. this.$nextTick(function () {
  243. this.GetChannelListList({
  244. caseid: this.defaultCaseId,
  245. page: 1,
  246. pagesize: 10000
  247. }).then(() => {
  248. this.GetCourseList({
  249. caseid: this.defaultCaseId,
  250. page: 1,
  251. pagesize: 10000
  252. }).then((res) => {
  253. this.courseList = res.list
  254. if (this.$route.query.id) {
  255. this.getCardById({
  256. id: this.$route.query.id
  257. }).then((res) => {
  258. // console.log(JSON.stringify(res.Card))
  259. this.cardInfo = res.Card
  260. if (res.Card.VideoUrl) {
  261. this.videoOff = true
  262. }
  263. if (res.Card.Images === null) {
  264. this.cardInfo.Images = [{
  265. CardImageUrl: ''
  266. }]
  267. }
  268. if (res.Card.StartDate) {
  269. this.date = [res.Card.StartDate, res.Card.EndDate]
  270. }
  271. })
  272. }
  273. })
  274. })
  275. })
  276. },
  277. computed: {
  278. ...mapChannelState({
  279. channelList: x => x.channelList,
  280. }),
  281. ...mapState({
  282. cases: x => x.app.cases.list,
  283. defaultCaseId: x => x.app.cases.default,
  284. OrgId: x => x.app.user.OrgId,
  285. }),
  286. pickerOptions () {
  287. const courseId = this.cardInfo.Targets[0].TargetId
  288. const couse = (this.courseList || []).filter(x => x.CourseId === courseId)[0] || {}
  289. const beginDate = new Date(couse.BeginDate).getTime()
  290. const endDate = new Date(couse.EndDate).getTime()
  291. return {
  292. disabledDate (time) {
  293. return time.getTime() < beginDate || time.getTime() > endDate
  294. }
  295. }
  296. },
  297. CaseId: {
  298. get () {
  299. return this.postData.caseid || this.defaultCaseId
  300. },
  301. set (val) {
  302. this.postData.caseid = val
  303. }
  304. }
  305. },
  306. methods: {
  307. ...mapCardActions([
  308. 'addCard',
  309. 'getCardById',
  310. 'editCard',
  311. ]),
  312. ...mapCourseActions([
  313. 'GetCourseList',
  314. ]),
  315. ...mapChannelActions([
  316. 'GetChannelListList',
  317. ]),
  318. caseChange () { // 选择案场
  319. this.GetChannelListList({
  320. caseid: this.cardInfo.CaseId,
  321. page: 1,
  322. pagesize: 10000
  323. })
  324. this.GetCourseList({
  325. caseid: this.cardInfo.CaseId,
  326. page: 1,
  327. pagesize: 10000
  328. }).then((res) => {
  329. this.courseList = res.list
  330. })
  331. this.cardInfo.Targets = [{
  332. TargetType: '',
  333. TargetId: '',
  334. TargetName: ''
  335. }]
  336. this.cardInfo.ChannelId = ''
  337. },
  338. deleteVideo () { // 删除视频
  339. this.cardInfo.VideoUrl = ''
  340. this.videoOff = false
  341. },
  342. videoSuccess (res, file) {
  343. this.videoOff = true
  344. this.cardInfo.VideoUrl = res.result.url
  345. },
  346. addGoods () { // 添加指定商品
  347. this.centerDialogVisible = true
  348. },
  349. checkInfo () { // 校验表单信息
  350. if (this.cardInfo.CaseId === '') {
  351. this.$message({
  352. type: 'error',
  353. message: '案场不能为空'
  354. })
  355. return false
  356. }
  357. if (this.cardInfo.Images === '') {
  358. this.$message({
  359. type: 'error',
  360. message: '卡图片不能为空'
  361. })
  362. return false
  363. }
  364. if (this.cardInfo.CardName === '') {
  365. this.$message({
  366. type: 'error',
  367. message: '卡名称不能为空'
  368. })
  369. return false
  370. }
  371. if (this.cardInfo.Price === '') {
  372. this.$message({
  373. type: 'error',
  374. message: '卡价格不能为空'
  375. })
  376. return false
  377. }
  378. if (this.cardInfo.TotalCount === '') {
  379. this.$message({
  380. type: 'error',
  381. message: '总张数不能为空'
  382. })
  383. return false
  384. }
  385. if (this.cardInfo.SendType === '') {
  386. this.$message({
  387. type: 'error',
  388. message: '发送类型不能为空'
  389. })
  390. return false
  391. }
  392. if (this.cardInfo.SendType === 'channel' && this.cardInfo.ChannelId === '') {
  393. this.$message({
  394. type: 'error',
  395. message: '渠道不能为空'
  396. })
  397. return false
  398. }
  399. if (this.cardInfo.Targets[0].TargetId === '') {
  400. this.$message({
  401. type: 'error',
  402. message: '目标课程不能为空'
  403. })
  404. return false
  405. }
  406. if (this.cardInfo.StartDate === '') {
  407. this.$message({
  408. type: 'error',
  409. message: '开始时间不能为空'
  410. })
  411. return false
  412. }
  413. if (this.cardInfo.EndDate === '') {
  414. this.$message({
  415. type: 'error',
  416. message: '截止时间不能为空'
  417. })
  418. return false
  419. }
  420. if (this.cardInfo.SendType === 'channel' && this.cardInfo.VideoUrl === '') {
  421. this.$message({
  422. type: 'error',
  423. message: '视频不能为空'
  424. })
  425. return false
  426. }
  427. if (this.cardInfo.Share.CardShareInfo === '') {
  428. this.$message({
  429. type: 'error',
  430. message: '分享描述不能为空'
  431. })
  432. return false
  433. }
  434. if (this.cardInfo.Share.CardUseRule === '') {
  435. this.$message({
  436. type: 'error',
  437. message: '使用规则不能为空'
  438. })
  439. return false
  440. }
  441. if (this.cardInfo.Share.CardUseInstruction === '') {
  442. this.$message({
  443. type: 'error',
  444. message: '使用说明不能为空'
  445. })
  446. return false
  447. }
  448. },
  449. submit () { // 保存
  450. if (!this.checkInfo()) {
  451. return false
  452. }
  453. if (this.$route.query.id) {
  454. if (this.date !== '') {
  455. this.cardInfo.StartDate = this.date[0]
  456. this.cardInfo.EndDate = this.date[1]
  457. }
  458. for (var x = 0; x < this.courseList.length; x++) {
  459. if (this.courseList[x].CourseId === this.cardInfo.Targets[0].TargetId) {
  460. this.cardInfo.Targets[0].TargetType = this.courseList[x].CourseType
  461. this.cardInfo.Targets[0].TargetName = this.courseList[x].CourseName
  462. }
  463. }
  464. this.cardInfo.TotalCount = this.cardInfo.TotalCount - 0
  465. this.editCard(this.cardInfo).then((res) => {
  466. this.$message({
  467. type: 'success',
  468. message: '操作成功'
  469. })
  470. this.$router.push({ name: 'cardList' })
  471. })
  472. } else {
  473. this.cardInfo.OrgId = this.OrgId
  474. if (this.date !== '') {
  475. this.cardInfo.StartDate = this.date[0]
  476. this.cardInfo.EndDate = this.date[1]
  477. }
  478. for (var n = 0; n < this.courseList.length; n++) {
  479. if (this.courseList[n].CourseId === this.cardInfo.Targets[0].TargetId) {
  480. this.cardInfo.Targets[0].TargetType = this.courseList[n].CourseType
  481. this.cardInfo.Targets[0].TargetName = this.courseList[n].CourseName
  482. }
  483. }
  484. this.cardInfo.TotalCount = this.cardInfo.TotalCount - 0
  485. // console.log(JSON.stringify(this.cardInfo))
  486. this.addCard(this.cardInfo).then((res) => {
  487. this.$message({
  488. type: 'success',
  489. message: '操作成功'
  490. })
  491. this.$router.push({ name: 'cardList' })
  492. })
  493. }
  494. },
  495. cancel () { // 取消
  496. this.$router.push({ name: 'couponList' })
  497. },
  498. handleAvatarSuccess (res, file) {
  499. if ((this.cardInfo.Images || []).length > 0) {
  500. this.cardInfo.Images[0].CardImageUrl = res.result.url
  501. } else {
  502. this.cardInfo.Images = [{
  503. CardImageUrl: res.result.url,
  504. }]
  505. }
  506. }
  507. }
  508. }
  509. </script>
  510. <!-- Add "scoped" attribute to limit CSS to this component only -->
  511. <style lang="scss" scoped>
  512. .addLine {
  513. > * {
  514. margin-right: 10px;
  515. }
  516. }
  517. .mainForm > ul > li > div > div > button {
  518. margin-top: 0;
  519. }
  520. </style>