add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="app-container goods-add">
  3. <el-divider content-position="left">基础信息</el-divider>
  4. <el-form ref="addItem" :rules="rules" :model="addData" label-width="120px">
  5. <el-row :gutter="40" style="width: 600px">
  6. <el-col :span="23">
  7. <el-form-item label="活动名称:" prop="title">
  8. <el-input v-model="addData.title" placeholder="输入活动名称" :readonly="readonly"/>
  9. </el-form-item>
  10. </el-col>
  11. <el-col :span="23">
  12. <el-form-item label="活动封面:" prop="picUrl">
  13. <image-upload
  14. v-model="marketingPicUrl" :readonly="readonly"
  15. :limit="1"
  16. :file-size="0.2"
  17. @change="$refs.addItem.validateField(['picUrl'])"
  18. />
  19. </el-form-item>
  20. </el-col>
  21. <el-col>
  22. <el-form-item label="活动日期:" prop="dateValue">
  23. <el-date-picker value-format="timestamp" v-model="addData.dateValue" type="datetimerange" :readonly="readonly"
  24. range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"/>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="16">
  28. <el-form-item label="初始用户数:">
  29. <el-input v-model="addData.fakeNum" :readonly="readonly"/>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="23">
  33. <el-form-item label="抽奖码获取方式:" prop="type">
  34. <el-col>邀请用户助力</el-col>
  35. <el-col>用户助力条件:
  36. <el-radio-group v-model="labelRadio" :disabled="readonly">
  37. <el-radio :label="1">每个账号终身仅助力一次</el-radio>
  38. <el-radio :label="2" disabled>无</el-radio>
  39. </el-radio-group>
  40. </el-col>
  41. </el-form-item>
  42. </el-col>
  43. </el-row>
  44. <el-divider content-position="left">奖品设置</el-divider>
  45. <el-row>
  46. <el-col :span="22">
  47. <el-form-item label="" prop="awardsList">
  48. <!-- 奖级列表 -->
  49. <awards-list ref="awards" v-model="awardsList" @handleCommand="handleCommand" @close="close"/>
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-divider content-position="left">活动详情</el-divider>
  54. <el-row>
  55. <el-col :span="22">
  56. <el-form-item label="" prop="description">
  57. <wang-editor ref="editor" v-model="addData.description"/>
  58. </el-form-item>
  59. </el-col>
  60. </el-row>
  61. </el-form>
  62. <el-row>
  63. <el-col :span="24" style="text-align: center">
  64. <el-button type="info" @click="$router.replace('/marketing/marketing')">取消</el-button>
  65. <el-button type="primary" @click="update()" v-if="!readonly">保存</el-button>
  66. </el-col>
  67. </el-row>
  68. <!-- 添加商品 -->
  69. <goods-add :dialog-visible="goodsTableVisible" @close="close" @confirmGoods="confirmGoods"
  70. v-if="goodsTableVisible"/>
  71. <!-- 添加券 -->
  72. <coupon-add :dialog-visible="couponTableVisible" @close="close" @confirmCoupon="confirmCoupon"
  73. v-if="couponTableVisible"/>
  74. <!-- 添加券包 -->
  75. <coupon-pkg-add :dialog-visible="couponPkgTableVisible" @close="close" @confirmCouponPkg="confirmCouponPkg"
  76. v-if="couponPkgTableVisible"/>
  77. <!-- 添加盲豆 -->
  78. <coin-add :dialog-visible="coinTableVisible" @close="close" @confirmCoin="confirmCoin" v-if="coinTableVisible"/>
  79. </div>
  80. </template>
  81. <script>
  82. import { publicFileGetUrl } from "@/api/common";
  83. import {getMarketingDetail, addMarketing} from '@/api/business/marketing'
  84. import Upload from '@/components/DragImageUpload'
  85. import WangEditor from '@/components/WangEditor'
  86. import AwardsList from "./components/AwardsList"
  87. import GoodsAdd from "./components/GoodsAdd"
  88. import CouponAdd from "./components/CouponAdd"
  89. import CouponPkgAdd from "./components/CouponPkgAdd"
  90. import CoinAdd from "./components/CoinAdd"
  91. export default {
  92. name: "add",
  93. components: {
  94. Upload,
  95. WangEditor,
  96. AwardsList,
  97. GoodsAdd,
  98. CouponAdd,
  99. CouponPkgAdd,
  100. CoinAdd,
  101. },
  102. data() {
  103. return {
  104. id: this.$route.query.id,
  105. addData: {
  106. picUrl: '',//活动主图
  107. startTime: '',//开始时间
  108. endTime: '',//结束时间
  109. fakeNum: 0,//初始用户数
  110. description: '',//活动详情
  111. awardsList: [],//奖级列表
  112. },
  113. labelRadio: 1,//单选框
  114. rules: {
  115. title: [{required: true, message: '请输入活动名称', trigger: 'blur'}],
  116. picUrl: [{required: true, message: '请上传活动封面', trigger: 'change'}],
  117. dateValue: [{required: true, message: '请设置活动日期', trigger: 'change'}]
  118. },
  119. readonly: this.$route.name === 'MarketingQuery',
  120. // 奖级列表
  121. awardsList: [
  122. {
  123. name: "一等奖",
  124. sort: 1,
  125. quantity: 0,
  126. prizeList: [],
  127. insideNum: 0,
  128. },
  129. {
  130. name: "二等奖",
  131. sort: 2,
  132. quantity: 0,
  133. prizeList: [],
  134. insideNum: 0,
  135. },
  136. {
  137. name: "三等奖",
  138. sort: 3,
  139. quantity: 0,
  140. prizeList: [],
  141. insideNum: 0,
  142. },
  143. {
  144. name: "四等奖",
  145. sort: 4,
  146. quantity: 0,
  147. prizeList: [],
  148. insideNum: 0,
  149. },
  150. {
  151. name: "五等奖",
  152. sort: 5,
  153. quantity: 0,//名额数量
  154. prizeList: [],//列表
  155. insideNum: 0,//内定数量
  156. }
  157. ],
  158. goodsTableVisible: false, // 添加商品弹框
  159. couponTitle: "", // 券名称
  160. couponTableVisible: false, // 添加卡券弹框
  161. couponPkgTableVisible: false, // 添加券包弹框
  162. coinTableVisible: false, // 添加盲豆弹框
  163. pageParams: {
  164. pageNum: 1,
  165. pageSize: 10,
  166. },
  167. dateValue: [],//开始与结束日期
  168. }
  169. },
  170. computed: {
  171. marketingPicUrl: {
  172. get() {
  173. return this.addData.picUrl ? this.addData.picUrl.split(',').map(item => {
  174. return {
  175. fileName: item
  176. }
  177. }) : []
  178. },
  179. set(val) {
  180. this.$set(this.addData, 'picUrl', val.map(item => {
  181. return item.fileName
  182. }).toString())
  183. }
  184. },
  185. },
  186. created() {
  187. if (this.id) {
  188. getMarketingDetail(this.id).then(res => {
  189. const { startTime, endTime, description, fakeNum,picUrl, realNum, title, awardsList, id } = res.data
  190. this.addData = { title, dateValue:[startTime,endTime], picUrl, fakeNum, realNum, description, awardsList, id }
  191. if(description) {
  192. this.$refs.editor.setContent(description)
  193. }
  194. if(awardsList){
  195. awardsList.forEach((item) => {
  196. item.prizeList.forEach((ele) => {
  197. (ele.picUrl = publicFileGetUrl + ele.picUrl.split(',')[0]),
  198. (ele.prizeType = JSON.parse(ele.prizeType).value);
  199. });
  200. });
  201. this.$nextTick(() => {
  202. this.$refs.awards.add(3, awardsList)
  203. })
  204. this.awardsList = awardsList
  205. }
  206. })
  207. }
  208. },
  209. methods: {
  210. // 保存
  211. update() {
  212. this.$refs.addItem.validate((valid, items) => {
  213. if (valid) {
  214. if(this.awardsList.length < 1) {
  215. this.msgError('请至少设置一个奖级的的奖品!')
  216. return;
  217. }
  218. // 判断没有设置奖品的奖级
  219. let prizeIndex = this.awardsList.findIndex((item) => {
  220. return !item.prizeList.length;
  221. });
  222. if (prizeIndex != -1) {
  223. this.$message.error(
  224. `请至少设置一个奖级的的奖品!`
  225. );
  226. return;
  227. }
  228. // 判断内定名额大于奖品名额
  229. let quantityIndex = this.awardsList.findIndex((item) => {
  230. return item.insideNum > item.quantity;
  231. });
  232. if (quantityIndex != -1) {
  233. this.$message.error(
  234. `${this.awardsList[quantityIndex].name}的内定名额大于奖品名额,请重新设置!`
  235. );
  236. return;
  237. }
  238. let quantityIndexTwo = this.awardsList.findIndex((item) => {
  239. return item.prizeList.length != 0 && item.quantity == 0;
  240. });
  241. if (quantityIndexTwo != -1) {
  242. this.$message.error(
  243. `${this.awardsList[quantityIndexTwo].name}的名额不能为0,请重新设置!`
  244. );
  245. return;
  246. }
  247. this.awardsList.forEach((item) => {
  248. item.prizeList = item.prizeList.map((ele) => {
  249. return {
  250. ...ele,
  251. refId: ele.refId || ele.goodsId || ele.couponId || ele.id ,
  252. prizeType: ele.prizeType,
  253. quantity: ele.quantity,
  254. value: Number(ele.coinValue),
  255. };
  256. });
  257. });
  258. const { fakeNum, description, title, picUrl } = this.addData
  259. addMarketing({
  260. title,
  261. description: encodeURI(description),
  262. fakeNum,
  263. startTime: this.addData.dateValue[0],
  264. endTime: this.addData.dateValue[1],
  265. awardsList: this.awardsList,
  266. picUrl, id:this.addData.id?this.addData.id:"",
  267. }).then(res => {
  268. if (res.code === 0) {
  269. this.$message({
  270. message: this.addData.id ? '修改成功!' : '添加成功!',
  271. type: 'success'
  272. })
  273. this.$store.dispatch('marketing/marketing', this.$route)
  274. this.$router.go(-1)
  275. }
  276. })
  277. } else {
  278. if (items && Object.keys(items).length > 0) {
  279. this.$message({
  280. message: items[Object.keys(items)[0]][0].message,
  281. type: 'warning'
  282. })
  283. }
  284. }
  285. })
  286. },
  287. // 添加奖品种类
  288. handleCommand(e) {
  289. if (e == "goods") {
  290. this.goodsTableVisible = true;
  291. } else if (e == "coupon") {
  292. this.couponTableVisible = true;
  293. } else if (e == "coupon_pkg") {
  294. this.couponPkgTableVisible = true;
  295. } else if (e == "coin") {
  296. this.coinTableVisible = true;
  297. }
  298. },
  299. // 关闭弹框
  300. close() {
  301. this.goodsTableVisible = false;
  302. this.couponTableVisible = false;
  303. this.couponPkgTableVisible = false;
  304. this.coinTableVisible = false;
  305. },
  306. // 确认选中商品
  307. confirmGoods(arr) {
  308. this.$refs.awards.add(1, arr)
  309. },
  310. // 确认选中卡券
  311. confirmCoupon(arr) {
  312. ;
  313. this.$refs.awards.add(1, arr)
  314. },
  315. // 确认选中券包
  316. confirmCouponPkg(arr) {
  317. ;
  318. this.$refs.awards.add(1, arr)
  319. },
  320. // 确认输入盲豆
  321. confirmCoin(obj) {
  322. this.$refs.awards.add(2, obj)
  323. },
  324. }
  325. }
  326. </script>
  327. <style scoped lang="scss">
  328. .goods-add {
  329. .tip {
  330. font-size: 12px;
  331. color: #999;
  332. }
  333. .el-divider {
  334. .is-left {
  335. color: #409EFF;
  336. font-size: 20px;
  337. font-weight: bolder;
  338. left: 10px;
  339. }
  340. }
  341. }
  342. </style>