123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <!-- <h1 style="font-size:22px;">{{isEdit === 0 ? '新建' : '编辑'}}{{couponInfo.CouponType === 'goods' ? '饮品优惠券' : '课程优惠券'}}</h1> -->
  5. <ul>
  6. <li class="flex-h">
  7. <span>选择案场:</span>
  8. <div class="flex-item">
  9. <div style="width:50%">
  10. <el-select v-model="couponInfo.CaseId" placeholder="请选择" @change="caseChange">
  11. <el-option
  12. v-for="item in cases"
  13. :key="item.CaseId"
  14. :label="item.CaseName"
  15. :value="item.CaseId">
  16. </el-option>
  17. </el-select>
  18. </div>
  19. </div>
  20. </li>
  21. <li class="flex-h">
  22. <span>券图片:</span>
  23. <div class="flex-item">
  24. <div>
  25. <el-upload
  26. class="avatar-uploader"
  27. action='string'
  28. :http-request="toolClass.upload"
  29. :show-file-list="false"
  30. :on-success="handleAvatarSuccess">
  31. <img v-if="couponInfo.Images[0].CouponImageUrl" :src="couponInfo.Images[0].CouponImageUrl" class="avatar">
  32. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  33. </el-upload>
  34. </div>
  35. </div>
  36. </li>
  37. <li class="flex-h">
  38. <span>券名称:</span>
  39. <div class="flex-item">
  40. <div style="width:200px;">
  41. <el-input
  42. placeholder="请输入"
  43. v-model="couponInfo.CouponName"
  44. clearable>
  45. </el-input>
  46. </div>
  47. </div>
  48. </li>
  49. <li class="flex-h">
  50. <span>券类型:</span>
  51. <div class="flex-item">
  52. <div style="width:50%">
  53. <el-select v-model="couponInfo.CouponType" placeholder="请选择" @change="couponTypeChange">
  54. <el-option
  55. v-for="item in TypeList"
  56. :key="item.id"
  57. :label="item.value"
  58. :value="item.id">
  59. </el-option>
  60. </el-select>
  61. </div>
  62. </div>
  63. </li>
  64. <li class="flex-h">
  65. <span>券价格:</span>
  66. <div class="flex-item">
  67. <div style="width:200px;">
  68. <el-input
  69. placeholder="请输入"
  70. v-model="couponInfo.Price"
  71. clearable>
  72. </el-input>
  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="couponInfo.TotalCount"
  83. clearable>
  84. </el-input>
  85. </div>
  86. </div>
  87. </li>
  88. <li class="flex-h">
  89. <span>发送类型:</span>
  90. <div class="flex-item">
  91. <div>
  92. <el-radio v-model="couponInfo.SendType" label="channel">渠道</el-radio>
  93. <el-radio v-if="couponInfo.CouponType === 'course'" v-model="couponInfo.SendType" label="case">案场</el-radio>
  94. <el-radio v-model="couponInfo.SendType" label="system">系统</el-radio>
  95. </div>
  96. </div>
  97. </li>
  98. <li class="flex-h" v-if="couponInfo.SendType === 'channel'">
  99. <span>选择渠道:</span>
  100. <div class="flex-item">
  101. <div style="width:50%">
  102. <el-select v-model="couponInfo.ChannelId" placeholder="请选择">
  103. <el-option
  104. v-for="item in channelList"
  105. :key="item.ChannelId"
  106. :label="item.ChannelName"
  107. :value="item.ChannelId">
  108. </el-option>
  109. </el-select>
  110. </div>
  111. </div>
  112. </li>
  113. <li class="flex-h">
  114. <span>目标商品:</span>
  115. <div class="flex-item">
  116. <div>
  117. <el-radio v-model="couponInfo.IsAll" label="1">全部商品</el-radio>
  118. <el-radio v-model="couponInfo.IsAll" label="0">指定商品</el-radio>
  119. </div>
  120. </div>
  121. </li>
  122. <li class="flex-h" v-if="couponInfo.IsAll === '0'">
  123. <div class="flex-item">
  124. <div style="border: 1px solid #eee;">
  125. <el-table
  126. :data="couponInfo.Targets"
  127. stripe
  128. style="width: 100%">
  129. <el-table-column
  130. prop="TargetName"
  131. label="商品">
  132. </el-table-column>
  133. <el-table-column
  134. prop="TargetType"
  135. label="分类">
  136. <template slot-scope="scope">
  137. {{returnGoodsType(scope.row.TargetType)}}
  138. </template>
  139. </el-table-column>
  140. <el-table-column label="操作">
  141. <template slot-scope="scope">
  142. <el-button
  143. size="mini"
  144. type="warning"
  145. @click="deleteGoodsItem(scope.$index, scope.row)">删除</el-button>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. <div style="text-align:center;padding:10px 0;">
  150. <el-button type="success" size="mini" @click="addGoods">添加商品</el-button>
  151. </div>
  152. </div>
  153. </div>
  154. </li>
  155. <li class="flex-h" v-if="couponInfo.CouponType === 'goods'">
  156. <span>券有效时间:</span>
  157. <div class="flex-item">
  158. <div>
  159. <div class="addLine flex-h" style="align-item:center;margin-bottom:20px;">
  160. <el-radio v-model="postData.TimeType" label="1">固定时间</el-radio>
  161. <el-date-picker
  162. v-model="couponInfo.StartDate"
  163. type="date"
  164. placeholder="选择起始日期">
  165. </el-date-picker>
  166. <span style="line-height:40px;">至</span>
  167. <el-date-picker
  168. v-model="couponInfo.EndDate"
  169. type="date"
  170. placeholder="选择截止日期">
  171. </el-date-picker>
  172. </div>
  173. <div class="addLine flex-h" style="align-item:center;">
  174. <el-radio v-model="postData.TimeType" label="2">领取后</el-radio>
  175. <span style="width:100px;">
  176. <el-input
  177. placeholder="请输入"
  178. v-model="couponInfo.ValidDays"
  179. clearable>
  180. </el-input>
  181. </span>
  182. <span style="line-height:40px;">天</span>
  183. </div>
  184. </div>
  185. </div>
  186. </li>
  187. <li class="flex-h" v-if="couponInfo.CouponType === 'course'">
  188. <span>券有效时间:</span>
  189. <div class="flex-item">
  190. <div>
  191. <el-date-picker
  192. v-model="couponInfo.StartDate"
  193. type="date"
  194. placeholder="选择起始日期">
  195. </el-date-picker>
  196. <span style="line-height:40px;">至</span>
  197. <el-date-picker
  198. v-model="couponInfo.EndDate"
  199. type="date"
  200. placeholder="选择截止日期">
  201. </el-date-picker>
  202. </div>
  203. </div>
  204. </li>
  205. <li class="flex-h">
  206. <span>视频:</span>
  207. <div class="flex-item">
  208. <div style="vertical-align: middle;">
  209. <a style="line-height: 40px;" v-if="videoOff" :href="couponInfo.VideoUrl" target="blank">{{couponInfo.VideoUrl}}</a>
  210. <el-upload
  211. class="avatar-uploader"
  212. action='string'
  213. :http-request="toolClass.upload"
  214. :show-file-list="false"
  215. :on-success="videoSuccess">
  216. <a style="line-height: 40px;padding: 0 10px;">{{videoOff ? '更换' : '添加'}}视频</a>
  217. </el-upload>
  218. <el-button v-if="videoOff" type="danger" @click="deleteVideo">删除视频</el-button>
  219. </div>
  220. </div>
  221. </li>
  222. <li class="flex-h">
  223. <span>分享描述:</span>
  224. <div class="flex-item">
  225. <div>
  226. <el-input
  227. type="textarea"
  228. :rows="2"
  229. placeholder="请输入"
  230. v-model="couponInfo.Share.CouponShareInfo">
  231. </el-input>
  232. </div>
  233. </div>
  234. </li>
  235. <li class="flex-h">
  236. <span>规则描述:</span>
  237. <div class="flex-item">
  238. <div>
  239. <el-input
  240. type="textarea"
  241. :rows="2"
  242. placeholder="请输入"
  243. v-model="couponInfo.Share.UseRule">
  244. </el-input>
  245. </div>
  246. </div>
  247. </li>
  248. <li class="flex-h">
  249. <span>使用说明:</span>
  250. <div class="flex-item">
  251. <div>
  252. <el-input
  253. type="textarea"
  254. :rows="2"
  255. placeholder="请输入"
  256. v-model="couponInfo.Share.UseInstruction">
  257. </el-input>
  258. </div>
  259. </div>
  260. </li>
  261. <li style="text-align:center">
  262. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  263. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  264. </li>
  265. </ul>
  266. </form>
  267. <el-dialog
  268. title="选择指定商品"
  269. :visible.sync="centerDialogVisible"
  270. width="650px"
  271. center>
  272. <div>
  273. <div v-if="couponInfo.CouponType === 'goods'">
  274. <el-table
  275. ref="multipleTable"
  276. :data="goodsList.list"
  277. tooltip-effect="dark"
  278. style="width: 100%"
  279. @selection-change="handleGoodsChange">
  280. <el-table-column
  281. type="selection">
  282. </el-table-column>
  283. <el-table-column
  284. prop="GoodsName"
  285. label="商品名称">
  286. </el-table-column>
  287. <el-table-column
  288. prop="TypeId"
  289. label="类别">
  290. <template slot-scope="scope">
  291. <span>{{returnGoodsType(scope.row.TypeId)}}</span>
  292. </template>
  293. </el-table-column>
  294. <el-table-column
  295. prop="Price"
  296. label="价格">
  297. </el-table-column>
  298. </el-table>
  299. <el-pagination
  300. @current-change="handleCurrentChange"
  301. :current-page.sync="postData.page"
  302. :page-size="postData.pagesize"
  303. layout="prev, pager, next, jumper"
  304. :total="total">
  305. </el-pagination>
  306. </div>
  307. <div v-if="couponInfo.CouponType === 'course'">
  308. <el-table
  309. ref="multipleTable"
  310. :data="courseList.list"
  311. tooltip-effect="dark"
  312. style="width: 100%"
  313. @selection-change="handleCourseChange">
  314. <el-table-column
  315. type="selection">
  316. </el-table-column>
  317. <el-table-column
  318. prop="CourseName"
  319. label="商品名称">
  320. </el-table-column>
  321. <el-table-column
  322. prop="BeginDate"
  323. label="开始时间">
  324. </el-table-column>
  325. <el-table-column
  326. prop="EndDate"
  327. label="结束时间">
  328. </el-table-column>
  329. <el-table-column
  330. prop="CourseType"
  331. label="类别">
  332. </el-table-column>
  333. <el-table-column
  334. prop="Price"
  335. label="价格">
  336. </el-table-column>
  337. </el-table>
  338. <el-pagination
  339. @current-change="handleCurrentChange"
  340. :current-page.sync="postData.page"
  341. :page-size="postData.pagesize"
  342. layout="prev, pager, next, jumper"
  343. :total="total">
  344. </el-pagination>
  345. </div>
  346. </div>
  347. <span slot="footer" class="dialog-footer">
  348. <el-button @click="centerDialogVisible = false">取 消</el-button>
  349. <el-button type="primary" @click="sureAddItem">确 定</el-button>
  350. </span>
  351. </el-dialog>
  352. </div>
  353. </template>
  354. <script>
  355. import { mapState, createNamespacedHelpers } from 'vuex'
  356. const { mapActions: mapCouponActions } = createNamespacedHelpers('coupon')
  357. const { mapState: mapChannelState, mapActions: mapChannelActions } = createNamespacedHelpers('channel')
  358. const { mapState: mapGoodsState, mapActions: mapGoodsActions } = createNamespacedHelpers('goods')
  359. const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')
  360. export default {
  361. name: '',
  362. data () {
  363. return {
  364. videoOff: false,
  365. total: 0,
  366. centerDialogVisible: false,
  367. type: this.$route.query.type || '', // goods、course
  368. isEdit: this.$route.query.id === undefined ? 0 : 1,
  369. ChannelList: [], // 渠道列表
  370. TypeList: [{ // 类型列表
  371. value: '商品券',
  372. id: 'goods'
  373. }, {
  374. value: '课程券',
  375. id: 'course'
  376. }],
  377. currentList: [{
  378. Name: 'ccc',
  379. Type: 'xxx'
  380. }], // 指定商品数据
  381. couponInfo: {
  382. CaseId: '',
  383. CouponName: '',
  384. CouponType: '',
  385. Price: '',
  386. TotalCount: '',
  387. SendType: '',
  388. IsAll: '',
  389. StartDate: '',
  390. EndDate: '',
  391. ValidDays: '',
  392. VideoUrl: '',
  393. ChannelId: '',
  394. Images: [{
  395. CouponImageUrl: ''
  396. }],
  397. Share: {
  398. CouponShareInfo: '',
  399. UseRule: '',
  400. UseInstruction: ''
  401. },
  402. Targets: []
  403. },
  404. postData: {
  405. page: 1,
  406. pagesize: 6,
  407. },
  408. currentSelectArr: [],
  409. }
  410. },
  411. mounted () {
  412. this.$nextTick(function () {
  413. this.GetChannelListList({
  414. caseid: this.defaultCaseId,
  415. page: 1,
  416. pagesize: 10000
  417. }).then(() => {
  418. this.GetGoodTypes({ pagesize: 1000, caseid: this.$route.query.caseid }).then(() => {
  419. if (this.$route.query.id) {
  420. this.getCouponById({
  421. id: this.$route.query.id
  422. }).then((res) => {
  423. // console.log(JSON.stringify(res))
  424. res.coupon.IsAll = String(res.coupon.IsAll)
  425. if (res.coupon.VideoUrl !== '') {
  426. this.videoOff = true
  427. }
  428. this.couponInfo = res.coupon
  429. })
  430. }
  431. })
  432. })
  433. })
  434. },
  435. computed: {
  436. ...mapState({
  437. cases: x => x.app.cases.list,
  438. defaultCaseId: x => x.app.cases.default
  439. }),
  440. ...mapChannelState({
  441. channelList: x => x.channelList,
  442. }),
  443. ...mapGoodsState({
  444. goodsList: x => x.goodsList,
  445. goodsTypes: x => x.goodsTypes.list,
  446. }),
  447. ...mapCourseState({
  448. courseList: x => x.courseList,
  449. }),
  450. CaseId: {
  451. get () {
  452. return this.couponInfo.caseid || this.defaultCaseId
  453. },
  454. set (val) {
  455. this.couponInfo.caseid = val
  456. }
  457. },
  458. },
  459. methods: {
  460. ...mapGoodsActions([
  461. 'GetGoodsList',
  462. 'GetGoodTypes',
  463. ]),
  464. ...mapCouponActions([
  465. 'addCoupon',
  466. 'getCouponById',
  467. 'editCoupon',
  468. ]),
  469. ...mapChannelActions([
  470. 'GetChannelListList',
  471. ]),
  472. ...mapCourseActions([
  473. 'GetCourseList',
  474. ]),
  475. returnGoodsType (val) {
  476. for (var n = 0; n < this.goodsTypes.length; n++) {
  477. if (this.goodsTypes[n].TypeId === val) {
  478. return this.goodsTypes[n].TypeName
  479. }
  480. }
  481. },
  482. deleteVideo () { // 删除视频
  483. this.couponInfo.VideoUrl = ''
  484. this.videoOff = false
  485. },
  486. caseChange () { // 选择案场
  487. this.couponInfo.ChannelId = ''
  488. this.GetChannelListList({
  489. caseid: this.couponInfo.CaseId,
  490. page: 1,
  491. pagesize: 10000
  492. })
  493. },
  494. sureAddItem () { // 确定添加指定商品
  495. var bool = true
  496. if (this.couponInfo.CouponType === 'goods') {
  497. for (var n = 0; n < this.currentSelectArr.length; n++) {
  498. if (this.couponInfo.Targets.length) {
  499. bool = true
  500. for (var a = 0; a < this.couponInfo.Targets.length; a++) {
  501. if (this.currentSelectArr[n].GoodsId === this.couponInfo.Targets[a].TargetId) {
  502. bool = false
  503. }
  504. }
  505. if (bool) {
  506. this.couponInfo.Targets.push({
  507. TargetName: this.currentSelectArr[n].GoodsName,
  508. TargetId: this.currentSelectArr[n].GoodsId,
  509. TargetType: this.currentSelectArr[n].TypeId
  510. })
  511. }
  512. } else {
  513. this.couponInfo.Targets.push({
  514. TargetName: this.currentSelectArr[n].GoodsName,
  515. TargetId: this.currentSelectArr[n].GoodsId,
  516. TargetType: this.currentSelectArr[n].TypeId
  517. })
  518. }
  519. }
  520. } else if (this.couponInfo.CouponType === 'course') {
  521. for (var x = 0; x < this.currentSelectArr.length; x++) {
  522. if (this.couponInfo.Targets.length) {
  523. bool = true
  524. for (var y = 0; y < this.couponInfo.Targets.length; y++) {
  525. if (this.currentSelectArr[x].CourseId === this.couponInfo.Targets[y].TargetId) {
  526. bool = false
  527. }
  528. }
  529. if (bool) {
  530. this.couponInfo.Targets.push({
  531. TargetName: this.currentSelectArr[x].CourseName,
  532. TargetId: this.currentSelectArr[x].CourseId,
  533. TargetType: this.currentSelectArr[x].CourseType
  534. })
  535. }
  536. } else {
  537. this.couponInfo.Targets.push({
  538. TargetName: this.currentSelectArr[x].CourseName,
  539. TargetId: this.currentSelectArr[x].CourseId,
  540. TargetType: this.currentSelectArr[x].CourseType
  541. })
  542. }
  543. }
  544. }
  545. this.centerDialogVisible = false
  546. },
  547. handleGoodsChange (val) {
  548. this.currentSelectArr = val
  549. },
  550. handleCourseChange (val) {
  551. this.currentSelectArr = val
  552. },
  553. couponTypeChange () {
  554. if (this.goodsList.length) {
  555. this.goodsList = []
  556. }
  557. if (this.courseList.length) {
  558. this.courseList = []
  559. }
  560. this.couponInfo.Targets = []
  561. },
  562. addGoods () { // 添加指定商品
  563. if (this.couponInfo.CouponType === 'goods') {
  564. this.GetGoodsList({
  565. ...this.postData,
  566. caseid: this.couponInfo.CaseId
  567. }).then((res) => {
  568. this.total = res.pagenum
  569. this.centerDialogVisible = true
  570. })
  571. } else if (this.couponInfo.CouponType === 'course') {
  572. this.GetCourseList({
  573. ...this.postData,
  574. caseid: this.couponInfo.CaseId
  575. }).then((res) => {
  576. this.total = res.pagenum
  577. this.centerDialogVisible = true
  578. })
  579. }
  580. },
  581. submit () { // 保存
  582. if (this.$route.query.id) {
  583. this.editCoupon({
  584. ...this.couponInfo,
  585. IsAll: this.couponInfo.IsAll - 0,
  586. TotalCount: this.couponInfo.TotalCount - 0,
  587. ValidDays: this.couponInfo.ValidDays || 0
  588. }).then((res) => {
  589. this.$alert('操作成功', '提示', {
  590. confirmButtonText: '确定',
  591. callback: action => {
  592. this.$router.push({ name: 'couponList' })
  593. }
  594. })
  595. })
  596. } else {
  597. this.addCoupon({
  598. ...this.couponInfo,
  599. IsAll: this.couponInfo.IsAll - 0,
  600. TotalCount: this.couponInfo.TotalCount - 0,
  601. ValidDays: this.couponInfo.ValidDays || 0
  602. }).then((res) => {
  603. this.$alert('操作成功', '提示', {
  604. confirmButtonText: '确定',
  605. callback: action => {
  606. this.$router.push({ name: 'couponList' })
  607. }
  608. })
  609. })
  610. }
  611. },
  612. cancel () { // 取消
  613. this.$router.push({ name: 'couponList' })
  614. },
  615. deleteGoodsItem (index, row) { // 删除指定商品item
  616. this.couponInfo.Targets.splice(index, 1)
  617. },
  618. handleAvatarSuccess (res, file) {
  619. this.couponInfo.Images[0].CouponImageUrl = res.result.url
  620. },
  621. videoSuccess (res, file) {
  622. this.videoOff = true
  623. this.couponInfo.VideoUrl = res.result.url
  624. },
  625. handleCurrentChange (val) { // 跳转到分页
  626. this.postData.page = val
  627. if (this.couponInfo.CouponType === 'goods') {
  628. this.GetGoodsList({
  629. ...this.postData,
  630. caseid: this.couponInfo.CaseId
  631. }).then((res) => {
  632. this.total = res.pagenum
  633. })
  634. } else if (this.couponInfo.CouponType === 'course') {
  635. this.GetCourseList({
  636. ...this.postData,
  637. caseid: this.couponInfo.CaseId
  638. }).then((res) => {
  639. this.total = res.pagenum
  640. })
  641. }
  642. }
  643. }
  644. }
  645. </script>
  646. <!-- Add "scoped" attribute to limit CSS to this component only -->
  647. <style lang="scss" scoped>
  648. .addLine {
  649. > * {
  650. margin-right: 10px;
  651. }
  652. }
  653. .mainForm > ul > li > div > div > button {
  654. margin-top: 0;
  655. }
  656. </style>