index.vue 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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-input v-model="activityName" placeholder="请输入内容"></el-input>
  10. </div>
  11. </div>
  12. </li>
  13. <li class="flex-h">
  14. <span>活动类型:<em>*</em></span>
  15. <div class="flex-item">
  16. <div>
  17. <el-select v-model="regValue" placeholder="请选择">
  18. <el-option
  19. v-for="item in regOptions"
  20. :key="item.regValue"
  21. :label="item.label"
  22. :value="item.regValue">
  23. </el-option>
  24. </el-select>
  25. </div>
  26. </div>
  27. </li>
  28. <li class="flex-h">
  29. <span>活动方式:<em>*</em></span>
  30. <div class="flex-item">
  31. <div>
  32. <el-select v-model="activeType" placeholder="请选择">
  33. <el-option
  34. v-for="item in activeTypeList"
  35. :key="item.id"
  36. :label="item.value"
  37. :value="item.id">
  38. </el-option>
  39. </el-select>
  40. </div>
  41. </div>
  42. </li>
  43. <li class="flex-h" v-if="activeType === 'giveCoupon'">
  44. <span>赠券卡券:<em>*</em></span>
  45. <div class="flex-item">
  46. <div>
  47. <el-select v-model="giftValue" placeholder="请选择">
  48. <el-option
  49. v-for="item in giftOptions"
  50. :key="item.giftValue"
  51. :label="item.label"
  52. :value="item.giftValue">
  53. </el-option>
  54. </el-select>
  55. </div>
  56. </div>
  57. </li>
  58. <li class="flex-h" v-if="activeType === 'giveCoupon'">
  59. <span>赠券数量:<em>*</em></span>
  60. <div class="flex-item">
  61. <div style="width:50%">
  62. <el-input v-model="giftNum" placeholder="请输入内容"></el-input>
  63. </div>
  64. </div>
  65. </li>
  66. <li class="flex-h">
  67. <span>活动描述:</span>
  68. <div class="flex-item">
  69. <div>
  70. <el-input
  71. type="textarea"
  72. :rows="10"
  73. placeholder="请输入内容"
  74. v-model="desc">
  75. </el-input>
  76. </div>
  77. </div>
  78. </li>
  79. <li style="text-align:center">
  80. <el-button type="primary" size="mini" @click="submitData">提交</el-button>
  81. <el-button type="warning" size="mini" @click="redirection('activitiesList')">返回</el-button>
  82. </li>
  83. </ul>
  84. </form>
  85. </div>
  86. </template>
  87. <script>
  88. import { mapState } from 'vuex'
  89. export default {
  90. data () {
  91. return {
  92. msg: '添加活动',
  93. postData: {
  94. TableId: '', // 桌位id
  95. AreaId: '', // 区域id
  96. CaseId: '', // 案场id
  97. OrgId: '', // 机构id
  98. TableNo: '', // 桌位编号
  99. Order: '', // 排序
  100. },
  101. regOptions: [{
  102. regValue: 'reigste',
  103. label: '注册'
  104. }],
  105. activeTypeList: [{
  106. value: '送券',
  107. id: 'giveCoupon'
  108. }],
  109. activeType: '',
  110. regValue: '',
  111. giftOptions: [], // [{giftValue: '1',label: '饮品通用券'}, {giftValue: '2',label: '课程通用券'}, {giftValue: '3',label: '小小外交官体验券'}]
  112. giftValue: '',
  113. giftLabel: '',
  114. activityName: '', // 活动名称
  115. activityType: this.regValue, // 活动类型
  116. resourceDesc: '', // 存储JSON (赠券类型,赠送数量,活动描述)
  117. giftNum: '', // 赠送数量
  118. desc: '', // 活动描述
  119. giftList: [] // 赠券卡券数据体
  120. }
  121. },
  122. mounted () {
  123. this.getCouponList()
  124. },
  125. computed: {
  126. ...mapState({
  127. defaultCaseId: x => x.app.cases.default,
  128. }),
  129. giftData: {
  130. get () {
  131. let jsonData = this.$data.giftList
  132. let data = []
  133. for (let i = 0; i < jsonData.length; i++) {
  134. let tempData = []
  135. tempData.giftValue = jsonData[i].CouponId
  136. tempData.label = jsonData[i].CouponName
  137. data.push(tempData)
  138. }
  139. return data
  140. }
  141. }
  142. },
  143. methods: {
  144. redirection (pathName) { // 重定向
  145. this.$router.push({ name: pathName })
  146. },
  147. submitData () { // 提交数据
  148. // 判断是否提交成功
  149. // 提交成功,跳转页面
  150. if (this.activityName === '') {
  151. this.$message({
  152. type: 'error',
  153. message: '活动名称不能为空'
  154. })
  155. return false
  156. }
  157. if (this.regValue === '') {
  158. this.$message({
  159. type: 'error',
  160. message: '活动类型不能为空'
  161. })
  162. return false
  163. }
  164. if (this.activeType === '') {
  165. this.$message({
  166. type: 'error',
  167. message: '活动方式不能为空'
  168. })
  169. return false
  170. }
  171. if (this.giftValue === '') {
  172. this.$message({
  173. type: 'error',
  174. message: '赠券卡券不能为空'
  175. })
  176. return false
  177. }
  178. if (this.giftNum - 0 < 1 && (this.giftNum - 0) % 1 !== 0) {
  179. this.$message({
  180. type: 'error',
  181. message: '赠券数量须为大于0正整数'
  182. })
  183. return false
  184. }
  185. let tempGiftOptions = this.$data.giftOptions
  186. let tempGiftValue = this.$data.giftValue
  187. for (let i = 0; i < tempGiftOptions.length; i++) {
  188. if (tempGiftOptions[i].giftValue === tempGiftValue) {
  189. this.$data.giftLabel = tempGiftOptions[i].label
  190. break
  191. }
  192. }
  193. let jsonString = '{"giftValue":"' + this.$data.giftValue + '","giftLabel":"' + this.$data.giftLabel + '","giftNum":"' + this.$data.giftNum + '","desc":"' + this.$data.desc + '"}'
  194. this.$ajax(this.$api.marketingActivities.addMarketing.url, {
  195. method: this.$api.marketingActivities.addMarketing.method,
  196. queryData: { activityName: this.$data.activityName, activityType: this.$data.regValue, activeType: this.activeType, resourceDesc: jsonString, CaseId: this.defaultCaseId }
  197. }).then(res => {
  198. // console.log(res)
  199. this.$message({
  200. type: 'success',
  201. message: '操作成功'
  202. })
  203. // 跳转路由
  204. this.redirection('activitiesList')
  205. })
  206. },
  207. getCouponList () {
  208. this.$ajax(this.$api.marketingActivities.getCouponList.url, {
  209. method: this.$api.marketingActivities.getCouponList.method,
  210. urlData: {
  211. type: 'system',
  212. },
  213. }).then(res => {
  214. this.giftList = res
  215. this.giftOptions = this.giftData
  216. })
  217. },
  218. }
  219. }
  220. </script>
  221. <!-- Add "scoped" attribute to limit CSS to this component only -->
  222. <style lang="scss" scoped>
  223. @import "page.scss";
  224. </style>