detail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <template>
  2. <div class="container" v-loading="loading">
  3. <el-form
  4. :model="form"
  5. :rules="rules"
  6. ref="form"
  7. label-position="right"
  8. label-width="130px">
  9. <div class="flexr">
  10. <div class="content flex1">
  11. <div class="section-title">Campaign Detail</div>
  12. <el-form-item
  13. prop="campaignTitle"
  14. label="Campaign Title:">
  15. <el-input
  16. v-model="form.campaignTitle"
  17. class="add-text"
  18. placeholder=""
  19. maxlength="100"/>
  20. </el-form-item>
  21. <el-form-item
  22. prop="startTime"
  23. label="Start Date Time:">
  24. <el-date-picker
  25. v-model="form.startTime"
  26. class="add-text"
  27. type="datetime"
  28. format="yyyy-MM-dd HH:mm"
  29. value-format="yyyy-MM-dd HH:mm"/>
  30. </el-form-item>
  31. <el-form-item
  32. prop="endTime"
  33. label="End Date Time:">
  34. <el-date-picker
  35. v-model="form.endTime"
  36. class="add-text"
  37. type="datetime"
  38. format="yyyy-MM-dd HH:mm"
  39. value-format="yyyy-MM-dd HH:mm"
  40. :default-value="form.startTime"/>
  41. </el-form-item>
  42. <el-form-item
  43. prop="campaignContent"
  44. label=""
  45. label-width="0">
  46. <label
  47. class="el-form-item__label"
  48. style="width: 150px;">Campaign Content:</label>
  49. <el-input
  50. v-model="form.campaignContent"
  51. class="area-text"
  52. type="textarea"
  53. placeholder=""
  54. maxlength="5000"
  55. :autosize="autoSize"/>
  56. <div class="add-checkbox" v-if="!isEdit">
  57. <el-checkbox
  58. v-model="form.switch"
  59. label="Use Campaign Title and Text to Create Notification Post"/>
  60. </div>
  61. </el-form-item>
  62. </div>
  63. <div class="content flex1">
  64. <div class="section-title">Images & Links</div>
  65. <el-form-item
  66. label=""
  67. label-width="0">
  68. <label
  69. class="el-form-item__label"
  70. style="float: none;">Photos (Max 4 photos and 2mb each):</label>
  71. <div class="flexcr">
  72. <el-upload
  73. class="logo-upload"
  74. action
  75. :limit="1"
  76. :show-file-list="false"
  77. :file-list="[]"
  78. :http-request="file => uploadImages(file, index)"
  79. accept=".jpg,.jpeg,.png,.gif,.JPG,.JPEG"
  80. v-loading="item.loading"
  81. v-for="(item, index) in images"
  82. :key="index">
  83. <div class="uploader-image" v-if="item.articleImagePath">
  84. <el-image
  85. :src="$imageSrc(item.articleImagePath)"
  86. title="Click to update image"/>
  87. <i
  88. title="Click to delete image"
  89. class="uploader-del el-icon-delete"
  90. @click.stop="deleteImages(index)"></i>
  91. </div>
  92. <i v-else
  93. class="el-icon-plus avatar-uploader-icon"
  94. title="Click to select file"/>
  95. </el-upload>
  96. </div>
  97. </el-form-item>
  98. <el-form-item
  99. label=""
  100. label-width="0">
  101. <label
  102. class="el-form-item__label"
  103. style="float: none;">LINKS:</label>
  104. <div style="max-width: 600px; display: grid;">
  105. <el-table
  106. class="article-links-table no-border"
  107. :data="form.links">
  108. <el-table-column
  109. label="Name Of Link"
  110. min-width="120px">
  111. <template slot-scope="{row}">
  112. <el-input
  113. v-model="row.articleLinkName"
  114. maxlength="100"/>
  115. </template>
  116. </el-table-column>
  117. <el-table-column
  118. label="Hyperlink"
  119. min-width="130px">
  120. <template slot-scope="{row}">
  121. <el-input
  122. v-model="row.articleLink"
  123. maxlength="150"/>
  124. </template>
  125. </el-table-column>
  126. <el-table-column
  127. label=""
  128. width="90px">
  129. <template slot-scope="{row,$index}">
  130. <div class="flexc" v-loading="row.loading">
  131. <i
  132. class="list-item-icon el-icon-remove-outline"
  133. style="color: #ED3F3F;"
  134. @click="onRemoveLink($index)"/>
  135. <i
  136. v-if="$index === form.links.length - 1"
  137. class="list-item-icon el-icon-circle-plus-outline"
  138. style="color: #82CF08;"
  139. @click="addLinkObj"/>
  140. </div>
  141. </template>
  142. </el-table-column>
  143. </el-table>
  144. </div>
  145. </el-form-item>
  146. </div>
  147. </div>
  148. <div class="content">
  149. <div class="section-title">Configure Discount</div>
  150. <el-table
  151. class="article-links-table no-border"
  152. :data="form.discounts"
  153. style="max-width: 800px;">
  154. <el-table-column
  155. label="User Type"
  156. min-width="80px">
  157. <template slot-scope="{row,$index}">
  158. <el-select
  159. style="width: 100%;"
  160. :value="row.userType"
  161. @change="type => changeUserType($index, type)"
  162. clearable>
  163. <el-option
  164. v-for="item in userTypeOptions"
  165. :key="item"
  166. :label="item"
  167. :value="item" />
  168. </el-select>
  169. </template>
  170. </el-table-column>
  171. <el-table-column
  172. label="Group Name"
  173. min-width="120px">
  174. <template slot-scope="{row}">
  175. <el-select
  176. style="width: 100%;"
  177. v-if="row.groupList.length"
  178. :disabled="row.userType == 'PUBLIC'"
  179. v-model="row.groupPk"
  180. clearable>
  181. <el-option
  182. v-for="(item,index) in row.groupList"
  183. :key="index"
  184. :label="item.name"
  185. :value="item.value"/>
  186. </el-select>
  187. </template>
  188. </el-table-column>
  189. <el-table-column
  190. label="Discount (%)"
  191. min-width="80px">
  192. <template slot-scope="{row}">
  193. <el-input
  194. v-model="row.discount"
  195. maxlength="5"/>
  196. </template>
  197. </el-table-column>
  198. <el-table-column
  199. label=""
  200. width="90px">
  201. <template slot-scope="{row,$index}">
  202. <div class="flexc" v-loading="row.loading">
  203. <i
  204. class="list-item-icon el-icon-remove-outline"
  205. style="color: #ED3F3F;"
  206. @click="onRemoveDiscount($index)"/>
  207. <i
  208. v-if="$index === form.discounts.length - 1"
  209. class="list-item-icon el-icon-circle-plus-outline"
  210. style="color: #82CF08;"
  211. @click="addDiscountObj"/>
  212. </div>
  213. </template>
  214. </el-table-column>
  215. </el-table>
  216. </div>
  217. <div class="content flexcr">
  218. <div class="buttons">
  219. <el-button
  220. @click="onClickCancel"
  221. type="primary"
  222. class="cancel-button">
  223. Cancel
  224. </el-button>
  225. <el-button
  226. @click="onClickSave"
  227. type="primary">
  228. Save
  229. </el-button>
  230. </div>
  231. <div
  232. class="update-by"
  233. v-if="isEdit">
  234. <span
  235. class="add-text"
  236. :title='"CREATED BY " + form.createdBy + " ON " + form.createdOn'>
  237. LAST UPDATED BY {{form.updatedBy}} TIMESTAMP: {{form.updatedOn}}
  238. </span>
  239. </div>
  240. </div>
  241. </el-form>
  242. </div>
  243. </template>
  244. <script>
  245. import api from '../../api/campaign.js'
  246. import apiUser from '@/http/api/apiUser'
  247. export default {
  248. data() {
  249. return {
  250. loading: false,
  251. form: {
  252. campaignId: "",
  253. startTime: "",
  254. endTime: "",
  255. campaignTitle: "",
  256. campaignContent: "",
  257. sendNotification: true,
  258. imagePaths: [],
  259. links: [],
  260. discounts: []
  261. },
  262. options: {
  263. type: []
  264. },
  265. images: [{
  266. articleImagePath: "",
  267. loading: false
  268. }],
  269. isEdit: false,
  270. rules: {
  271. startTime: [{
  272. message: "Please select start date time",
  273. trigger: "change",
  274. required: true,
  275. }],
  276. endTime: [{
  277. message: "Please select end date time",
  278. trigger: "change",
  279. required: true,
  280. }],
  281. campaignTitle: [{
  282. message: "Please input campaign title",
  283. trigger: "blur",
  284. required: true,
  285. }],
  286. campaignContent: [{
  287. message: "Please input campaign content",
  288. trigger: "blur",
  289. required: true,
  290. }]
  291. },
  292. autoSize: {
  293. minRows: 20,
  294. maxRows: 50
  295. },
  296. userTypeOptions: [],
  297. groupOptions: {
  298. PUBLIC: [{
  299. name: "None",
  300. value: ""
  301. }]
  302. }
  303. };
  304. },
  305. created() {
  306. this.addLinkObj();
  307. this.addDiscountObj();
  308. this.getUserTypeOption();
  309. if (this.$route.params.id) {
  310. this.loading = true;
  311. this.isEdit = true;
  312. this.getCampaignDetail();
  313. }
  314. },
  315. methods: {
  316. onClickCancel() {
  317. this.$nextTick(() => {
  318. this.$router.replace({
  319. path: "/marketing-management/campaign"
  320. })
  321. })
  322. },
  323. getUserTypeOption() {
  324. apiUser.getUserTypeOptions().then(res => {
  325. if (res.data) {
  326. this.userTypeOptions = res.data
  327. }
  328. }).catch(err => {
  329. this.$message({
  330. message: error,
  331. type: 'error'
  332. })
  333. })
  334. },
  335. getCampaignDetail() {
  336. api.viewCampaign(this.$route.params.id).then(res => {
  337. if (res.data) {
  338. let info = res.data
  339. this.images = []
  340. info.imagePaths.forEach(item => {
  341. this.images.push({
  342. ...item,
  343. loading: false
  344. })
  345. })
  346. info.discounts.forEach(item => {
  347. item.groupList = []
  348. })
  349. this.form = info;
  350. this.$nextTick(() => {
  351. this.form.discounts.forEach((item, index) => {
  352. setTimeout(() => {
  353. this.changeUserType(index, item.userType)
  354. }, 300 * index)
  355. })
  356. })
  357. this.addImageObj();
  358. }
  359. }).catch(err => {
  360. this.$message.error(err)
  361. }).finally(() => {
  362. this.loading = false;
  363. })
  364. },
  365. addImageObj() {
  366. if (this.images.length < 4) {
  367. this.images.push({
  368. articleImagePath: "",
  369. loading: false
  370. })
  371. }
  372. },
  373. uploadImages(file, index) {
  374. this.images[index].loading = true;
  375. const formData = new FormData()
  376. formData.append('file', file.file)
  377. api.uploadImages(formData).then(res => {
  378. if (res.data.picturePath) {
  379. if (!this.images[index].articleImagePath) {
  380. this.addImageObj();
  381. }
  382. this.images[index].articleImagePath = res.data.picturePath
  383. }
  384. }).catch(err => {
  385. this.$message({
  386. message: err,
  387. type: 'error'
  388. })
  389. }).finally(() => {
  390. this.images[index].loading = false;
  391. })
  392. },
  393. deleteImages(index) {
  394. const item = this.images[index];
  395. if (item.articleImageId) {
  396. this.$confirm('Confirm delete?', 'Delete', {
  397. confirmButtonText: 'Confirm',
  398. cancelButtonText: 'Cancel',
  399. type: 'warning'
  400. }).then(res => {
  401. this.deleteImageById(item.articleImageId, index);
  402. })
  403. } else {
  404. this.images.splice(index, 1);
  405. this.addImageObj()
  406. }
  407. },
  408. deleteImageById(id, index) {
  409. this.images[index].loading = true;
  410. api.deleteCampaignImage(id).then(res => {
  411. this.images.splice(index, 1);
  412. this.addImageObj()
  413. }).catch(err => {
  414. this.$message({
  415. message: err,
  416. type: 'error'
  417. })
  418. this.images[index].loading = false;
  419. })
  420. },
  421. addLinkObj() {
  422. this.form.links.push({
  423. loading: false,
  424. articleLink: "",
  425. articleLinkName: ""
  426. })
  427. },
  428. onRemoveLink(index) {
  429. const item = this.form.links[index];
  430. if (item.articleLinkId) {
  431. this.$confirm('Confirm delete?', 'Delete', {
  432. confirmButtonText: 'Confirm',
  433. cancelButtonText: 'Cancel',
  434. type: 'warning'
  435. }).then(res => {
  436. this.deleteLinkById(item.articleLinkId, index);
  437. })
  438. } else {
  439. this.form.links.splice(index, 1);
  440. if (this.form.links.length == 0) {
  441. this.addLinkObj()
  442. }
  443. }
  444. },
  445. deleteLinkById(id, index) {
  446. this.form.links[index].loading = true;
  447. api.deleteCampaignLink(id).then(res => {
  448. this.form.links.splice(index, 1);
  449. if (this.form.links.length == 0) {
  450. this.addLinkObj()
  451. }
  452. }).catch(err => {
  453. this.$message({
  454. message: err,
  455. type: 'error'
  456. })
  457. this.form.links[index].loading = false;
  458. })
  459. },
  460. addDiscountObj() {
  461. this.form.discounts.push({
  462. loading: false,
  463. userType: "",
  464. groupPk: "",
  465. discount: "",
  466. groupList: []
  467. })
  468. },
  469. onRemoveDiscount(index) {
  470. const item = this.form.discounts[index];
  471. if (item.articleDiscountId) {
  472. this.$confirm('Confirm delete?', 'Delete', {
  473. confirmButtonText: 'Confirm',
  474. cancelButtonText: 'Cancel',
  475. type: 'warning'
  476. }).then(res => {
  477. this.deleteDiscountById(item.articleDiscountId, index);
  478. })
  479. } else {
  480. this.form.discounts.splice(index, 1);
  481. if (this.form.discounts.length == 0) {
  482. this.addDiscountObj()
  483. }
  484. }
  485. },
  486. deleteDiscountById(id, index) {
  487. this.form.discounts[index].loading = true;
  488. api.deleteCampaignDiscount(id).then(res => {
  489. this.form.discounts.splice(index, 1);
  490. if (this.form.discounts.length == 0) {
  491. this.addDiscountObj()
  492. }
  493. }).catch(err => {
  494. this.$message({
  495. message: err,
  496. type: 'error'
  497. })
  498. this.form.discounts[index].loading = false;
  499. })
  500. },
  501. changeUserType(dsIndex, dsType) {
  502. let type = this.form.discounts[dsIndex].userType;
  503. if (dsType != type) {
  504. this.form.discounts[dsIndex].userType = dsType;
  505. this.form.discounts[dsIndex].groupPk = "";
  506. }
  507. if (dsType) {
  508. if (this.groupOptions[dsType] && this.groupOptions[dsType].length > 0) {
  509. this.form.discounts[dsIndex].groupList = this.groupOptions[dsType];
  510. } else {
  511. this.groupOptions[dsType] = []
  512. this.getGroupOptions(dsIndex, dsType);
  513. }
  514. } else {
  515. this.form.discounts[dsIndex].groupList = []
  516. }
  517. },
  518. getGroupOptions(index, type) {
  519. apiUser.getGroupByType(type).then(res => {
  520. if (res.data) {
  521. this.groupOptions[type] = res.data
  522. this.changeUserType(index, type)
  523. }
  524. }).catch(err => {
  525. this.$message({
  526. message: err,
  527. type: 'error'
  528. })
  529. this.groupOptions[type] = ""
  530. })
  531. },
  532. onClickSave() {
  533. this.$refs['form'].validate((valid) => {
  534. if (valid) {
  535. const images = this.images.filter(item => item.articleImagePath)
  536. if (images.length == 0) {
  537. this.$message({
  538. message: "Please upload at least one image",
  539. type: 'error'
  540. })
  541. return;
  542. }
  543. const links = this.form.links.filter(item => item.articleLinkName);
  544. if (links.length == 0) {
  545. this.$message({
  546. message: "Please add at least one link",
  547. type: 'error'
  548. })
  549. return;
  550. }
  551. const discounts = this.form.discounts.filter(item => {
  552. if (item.userType == "PUBLIC") {
  553. return item.userType && item.discount
  554. } else {
  555. return item.userType && item.groupPk && item.discount
  556. }
  557. })
  558. const params = {
  559. ...this.form,
  560. links: links,
  561. imagePaths: images,
  562. discounts: discounts
  563. }
  564. this.loading = true;
  565. this.isEdit ? this.updateArticle(params) : this.addArticle(params);
  566. }
  567. })
  568. },
  569. addArticle(params) {
  570. api.addCampaign(params).then(res => {
  571. this.$message({
  572. type: 'success',
  573. message: "Add successfully"
  574. });
  575. this.onClickCancel();
  576. }).catch(err => {
  577. this.loading = false;
  578. this.$message({
  579. type: 'error',
  580. message: err
  581. })
  582. });
  583. },
  584. updateArticle(params) {
  585. api.updateCampaign(params).then(res => {
  586. this.$message({
  587. type: 'success',
  588. message: "Update successfully"
  589. });
  590. this.onClickCancel();
  591. }).catch(err => {
  592. this.loading = false;
  593. this.$message({
  594. type: 'error',
  595. message: err
  596. })
  597. });
  598. }
  599. }
  600. }
  601. </script>
  602. <style lang="scss" scoped>
  603. @import '../../styles/variables.scss';
  604. .container {
  605. width: 100%;
  606. padding: 20px 60px;
  607. min-height: $mainAppMinHeight;
  608. background-color: #F0F5FC;
  609. }
  610. .content {
  611. min-width: 400px;
  612. margin: 0 8px 16px;
  613. padding: 15px 60px;
  614. border-radius: 6px;
  615. background-color: white;
  616. }
  617. .section-title {
  618. color: #333;
  619. margin-top: 20px;
  620. margin-bottom: 30px;
  621. font-size: 15px;
  622. user-select: none;
  623. line-height: 24px;
  624. font-weight: bold;
  625. font-family: sans-serif;
  626. text-transform: uppercase;
  627. }
  628. .add-text {
  629. width: 100%;
  630. min-width: 200px;
  631. }
  632. .area-text {
  633. width: 100%;
  634. min-width: 200px;
  635. }
  636. .add-text ::v-deep .el-textarea__inner,
  637. .area-text ::v-deep .el-textarea__inner {
  638. font-family: sans-serif;
  639. }
  640. .add-checkbox {
  641. overflow: auto;
  642. padding: 10px 0;
  643. &::v-deep {
  644. .el-checkbox.is-checked .el-checkbox__label{
  645. font-weight: bold;
  646. }
  647. }
  648. }
  649. .hr {
  650. height: 2px;
  651. margin: 10px -40px;
  652. background-color: #F0F5FC;
  653. }
  654. .buttons {
  655. padding-top: 15px;
  656. padding-bottom: 15px;
  657. }
  658. @media screen and (max-width: 500px) {
  659. .container {
  660. padding: 0px;
  661. }
  662. .content {
  663. padding: 15px 30px;
  664. }
  665. }
  666. .logo-upload {
  667. width: 148px;
  668. height: 148px;
  669. position: relative;
  670. margin-right: 15px;
  671. margin-bottom: 15px;
  672. ::v-deep .el-image {
  673. width: 148px;
  674. height: 148px;
  675. border-radius: 6px;
  676. }
  677. }
  678. .avatar-uploader-icon {
  679. width: 148px;
  680. height: 148px;
  681. color: #8c939d;
  682. cursor: pointer;
  683. font-size: 28px;
  684. text-align: center;
  685. line-height: 148px;
  686. border-radius: 6px;
  687. border: 1px dashed #d9d9d9;
  688. }
  689. .uploader-image {
  690. width: 148px;
  691. height: 148px;
  692. text-align: left;
  693. position: relative;
  694. }
  695. .uploader-image ::v-deep img {
  696. object-fit: cover;
  697. }
  698. .uploader-del {
  699. right: 4px;
  700. bottom: 4px;
  701. color: #fff;
  702. padding: 5px;
  703. display: none;
  704. border-radius: 30px;
  705. position: absolute;
  706. background-color: rgba(1,1,1,.4);
  707. }
  708. .uploader-image:hover .uploader-del {
  709. display: block;
  710. }
  711. .article-links-table ::v-deep .el-table__header th {
  712. color: #606266;
  713. border: none;
  714. padding: 10px 0 0;
  715. font-weight: normal;
  716. background: transparent;
  717. }
  718. .article-links-table ::v-deep td {
  719. border: none;
  720. padding: 1px 0;
  721. background: #fff !important;
  722. }
  723. .article-links-table ::v-deep .cell {
  724. padding: 0px 8px 10px;
  725. }
  726. .list-item-icon {
  727. height: 30px;
  728. cursor: pointer;
  729. font-size: 26px;
  730. font-weight: 500;
  731. line-height: 30px;
  732. }
  733. .list-item-icon + .list-item-icon {
  734. margin-left: 15px;
  735. }
  736. </style>