add-edit.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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:'bargain/banner/index'})" 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="sort">
  40. <el-input v-model="ruleForm.sort" auto-complete="off"></el-input>
  41. </el-form-item>
  42. <el-form-item label="跳转链接" size="small" prop="pic_link">
  43. <el-input v-model="navicatLink" placeholder="点击选择链接" readonly size="small">
  44. <com-pick-link slot="append" @selected="linkSelected($event)">
  45. <el-button size="small">选择链接</el-button>
  46. </com-pick-link>
  47. </el-input>
  48. </el-form-item>
  49. <el-form-item label="是否启用" prop="is_show">
  50. <el-switch
  51. v-model="ruleForm.is_show"
  52. :active-value="1"
  53. :inactive-value="0"
  54. inactive-text="不启用"
  55. active-text="启用"
  56. >
  57. </el-switch>
  58. </el-form-item>
  59. <el-form-item prop="pic_path">
  60. <label slot="label">
  61. <span>广告图片</span>
  62. <el-tooltip effect="dark" content="上传图片,建议尺寸:750 * 300" placement="top">
  63. <i class="el-icon-info"></i>
  64. </el-tooltip>
  65. </label>
  66. <com-attachment v-model="ruleForm.pic_path" :multiple="false" :max="1">
  67. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 300" placement="top">
  68. <el-button size="mini">选择图片</el-button>
  69. </el-tooltip>
  70. </com-attachment>
  71. <div class="customize-share-title">
  72. <com-image mode="aspectFill" width='80px' height='80px'
  73. :src="ruleForm.pic_path ? ruleForm.pic_path : ''"></com-image>
  74. <el-button v-if="ruleForm.pic_path" class="del-btn" size="mini"
  75. type="danger" icon="el-icon-close" circle
  76. @click="ruleForm.pic_path = ''"></el-button>
  77. </div>
  78. </el-form-item>
  79. <div flex="dir:right">
  80. <div>
  81. <el-button class="button-item" type="primary" size="small" :loading=btnLoading @click="submit('ruleForm')">提交</el-button>
  82. </div>
  83. </div>
  84. </el-form>
  85. </div>
  86. </el-card>
  87. </section>
  88. <script>
  89. const app = new Vue({
  90. el: '#app',
  91. data() {
  92. return {
  93. loading: false,
  94. btnLoading: false,
  95. navicatLink: '',
  96. ruleForm: {
  97. sort:'',
  98. is_show: '',
  99. pic_path:'',
  100. pic_link: '',
  101. },
  102. formRules: {
  103. // title: [
  104. // { required: true, pattern:/\S/, message: '名称不能为空', trigger: 'blur' },
  105. // { min: 1, max: 30, message: "分类名称长度在2-255个字符内", trigger: 'blur' }
  106. // ],
  107. sort: [
  108. { required: true, pattern: /^[0-9]\d{0,8}$/, message: '排序必须在9位整数内', trigger: 'blur' }
  109. ],
  110. // pic_link: [
  111. // { required: true, pattern:/\S/, message: '请填写广告跳转链接', trigger: 'blur' },
  112. // {pattern: /^(https?:\/\/(([a-zA-Z0-9]+-?)+[a-zA-Z0-9]+\.)+[a-zA-Z]+)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/, message: '链接格式不合法', trigger: 'blur'}
  113. // ],
  114. is_show: [{ required: true, message: '请选择是否启用广告', trigger: 'blur' }],
  115. pic_path: [
  116. { required: true, message: '请上传图片', trigger: 'blur' }
  117. ],
  118. },
  119. };
  120. },
  121. methods: {
  122. submit(formName) {
  123. this.$refs[formName].validate((valid,obj) => {
  124. if (valid) {
  125. this.btnLoading = true;
  126. request({
  127. params: {
  128. r: 'bargain/banner/storage',
  129. },
  130. data: this.ruleForm,
  131. method: 'post'
  132. }).then(e => {
  133. this.btnLoading = false;
  134. if (e.data.code == 0) {
  135. const h = this.$createElement;
  136. this.$message({
  137. message: e.data.msg,
  138. type: 'success'
  139. });
  140. setTimeout(function(){
  141. navigateTo({ r: 'bargain/banner/index' });
  142. },300);
  143. } else {
  144. this.$message({
  145. message: e.data.msg,
  146. type: 'error'
  147. });
  148. }
  149. }).catch(e => {
  150. this.btnLoading = false;
  151. this.$message.error(e.data.msg);
  152. });
  153. }else{
  154. var msg = '';
  155. for (let index in obj) {
  156. msg = msg + '*' + obj[index][0].message + ' ';
  157. }
  158. this.$message({
  159. message: msg,
  160. type: 'error'
  161. });
  162. return false;
  163. }
  164. });
  165. },
  166. linkSelected(e) {
  167. console.log(e);
  168. if (!e.length) {
  169. this.ruleForm.pic_link = '';
  170. return false;
  171. }
  172. this.ruleForm.pic_link = e[0];
  173. this.navicatLink = e[0].title + ' [ ' + e[0].route + ' ]';
  174. return ;
  175. },
  176. getbannerInfo() {
  177. this.loading = true;
  178. let _this = this;
  179. request({
  180. params: {
  181. r: 'bargain/banner/storage',
  182. id: getQuery('id'),
  183. },
  184. method: 'get'
  185. }).then(e => {
  186. this.loading = false;
  187. if (e.data.code == 0) {
  188. _this.ruleForm = e.data.data;
  189. _this.navicatLink = e.data.data.pic_link.title + ' [ ' + e.data.data.pic_link.route + ' ]';
  190. }
  191. }).catch(e => {
  192. this.loading = false;
  193. this.$alert(e.data.msg, '提示', {
  194. confirmButtonText: '确定'
  195. })
  196. });
  197. },
  198. },
  199. mounted() {
  200. if (getQuery('id')) {
  201. this.getbannerInfo();
  202. }
  203. }
  204. })
  205. </script>