add.vue 7.7 KB
Newer Older
宋雄's avatar
宋雄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
<template>
  <a-spin :spinning="confirmLoading">
    <div class="top-card">
      <span class="card-title">新增模板</span>
      <a-row type="flex" justify="start">
        <a-button @click="backbtn">返回</a-button>
        <a-button style="margin-left: 10px" type="primary" @click="handlePreviewPdf">预览</a-button>
        <a-button style="margin-left: 10px" type="primary" @click="handleSaveToPdf">导出pdf</a-button>
        <a-button style="margin-left: 10px" type="primary" @click="handleSave()">保存</a-button>
      </a-row>
    </div>
    <div class="template-contract-box">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="收费名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateName">
              <a-input placeholder="请输入收费名称" v-model="model.templateName"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="收费类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateType">
              <a-select style="width: 100%" v-model="model.templateType" placeholder="请选择收费类型" label-in-value>
                <a-select-option v-for="item in chargeList" :key="item.id" :value="item.id">{{item.typeName}}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <my-editor-with-mention ref="editorHtml"></my-editor-with-mention>

      <vue-html2pdf
        :show-layout="false"
        :float-layout="true"
        :enable-download="true"
        :preview-modal="false"
        :html-to-pdf-options="pdfOptions"
        :paginate-elements-by-height="1400"
        filename="tempFileName"
        :pdf-quality="2"
        :manual-pagination="false"
        pdf-format="a4"
        pdf-orientation="landscape"
        pdf-content-width="98%"
        @progress="onProgress"
        ref="html2PdfDownLoad"
      >
        <section slot="pdf-content">
          <!-- PDF Content Here -->
          <span id="report" v-html="content"></span>
        </section>
      </vue-html2pdf>

      <vue-html2pdf
        :show-layout="false"
        :float-layout="true"
        :enable-download="false"
        :preview-modal="true"
        :html-to-pdf-options="pdfOptions"
        :paginate-elements-by-height="1400"
        filename="tempFileName"
        :pdf-quality="2"
        :manual-pagination="false"
        pdf-format="a4"
        pdf-orientation="landscape"
        pdf-content-width="98%"
        @progress="onProgress"
        ref="html2PdfPreview"
      >
        <section slot="pdf-content">
          <!-- PDF Content Here -->
          <span id="report" v-html="content"></span>
        </section>
      </vue-html2pdf>
    </div>
  </a-spin>
</template>

<script>
import {getChargeListApi, addReceiptTemplate} from '@/api/api'
import MyEditorWithMention from './components/MyEditorWithMention'
import VueHtml2pdf from "vue-html2pdf";
const tableHtml = '<table border="1" cellspacing="0" style="width: 100%;"><tbody><tr><th colSpan="1" rowSpan="1">序号</th><th colSpan="1" rowSpan="1">品名</th><th colSpan="1" rowSpan="1">产地品牌</th><th colSpan="1" rowSpan="1">规格型号</th><th colSpan="1" rowSpan="1">数量</th><th colSpan="1" rowSpan="1">税率</th><th colSpan="1" rowSpan="1">单位</th><th colSpan="1" rowSpan="1">单价</th><th colSpan="1" rowSpan="1">总金额(不含税)</th><th colSpan="1" rowSpan="1">税额</th><th colSpan="1" rowSpan="1">总金额(含税)</th><th colSpan="1" rowSpan="1">备注</th></tr><tr><td colspan="1" rowspan="1" style="text-align: center;">1</td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td></tr><tr><td colSpan="1" rowSpan="1">合计</td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1"></td></tr><tr><td colSpan="3" rowSpan="1" style="text-align: center;">合同金额(大写):</td><td colSpan="9" rowSpan="1"></td></tr></tbody></table>'

export default {
  name: 'templateContractAdd',
  inject:['closeCurrent'],
  components: {
    MyEditorWithMention,
    VueHtml2pdf
  },
  data() {
    return {
      content: '',
      previewModal: false,
      downloadFile: false,
      pdfOptions: {
        margin: [20, 10, 20, 10],
        filename: ''
      },
      confirmLoading: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      chargeList: [],
      model: {
        templateName: '',
        // templateType: {key: "1660940550578327554",label: "水费"},
宋雄's avatar
宋雄 committed
113
        templateType: 'SFLX00004'
宋雄's avatar
宋雄 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
      },
      validatorRules: {
        templateName: [{ required: true, message: '请输入收费名称', trigger: 'blur' }],
        templateType: [{ required: true, message: '请选择收费类型', trigger: 'change' }]
      }
    }
  },
  methods: {
    async getChargeList() {
      let {result} = await getChargeListApi()
      this.chargeList = result
    },
    onProgress(e) {
      console.log(e)
    },
    backbtn() {
      this.closeCurrent()
    },
    handleSave() {
      this.$refs.form.validate(valid => {
        if(valid) {
          this.confirmLoading = true;
          addReceiptTemplate({
            templateName: this.model.templateName,
            templateType: this.model.templateType.key,
            typeName: this.model.templateType.label,
            templateStyle: this.content
          }).then(res=> {
            this.$message.warning(res.message);
            this.backbtn()
          }).finally(() => {
            this.confirmLoading = false;
          })
        }
      })
    },
    handleSaveToPdf() {
      this.pdfOptions.filename = '收费模板'
      this.content = this.$refs.editorHtml.curHtml.replace('<p><span data-w-e-type="mention" data-w-e-is-void data-w-e-is-inline data-value="产品列表" data-info="%7B%22id%22%3A%22e%22%7D">@产品列表</span></p>', tableHtml)
      console.log(this.content)
      this.$refs.html2PdfDownLoad.generatePdf();
    },
    handlePreviewPdf() {
      this.content = this.$refs.editorHtml.curHtml.replace('<p><span data-w-e-type="mention" data-w-e-is-void data-w-e-is-inline data-value="产品列表" data-info="%7B%22id%22%3A%22e%22%7D">@产品列表</span></p>', tableHtml)
      // this.downloadFile = false
      // this.previewModal = true
      this.$refs.html2PdfPreview.generatePdf()
    }
  },
  created () {
    this.getChargeList()
  },
  mounted() {
    this.content = this.$refs.editorHtml.curHtml
  }
}
</script>

<style lang="less" scoped>
.template-contract-box {
  background-color: #fff;
  padding: 25px 5px 5px;
  margin-top: 10px;
}
.top-card {
  -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: 1px solid #ebeef5;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 4px;
  padding: 15px 20px;

  .card-title {
    font-weight: 700;
    margin-right: 15px;
    color: #000;
  }
}
.box-card {
  width: 800px;
}
.page-break-after {
  page-break-after: always;
}
</style>