accountRule.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div>
  3. <div class="div-border" v-for="(item,rowIndex) in ruleList" :key="rowIndex">
  4. <el-row :gutter="20" style="margin-top: 10px;margin-left: 10px">
  5. <el-col style="margin-bottom: 10px">
  6. <el-button type="primary" icon="el-icon-delete" style="float: right;margin-right: 10px" :disabled="!disabled" v-if="index !== rowIndex && ruleList.length > 1 && tool.checkAuth($route.name,'delete')" @click="onDel(item)"></el-button>
  7. <el-button type="primary" icon="el-icon-edit" style="float: right;margin-right: 10px" v-if="index !== rowIndex && tool.checkAuth($route.name,'update')" :disabled="!disabled" @click="onEdit(rowIndex)"></el-button>
  8. <el-button type="warning" icon="el-icon-circle-check" style="float: right;margin-right: 10px" v-if="isSave && index === rowIndex && tool.checkAuth($route.name,'update')" :disabled="!disabled" @click="onSave(item,rowIndex)"></el-button>
  9. </el-col>
  10. <el-form :model="item" :rules="rules" ref="form" label-width="120px" label-position="right" size="mini" :disabled="!disabled || !isSave || index !== rowIndex">
  11. <el-col :span="20">
  12. <el-form-item label="账号类型:" prop="usertype" >
  13. <el-select v-model="item.usertype" placeholder="请选择" style="width: 100%" >
  14. <el-option
  15. v-for="item in accountType"
  16. :key="item.value"
  17. :label="item.label"
  18. :value="item.value">
  19. </el-option>
  20. </el-select>
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="20">
  24. <el-form-item label="版本:" prop="sys_site_systempartitionid">
  25. <el-select v-model="item.sys_site_systempartitionid" placeholder="请选择" style="width: 100%">
  26. <el-option
  27. v-for="item in versionList"
  28. :key="item.sys_site_systempartitionid"
  29. :label="item.partitionname"
  30. :value="item.sys_site_systempartitionid">
  31. </el-option>
  32. </el-select>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="24" >
  36. <div style="width: 650px;margin-left: 15px" v-for="(ruleItem,ruleIndex) in item.paymentrules" :key="ruleIndex">
  37. <el-col :span="6">
  38. <el-form-item label="最少人数:" label-width="90px"
  39. :prop="'paymentrules.' + ruleIndex + '.min'"
  40. :rules="{required: true, message: '人数不能为空', trigger: 'blur'}">
  41. <el-input v-model="ruleItem.min" placeholder="请填写人数" type="number"></el-input>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="6">
  45. <el-form-item label="最多人数:" label-width="90px"
  46. :prop="'paymentrules.' + ruleIndex + '.max'"
  47. :rules="{required: true, message: '人数不能为空', trigger: 'blur'}">
  48. <el-input v-model="ruleItem.max" placeholder="请填写人数" type="number"></el-input>
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="7">
  52. <el-form-item label="定价(元):" label-width="90px"
  53. :prop="'paymentrules.' + ruleIndex + '.price'"
  54. :rules="{required: true,pattern:/^\d+(.\d{1,2})?$/, message: '只能输入数字且最多2位小数', trigger: 'blur'}">
  55. <el-input v-model="ruleItem.price" placeholder="请填写金额(元)" type="number"></el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="4">
  59. <el-button size="mini" type="primary" icon="el-icon-plus" circle v-if="ruleIndex === item.paymentrules.length -1 && tool.checkAuth($route.name,'insert')" class="inline-16" @click="addPrice(rowIndex)"></el-button>
  60. <el-button size="mini" type="info" icon="el-icon-close" circle v-if="item.paymentrules.length >1 && tool.checkAuth($route.name,'update')" @click="delPrice(ruleIndex,rowIndex)"></el-button>
  61. </el-col>
  62. </div>
  63. </el-col>
  64. </el-form>
  65. </el-row>
  66. </div>
  67. <div class="div-button">
  68. <el-button style="border: none;" :disabled="!disabled" icon="el-icon-plus" class="btn-block" @click="addRule" v-if="tool.checkAuth($route.name,'insert')">添 加</el-button>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import {log} from "@antv/g2plot/lib/utils";
  74. export default {
  75. name: "accountRule",
  76. props:["disabled"],
  77. data() {
  78. return {
  79. form: {
  80. "type": 1, //1:按账号付费,2:按主体付费
  81. "sys_site_paymentrulesid": 0,
  82. "sys_site_systempartitionid": '', //系统版本ID
  83. "usertype": '', //用户类型,按账号付费时必填
  84. "paymentrules": [
  85. {
  86. "min": 0,
  87. "max": 5,
  88. "price": 100
  89. }
  90. ], //定价规则,按账号付费时必填
  91. "price": '' //定价,按主体付费时必填
  92. },
  93. rules:{
  94. usertype: [
  95. { required: true, message: '请选择账户类型', trigger: 'change' },
  96. ],
  97. sys_site_systempartitionid: [
  98. { required: true, message: '请选择版本', trigger: 'change' },
  99. ],
  100. },
  101. isSave:false,
  102. accountType:[
  103. {
  104. value: '21',
  105. label: '主账号'
  106. },
  107. {
  108. value: '22',
  109. label: '子账号'
  110. }
  111. ],
  112. versionList:[],
  113. ruleList:[],
  114. index:''
  115. }
  116. },
  117. methods: {
  118. /*查询按账号付费规则*/
  119. async listData(){
  120. this.ruleList = []
  121. const res = await this.$api.requested({
  122. "classname": "webmanage.site.paymentrules",
  123. "method": "list",
  124. "content": {
  125. "type": 1, //1:按账号付费,2:按主体付费
  126. "pageNumber": 1,
  127. "pageSize": 20,
  128. "where": {
  129. "condition": ""
  130. }
  131. },
  132. })
  133. if (res.data.length < 1){
  134. this.ruleList.push({
  135. "type": 1, //1:按账号付费,2:按主体付费
  136. "sys_site_paymentrulesid": 0,
  137. "sys_site_systempartitionid": '', //系统版本ID
  138. "usertype": '', //用户类型,按账号付费时必填
  139. "paymentrules": [
  140. {
  141. "min": '',
  142. "max": '',
  143. "price": ''
  144. },
  145. ], //定价规则,按账号付费时必填
  146. "price": '' //定价,按主体付费时必填
  147. })
  148. }else {
  149. this.ruleList = res.data
  150. }
  151. this.ruleList.forEach(item=>{
  152. if (item.usertype == '21'){
  153. item.usertype = '主账号'
  154. }else {
  155. item.usertype = '子账号'
  156. }
  157. })
  158. },
  159. /*获取版本信息*/
  160. async queryVersion(){
  161. const res = await this.$api.requested({
  162. "classname": "webmanage.site.systempartition",
  163. "method": "list",
  164. "content": {
  165. "pageNumber": 1,
  166. "pageSize": 20,
  167. "where": {
  168. "condition": ""
  169. }
  170. },
  171. })
  172. this.versionList = res.data
  173. },
  174. /*配置价格*/
  175. addPrice(val){
  176. this.ruleList[val].paymentrules.push({
  177. "min": '',
  178. "max": '',
  179. "price": ''
  180. })
  181. },
  182. delPrice(val,rowIndex) {
  183. console.log(val,'删除价格')
  184. console.log(this.ruleList)
  185. this.ruleList[rowIndex].paymentrules.splice(val,1)
  186. },
  187. onEdit(val){
  188. this.index = val
  189. this.isSave = true
  190. },
  191. /*提交保存*/
  192. onSave(val,rowIndex){
  193. console.log(val,'保存')
  194. if (val.usertype === '主账号'){
  195. val.usertype = '21'
  196. }else if (val.usertype === '子账号'){
  197. val.usertype = '22'
  198. }
  199. val = {
  200. "type": 1, //1:按账号付费,2:按主体付费
  201. "sys_site_paymentrulesid": val.sys_site_paymentrulesid,
  202. "sys_site_systempartitionid": val.sys_site_systempartitionid, //系统版本ID
  203. "usertype": val.usertype, //用户类型,按账号付费时必填
  204. "paymentrules": val.paymentrules, //定价规则,按账号付费时必填
  205. "price": val.price //定价,按主体付费时必填
  206. }
  207. this.$refs.form[rowIndex].validate(async (valid) => {
  208. if (!valid) return false
  209. const res = await this.$api.requested({
  210. "classname": "webmanage.site.paymentrules",
  211. "method": "insertOrUpdate",
  212. "content": val,
  213. })
  214. this.isSave = false
  215. this.index = ''
  216. this.listData()
  217. })
  218. },
  219. /*新增规则*/
  220. addRule(val){
  221. this.ruleList.push({
  222. "type": 1, //1:按账号付费,2:按主体付费
  223. "sys_site_paymentrulesid": 0,
  224. "sys_site_systempartitionid": '', //系统版本ID
  225. "usertype": '', //用户类型,按账号付费时必填
  226. "paymentrules": [
  227. {
  228. "min": '',
  229. "max": '',
  230. "price": ''
  231. },
  232. ], //定价规则,按账号付费时必填
  233. "price": '' //定价,按主体付费时必填
  234. })
  235. this.index = this.ruleList.length -1
  236. this.isSave = true
  237. },
  238. /*删除规则*/
  239. async onDel(val){
  240. this.$confirm('此操作将永久删除该规则, 是否继续?', '提示', {
  241. confirmButtonText: '确定',
  242. cancelButtonText: '取消',
  243. type: 'warning'
  244. }).then(async () => {
  245. const res = await this.$api.requested({
  246. "classname": "webmanage.site.paymentrules",
  247. "method": "delete",
  248. "content": {
  249. "sys_site_paymentrulesid": val.sys_site_paymentrulesid
  250. },
  251. })
  252. this.tool.showMessage(res,()=>{
  253. this.listData()
  254. })
  255. }).catch(() => {
  256. this.$message({
  257. type: 'info',
  258. message: '已取消删除'
  259. });
  260. });
  261. }
  262. },
  263. mounted() {
  264. this.listData()
  265. this.queryVersion()
  266. }
  267. }
  268. </script>
  269. <style scoped>
  270. .div-border{
  271. width: 100%;
  272. height: 390px;
  273. border: 2px dashed #c9c3c3;
  274. border-radius: 5px;
  275. margin-bottom: 20px;
  276. overflow:auto;
  277. }
  278. .div-button{
  279. width: 100%;
  280. height: 30px;
  281. border: 2px dashed #c9c3c3;
  282. border-radius: 5px;
  283. margin-bottom: 20px;
  284. }
  285. .btn-block {
  286. display: block;
  287. width: 100%;
  288. padding-right: 0;
  289. padding-left: 0;
  290. padding-top: 10px;
  291. }
  292. </style>