123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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>选择案场:<em>*</em></span>
  8. <div class="flex-item">
  9. <div style="width:50%">
  10. <el-select v-model="couponInfo.CaseId" placeholder="请选择" @change="caseChange" :disabled="isEdit">
  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>券图片:<em>*</em></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>券名称:<em>*</em></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>券类型:<em>*</em></span>
  51. <div class="flex-item">
  52. <div style="width:50%">
  53. <el-select v-model="couponInfo.CouponType" placeholder="请选择" @change="couponTypeChange" :disabled="isEdit">
  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>券价格:<em>*</em></span>
  66. <div class="flex-item">
  67. <div style="width:200px;">
  68. <el-input
  69. :disabled="isEdit"
  70. placeholder="请输入"
  71. v-model="couponInfo.Price"
  72. clearable>
  73. </el-input>
  74. </div>
  75. </div>
  76. </li>
  77. <li class="flex-h">
  78. <span>总张数:<em>*</em></span>
  79. <div class="flex-item">
  80. <div style="width:200px;">
  81. <el-input
  82. :disabled="isEdit"
  83. placeholder="请输入"
  84. v-model="couponInfo.TotalCount"
  85. clearable>
  86. </el-input>
  87. </div>
  88. </div>
  89. </li>
  90. <li class="flex-h">
  91. <span>发送类型:<em>*</em></span>
  92. <div class="flex-item">
  93. <div>
  94. <el-radio v-model="couponInfo.SendType" label="channel" :disabled="isEdit">渠道</el-radio>
  95. <el-radio v-model="couponInfo.SendType" label="case" :disabled="isEdit">案场</el-radio>
  96. <el-radio v-model="couponInfo.SendType" label="system" :disabled="isEdit">系统</el-radio>
  97. </div>
  98. </div>
  99. </li>
  100. <li class="flex-h" v-if="couponInfo.SendType === 'channel'">
  101. <span>选择渠道:<em>*</em></span>
  102. <div class="flex-item">
  103. <div style="width:50%">
  104. <el-select v-model="couponInfo.ChannelId" placeholder="请选择" :disabled="isEdit">
  105. <el-option
  106. v-for="item in channelList"
  107. :key="item.ChannelId"
  108. :label="item.ChannelName"
  109. :value="item.ChannelId">
  110. </el-option>
  111. </el-select>
  112. </div>
  113. </div>
  114. </li>
  115. <li class="flex-h">
  116. <span>目标商品:<em>*</em></span>
  117. <div class="flex-item">
  118. <div>
  119. <el-radio v-model="couponInfo.IsAll" :label="1" :disabled="isEdit">全部商品</el-radio>
  120. <el-radio v-model="couponInfo.IsAll" :label="0" :disabled="isEdit">指定商品</el-radio>
  121. </div>
  122. </div>
  123. </li>
  124. <li class="flex-h" v-if="couponInfo.IsAll === 0">
  125. <div class="flex-item">
  126. <div style="border: 1px solid #eee;">
  127. <el-table
  128. :data="couponInfo.Targets"
  129. stripe
  130. style="width: 100%">
  131. <el-table-column
  132. prop="TargetName"
  133. label="商品">
  134. </el-table-column>
  135. <el-table-column
  136. prop="TargetType"
  137. label="分类">
  138. <template slot-scope="scope">
  139. {{returnGoodsType(scope.row.TargetType)}}
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="操作">
  143. <template slot-scope="scope">
  144. <el-button
  145. size="mini"
  146. type="warning"
  147. @click="deleteGoodsItem(scope.$index, scope.row)" :disabled="isEdit">删除</el-button>
  148. </template>
  149. </el-table-column>
  150. </el-table>
  151. <div style="text-align:center;padding:10px 0;">
  152. <el-button type="success" size="mini" @click="addGoods" :disabled="isEdit">添加商品</el-button>
  153. </div>
  154. </div>
  155. </div>
  156. </li>
  157. <li class="flex-h" v-if="couponInfo.CouponType === 'goods'">
  158. <span>券有效时间:<em>*</em></span>
  159. <div class="flex-item">
  160. <div>
  161. <div class="addLine flex-h" style="align-item:center;margin-bottom:20px;">
  162. <el-radio v-model="TimeType" :label="1" :disabled="isEdit">固定时间</el-radio>
  163. <el-date-picker
  164. value-format="yyyy-MM-ddT00:00:00+08:00"
  165. :disabled="isEdit"
  166. v-model="couponInfo.StartDate"
  167. :picker-options="pickerOptions"
  168. type="date"
  169. placeholder="选择起始日期">
  170. </el-date-picker>
  171. <span style="line-height:40px;">至</span>
  172. <el-date-picker
  173. value-format="yyyy-MM-ddT23:59:59+08:00"
  174. :disabled="isEdit"
  175. v-model="couponInfo.EndDate"
  176. :picker-options="pickerOptions"
  177. type="date"
  178. placeholder="选择截止日期">
  179. </el-date-picker>
  180. </div>
  181. <div class="addLine flex-h" style="align-item:center;">
  182. <el-radio v-model="TimeType" :label="2" :disabled="isEdit">领取后</el-radio>
  183. <span style="width:100px;">
  184. <el-input
  185. :disabled="isEdit"
  186. placeholder="请输入"
  187. v-model="couponInfo.ValidDays"
  188. clearable>
  189. </el-input>
  190. </span>
  191. <span style="line-height:40px;">天</span>
  192. </div>
  193. </div>
  194. </div>
  195. </li>
  196. <li class="flex-h" v-if="couponInfo.CouponType === 'course'">
  197. <span>券有效时间:<em>*</em></span>
  198. <div class="flex-item">
  199. <div>
  200. <el-date-picker
  201. value-format="yyyy-MM-ddT00:00:00+08:00"
  202. :disabled="isEdit"
  203. v-model="couponInfo.StartDate"
  204. :picker-options="pickerOptions"
  205. type="date"
  206. placeholder="选择起始日期">
  207. </el-date-picker>
  208. <span style="line-height:40px;">至</span>
  209. <el-date-picker
  210. value-format="yyyy-MM-ddT23:59:59+08:00"
  211. :disabled="isEdit"
  212. v-model="couponInfo.EndDate"
  213. :picker-options="pickerOptions"
  214. type="date"
  215. placeholder="选择截止日期">
  216. </el-date-picker>
  217. </div>
  218. </div>
  219. </li>
  220. <li class="flex-h" v-if="couponInfo.SendType !== 'case' && couponInfo.SendType !== 'system'">
  221. <span>视频:</span>
  222. <div class="flex-item">
  223. <div style="vertical-align: middle;">
  224. <a style="line-height: 40px;" v-if="videoOff" :href="couponInfo.VideoUrl" target="blank">{{couponInfo.VideoUrl}}</a>
  225. <el-upload
  226. class="avatar-uploader"
  227. action='string'
  228. :http-request="toolClass.upload"
  229. :show-file-list="false"
  230. :on-success="videoSuccess">
  231. <a style="line-height: 40px;padding: 0 10px;" :disabled="isEdit">{{videoOff ? '更换' : '添加'}}视频</a>
  232. </el-upload>
  233. <el-button v-if="videoOff" type="danger" @click="deleteVideo">删除视频</el-button>
  234. </div>
  235. </div>
  236. </li>
  237. <li class="flex-h">
  238. <span>分享描述:<em>*</em></span>
  239. <div class="flex-item">
  240. <div>
  241. <el-input
  242. type="textarea"
  243. :rows="2"
  244. placeholder="请输入"
  245. v-model="couponInfo.Share.CouponShareInfo">
  246. </el-input>
  247. </div>
  248. </div>
  249. </li>
  250. <li class="flex-h">
  251. <span>规则描述:<em>*</em></span>
  252. <div class="flex-item">
  253. <div>
  254. <el-input
  255. type="textarea"
  256. :rows="2"
  257. placeholder="请输入"
  258. v-model="couponInfo.Share.UseRule">
  259. </el-input>
  260. </div>
  261. </div>
  262. </li>
  263. <li class="flex-h">
  264. <span>使用说明:<em>*</em></span>
  265. <div class="flex-item">
  266. <div>
  267. <el-input
  268. type="textarea"
  269. :rows="2"
  270. placeholder="请输入"
  271. v-model="couponInfo.Share.UseInstruction">
  272. </el-input>
  273. </div>
  274. </div>
  275. </li>
  276. <li style="text-align:center">
  277. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  278. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  279. </li>
  280. </ul>
  281. </form>
  282. <el-dialog
  283. title="选择指定商品"
  284. :visible.sync="centerDialogVisible"
  285. @close="postData.page=1;total=1"
  286. width="650px"
  287. center>
  288. <div>
  289. <div v-if="couponInfo.CouponType === 'goods'">
  290. <el-table
  291. ref="multipleTable1"
  292. :data="goodsList"
  293. tooltip-effect="dark"
  294. style="width: 100%"
  295. @selection-change="handleGoodsChange">
  296. <el-table-column
  297. type="selection">
  298. </el-table-column>
  299. <el-table-column
  300. prop="GoodsName"
  301. label="商品名称">
  302. </el-table-column>
  303. <el-table-column
  304. prop="TypeId"
  305. label="类别">
  306. </el-table-column>
  307. <el-table-column
  308. prop="Price"
  309. label="价格">
  310. </el-table-column>
  311. </el-table>
  312. <el-pagination
  313. @current-change="handleCurrentChange"
  314. :current-page.sync="postData.page"
  315. :page-size="postData.pagesize"
  316. layout="prev, pager, next, jumper"
  317. :total="total">
  318. </el-pagination>
  319. </div>
  320. <div v-if="couponInfo.CouponType === 'course'">
  321. <el-table
  322. ref="multipleTable2"
  323. :data="courseList"
  324. tooltip-effect="dark"
  325. style="width: 100%"
  326. @selection-change="handleCourseChange">
  327. <el-table-column
  328. type="selection">
  329. </el-table-column>
  330. <el-table-column
  331. prop="CourseName"
  332. label="课程名称">
  333. </el-table-column>
  334. <el-table-column
  335. prop="BeginDate"
  336. label="开始时间">
  337. </el-table-column>
  338. <el-table-column
  339. prop="EndDate"
  340. label="结束时间">
  341. </el-table-column>
  342. <el-table-column
  343. prop="LocationName"
  344. label="类别">
  345. </el-table-column>
  346. <el-table-column
  347. prop="Price"
  348. label="价格">
  349. </el-table-column>
  350. </el-table>
  351. <el-pagination
  352. @current-change="handleCurrentChange"
  353. :current-page.sync="postData.page"
  354. :page-size="postData.pagesize"
  355. layout="prev, pager, next, jumper"
  356. :total="total">
  357. </el-pagination>
  358. </div>
  359. </div>
  360. <span slot="footer" class="dialog-footer">
  361. <el-button @click="centerDialogVisible = false">取 消</el-button>
  362. <el-button type="primary" @click="sureAddItem">确 定</el-button>
  363. </span>
  364. </el-dialog>
  365. </div>
  366. </template>
  367. <script>
  368. import { mapState, createNamespacedHelpers } from 'vuex'
  369. const { mapActions: mapCouponActions } = createNamespacedHelpers('coupon')
  370. const { mapState: mapChannelState, mapActions: mapChannelActions } = createNamespacedHelpers('channel')
  371. const { mapState: mapGoodsState, mapActions: mapGoodsActions } = createNamespacedHelpers('goods')
  372. const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')
  373. export default {
  374. name: '',
  375. data () {
  376. return {
  377. courseList: [],
  378. goodsList: [],
  379. videoOff: false,
  380. total: 0,
  381. centerDialogVisible: false,
  382. type: this.$route.query.type || '', // goods、course
  383. isEdit: !!this.$route.query.id,
  384. ChannelList: [], // 渠道列表
  385. TypeList: [{ // 类型列表
  386. value: '商品券',
  387. id: 'goods'
  388. }, {
  389. value: '课程券',
  390. id: 'course'
  391. }],
  392. currentList: [{
  393. Name: 'ccc',
  394. Type: 'xxx'
  395. }], // 指定商品数据
  396. TimeType: 1,
  397. couponInfo: {
  398. CaseId: '',
  399. CouponName: '',
  400. CouponType: '',
  401. Price: '',
  402. TotalCount: '',
  403. SendType: 'system',
  404. IsAll: 1,
  405. StartDate: '',
  406. EndDate: '',
  407. ValidDays: '',
  408. VideoUrl: '',
  409. ChannelId: '',
  410. Images: [{
  411. CouponImageUrl: ''
  412. }],
  413. Share: {
  414. CouponShareInfo: '',
  415. UseRule: '',
  416. UseInstruction: ''
  417. },
  418. Targets: []
  419. },
  420. postData: {
  421. page: 1,
  422. pagesize: 6,
  423. },
  424. currentSelectArr: [],
  425. }
  426. },
  427. mounted () {
  428. this.$nextTick(function () {
  429. this.GetChannelListList({
  430. caseid: this.defaultCaseId,
  431. page: 1,
  432. pagesize: 10000
  433. }).then(() => {
  434. this.GetGoodTypes({ pagesize: 1000, caseid: this.$route.query.caseid }).then(() => {
  435. if (this.$route.query.id) {
  436. this.getCouponById({
  437. id: this.$route.query.id
  438. }).then((res) => {
  439. // console.log(JSON.stringify(res))
  440. if (res.coupon.CaseId !== '') {
  441. var aRes = res
  442. this.GetChannelListList({
  443. caseid: res.coupon.CaseId,
  444. page: 1,
  445. pagesize: 10000
  446. }).then((res) => {
  447. if (aRes.coupon.VideoUrl !== '') {
  448. this.videoOff = true
  449. }
  450. this.couponInfo = aRes.coupon
  451. if (aRes.coupon.StartDate === '0001-01-01T00:00:00Z' || aRes.coupon.StartDate === '') {
  452. this.couponInfo.StartDate = ''
  453. this.TimeType = 2
  454. } else {
  455. this.TimeType = 1
  456. }
  457. if (aRes.coupon.EndDate === '0001-01-01T00:00:00Z' || aRes.coupon.EndDate === '') {
  458. this.couponInfo.EndDate = ''
  459. }
  460. })
  461. } else {
  462. if (res.coupon.VideoUrl !== '') {
  463. this.videoOff = true
  464. }
  465. this.couponInfo = res.coupon
  466. if (aRes.coupon.StartDate === '0001-01-01T00:00:00Z' || aRes.coupon.StartDate === '') {
  467. this.couponInfo.StartDate = ''
  468. this.TimeType = 2
  469. } else {
  470. this.TimeType = 1
  471. }
  472. if (aRes.coupon.EndDate === '0001-01-01T00:00:00Z' || aRes.coupon.EndDate === '') {
  473. this.couponInfo.EndDate = ''
  474. }
  475. }
  476. })
  477. }
  478. })
  479. })
  480. })
  481. },
  482. computed: {
  483. ...mapState({
  484. cases: x => x.app.cases.list,
  485. defaultCaseId: x => x.app.cases.default
  486. }),
  487. ...mapChannelState({
  488. channelList: x => x.channelList,
  489. }),
  490. ...mapGoodsState({
  491. // goodsList: x => x.goodsList,
  492. goodsTypes: x => x.goodsTypes.list,
  493. }),
  494. ...mapCourseState({
  495. // courseList: x => x.courseLister,
  496. }),
  497. CaseId: {
  498. get () {
  499. return this.couponInfo.caseid || this.defaultCaseId
  500. },
  501. set (val) {
  502. this.couponInfo.caseid = val
  503. }
  504. },
  505. pickerOptions () {
  506. var beginDate = Date.now() - 24 * 60 * 60 * 1000
  507. return {
  508. disabledDate (time) {
  509. return time.getTime() < beginDate
  510. }
  511. }
  512. },
  513. },
  514. methods: {
  515. ...mapGoodsActions([
  516. 'GetGoodsList',
  517. 'GetGoodTypes',
  518. ]),
  519. ...mapCouponActions([
  520. 'addCoupon',
  521. 'getCouponById',
  522. 'editCoupon',
  523. ]),
  524. ...mapChannelActions([
  525. 'GetChannelListList',
  526. ]),
  527. ...mapCourseActions([
  528. 'getCourseLister',
  529. ]),
  530. returnGoodsType (val) {
  531. for (var n = 0; n < this.goodsTypes.length; n++) {
  532. if (this.goodsTypes[n].TypeId === val) {
  533. return this.goodsTypes[n].TypeName
  534. }
  535. }
  536. },
  537. deleteVideo () { // 删除视频
  538. this.couponInfo.VideoUrl = ''
  539. this.videoOff = false
  540. },
  541. caseChange () { // 选择案场
  542. this.couponInfo.ChannelId = ''
  543. this.GetChannelListList({
  544. caseid: this.couponInfo.CaseId,
  545. page: 1,
  546. pagesize: 10000
  547. })
  548. },
  549. sureAddItem () { // 确定添加指定商品
  550. var bool = true
  551. this.couponInfo.Targets = this.couponInfo.Targets || []
  552. if (this.couponInfo.CouponType === 'goods') {
  553. for (var n = 0; n < this.currentSelectArr.length; n++) {
  554. if (this.couponInfo.Targets.length) {
  555. bool = true
  556. for (var a = 0; a < this.couponInfo.Targets.length; a++) {
  557. if (this.currentSelectArr[n].GoodsId === this.couponInfo.Targets[a].TargetId) {
  558. bool = false
  559. }
  560. }
  561. if (bool) {
  562. this.couponInfo.Targets.push({
  563. TargetName: this.currentSelectArr[n].GoodsName,
  564. TargetId: this.currentSelectArr[n].GoodsId,
  565. TargetType: this.currentSelectArr[n].TypeId
  566. })
  567. }
  568. } else {
  569. this.couponInfo.Targets.push({
  570. TargetName: this.currentSelectArr[n].GoodsName,
  571. TargetId: this.currentSelectArr[n].GoodsId,
  572. TargetType: this.currentSelectArr[n].TypeId
  573. })
  574. }
  575. }
  576. } else if (this.couponInfo.CouponType === 'course') {
  577. for (var x = 0; x < this.currentSelectArr.length; x++) {
  578. if (this.couponInfo.Targets.length) {
  579. bool = true
  580. for (var y = 0; y < this.couponInfo.Targets.length; y++) {
  581. if (this.currentSelectArr[x].CourseId === this.couponInfo.Targets[y].TargetId) {
  582. bool = false
  583. }
  584. }
  585. if (bool) {
  586. this.couponInfo.Targets.push({
  587. TargetName: this.currentSelectArr[x].CourseName,
  588. TargetId: this.currentSelectArr[x].CourseId,
  589. TargetType: this.currentSelectArr[x].CourseType
  590. })
  591. }
  592. } else {
  593. this.couponInfo.Targets.push({
  594. TargetName: this.currentSelectArr[x].CourseName,
  595. TargetId: this.currentSelectArr[x].CourseId,
  596. TargetType: this.currentSelectArr[x].CourseType
  597. })
  598. }
  599. }
  600. }
  601. this.centerDialogVisible = false
  602. },
  603. handleGoodsChange (val) {
  604. this.currentSelectArr = val
  605. },
  606. handleCourseChange (val) {
  607. this.currentSelectArr = val
  608. },
  609. couponTypeChange () {
  610. this.couponInfo.Targets = []
  611. if (this.couponInfo.CouponType === 'course') {
  612. this.TimeType = 1
  613. }
  614. },
  615. addGoods () { // 添加指定商品
  616. if (this.couponInfo.CouponType === 'goods') {
  617. this.postData.page = 1
  618. this.total = 1
  619. this.GetGoodsList({
  620. ...this.postData,
  621. caseid: this.couponInfo.CaseId
  622. }).then((res) => {
  623. this.goodsList = []
  624. for (var n = 0; n < res.list.length; n++) {
  625. this.goodsList.push({ ...res.list[n], TypeId: this.returnGoodsType(res.list[n].TypeId) })
  626. }
  627. this.total = res.pagenum
  628. this.centerDialogVisible = true
  629. })
  630. } else if (this.couponInfo.CouponType === 'course') {
  631. this.postData.page = 1
  632. this.total = 1
  633. this.getCourseLister({
  634. ...this.postData,
  635. caseid: this.couponInfo.CaseId
  636. }).then((res) => {
  637. this.courseList = []
  638. for (var n = 0; n < (res.list || []).length; n++) {
  639. this.courseList.push({ ...res.list[n], BeginDate: this.toolClass.dateFormat(res.list[n].BeginDate), EndDate: this.toolClass.dateFormat(res.list[n].EndDate) })
  640. }
  641. this.total = res.pagenum
  642. this.centerDialogVisible = true
  643. // console.log(JSON.stringify(this.courseList))
  644. })
  645. }
  646. },
  647. checkInfo () { // 校验表单信息
  648. if (this.couponInfo.CaseId === '') {
  649. this.$message({
  650. type: 'error',
  651. message: '案场不能为空'
  652. })
  653. return false
  654. }
  655. if (this.couponInfo.Images[0].CouponImageUrl === '') {
  656. this.$message({
  657. type: 'error',
  658. message: '券图片不能为空'
  659. })
  660. return false
  661. }
  662. if (this.couponInfo.CouponName === '') {
  663. this.$message({
  664. type: 'error',
  665. message: '券名称不能为空'
  666. })
  667. return false
  668. }
  669. if (this.couponInfo.CouponType === '') {
  670. this.$message({
  671. type: 'error',
  672. message: '券类型不能为空'
  673. })
  674. return false
  675. }
  676. if (this.couponInfo.Price === '') {
  677. this.$message({
  678. type: 'error',
  679. message: '券价格不能为空'
  680. })
  681. return false
  682. }
  683. if (this.couponInfo.TotalCount === '') {
  684. this.$message({
  685. type: 'error',
  686. message: '总张数不能为空'
  687. })
  688. return false
  689. }
  690. if (this.couponInfo.SendType === '') {
  691. this.$message({
  692. type: 'error',
  693. message: '发送类型不能为空'
  694. })
  695. return false
  696. }
  697. if (this.couponInfo.SendType === 'channel' && this.couponInfo.ChannelId === '') {
  698. this.$message({
  699. type: 'error',
  700. message: '渠道不能为空'
  701. })
  702. return false
  703. }
  704. if (!(this.couponInfo.IsAll - 0) && !this.courseList.length && !this.goodsList.length && !this.isEdit) {
  705. this.$message({
  706. type: 'error',
  707. message: '目标商品不能为空'
  708. })
  709. return false
  710. }
  711. // if (this.couponInfo.SendType === 'channel' && this.couponInfo.VideoUrl === '') {
  712. // this.$message({
  713. // type: 'error',
  714. // message: '视频不能为空'
  715. // })
  716. // return false
  717. // }
  718. if (this.couponInfo.CouponType === 'goods') {
  719. if (this.TimeType === 1 && this.couponInfo.StartDate === '') {
  720. this.$message({
  721. type: 'error',
  722. message: '开始时间不能为空'
  723. })
  724. return false
  725. } else if (this.TimeType === 1 && this.couponInfo.EndDate === '') {
  726. this.$message({
  727. type: 'error',
  728. message: '截止时间不能为空'
  729. })
  730. return false
  731. } else if (this.TimeType === 2 && this.couponInfo.ValidDays === '') {
  732. this.$message({
  733. type: 'error',
  734. message: '领取后天数不能为空'
  735. })
  736. return false
  737. }
  738. }
  739. if (this.couponInfo.Share.CouponShareInfo === '') {
  740. this.$message({
  741. type: 'error',
  742. message: '分享描述不能为空'
  743. })
  744. return false
  745. }
  746. if (this.couponInfo.Share.UseRule === '') {
  747. this.$message({
  748. type: 'error',
  749. message: '使用规则不能为空'
  750. })
  751. return false
  752. }
  753. if (this.couponInfo.Share.UseInstruction === '') {
  754. this.$message({
  755. type: 'error',
  756. message: '使用说明不能为空'
  757. })
  758. return false
  759. }
  760. return true
  761. },
  762. submit () { // 保存
  763. if (this.$route.query.id) {
  764. if (this.couponInfo.ValidDays) {
  765. this.couponInfo.StartDate = undefined
  766. this.couponInfo.EndDate = undefined
  767. }
  768. if (!this.checkInfo()) {
  769. return false
  770. }
  771. this.editCoupon({
  772. ...this.couponInfo,
  773. IsAll: this.couponInfo.IsAll - 0,
  774. TotalCount: this.couponInfo.TotalCount - 0,
  775. ValidDays: this.couponInfo.ValidDays - 0 || 0
  776. }).then((res) => {
  777. this.$message({
  778. type: 'success',
  779. message: '操作成功'
  780. })
  781. this.$router.push({ name: 'couponList' })
  782. })
  783. } else {
  784. if (!this.checkInfo()) {
  785. return false
  786. }
  787. if (this.couponInfo.ValidDays) {
  788. this.couponInfo.StartDate = undefined
  789. this.couponInfo.EndDate = undefined
  790. } else {
  791. if (this.couponInfo.StartDate === '') {
  792. this.$message({
  793. type: 'error',
  794. message: '开始时间不能为空'
  795. })
  796. return false
  797. }
  798. if (this.couponInfo.EndDate === '') {
  799. this.$message({
  800. type: 'error',
  801. message: '截止时间不能为空'
  802. })
  803. return false
  804. }
  805. if (new Date(this.couponInfo.StartDate).getTime() > new Date(this.couponInfo.EndDate).getTime()) {
  806. this.$message({
  807. type: 'error',
  808. message: '开始时间不能大于截止时间'
  809. })
  810. return false
  811. }
  812. }
  813. this.addCoupon({
  814. ...this.couponInfo,
  815. IsAll: this.couponInfo.IsAll - 0,
  816. TotalCount: this.couponInfo.TotalCount - 0,
  817. ValidDays: this.couponInfo.ValidDays - 0 || 0
  818. }).then((res) => {
  819. this.$message({
  820. type: 'success',
  821. message: '操作成功'
  822. })
  823. this.$router.push({ name: 'couponList' })
  824. })
  825. }
  826. },
  827. cancel () { // 取消
  828. this.$router.push({ name: 'couponList' })
  829. },
  830. deleteGoodsItem (index, row) { // 删除指定商品item
  831. this.couponInfo.Targets.splice(index, 1)
  832. },
  833. handleAvatarSuccess (res, file) {
  834. this.couponInfo.Images[0].CouponImageUrl = res.result.url
  835. },
  836. videoSuccess (res, file) {
  837. this.videoOff = true
  838. this.couponInfo.VideoUrl = res.result.url
  839. },
  840. handleCurrentChange (val) { // 跳转到分页
  841. this.postData.page = val
  842. if (this.couponInfo.CouponType === 'goods') {
  843. this.GetGoodsList({
  844. ...this.postData,
  845. caseid: this.couponInfo.CaseId
  846. }).then((res) => {
  847. this.goodsList = []
  848. for (var n = 0; n < res.list.length; n++) {
  849. this.goodsList.push({ ...res.list[n], TypeId: this.returnGoodsType(res.list[n].TypeId) })
  850. }
  851. this.total = res.pagenum
  852. })
  853. } else if (this.couponInfo.CouponType === 'course') {
  854. this.getCourseLister({
  855. ...this.postData,
  856. caseid: this.couponInfo.CaseId
  857. }).then((res) => {
  858. this.courseList = []
  859. for (var n = 0; n < res.list.length; n++) {
  860. this.courseList.push({ ...res.list[n], BeginDate: this.toolClass.dateFormat(res.list[n].BeginDate), EndDate: this.toolClass.dateFormat(res.list[n].EndDate) })
  861. }
  862. this.total = res.pagenum
  863. })
  864. }
  865. }
  866. }
  867. }
  868. </script>
  869. <!-- Add "scoped" attribute to limit CSS to this component only -->
  870. <style lang="scss" scoped>
  871. .addLine {
  872. > * {
  873. margin-right: 10px;
  874. }
  875. }
  876. .mainForm > ul > li > div > div > button {
  877. margin-top: 0;
  878. }
  879. </style>