edit.vue 28KB

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