add-edit.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-image');
  4. ComponentHelper::loadComponentView('com-pick-link');
  5. ?>
  6. <style>
  7. .form-button {
  8. margin: 0!important;
  9. }
  10. .form-button .el-form-item__content {
  11. margin-left: 0!important;
  12. }
  13. .button-item {
  14. padding: 9px 25px;
  15. }
  16. .text {
  17. cursor: pointer;
  18. color: #419EFB;
  19. }
  20. .customize-share-title{
  21. position: relative;
  22. width: 80px;
  23. }
  24. .del-btn{
  25. position: absolute;
  26. right: -12px;
  27. top: -12px;
  28. }
  29. </style>
  30. <section id="app" v-cloak>
  31. <el-card class="box-card" shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  32. <div slot="header" class="clearfix">
  33. <div flex="cross:center box:first">
  34. <div><span @click="$navigate({r:'course/default/bannars'})" class="text">广告设置</span>/广告设置编辑</div>
  35. </div>
  36. </div>
  37. <div class="form-body">
  38. <el-form :model="ruleForm" label-width="80px" v-loading="loading" :rules="formRules" ref="ruleForm" style="margin-left: 25px;">
  39. <el-form-item label="广告名称" size="small" prop="title">
  40. <el-input v-model="ruleForm.title" auto-complete="off"></el-input>
  41. </el-form-item>
  42. <el-form-item label="排序" size="small" prop="sort">
  43. <el-input v-model="ruleForm.sort" auto-complete="off"></el-input>
  44. </el-form-item>
  45. <el-form-item label="跳转链接" size="small" prop="pic_link">
  46. <!-- <el-input v-model="ruleForm.pic_link" auto-complete="off" placeholder="(请填写完整)格式:https://www.baidu.com"></el-input> -->
  47. <el-input v-model="navicatLink" placeholder="点击选择链接" readonly size="small">
  48. <com-pick-link slot="append" @selected="linkSelected($event)">
  49. <el-button size="small">选择链接</el-button>
  50. </com-pick-link>
  51. </el-input>
  52. </el-form-item>
  53. <el-form-item label="是否启用" prop="is_show">
  54. <el-switch
  55. v-model="ruleForm.is_show"
  56. :active-value="1"
  57. :inactive-value="0"
  58. inactive-text="不启用"
  59. active-text="启用"
  60. >
  61. </el-switch>
  62. </el-form-item>
  63. <el-form-item prop="pic_path">
  64. <label slot="label">
  65. <span>广告图片</span>
  66. <el-tooltip effect="dark" content="上传图片,建议尺寸:750 * 300" placement="top">
  67. <i class="el-icon-info"></i>
  68. </el-tooltip>
  69. </label>
  70. <com-attachment v-model="ruleForm.pic_path" :multiple="false" :max="1">
  71. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 300" placement="top">
  72. <el-button size="mini">选择图片</el-button>
  73. </el-tooltip>
  74. </com-attachment>
  75. <div class="customize-share-title">
  76. <com-image mode="aspectFill" width='80px' height='80px'
  77. :src="ruleForm.pic_path ? ruleForm.pic_path : ''"></com-image>
  78. <el-button v-if="ruleForm.pic_path" class="del-btn" size="mini"
  79. type="danger" icon="el-icon-close" circle
  80. @click="ruleForm.pic_path = ''"></el-button>
  81. </div>
  82. <!-- <el-button @click="app_share.dialog = true;app_share.type = 'pic_bg'"
  83. type="text">查看图例
  84. </el-button> -->
  85. </el-form-item>
  86. <div flex="dir:right">
  87. <div>
  88. <el-button class="button-item" type="primary" size="small" :loading=btnLoading @click="submit('ruleForm')">提交</el-button>
  89. </div>
  90. </div>
  91. </el-form>
  92. </div>
  93. </el-card>
  94. </section>
  95. <script>
  96. const app = new Vue({
  97. el: '#app',
  98. data() {
  99. return {
  100. loading: false,
  101. btnLoading: false,
  102. navicatLink: '',
  103. ruleForm: {
  104. title:'',
  105. sort:'',
  106. is_show: '',
  107. pic_path:'',
  108. pic_link: '',
  109. },
  110. formRules: {
  111. title: [
  112. { required: true, pattern:/\S/, message: '名称不能为空', trigger: 'blur' },
  113. { min: 1, max: 30, message: "分类名称长度在2-255个字符内", trigger: 'blur' }
  114. ],
  115. sort: [
  116. { required: true, pattern: /^[0-9]\d{0,8}$/, message: '排序必须在9位整数内', trigger: 'blur' }
  117. ],
  118. // pic_link: [
  119. // { required: true, pattern:/\S/, message: '请填写广告跳转链接', trigger: 'blur' },
  120. // {pattern: /^(https?:\/\/(([a-zA-Z0-9]+-?)+[a-zA-Z0-9]+\.)+[a-zA-Z]+)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/, message: '链接格式不合法', trigger: 'blur'}
  121. // ],
  122. is_show: [{ required: true, message: '请选择是否启用广告', trigger: 'blur' }],
  123. pic_path: [
  124. { required: true, message: '请上传图片', trigger: 'blur' }
  125. ],
  126. },
  127. };
  128. },
  129. methods: {
  130. submit(formName) {
  131. this.$refs[formName].validate((valid,obj) => {
  132. if (valid) {
  133. this.btnLoading = true;
  134. request({
  135. params: {
  136. r: 'course/bannar/storage',
  137. },
  138. data: this.ruleForm,
  139. method: 'post'
  140. }).then(e => {
  141. this.btnLoading = false;
  142. if (e.data.code == 0) {
  143. const h = this.$createElement;
  144. this.$message({
  145. message: e.data.msg,
  146. type: 'success'
  147. });
  148. setTimeout(function(){
  149. navigateTo({ r: 'course/default/bannars' });
  150. },300);
  151. } else {
  152. this.$message({
  153. message: e.data.msg,
  154. type: 'error'
  155. });
  156. }
  157. }).catch(e => {
  158. this.btnLoading = false;
  159. this.$message.error(e.data.msg);
  160. });
  161. }else{
  162. var msg = '';
  163. for (let index in obj) {
  164. msg = msg + '*' + obj[index][0].message + ' ';
  165. }
  166. this.$message({
  167. message: msg,
  168. type: 'error'
  169. });
  170. return false;
  171. }
  172. });
  173. },
  174. linkSelected(e) {
  175. console.log(e);
  176. if (!e.length) {
  177. this.ruleForm.pic_link = '';
  178. return false;
  179. }
  180. this.ruleForm.pic_link = e[0];
  181. this.navicatLink = e[0].title + ' [ ' + e[0].route + ' ]';
  182. return ;
  183. },
  184. getBannarInfo() {
  185. this.loading = true;
  186. let _this = this;
  187. request({
  188. params: {
  189. r: 'course/bannar/storage',
  190. id: getQuery('id'),
  191. },
  192. method: 'get'
  193. }).then(e => {
  194. this.loading = false;
  195. if (e.data.code == 0) {
  196. _this.ruleForm = e.data.data;
  197. _this.navicatLink = e.data.data.pic_link.title + ' [ ' + e.data.data.pic_link.route + ' ]';
  198. }
  199. }).catch(e => {
  200. this.loading = false;
  201. this.$alert(e.data.msg, '提示', {
  202. confirmButtonText: '确定'
  203. })
  204. });
  205. },
  206. },
  207. mounted() {
  208. if (getQuery('id')) {
  209. this.getBannarInfo();
  210. }
  211. }
  212. })
  213. </script>