combo-edit.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="app-container">
  3. <el-divider content-position="left">会员套餐配置</el-divider>
  4. <div class="list">
  5. <div v-for="(item, index) in packageList" :key="index" class="section">
  6. <div class="control">
  7. <span>套餐{{ index + 1 }}</span>
  8. </div>
  9. <div class="control">
  10. <span>期限</span>
  11. <el-input v-model="item.duration" size="mini" style="width: 80px; margin-right: 16px" />
  12. <el-select v-model="item.unit" placeholder="请选择" size="mini">
  13. <el-option label="月" :value="1" />
  14. <el-option label="年" :value="2" />
  15. </el-select>
  16. </div>
  17. <div class="control">
  18. <span>原价</span>
  19. <el-input v-model="item.originalPrice" size="mini" />
  20. <span>元</span>
  21. </div>
  22. <div class="control">
  23. <span>现价</span>
  24. <el-input v-model="item.price" size="mini" />
  25. <span>元</span>
  26. </div>
  27. <div class="control">
  28. <el-button
  29. v-if="index === packageList.length - 1"
  30. type="primary"
  31. size="mini"
  32. @click="insertOnePackage"
  33. >添加</el-button>
  34. <el-button
  35. v-if="canRemovePackage"
  36. type="danger"
  37. size="mini"
  38. @click="removeOnePackage(item, index)"
  39. >删除</el-button>
  40. </div>
  41. </div>
  42. </div>
  43. <el-divider content-position="left">会员订制服务配置</el-divider>
  44. <div class="list">
  45. <div v-for="(item, index) in serviceList" :key="index" class="section">
  46. <div class="control">
  47. <span>订制服务{{ index + 1 }}</span>
  48. </div>
  49. <div class="control">
  50. <span>订制服务名称</span>
  51. <el-input v-model="item.name" size="mini" />
  52. </div>
  53. <div class="control">
  54. <el-button
  55. v-if="index === serviceList.length - 1"
  56. type="primary"
  57. size="mini"
  58. @click="insertOneSerivice"
  59. >添加</el-button>
  60. <el-button
  61. v-if="canRemoveService"
  62. type="danger"
  63. size="mini"
  64. @click="removeOneService(item, index)"
  65. >删除</el-button>
  66. </div>
  67. </div>
  68. </div>
  69. <el-divider />
  70. <!-- 确认 取消 -->
  71. <div class="control-box">
  72. <el-button type="warning" @click="navigateBack">返回</el-button>
  73. <el-button type="primary" @click="updateConfigure">保存</el-button>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import { fetchConfigureList, updateConfigure } from '@/api/member'
  79. export default {
  80. name: 'ComboEdit',
  81. data() {
  82. return {
  83. dateType: 1,
  84. packageList: [],
  85. serviceList: []
  86. }
  87. },
  88. computed: {
  89. canRemovePackage() {
  90. return this.packageList.length > 1
  91. },
  92. canRemoveService() {
  93. return this.serviceList.length > 1
  94. }
  95. },
  96. created() {
  97. this.fetchConfigureList()
  98. },
  99. methods: {
  100. // 获取套餐 服务配置列表
  101. fetchConfigureList() {
  102. fetchConfigureList()
  103. .then((res) => {
  104. this.packageList = res.data.packageList
  105. this.serviceList = res.data.serviceList
  106. if (this.packageList.length === 0) {
  107. this.insertOnePackage()
  108. }
  109. if (this.serviceList.length === 0) {
  110. this.insertOneSerivice()
  111. }
  112. })
  113. .catch((error) => {
  114. console.log(error)
  115. })
  116. },
  117. // 校验文本框内容
  118. validateInputContent() {
  119. const hasEmptyPackage = this.packageList.some((item) => {
  120. for (const key in item) {
  121. if (!item[key]) return false
  122. }
  123. return true
  124. })
  125. const hasEmptyService = this.serviceList.some((item) => {
  126. for (const key in item) {
  127. if (!item[key]) return false
  128. }
  129. return true
  130. })
  131. return hasEmptyService && hasEmptyPackage
  132. },
  133. // 更新套餐 服务配置列表
  134. updateConfigure() {
  135. if (!this.validateInputContent()) {
  136. this.$message.warning('已添加项不能为空')
  137. return
  138. }
  139. updateConfigure({ packageList: this.packageList, serviceList: this.serviceList })
  140. .then((res) => {
  141. console.log(res)
  142. this.$message.success('套餐配置保存成功')
  143. })
  144. .catch((error) => {
  145. console.log(error)
  146. })
  147. },
  148. // 添加一条空套餐记录
  149. insertOnePackage() {
  150. this.packageList.push({
  151. duration: '',
  152. unit: 1,
  153. originalPrice: '',
  154. price: ''
  155. })
  156. },
  157. // 添加一条空服务记录
  158. insertOneSerivice() {
  159. this.serviceList.push({
  160. name: ''
  161. })
  162. },
  163. // 删除一条套餐记录
  164. removeOnePackage(item, index) {
  165. if (item.id) {
  166. this.$confirm('确认删除该项配置?', '提示', {
  167. confirmButtonText: '确定',
  168. cancelButtonText: '取消',
  169. type: 'warning'
  170. })
  171. .then(() => {
  172. this.packageList.splice(index, 1)
  173. })
  174. .catch(() => {
  175. this.$message({
  176. type: 'info',
  177. message: '已取消删除'
  178. })
  179. })
  180. } else {
  181. this.packageList.splice(index, 1)
  182. }
  183. },
  184. // 删除一条服务记录
  185. removeOneService(item, index) {
  186. if (item.id) {
  187. this.$confirm('确认删除该项配置?', '提示', {
  188. confirmButtonText: '确定',
  189. cancelButtonText: '取消',
  190. type: 'warning'
  191. })
  192. .then(() => {
  193. this.serviceList.splice(index, 1)
  194. })
  195. .catch(() => {
  196. this.$message({
  197. type: 'info',
  198. message: '已取消删除'
  199. })
  200. })
  201. } else {
  202. this.serviceList.splice(index, 1)
  203. }
  204. }
  205. }
  206. }
  207. </script>
  208. <style scoped lang="scss">
  209. .list {
  210. margin-bottom: 60px;
  211. }
  212. .section {
  213. margin: 24px 0;
  214. margin-left: 32px;
  215. .control {
  216. display: inline-block;
  217. margin-bottom: 10px;
  218. margin-right: 10px;
  219. > span,
  220. > .el-input {
  221. display: inline-block;
  222. vertical-align: middle;
  223. }
  224. > span {
  225. margin: 0 10px;
  226. font-size: 14px;
  227. }
  228. > .el-input {
  229. width: 160px;
  230. }
  231. > .el-select {
  232. width: 100px;
  233. }
  234. }
  235. }
  236. </style>