edit.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @copyright: Copyright (c) 2021 广东七件事集团
  5. * @Author: lun
  6. * @Date: 2021-12-31 21:04:34
  7. */
  8. ?>
  9. <div id="app" v-cloak>
  10. <el-card v-loading="loading" style="border:0;min-width: 1200px;" shadow="never" body-style="background-color: #f3f3f3;padding: 0 0;">
  11. <el-form :model="ruleForm"
  12. ref="ruleForm"
  13. :rules="rules"
  14. label-width="172px"
  15. style="position: relative"
  16. size="small">
  17. <el-card shadow="never" class="mt-24">
  18. <div slot="header">
  19. <span>广告编辑</span>
  20. </div>
  21. <el-form-item prop="title" label="标题">
  22. <el-col :span="12">
  23. <el-input type="text" v-model="ruleForm.title"></el-input>
  24. </el-col>
  25. </el-form-item>
  26. <el-form-item label="广告图片" prop="cover">
  27. <el-col :span="12">
  28. <com-attachment v-model="ruleForm.cover" :multiple="false" :max="1">
  29. <el-tooltip class="item" effect="dark" content="建议尺寸:702 * 320" placement="top">
  30. <el-button size="mini">选择图片</el-button>
  31. </el-tooltip>
  32. </com-attachment>
  33. <div class="customize-share-title" v-if="ruleForm.cover" >
  34. <image mode="aspectFill" width='160px' height='80px' :src="ruleForm.cover ? ruleForm.cover : ''"></image>
  35. <el-button v-if="ruleForm.cover" class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="ruleForm.cover = ''"></el-button>
  36. </div>
  37. </el-col>
  38. </el-form-item>
  39. <el-form-item label="链接跳转">
  40. <el-col :span="12">
  41. <div flex="box:last">
  42. <el-input type="text" placeholder="请选择链接" v-model="ruleForm.link.route" :disabled="true"></el-input>
  43. <com-pick-link @selected="selectLink" ignore="navigate">
  44. <el-button>选择链接</el-button>
  45. </com-pick-link>
  46. </div>
  47. </el-col>
  48. </el-form-item>
  49. <el-form-item label="排序" prop="sort">
  50. <el-col :span="12">
  51. <el-input type="age" v-model.number="ruleForm.sort"></el-input>
  52. </el-col>
  53. </el-form-item>
  54. <el-form-item>
  55. <el-col :span="12">
  56. <el-button :loading="submitLoading" size="small" type="primary"
  57. @click="submit('ruleForm')">保存
  58. </el-button>
  59. </el-col>
  60. </el-form-item>
  61. </el-card>
  62. </el-form>
  63. </el-card>
  64. </div>
  65. <script>
  66. const app = new Vue({
  67. el: '#app',
  68. data() {
  69. var checkSort = (rule, value, callback) => {
  70. if (!value) {
  71. return callback(new Error('排序不能为空'));
  72. }
  73. if (value < 0 || value > 999) {
  74. callback(new Error('排序在 1~999 之间'));
  75. } else {
  76. callback();
  77. }
  78. };
  79. return {
  80. loading: false,
  81. submitLoading: false,
  82. ruleForm: {
  83. title: '',
  84. cover: '',
  85. sort: 1,
  86. link: {
  87. url: '',
  88. open_type: '',
  89. params: '',
  90. },
  91. },
  92. rules: {
  93. title: [
  94. { required: true, message: '请输入标题', trigger: 'blur' },
  95. { min: 1, max: 12, message: '长度在 1 到 12 个字符', trigger: 'blur' }
  96. ],
  97. cover: [
  98. { required: true, message: '请上传轮播图', trigger: 'change' },
  99. ],
  100. sort: [
  101. { validator: checkSort, trigger: 'blur' }
  102. ],
  103. }
  104. };
  105. },
  106. created() {
  107. this.loadData();
  108. },
  109. methods: {
  110. selectLink(e) {
  111. console.log(e);
  112. let self = this;
  113. let link = {};
  114. e.forEach(function (item) {
  115. link = {
  116. title: item.title,
  117. route: item.route,
  118. open_type: item.params.open_type,
  119. params: item.params,
  120. }
  121. })
  122. self.ruleForm.link = link;
  123. },
  124. loadData() {
  125. this.loading = true;
  126. request({
  127. params: {
  128. r: 'rebate/ad/edit',
  129. id: getQuery('id')
  130. },
  131. method: 'get',
  132. }).then(e => {
  133. this.loading = false;
  134. if (e.data.code === 0) {
  135. let data = e.data.data
  136. if (!isEmpty(data)) {
  137. // if(data.link != "") data.link = JSON.parse(data.link);
  138. this.ruleForm = data;
  139. }
  140. } else {
  141. this.$message.error(e.data.msg);
  142. }
  143. }).catch(e => {
  144. });
  145. },
  146. submit(formName) {
  147. this.ruleForm.title = this.ruleForm.title.toString();
  148. this.$refs[formName].validate((valid) => {
  149. if (valid) {
  150. this.submitLoading = true;
  151. this.ruleForm.id = getQuery('id');
  152. request({
  153. params: {
  154. r: 'rebate/ad/edit',
  155. },
  156. method: 'post',
  157. data: this.ruleForm,
  158. }).then(e => {
  159. this.submitLoading = false;
  160. if (e.data.code === 0) {
  161. this.$message.success(e.data.msg);
  162. navigateTo({
  163. r: 'rebate/ad/index'
  164. })
  165. } else {
  166. this.$message.error(e.data.msg);
  167. }
  168. }).catch(e => {
  169. });
  170. } else {
  171. console.log('error submit!!');
  172. return false;
  173. }
  174. });
  175. },
  176. },
  177. computed: {
  178. }
  179. });
  180. </script>