AddProductLine.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div>
  3. <!-------------面包屑-------------->
  4. <crumbs :title="`产品线管理-${isEdit?'修改':'添加'}产品线`" linkTo="productDetail">
  5. </crumbs>
  6. <!--------------表单--------------->
  7. <div class="contents">
  8. <el-form ref="form" :rules="rules" :model="form" label-width="80px" class="add-product-form">
  9. <h4>基本信息</h4>
  10. <el-form-item label="产品名称" required prop="name">
  11. <el-input class="inp" v-model="form.name" size="small"></el-input>
  12. </el-form-item>
  13. <el-form-item label="URL" prop="url" size="small" style="margin-top: 15px;" required>
  14. <el-input class="inp" v-model="form.url" :disabled="isEdit?true:false" maxlength="2083"></el-input>
  15. </el-form-item>
  16. <el-form-item label="是否试用" prop="trialStatus" required style="margin-bottom: 16px;">
  17. <el-radio-group v-model="form.trialStatus" :disabled="isEdit?true:false">
  18. <el-radio :label="1">是</el-radio>
  19. <el-radio :label="0">否</el-radio>
  20. </el-radio-group>
  21. </el-form-item>
  22. <el-form-item v-if="form.trialStatus=='1'" label="试用URL" prop="trialUrl" size="small" style="margin-top: 10px;" required>
  23. <el-input class="inp" v-model="form.trialUrl" :disabled="isEdit?true:false" maxlength="2083"></el-input>
  24. </el-form-item>
  25. <el-form-item label="产品描述" prop="decription" required class="adjust-error">
  26. <el-input type="textarea"
  27. v-model="form.decription"
  28. placeholder="请填写描述文档"
  29. style="width: 300px;"
  30. ></el-input>
  31. </el-form-item>
  32. <el-form-item label="接入模式" required prop="accessType">
  33. <el-checkbox-group v-model="form.accessType" :disabled="isEdit?true:false">
  34. <el-checkbox v-for="(it,index) in accessType" :label="it.key+''" name="accessType">{{it.name}}</el-checkbox>
  35. </el-checkbox-group>
  36. </el-form-item>
  37. <el-form-item label="收费模式" required prop="chargeType" style="margin-bottom: 10px;">
  38. <el-checkbox-group v-model="form.chargeType" :disabled="isEdit?true:false">
  39. <el-checkbox v-for="(it,index) in chargeType" :label="it.key+''" name="chargeType">{{it.name}}</el-checkbox>
  40. </el-checkbox-group>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button size="small" type="primary" @click="addProductLine">确定{{isEdit?'修改':'添加'}}</el-button>
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import api from '@api/admin.js';
  51. import utils from '@api/utils.js';
  52. export default {
  53. name: 'add-product-line',
  54. data: function () {
  55. const urlValidate = (rule,value,callback)=>{
  56. if(!value){
  57. return callback(new Error('请输入URL'));
  58. }
  59. if(!utils.url.test(value)){
  60. return callback(new Error('请输入正确的URL'));
  61. }
  62. callback();
  63. };
  64. const nameValidate = (rule, value, callback) => {
  65. if (!value) {
  66. return callback(new Error('请输入产品名称'));
  67. }
  68. if (value.length > 44) {
  69. this.form.name = value.substr(0, 44);
  70. this.$message({
  71. showClose: true,
  72. type: 'warning',
  73. message: '产品名称最多可输入44个字'
  74. })
  75. }
  76. callback();
  77. };
  78. const decriptionValidate = (rule, value, callback) => {
  79. if (!value) {
  80. return callback(new Error('请输入产品描述'));
  81. }
  82. if (value.length > 200) {
  83. this.form.decription = value.substr(0, 200);
  84. this.$message({
  85. showClose: true,
  86. type: 'warning',
  87. message: '产品描述最多可输入200个字'
  88. })
  89. }
  90. callback();
  91. };
  92. return {
  93. accessType:[],
  94. accessType:[],
  95. isEdit:false,
  96. form: {
  97. name: '',
  98. url: '',
  99. accessType: [],
  100. chargeType: [],
  101. decription: '',
  102. trialStatus: '',
  103. trialUrl:''
  104. },
  105. rules:{
  106. name:[
  107. { required: true, validator: nameValidate, trigger: ['blur', 'change'] }
  108. ],
  109. accessType:[
  110. { required: true, message: '请选择接入模式', trigger: ['blur', 'change'] }
  111. ],
  112. chargeType:[
  113. { required: true, message: '请选择收费模式', trigger: ['blur', 'change'] }
  114. ],
  115. decription:[
  116. { required: true, validator: decriptionValidate, trigger: ['blur', 'change'] }
  117. ],
  118. trialStatus:[
  119. { required: true, message: '请选择是否试用', trigger: ['blur', 'change'] }
  120. ],
  121. trialUrl:[
  122. { validator: urlValidate, trigger: ['blur', 'change'] }
  123. ],
  124. url:[
  125. { validator: urlValidate, trigger: ['blur', 'change'] }
  126. ],
  127. }
  128. }
  129. },
  130. created() {
  131. //获取枚举类型
  132. const enums = JSON.parse(localStorage.getItem('enumsData'));
  133. this.accessType = enums.accessTypeEnum;
  134. this.chargeType = enums.chargeTypeEnum;
  135. //编辑时获取参数
  136. console.log(this.$route.params);
  137. const info = this.$route.params.info;
  138. if(info){
  139. this.isEdit = true;
  140. this.form.accessType = info.accessType.split(",");
  141. this.form.chargeType = info.chargeType.split(",");
  142. this.form.decription = info.decription;
  143. this.form.url = info.url;
  144. this.form.name = info.name;
  145. this.form.trialStatus = info.trialStatus;
  146. this.form.id = info.id;
  147. this.form.trialUrl = info.trialUrl;
  148. }
  149. },
  150. methods: {
  151. addProductLine() {
  152. this.$refs.form.validate((valid)=>{
  153. if(valid){
  154. const req = this.isEdit?api.editProductLine:api.addProductLine;
  155. let param = Object.assign({},this.form);
  156. param.accessType = this.form.accessType.join(",");
  157. param.chargeType = this.form.chargeType.join(",");
  158. req(param).then((res) => {
  159. if (res.data.code == '0') {
  160. this.$message({showClose: true,message: "操作成功", type: 'success'});
  161. this.$router.push({path: '/admin/LT-CPXGL'});
  162. }else {
  163. this.$message({
  164. showClose: true,
  165. message: res.data.msg,
  166. type: 'warning'
  167. });
  168. if(res.data.code == '00020001'){ //产品不存在,跳转到产品线管理页面
  169. this.$router.push({path:'/admin/LT-CPXGL'});
  170. }
  171. }
  172. }).catch((error) => {
  173. this.$message({
  174. showClose: true,
  175. message: "服务器正忙...",
  176. type: 'warning'
  177. });
  178. })
  179. }
  180. });
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="less">
  186. .add-product-form .adjust-error{
  187. margin-bottom:10px;
  188. .el-form-item__error{
  189. top:100%;
  190. }
  191. }
  192. </style>
  193. <style lang="less" scoped>
  194. @import "../../less/admin.less";
  195. .add-product-form {
  196. background: #fff;
  197. padding: 20px 10px 30px;
  198. .inp{
  199. width: 300px;
  200. }
  201. & > div {
  202. margin-left: 9px;
  203. }
  204. }
  205. h4 {
  206. text-indent: 20px;
  207. font-size: 15px;
  208. margin-bottom: 20px;
  209. }
  210. </style>