vip_setting.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div id="vip-setting">
  3. <el-button
  4. v-for="(title, i) of titles"
  5. :key="i"
  6. :type="i === currentIndex ? 'primary' : 'button'"
  7. @click="clickTitle(i)"
  8. >{{title}}</el-button>
  9. <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
  10. <h3>会员定价</h3>
  11. <h4>月付</h4>
  12. <el-form-item label="原价" prop="monthly_origin_price">
  13. <el-input v-model="ruleForm.monthly_origin_price"></el-input>
  14. </el-form-item>
  15. <el-form-item label="现价" prop="monthly_real_price">
  16. <el-input v-model="ruleForm.monthly_real_price"></el-input>
  17. </el-form-item>
  18. <el-form-item prop="can_buy_monthly">
  19. <el-checkbox label="支持购买" v-model="ruleForm.can_buy_monthly"></el-checkbox>
  20. </el-form-item>
  21. <h4>季付</h4>
  22. <el-form-item label="原价" prop="quarterly_origin_price">
  23. <el-input v-model="ruleForm.quarterly_origin_price"></el-input>
  24. </el-form-item>
  25. <el-form-item label="现价" prop="quarterly_real_price">
  26. <el-input v-model="ruleForm.quarterly_real_price"></el-input>
  27. </el-form-item>
  28. <el-form-item prop="can_buy_quarterly">
  29. <el-checkbox label="支持购买" v-model="ruleForm.can_buy_quarterly"></el-checkbox>
  30. </el-form-item>
  31. <h4>年付</h4>
  32. <el-form-item label="原价" prop="yearly_origin_price">
  33. <el-input v-model="ruleForm.yearly_origin_price"></el-input>
  34. </el-form-item>
  35. <el-form-item label="现价" prop="yearly_real_price">
  36. <el-input v-model="ruleForm.yearly_real_price"></el-input>
  37. </el-form-item>
  38. <el-form-item prop="can_buy_yearly">
  39. <el-checkbox label="支持购买" v-model="ruleForm.can_buy_yearly"></el-checkbox>
  40. </el-form-item>
  41. <h3>服务费减免</h3>
  42. <el-form-item label="整包" prop="project_reduction_rate">
  43. <el-input v-model="ruleForm.project_reduction_rate"></el-input>%
  44. </el-form-item>
  45. <el-form-item label="云端" prop="job_reduction_rate">
  46. <el-input v-model="ruleForm.job_reduction_rate"></el-input>%
  47. </el-form-item>
  48. <br>
  49. <el-form-item>
  50. <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
  51. </el-form-item>
  52. </el-form>
  53. </div>
  54. </template>
  55. <script>
  56. export default {
  57. data() {
  58. return {
  59. ruleForm: {},
  60. rules: {
  61. mOrigin: [
  62. { required: true, message: '请输入数字', trigger: 'blur' },
  63. ],
  64. mCurrent: [
  65. { required: true, message: '请输入数字', trigger: 'blur' },
  66. ],
  67. sOrigin: [
  68. { required: true, message: '请输入数字', trigger: 'blur' },
  69. ],
  70. sCurrent: [
  71. { required: true, message: '请输入数字', trigger: 'blur' },
  72. ],
  73. yOrigin: [
  74. { required: true, message: '请输入数字', trigger: 'blur' },
  75. ],
  76. sCurrent: [
  77. { required: true, message: '请输入数字', trigger: 'blur' },
  78. ],
  79. tPercent: [
  80. { required: true, message: '请输入数字', trigger: 'blur' },
  81. ],
  82. cPercent: [
  83. { required: true, message: '请输入数字', trigger: 'blur' },
  84. ],
  85. },
  86. // 当前 title 索引
  87. currentIndex: 0,
  88. // vip 的类型名字
  89. titles: [],
  90. // vip 列表
  91. list: [],
  92. }
  93. },
  94. mounted() {
  95. this.getList();
  96. },
  97. methods: {
  98. /**
  99. * 点击 title
  100. */
  101. clickTitle(i) {
  102. this.currentIndex = i;
  103. this.resetForm();
  104. this.getDetail(this.list[i]);
  105. },
  106. /**
  107. * 重置
  108. */
  109. resetForm(formName = 'ruleForm') {
  110. this.$refs[formName].resetFields();
  111. },
  112. /**
  113. * 保存或更新
  114. */
  115. async update() {
  116. const ruleForm = this.ruleForm;
  117. const can_buy_monthly = ruleForm.can_buy_monthly ? '1' : '0';
  118. const can_buy_quarterly = ruleForm.can_buy_quarterly ? '1' : '0';
  119. const can_buy_yearly = ruleForm.can_buy_yearly ? '1' : '0';
  120. const res = await this.$post("/api/admin/vip/update", {
  121. ...ruleForm,
  122. can_buy_monthly,
  123. can_buy_quarterly,
  124. can_buy_yearly,
  125. });
  126. if(res) this.$message({
  127. message: '更新成功',
  128. type: 'success'
  129. })
  130. },
  131. /**
  132. * 提交
  133. */
  134. submitForm(formName) {
  135. this.$refs[formName].validate((valid) => {
  136. if(valid) {
  137. console.log(this.ruleForm);
  138. this.update();
  139. } else {
  140. console.log('error submit!!');
  141. return false;
  142. }
  143. });
  144. },
  145. /**
  146. * 获取详情数据
  147. */
  148. async getDetail({ id }) {
  149. const res = await this.$post("/api/admin/vip/getDetail", { id });
  150. const data = res.data;
  151. const can_buy_monthly = data.can_buy_monthly === '1';
  152. const can_buy_quarterly = data.can_buy_quarterly === '1';
  153. const can_buy_yearly = data.can_buy_yearly === '1';
  154. // ruleForm 相当于 detail, 这里同步下关键词
  155. this.ruleForm = {
  156. ...data,
  157. can_buy_monthly,
  158. can_buy_quarterly,
  159. can_buy_yearly,
  160. };
  161. },
  162. /**
  163. * 获取列表数据
  164. */
  165. async getList() {
  166. const res = await this.$post("/api/admin/vip/getList");
  167. // console.log(res)
  168. this.list = res.data;
  169. this.titles = this.list.map(i => i.name);
  170. // 模拟点击一次
  171. this.clickTitle(0);
  172. }
  173. }
  174. }
  175. </script>
  176. <style>
  177. #vip-setting {
  178. padding: 20px;
  179. }
  180. .table {
  181. height: 100%;
  182. height: calc(100% - 80px);
  183. }
  184. .el-input {
  185. width: auto;
  186. }
  187. .el-check-group,
  188. .el-form-item,
  189. .el-form-item__content {
  190. display: inline-block;
  191. }
  192. </style>