combo-edit.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <style>
  2. .addons-cate {
  3. padding: 10px 0;
  4. }
  5. .addons-item {
  6. margin-bottom: 20px;
  7. }
  8. .el-checkbox.is-bordered+.el-checkbox.is-bordered {
  9. margin-left: 0;
  10. }
  11. .el-checkbox-group {
  12. font-size: 14px;
  13. }
  14. </style>
  15. <div id="app" v-cloak>
  16. <el-card v-loading="loading" style="border:0;min-width: 1200px;" shadow="never" body-style="background-color: #f3f3f3;padding: 0 0;">
  17. <el-form :model="ruleForm"
  18. ref="ruleForm"
  19. label-width="172px"
  20. :rules="rules"
  21. style="position: relative"
  22. size="small">
  23. <el-card shadow="never" class="mt-24">
  24. <div slot="header">
  25. <span>套餐编辑</span>
  26. </div>
  27. <el-form-item label="套餐名称" prop="title">
  28. <el-col :span="12">
  29. <el-input type="text" style="width: 350px;" v-model.trim="ruleForm.title"></el-input>
  30. </el-col>
  31. </el-form-item>
  32. <el-form-item label="套餐说明">
  33. <el-col :span="12">
  34. <el-input
  35. type="textarea"
  36. :autosize="{ minRows: 2, maxRows: 6}"
  37. placeholder="请输入内容"
  38. v-model="ruleForm.description">
  39. </el-input>
  40. </el-col>
  41. </el-form-item>
  42. <el-form-item label="应用有效期" prop="expire">
  43. <el-col :span="12">
  44. <el-checkbox v-model="ruleForm.expire.is_forever" style="margin-right: 10px;">永久有效</el-checkbox>
  45. <template v-if="ruleForm.expire.is_forever == false">
  46. <el-input style="width:150px" v-model="ruleForm.expire.duration" onInput="value=toNumber(value)"></el-input>
  47. <el-select v-model="ruleForm.expire.unit" style="width: 64px;">
  48. <el-option label="月" :value="1">月</el-option>
  49. <el-option label="年" :value="2">年</el-option>
  50. </el-select>
  51. </template>
  52. </el-col>
  53. </el-form-item>
  54. <el-form-item label="所有应用" prop="addons">
  55. <el-col :span="24">
  56. <el-alert
  57. title="温情提示: 套餐新增或删除时,将对已使用该套餐的所有店铺产生影响, 请选择客户访问店铺时间较少的时段调整. 如:店铺已购买小票打印应用且应用的到期时间小于套餐到期时间,此时修改套餐将小票打印调整为免费时, 店铺购买的应用到期时间将保留,且标记“套餐内免费使用”,套餐到期之前可免费使用该应用. 如果再次修改套餐取消免费使用,则保留应用到期时间,应用过期后需要续费使用"
  58. type="warning">
  59. </el-alert>
  60. <el-checkbox-group v-model="ruleForm.addons">
  61. <div v-for="(item, key) in addons_list" :key="key">
  62. <p class="addons-cate">{{ item.title }}</p>
  63. <div>
  64. <el-checkbox class="addons-item" v-for="(addon, index) in item.list" :key="index" size="medium" :label="addon.name" border>{{ addon.title }}</el-checkbox>
  65. </div>
  66. </div>
  67. </el-checkbox-group>
  68. </el-col>
  69. </el-form-item>
  70. <el-form-item>
  71. <el-col :span="12">
  72. <el-button :loading="submitLoading" size="small" type="primary"
  73. @click="submit('ruleForm')">保存
  74. </el-button>
  75. </el-col>
  76. </el-form-item>
  77. </el-card>
  78. </el-form>
  79. </el-card>
  80. </div>
  81. <script>
  82. const app = new Vue({
  83. el: '#app',
  84. data() {
  85. return {
  86. loading: false,
  87. submitLoading: false,
  88. ruleForm: {
  89. title: null,
  90. description: null,
  91. addons: [],
  92. expire: {
  93. is_forever: true,
  94. duration: 1,
  95. unit: 1
  96. }
  97. },
  98. addons_list: {},
  99. rules: {
  100. title: [
  101. { required: true, message: '请输入套餐名称', trigger: 'blur' },
  102. { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
  103. ],
  104. description: [
  105. { required: true, message: '请输入套餐说明', trigger: 'blur' },
  106. { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
  107. ],
  108. addons: [
  109. { type: 'array', required: true, message: '请至少选择一个应用', trigger: 'blur' }
  110. ],
  111. }
  112. };
  113. },
  114. created() {
  115. this.loadData();
  116. },
  117. methods: {
  118. loadData() {
  119. this.loading = true;
  120. request({
  121. params: {
  122. r: 'admin/addons/combo-edit',
  123. id: getQuery('id')
  124. },
  125. method: 'get',
  126. }).then(e => {
  127. this.loading = false;
  128. if (e.data.code === 0) {
  129. if (e.data.data) {
  130. if (!isEmpty(e.data.data.detail)) {
  131. this.ruleForm = e.data.data.detail;
  132. this.ruleForm.addons = JSON.parse(this.ruleForm.addons);
  133. this.ruleForm.expire = JSON.parse(this.ruleForm.expire);
  134. }
  135. if (!isEmpty(e.data.data.addons_list)) this.addons_list = e.data.data.addons_list;
  136. }
  137. } else {
  138. this.$message.error(e.data.msg);
  139. }
  140. }).catch(e => {
  141. });
  142. },
  143. submit(formName) {
  144. this.$refs[formName].validate((valid) => {
  145. if (valid) {
  146. this.submitLoading = true;
  147. this.ruleForm.id = getQuery('id');
  148. this.ruleForm.addons = JSON.stringify(this.ruleForm.addons);
  149. this.ruleForm.expire = JSON.stringify(this.ruleForm.expire);
  150. request({
  151. params: {
  152. r: 'admin/addons/combo-edit',
  153. },
  154. method: 'post',
  155. data: {
  156. detail: this.ruleForm
  157. },
  158. }).then(e => {
  159. this.submitLoading = false;
  160. if (e.data.code === 0) {
  161. this.$message.success(e.data.msg);
  162. navigateTo({
  163. r: 'admin/addons/combo'
  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>