MedicineInfoPg.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <el-form
  3. :rules="rules"
  4. :model="data"
  5. ref="form"
  6. class="sub-form"
  7. :validate-on-rule-change="false"
  8. >
  9. <!--<el-input v-model="form.orderNo" :value="index" type="hidden"></el-input>-->
  10. <!-- <el-form-item label="是否属于诊断依据:" prop="isReason" label-width="160px">
  11. <el-select v-model="data.isReason" placeholder="请选择">
  12. <el-option label="否" :value="0"></el-option>
  13. <el-option label="是" :value="1"></el-option>
  14. </el-select>
  15. </el-form-item>-->
  16. <el-form-item label="段落标题:" prop="title" label-width="160px">
  17. <el-input v-model="data.title"></el-input>
  18. </el-form-item>
  19. <el-form-item label="内容类型:" prop="position" label-width="160px">
  20. <el-checkbox-group v-model="data.position">
  21. <el-checkbox v-for="it in positions" :key="it.key" :label="it.key">{{it.name}}</el-checkbox>
  22. </el-checkbox-group>
  23. </el-form-item>
  24. <el-form-item label="内容" prop="content" label-width="160px" ref="editor">
  25. <quillEditor
  26. v-model="data.content"
  27. :options="editorOption"
  28. class="ql-editor"
  29. ref="quillEditor"
  30. ></quillEditor>
  31. </el-form-item>
  32. <div class="order-btn">
  33. <a v-if="index!==0" :class="index===total-1?'order-spc':'order-up'" @click="reOrder(1)">上升</a>
  34. <a v-if="index!==total-1" :class="index===0?'order-spc':'order-down'" @click="reOrder(0)">下降</a>
  35. </div>
  36. <el-form-item label-width="160px" class="btns">
  37. <el-button @click="addEmit">添加段落</el-button>
  38. <el-button @click="delEmit" type="info">删除本段落</el-button>
  39. </el-form-item>
  40. </el-form>
  41. </template>
  42. <script>
  43. import 'quill/dist/quill.core.css';
  44. import 'quill/dist/quill.snow.css';
  45. import 'quill/dist/quill.bubble.css';
  46. import { quillEditor, Quill } from 'vue-quill-editor';
  47. import config from '@api/config';
  48. import { container, ImageExtend, QuillWatch } from 'quill-image-extend-module';
  49. Quill.register('modules/ImageExtend', ImageExtend);
  50. export default {
  51. props: ['data', 'index', 'isEdit', 'total', 'showType'],
  52. name: 'MedicineInfoParagraph',
  53. components: {
  54. quillEditor
  55. },
  56. data() {
  57. return {
  58. toolbars: [
  59. [
  60. ['bold', 'underline', 'strike'],
  61. [{ list: 'ordered' }, { list: 'bullet' }],
  62. [{ script: 'sub' }, { script: 'super' }],
  63. [{ color: [] }, { background: [] }],
  64. [{ align: [] }],
  65. ['image']
  66. ]
  67. ],
  68. toolbarMode: 0,
  69. editorOption: {
  70. modules: {
  71. ImageExtend: {
  72. loading: true,
  73. name: 'upfile',
  74. size: 1,
  75. sizeError: () => {
  76. this.$message({
  77. showClose: true,
  78. message: '请上传 1M 以内的图片!',
  79. type: 'warning'
  80. });
  81. },
  82. action: config.urls.promptServer,
  83. response: res => {
  84. if (res.code == '0') {
  85. return config.imgHost + res.data.url;
  86. } else {
  87. this.$message({
  88. showClose: true,
  89. message: res.msg,
  90. type: 'warning'
  91. });
  92. }
  93. }
  94. },
  95. toolbar: {
  96. container: container,
  97. handlers: {
  98. image: function() {
  99. QuillWatch.emit(this.quill.id);
  100. }
  101. }
  102. }
  103. }
  104. },
  105. form: {
  106. position: [],
  107. orderNo: 0
  108. },
  109. positions: [], //位置列表
  110. rules: {}
  111. };
  112. },
  113. watch: {
  114. 'data.content': function() {
  115. if (this.data.content !== '') {
  116. this.$refs.editor && this.$refs.editor.clearValidate(); // 清除校验
  117. }
  118. if (this.data.content === '') {
  119. // console.log('内容为空');
  120. this.$refs['form'].validateField('content'); // 手动校验
  121. }
  122. this.data.text = this.$refs.quillEditor.quill.root.innerText;
  123. }
  124. },
  125. created() {
  126. // console.log(this.showType, 'showType','需要显示的类型');
  127. this.editorOption.modules.toolbar.container = this.toolbars[
  128. this.toolbarMode
  129. ];
  130. this.renderPositions();
  131. if (this.isEdit) {
  132. setTimeout(() => {
  133. this.rules = {
  134. position: [
  135. { required: true, message: '请选择内容类型', trigger: 'change' }
  136. ],
  137. title: [
  138. { required: true, message: '请输入段落标题', trigger: 'change' },
  139. { max: 30, message: '标题名称不能超过30字', trigger: 'change' }
  140. ],
  141. content: [
  142. { required: true, message: '请输入段落内容', trigger: 'change' }
  143. ]
  144. };
  145. }, 100);
  146. } else {
  147. this.rules = {
  148. position: [
  149. { required: true, message: '请选择内容类型', trigger: 'change' }
  150. ],
  151. title: [
  152. { required: true, message: '请输入段落标题', trigger: 'change' },
  153. { max: 30, message: '标题名称不能超过30字', trigger: 'change' }
  154. ],
  155. content: [
  156. { required: true, message: '请输入段落内容', trigger: 'change' }
  157. ]
  158. };
  159. }
  160. setTimeout(() => {
  161. this.filterHiddenPosition();
  162. }, 200);
  163. },
  164. mounted() {},
  165. methods: {
  166. reOrder(i) {
  167. this.$emit('reOrder', i, this.index);
  168. },
  169. addEmit() {
  170. this.$emit('add');
  171. },
  172. delEmit() {
  173. this.$emit('del', this.index);
  174. },
  175. filterHiddenPosition() {
  176. const pos = this.data.position;
  177. const pArr = this.positions.map(it => {
  178. return it.key;
  179. });
  180. const pStr = pArr.join(',');
  181. const arr = pos.filter(it => {
  182. return pStr.indexOf(it) > -1;
  183. });
  184. this.data.position = arr;
  185. },
  186. // 渲染内容类型
  187. renderPositions() {
  188. //显示位置枚举列表
  189. const pos = localStorage.getItem('knowledgeEnumsData');
  190. console.log('this.showType,', this.showType);
  191. let positions = config.contentTypes;
  192. if (this.showType == 1) {
  193. // 诊断
  194. this.positions = positions.filter(item => item.key !== 2);
  195. } else if (
  196. this.showType == 3 ||
  197. this.showType == 4 ||
  198. this.showType == 5 ||
  199. this.showType == 6
  200. ) {
  201. // 检验/检查
  202. this.positions = positions.filter(item => {
  203. return item.key <= 2;
  204. });
  205. } else if (
  206. this.showType == 2 ||
  207. this.showType == 7 ||
  208. this.showType == 8 ||
  209. this.showType == 9 ||
  210. this.showType == 10
  211. ) {
  212. // 药品/手术
  213. this.positions = positions.filter(item => item.key === 1);
  214. } else {
  215. this.positions = positions;
  216. }
  217. }
  218. /*emitVal(){
  219. let data = this.form;
  220. let pst=this.form.position;
  221. const content = this.form.content.replace(config.imgHost,'{imageUrlPrefix}');
  222. const text = this.$refs.quillEditor;console.log(text)
  223. pst = typeof pst=='string'?pst:pst.join(',');
  224. data = Object.assign({},data,{
  225. position:this.form.position?pst:'',
  226. orderNo:this.index,
  227. text:'',
  228. content:content});
  229. this.$emit("change",this.index,data);
  230. }*/
  231. }
  232. };
  233. </script>
  234. <style lang="less">
  235. .quill-editor.ql-editor {
  236. padding-left: 0 !important;
  237. }
  238. .is-error .el-form-item__error {
  239. top: auto;
  240. }
  241. .sub-form {
  242. position: relative;
  243. }
  244. .order-btn {
  245. position: absolute;
  246. top: 12px;
  247. right: 0;
  248. a {
  249. margin-bottom: 20px;
  250. border: 1px solid #22ccc8;
  251. color: #22ccc8;
  252. padding: 5px 10px;
  253. border-radius: 4px;
  254. cursor: pointer;
  255. font-size: 12px;
  256. }
  257. .order-spc {
  258. margin-top: 28px;
  259. }
  260. .order-down {
  261. margin-left: 20px;
  262. }
  263. }
  264. /**富文本编辑器样式修改***/
  265. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  266. .ql-snow .ql-picker.ql-size .ql-picker-item::before,
  267. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  268. it .ql-editor,
  269. .quill-editor {
  270. padding-top: 0px !important;
  271. margin-top: -8px;
  272. min-height: 48px;
  273. p {
  274. padding-top: 8px;
  275. }
  276. }
  277. .ql-editor.ql-blank::before {
  278. padding-top: 0px;
  279. }
  280. .btns {
  281. margin-top: 20px;
  282. }
  283. </style>