add.vue 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>规格名:</span>
  7. <div class="flex-item">
  8. <div style="width:50%">
  9. <el-input
  10. placeholder="请输入规格名"
  11. v-model="postData.SpecName"
  12. clearable>
  13. </el-input>
  14. </div>
  15. </div>
  16. </li>
  17. <li class="flex-h">
  18. <span>选择案场:</span>
  19. <div class="flex-item">
  20. <div style="width:50%">
  21. <el-select v-model="CaseId" placeholder="请选择">
  22. <el-option
  23. v-for="item in cases"
  24. :key="item.CaseId"
  25. :label="item.CaseName"
  26. :value="item.CaseId">
  27. </el-option>
  28. </el-select>
  29. </div>
  30. </div>
  31. </li>
  32. <li style="text-align:center">
  33. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  34. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  35. </li>
  36. </ul>
  37. </form>
  38. </div>
  39. </template>
  40. <script>
  41. import { mapState } from 'vuex'
  42. export default {
  43. name: '',
  44. data () {
  45. return {
  46. postData: {
  47. SpecId: '', // 规格id(新增传空值)
  48. SpecName: '', // 规格名称
  49. Status: '', // 状态(无状态可传空值)
  50. OrgId: '', // 机构id
  51. CaseId: '', // 案场id
  52. }
  53. }
  54. },
  55. computed: {
  56. ...mapState({
  57. cases: x => x.app.cases.list,
  58. defaultCaseId: x => x.app.cases.default,
  59. OrgId: x => x.app.user.OrgId,
  60. }),
  61. CaseId: {
  62. get () {
  63. return this.postData.CaseId === '' ? this.defaultCaseId || '' : this.postData.CaseId
  64. },
  65. set (val) {
  66. this.postData.CaseId = val
  67. }
  68. }
  69. },
  70. components: {},
  71. methods: {
  72. submit () { // 提交数据
  73. this.postData.OrgId = this.OrgId
  74. if (this.postData.CaseId === '') this.postData.CaseId = this.CaseId
  75. this.$ajax(this.$api.goodsManager.addGoodsSpec.url, {
  76. method: this.$api.goodsManager.addGoodsSpec.method,
  77. data: this.postData
  78. }).then(res => {
  79. this.$message({
  80. type: 'success',
  81. message: '操作成功'
  82. })
  83. this.$router.push({ name: 'goodsSpecManager' })
  84. })
  85. },
  86. cancel () {
  87. this.$router.push({ name: 'goodsSpecManager' })
  88. }
  89. },
  90. mounted () { }
  91. }
  92. </script>
  93. <!-- Add "scoped" attribute to limit CSS to this component only -->
  94. <style lang="scss" scoped>
  95. </style>