edit.vue 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. </el-date-picker>
  125. </div>
  126. </div>
  127. </div>
  128. </li>
  129. <li class="flex-h" v-if="cardInfo.SendType !== 'case' && cardInfo.SendType !== 'system'">
  130. <span>视频:<em>*</em></span>
  131. <div class="flex-item">
  132. <div style="vertical-align: middle;">
  133. <a style="line-height: 40px;" v-if="videoOff" :href="cardInfo.VideoUrl" target="blank">{{cardInfo.VideoUrl}}</a>
  134. <el-upload
  135. class="avatar-uploader"
  136. action='string'
  137. :http-request="toolClass.upload"
  138. :show-file-list="false"
  139. :on-success="videoSuccess">
  140. <a style="line-height: 40px;padding: 0 10px;">{{videoOff ? '更换' : '添加'}}视频</a>
  141. </el-upload>
  142. <el-button v-if="videoOff" type="danger" @click="deleteVideo">删除视频</el-button>
  143. </div>
  144. </div>
  145. </li>
  146. <li class="flex-h">
  147. <span>分享描述:<em>*</em></span>
  148. <div class="flex-item">
  149. <div>
  150. <el-input
  151. type="textarea"
  152. :rows="2"
  153. placeholder="请输入"
  154. v-model="cardInfo.Share.CardShareInfo">
  155. </el-input>
  156. </div>
  157. </div>
  158. </li>
  159. <li class="flex-h">
  160. <span>规则描述:<em>*</em></span>
  161. <div class="flex-item">
  162. <div>
  163. <el-input
  164. type="textarea"
  165. :rows="2"
  166. placeholder="请输入"
  167. v-model="cardInfo.Share.CardUseRule">
  168. </el-input>
  169. </div>
  170. </div>
  171. </li>
  172. <li class="flex-h">
  173. <span>使用说明:<em>*</em></span>
  174. <div class="flex-item">
  175. <div>
  176. <el-input
  177. type="textarea"
  178. :rows="2"
  179. placeholder="请输入"
  180. v-model="cardInfo.Share.CardUseInstruction">
  181. </el-input>
  182. </div>
  183. </div>
  184. </li>
  185. <li style="text-align:center">
  186. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  187. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  188. </li>
  189. </ul>
  190. </form>
  191. </div>
  192. </template>
  193. <script>
  194. import { mapState, createNamespacedHelpers } from 'vuex'
  195. const { mapActions: mapCardActions } = createNamespacedHelpers('card')
  196. const { mapState: mapChannelState, mapActions: mapChannelActions } = createNamespacedHelpers('channel')
  197. const { mapActions: mapCourseActions } = createNamespacedHelpers('course')
  198. export default {
  199. name: '',
  200. data () {
  201. return {
  202. date: '',
  203. courseList: [],
  204. videoOff: false,
  205. total: 0,
  206. type: this.$route.query.type,
  207. isEdit: this.$route.query.id === undefined ? 0 : 1,
  208. ChannelList: [], // 渠道列表
  209. TypeList: [], // 类型列表
  210. GoodsList: [], // 商品列表
  211. currentList: [{
  212. Name: 'ccc',
  213. Type: 'xxx'
  214. }], // 指定商品数据
  215. cardInfo: {
  216. CardName: '',
  217. SendType: '',
  218. VideoUrl: '',
  219. Price: ' ',
  220. StartDate: '',
  221. EndDate: '',
  222. TotalCount: '',
  223. CaseId: '',
  224. OrgId: '',
  225. Share: {
  226. CardShareInfo: '',
  227. CardUseRule: '',
  228. CardUseInstruction: '',
  229. },
  230. Images: null,
  231. Targets: [{}],
  232. ChannelId: ''
  233. },
  234. postData: {
  235. page: 1,
  236. pagesize: 10,
  237. },
  238. }
  239. },
  240. mounted () {
  241. this.$nextTick(function () {
  242. this.GetChannelListList({
  243. caseid: this.defaultCaseId,
  244. page: 1,
  245. pagesize: 10000
  246. }).then(() => {
  247. this.getCourseLister({
  248. caseid: this.defaultCaseId,
  249. page: 1,
  250. pagesize: 10000
  251. }).then((res) => {
  252. this.courseList = res.list
  253. if (this.$route.query.id) {
  254. this.getCardById({
  255. id: this.$route.query.id
  256. }).then((res) => {
  257. // console.log(JSON.stringify(res.Card))
  258. this.cardInfo = res.Card
  259. if (res.Card.VideoUrl) {
  260. this.videoOff = true
  261. }
  262. if (res.Card.Images === null) {
  263. this.cardInfo.Images = [{
  264. CardImageUrl: ''
  265. }]
  266. }
  267. if (res.Card.StartDate) {
  268. this.date = [res.Card.StartDate, res.Card.EndDate]
  269. }
  270. })
  271. }
  272. })
  273. })
  274. })
  275. },
  276. computed: {
  277. ...mapChannelState({
  278. channelList: x => x.channelList,
  279. }),
  280. ...mapState({
  281. cases: x => x.app.cases.list,
  282. defaultCaseId: x => x.app.cases.default,
  283. OrgId: x => x.app.user.OrgId,
  284. }),
  285. CaseId: {
  286. get () {
  287. return this.postData.caseid || this.defaultCaseId
  288. },
  289. set (val) {
  290. this.postData.caseid = val
  291. }
  292. }
  293. },
  294. methods: {
  295. ...mapCardActions([
  296. 'addCard',
  297. 'getCardById',
  298. 'editCard',
  299. ]),
  300. ...mapCourseActions([
  301. 'getCourseLister',
  302. ]),
  303. ...mapChannelActions([
  304. 'GetChannelListList',
  305. ]),
  306. caseChange () { // 选择案场
  307. this.GetChannelListList({
  308. caseid: this.cardInfo.CaseId,
  309. page: 1,
  310. pagesize: 10000
  311. })
  312. this.getCourseLister({
  313. caseid: this.cardInfo.CaseId,
  314. page: 1,
  315. pagesize: 10000
  316. }).then((res) => {
  317. this.courseList = res.list
  318. })
  319. this.cardInfo.Targets = [{
  320. TargetType: '',
  321. TargetId: '',
  322. TargetName: ''
  323. }]
  324. this.cardInfo.ChannelId = ''
  325. },
  326. deleteVideo () { // 删除视频
  327. this.cardInfo.VideoUrl = ''
  328. this.videoOff = false
  329. },
  330. videoSuccess (res, file) {
  331. this.videoOff = true
  332. this.cardInfo.VideoUrl = res.result.url
  333. },
  334. addGoods () { // 添加指定商品
  335. this.centerDialogVisible = true
  336. },
  337. checkInfo () { // 校验表单信息
  338. if (this.cardInfo.CaseId === '') {
  339. this.$message({
  340. type: 'error',
  341. message: '案场不能为空'
  342. })
  343. return false
  344. }
  345. if (this.cardInfo.Images === '') {
  346. this.$message({
  347. type: 'error',
  348. message: '卡图片不能为空'
  349. })
  350. return false
  351. }
  352. if (this.cardInfo.CardName === '') {
  353. this.$message({
  354. type: 'error',
  355. message: '卡名称不能为空'
  356. })
  357. return false
  358. }
  359. if (this.cardInfo.Price === '') {
  360. this.$message({
  361. type: 'error',
  362. message: '卡价格不能为空'
  363. })
  364. return false
  365. }
  366. if (this.cardInfo.TotalCount === '') {
  367. this.$message({
  368. type: 'error',
  369. message: '总张数不能为空'
  370. })
  371. return false
  372. }
  373. if (this.cardInfo.SendType === '') {
  374. this.$message({
  375. type: 'error',
  376. message: '发送类型不能为空'
  377. })
  378. return false
  379. }
  380. if (this.cardInfo.SendType === 'channel' && this.cardInfo.ChannelId === '') {
  381. this.$message({
  382. type: 'error',
  383. message: '渠道不能为空'
  384. })
  385. return false
  386. }
  387. if (this.cardInfo.Targets[0].TargetId === '') {
  388. this.$message({
  389. type: 'error',
  390. message: '目标课程不能为空'
  391. })
  392. return false
  393. }
  394. if (this.cardInfo.StartDate === '') {
  395. this.$message({
  396. type: 'error',
  397. message: '开始时间不能为空'
  398. })
  399. return false
  400. }
  401. if (this.cardInfo.EndDate === '') {
  402. this.$message({
  403. type: 'error',
  404. message: '截止时间不能为空'
  405. })
  406. return false
  407. }
  408. if (this.cardInfo.SendType === 'channel' && this.cardInfo.VideoUrl === '') {
  409. this.$message({
  410. type: 'error',
  411. message: '视频不能为空'
  412. })
  413. return false
  414. }
  415. if (this.cardInfo.Share.CardShareInfo === '') {
  416. this.$message({
  417. type: 'error',
  418. message: '分享描述不能为空'
  419. })
  420. return false
  421. }
  422. if (this.cardInfo.Share.CardUseRule === '') {
  423. this.$message({
  424. type: 'error',
  425. message: '使用规则不能为空'
  426. })
  427. return false
  428. }
  429. if (this.cardInfo.Share.CardUseInstruction === '') {
  430. this.$message({
  431. type: 'error',
  432. message: '使用说明不能为空'
  433. })
  434. return false
  435. }
  436. return true
  437. },
  438. submit () { // 保存
  439. if (this.$route.query.id) {
  440. if (this.date !== '') {
  441. this.cardInfo.StartDate = this.date[0]
  442. this.cardInfo.EndDate = this.date[1]
  443. }
  444. this.courseList = this.courseList || []
  445. for (var x = 0; x < this.courseList.length; x++) {
  446. if (this.courseList[x].CourseId === this.cardInfo.Targets[0].TargetId) {
  447. this.cardInfo.Targets[0].TargetType = this.courseList[x].CourseType
  448. this.cardInfo.Targets[0].TargetName = this.courseList[x].CourseName
  449. }
  450. }
  451. this.cardInfo.TotalCount = this.cardInfo.TotalCount - 0
  452. if (!this.checkInfo()) {
  453. return false
  454. }
  455. this.editCard(this.cardInfo).then((res) => {
  456. this.$message({
  457. type: 'success',
  458. message: '操作成功'
  459. })
  460. this.$router.push({ name: 'cardList' })
  461. })
  462. } else {
  463. this.cardInfo.OrgId = this.OrgId
  464. if (this.date !== '') {
  465. this.cardInfo.StartDate = this.date[0]
  466. this.cardInfo.EndDate = this.date[1]
  467. }
  468. this.courseList = this.courseList || []
  469. for (var n = 0; n < this.courseList.length; n++) {
  470. if (this.courseList[n].CourseId === this.cardInfo.Targets[0].TargetId) {
  471. this.cardInfo.Targets[0].TargetType = this.courseList[n].CourseType
  472. this.cardInfo.Targets[0].TargetName = this.courseList[n].CourseName
  473. }
  474. }
  475. this.cardInfo.TotalCount = this.cardInfo.TotalCount - 0
  476. if (!this.checkInfo()) {
  477. return false
  478. }
  479. this.addCard(this.cardInfo).then((res) => {
  480. this.$message({
  481. type: 'success',
  482. message: '操作成功'
  483. })
  484. this.$router.push({ name: 'cardList' })
  485. })
  486. }
  487. },
  488. cancel () { // 取消
  489. this.$router.push({ name: 'cardList' })
  490. },
  491. handleAvatarSuccess (res, file) {
  492. if ((this.cardInfo.Images || []).length > 0) {
  493. this.cardInfo.Images[0].CardImageUrl = res.result.url
  494. } else {
  495. this.cardInfo.Images = [{
  496. CardImageUrl: res.result.url,
  497. }]
  498. }
  499. }
  500. }
  501. }
  502. </script>
  503. <!-- Add "scoped" attribute to limit CSS to this component only -->
  504. <style lang="scss" scoped>
  505. .addLine {
  506. > * {
  507. margin-right: 10px;
  508. }
  509. }
  510. .mainForm > ul > li > div > div > button {
  511. margin-top: 0;
  512. }
  513. </style>