edit.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <style>
  2. .form-body {
  3. padding: 20px 50% 20px 20px;
  4. background-color: #fff;
  5. margin-bottom: 20px;
  6. min-width: 1000px;
  7. }
  8. .form-button {
  9. margin: 0;
  10. }
  11. .form-button .el-form-item__content {
  12. margin-left: 0 !important;
  13. }
  14. .button-item {
  15. padding: 9px 25px;
  16. }
  17. .el-dialog__body {
  18. padding: 0 !important;
  19. }
  20. .el-dialog__header {
  21. padding: 0 !important;
  22. }
  23. </style>
  24. <?php
  25. use yii\helpers\Url;
  26. $diyRoute = Url::to(['goods-template/diy']);
  27. ?>
  28. <div id="app" v-cloak>
  29. <el-card class="box-card" v-loading="listLoading" shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  30. <div slot="header" class="clearfix">
  31. <el-breadcrumb separator="/">
  32. <el-breadcrumb-item><span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'mall/goods-template/index'})">广告模板</span></el-breadcrumb-item>
  33. <el-breadcrumb-item>模板编辑</el-breadcrumb-item>
  34. </el-breadcrumb>
  35. </div>
  36. <div class="form-body">
  37. <el-form :model="form" label-width="150px" :rules="FormRules" ref="form">
  38. <el-form-item label="模板名称" prop="name" required>
  39. <el-input size="small" v-model="form.name" autocomplete="off"></el-input>
  40. </el-form-item>
  41. <el-form-item label="模板编号" prop="id">
  42. <el-input size="small" v-model="form.id" disabled autocomplete="off"></el-input>
  43. </el-form-item>
  44. <el-form-item label="是否为默认模版" prop="is_default">
  45. <el-radio-group v-model="form.is_default">
  46. <el-radio :label="0">否</el-radio>
  47. <el-radio :label="1">是</el-radio>
  48. </el-radio-group>
  49. </el-form-item>
  50. <el-form-item label="状态" prop="status">
  51. <el-radio-group v-model="form.status">
  52. <el-radio :label="1">启用</el-radio>
  53. <el-radio :label="0">禁用</el-radio>
  54. </el-radio-group>
  55. </el-form-item>
  56. <el-form-item label="商品样式" prop="template_id">
  57. <el-button plain style="width: 200px;" @click="styleDialog">{{form.template_id > 0 ? "编辑样式": "设置样式"}}</el-button>
  58. </el-form-item>
  59. </el-form>
  60. </div>
  61. <el-button class="button-item" type="primary" :loading="btnLoading" @click="onSubmit">提交</el-button>
  62. </el-card>
  63. <el-dialog width="100%" height="100%" :fullscreen="isfullscreen" :visible.sync="visibleDialog" :close-on-click-modal="false">
  64. <div style="width:100%;height: 100%;position: absolute;">
  65. <iframe style="width: 100%;height: 100%;" :src="diyRoute">
  66. </iframe>
  67. </div>
  68. </el-dialog>
  69. </div>
  70. <script>
  71. const app = new Vue({
  72. el: '#app',
  73. data() {
  74. return {
  75. form: {
  76. id: 0,
  77. name: '',
  78. is_default: 0,
  79. status: 1,
  80. template_id: 0,
  81. },
  82. listLoading: false,
  83. btnLoading: false,
  84. FormRules: {},
  85. visibleDialog: false,
  86. isfullscreen: true,
  87. diyRoute: "<?= $diyRoute; ?>",
  88. };
  89. },
  90. methods: {
  91. styleDialog() {
  92. this.visibleDialog = true;
  93. },
  94. onSubmit() {
  95. this.$refs.form.validate((valid) => {
  96. if (valid) {
  97. if (!this.form.template_id || this.form.template_id <= 0) {
  98. this.$message.error('请设置商品样式后再提交');
  99. return;
  100. }
  101. this.btnLoading = true;
  102. console.log(this.form);
  103. request({
  104. params: {
  105. r: 'mall/goods-template/edit',
  106. },
  107. data: this.form,
  108. method: 'post'
  109. }).then(e => {
  110. if (e.data.code === 0) {
  111. navigateTo({
  112. r: 'mall/goods-template/index'
  113. });
  114. } else {
  115. this.$message.error(e.data.msg);
  116. }
  117. this.btnLoading = false;
  118. }).catch(e => {
  119. this.btnLoading = false;
  120. });
  121. }
  122. });
  123. },
  124. getDetail() {
  125. this.listLoading = true;
  126. request({
  127. params: {
  128. r: 'mall/goods-template/edit',
  129. id: getQuery('id'),
  130. },
  131. }).then(e => {
  132. if (e.data.code == 0) {
  133. this.form = Object.assign(this.form, e.data.data);
  134. if (this.form.template_id > 0) {
  135. this.diyRoute = this.diyRoute + '&id=' + this.form.template_id;
  136. }
  137. } else {
  138. this.$message.error(e.data.msg);
  139. }
  140. this.listLoading = false;
  141. }).catch(e => {
  142. this.listLoading = false;
  143. });
  144. },
  145. },
  146. mounted() {
  147. this.getDetail();
  148. window.addEventListener('message', (ev) => {
  149. let data = ev.data;
  150. if (Object.prototype.toString.call(data) === '[object String]') {
  151. data = JSON.parse(data);
  152. if (Object.keys(data).length !== 0) {
  153. if (this.form.template_id <= 0) this.form.template_id = data.id;
  154. }
  155. }
  156. this.visibleDialog = false;
  157. }, false);
  158. }
  159. })
  160. </script>