MarketCode.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div>
  3. <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small"
  4. style="max-width: 500px;">
  5. <el-form-item prop="market" label="推广人">
  6. <el-input v-model="formData.market" :disabled="'market'==subColumn"></el-input>
  7. </el-form-item>
  8. <el-form-item prop="code" label="推广CODE">
  9. <el-input v-model="formData.code" :disabled="'code'==subColumn"></el-input>
  10. </el-form-item>
  11. <el-form-item prop="typeId" label="类型">
  12. <template>
  13. <el-select v-model="formData.typeId" clearable placeholder="请选择" :disabled="'typeId'==subColumn">
  14. <el-option
  15. v-for="item in typeIdOptions"
  16. :key="item.value"
  17. :label="item.label"
  18. :value="item.value">
  19. </el-option>
  20. </el-select>
  21. </template>
  22. </el-form-item>
  23. <el-form-item prop="remark" label="备注">
  24. <el-input v-model="formData.remark" :disabled="'remark'==subColumn"></el-input>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
  28. <el-button @click="onDelete" v-if="formData.id" type="danger">删除</el-button>
  29. <el-button @click="$router.go(-1)">取消</el-button>
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. </template>
  34. <script>
  35. import formValidator from '../formValidator'
  36. export default {
  37. created() {
  38. if (this.$route.query.column) {
  39. this.subColumn = this.$route.query.column.split(',')[1];
  40. this.subValue = this.$route.query.column.split(',')[0];
  41. }
  42. if (this.$route.query.id) {
  43. this.$http.get({
  44. url: '/marketCode/getOne',
  45. data: {
  46. id: this.$route.query.id
  47. }
  48. }).then(res => {
  49. if (res.success) {
  50. this.formData = res.data;
  51. if (this.$route.query.column) {
  52. this.formData[this.subColumn] = this.subValue;
  53. }
  54. }
  55. })
  56. }else {
  57. if (this.$route.query.column) {
  58. this.formData[this.subColumn] = this.subValue;
  59. }
  60. }
  61. this.$http.get({
  62. url:'/marketType/all'
  63. }).then(res => {
  64. if (res.success) {
  65. if (res.data.length > 0) {
  66. res.data.forEach(item => {
  67. this.typeIdOptions.push({label: item.typeName, value:item.id});
  68. })
  69. }
  70. }
  71. });
  72. },
  73. data() {
  74. return {
  75. saving: false,
  76. formData: {},
  77. rules: {
  78. market:
  79. [
  80. {required: true, message: '请输入 推广人', trigger: 'blur'},
  81. ],
  82. code:
  83. [
  84. {required: true, message: '请输入 推广CODE', trigger: 'blur'},
  85. ],
  86. typeId:
  87. [
  88. {required: true, message: '请输入 类型', trigger: 'blur'},
  89. ],
  90. },
  91. typeIdOptions:[],
  92. subColumn: '',
  93. subValue: '',
  94. }
  95. },
  96. methods: {
  97. onSave() {
  98. this.$refs.form.validate((valid) => {
  99. if (valid) {
  100. this.submit();
  101. } else {
  102. return false;
  103. }
  104. });
  105. },
  106. submit() {
  107. var data = JSON.parse(JSON.stringify(this.formData));
  108. this.$http.post({
  109. url: this.formData.id ? '/marketCode/update' : '/marketCode/save',
  110. data: data
  111. }).then(res => {
  112. if (res.success) {
  113. this.$message.success('成功');
  114. this.$router.go(-1);
  115. } else {
  116. this.$message.warning('失败')
  117. }
  118. });
  119. },
  120. onDelete() {
  121. this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' }).then(() => {
  122. return this.$http.post({
  123. url: '/marketCode/del',
  124. data: { id: this.formData.id }
  125. })
  126. }).then(() => {
  127. this.$message.success('删除成功');
  128. this.$router.go(-1);
  129. }).catch(action => {
  130. if (action === 'cancel') {
  131. this.$message.info('删除取消');
  132. } else {
  133. this.$message.error('删除失败');
  134. }
  135. })
  136. },
  137. }
  138. }
  139. </script>
  140. <style lang="less" scoped>
  141. </style>