addEdit.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="'新建需求'"
  5. :center="true"
  6. align="left"
  7. top="5vh"
  8. width="1040px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="showModelThis = false"
  15. >
  16. <el-card style="margin-top: -20px">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. :rules="rulesThis"
  24. label-width="0px"
  25. class="demo-ruleForm"
  26. >
  27. <el-row>
  28. <el-col :span="12">
  29. <el-form-item prop="title">
  30. <el-input
  31. v-model="ruleForm.title"
  32. maxlength="250"
  33. :size="'medium'"
  34. :placeholder="'标题'"
  35. :disabled="isDetail"
  36. />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="12" style="padding: 0 0 0 10px">
  40. <el-form-item prop="model_id">
  41. <good-class
  42. :value="ruleForm.model_id"
  43. :size="'medium'"
  44. @handleChange="goods_class_change"
  45. :disabled="isDetail"
  46. :type="'1'"
  47. :placeholder="'功能区'"
  48. />
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="24" v-if="!loading">
  52. <tinymce
  53. v-model="ruleForm.remark"
  54. :width="'100%'"
  55. :height="'300px'"
  56. />
  57. </el-col>
  58. </el-row>
  59. </el-form>
  60. </el-col>
  61. <el-col :span="24" style="text-align: right; padding: 15px 0 0 0">
  62. <el-button
  63. v-if="!isDetail"
  64. :size="'mini'"
  65. type="primary"
  66. @click="submitForm"
  67. >保 存
  68. </el-button>
  69. <el-button :size="'mini'" @click="showModelThis = false">{{
  70. isDetail ? "关 闭" : "取 消"
  71. }}</el-button>
  72. </el-col>
  73. </el-row>
  74. </el-card>
  75. </el-dialog>
  76. </template>
  77. <script>
  78. import asyncRequest from "@/apis/service/purchaseAndSale/adjust";
  79. import resToken from "@/mixins/resToken";
  80. import Tinymce from "@/components/Tinymce";
  81. import { platformType } from "./columns";
  82. import contrastModelVue from "./contrastModel.vue";
  83. export default {
  84. name: "adjust",
  85. props: ["showModel", "id", "isDetail", "sitem"],
  86. mixins: [resToken],
  87. components: {
  88. Tinymce,
  89. },
  90. data() {
  91. return {
  92. loading: false,
  93. organizeList: [],
  94. showModelThis: this.showModel,
  95. ruleForm: {
  96. title: "", // 账号
  97. company_type: platformType,
  98. model_id: [], // 功能区
  99. remark: "",
  100. },
  101. rulesThis: this.rules,
  102. rules: {
  103. title: [
  104. {
  105. required: true,
  106. message: "请输入标题",
  107. trigger: "blur",
  108. },
  109. ],
  110. model_id: [
  111. {
  112. type: "array",
  113. required: true,
  114. message: "请选择功能区",
  115. trigger: "change",
  116. },
  117. ],
  118. remark: [
  119. {
  120. required: true,
  121. message: "请输入描述",
  122. trigger: "blur",
  123. },
  124. ],
  125. },
  126. };
  127. },
  128. watch: {
  129. showModel: function (val) {
  130. this.showModelThis = val;
  131. if (val) {
  132. this.initForm();
  133. }
  134. },
  135. showModelThis(val) {
  136. if (!val) {
  137. this.$emit("cancel");
  138. }
  139. },
  140. },
  141. mounted() {},
  142. methods: {
  143. async initForm() {
  144. this.loading = true;
  145. this.rulesThis = this.rules;
  146. await this.resetForm();
  147. this.loading = false;
  148. },
  149. async resetForm() {
  150. // 重置
  151. await this.$nextTick(() => {
  152. if (this.$refs.ruleForm) {
  153. this.$refs.ruleForm.resetFields();
  154. this.$refs.ruleForm.clearValidate();
  155. this.ruleForm = {
  156. title: "", // 账号
  157. company_type: platformType,
  158. model_id: [], // 功能区
  159. remark: `<h4>【故障现象描述:】</h4>\n<p style="font-size: 12px;">必填 Ctrl+V粘贴截图</p>\n<h4>【期望结果描述:】</h4>\n<p style="font-size: 12px;">必填 Ctrl+V粘贴截图</p>`,
  160. };
  161. }
  162. });
  163. },
  164. goods_class_change(e) {
  165. this.ruleForm.model_id = e;
  166. this.$refs.ruleForm.validateField("model_id");
  167. },
  168. async submitForm() {
  169. await this.$refs.ruleForm.validate(async (valid) => {
  170. if (valid) {
  171. this.loading = true;
  172. let model = JSON.parse(JSON.stringify(this.ruleForm));
  173. let remark = model.remark;
  174. remark = remark.replace(/\n/g, "");
  175. remark = remark.replace(/"/g, "'");
  176. model.remark = remark;
  177. let length = 5000;
  178. if (model.remark.length > length) {
  179. this.$message.warning("描述文字及标签总长度不能超过5000!");
  180. this.loading = false;
  181. return;
  182. }
  183. let res = await asyncRequest.add(model);
  184. this.loading = false;
  185. if (res && res.code === 0) {
  186. this.$notify.success({
  187. title: "添加成功",
  188. message: "",
  189. });
  190. this.showModelThis = false;
  191. // 刷新
  192. this.$emit("refresh");
  193. } else if (res && res.code >= 100 && res.code <= 104) {
  194. await this.logout();
  195. } else {
  196. this.$message.warning(res.message);
  197. }
  198. } else {
  199. console.log("error submit!!");
  200. return false;
  201. }
  202. });
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="scss" scoped>
  208. .account {
  209. }
  210. </style>