Эх сурвалжийг харах

Merge remote-tracking branch 'origin/demo_' into demo_

hfxc226 2 жил өмнө
parent
commit
31c3e87f81

+ 145 - 9
src/views/sb/scraps/modules/SbCustomFormView.vue

@@ -6,13 +6,13 @@
     class="ant-modal2"
     :confirmLoading="confirmLoading"
     @cancel="handleCancel"
-    @ok='save'
+    @ok="save"
   >
     <a-form :form="form">
       <row-list :col="1">
         <row-item v-for="(item, index) in data" :key="index">
           <a-form-item
-            v-show='hiddenFlag'
+            v-show="hiddenFlag"
             :labelCol="BaseTool.Constant.labelCol"
             :wrapperCol="BaseTool.Constant.wrapperCol"
             v-if="item.type === 5"
@@ -31,7 +31,7 @@
             :wrapperCol="BaseTool.Constant.wrapperCol"
             v-if="item.type === 1 && (item.disabledFlag === 1 || item.disabledFlag === '1')"
             :label="item.label">
-            <a-input disabled='disabled' v-decorator="[item.fieldName, {initialValue: item.value, rules: [{required: item.required, message: '不能为空'}]}]"/>
+            <a-input disabled="disabled" v-decorator="[item.fieldName, {initialValue: item.value, rules: [{required: item.required, message: '不能为空'}]}]"/>
           </a-form-item>
           <a-form-item
             :labelCol="BaseTool.Constant.labelCol"
@@ -68,23 +68,66 @@
               style="width: 70%"
               disabled
               v-decorator="['sbName', {rules: [{required: true, message: '设备不能为空'}]}]" />
-            <a-input type='hidden' v-decorator="['sbId']" />
+            <a-input type="hidden" v-decorator="['sbId']" />
             <a-button style="width: 30%" type="primary" @click="sbInfoHandleSelect">选择</a-button>
           </a-form-item>
+          <a-form-item
+            :labelCol="BaseTool.Constant.labelCol"
+            :wrapperCol="BaseTool.Constant.wrapperCol"
+            v-if="item.type === 6"
+            :label="item.label">
+            <a-button type="primary" @click="uploadFile(item,index)">上传文件</a-button>
+
+            <a-modal v-model="uploadFiledVisible" title="上传文件" :footer="null" @cancel="uploadFiledVisible = false">
+              <a-upload
+                :action="uploadUrl"
+                :multiple="true"
+                :file-list="defaultCheckFileList"
+                @change="handleCheckFileChange"
+                :headers="headers"
+              >
+                <a-button> <a-icon type="upload" /> 上传 </a-button>
+              </a-upload>
+            </a-modal>
+          </a-form-item>
+          <a-form-item
+            :labelCol="BaseTool.Constant.labelCol"
+            :wrapperCol="BaseTool.Constant.wrapperCol"
+            v-if="item.type === 7"
+            :label="item.label">
+            <a-button type="primary" @click="uploadImg(item,index)">上传图片</a-button>
+            <a-modal v-model="uploadVisible" title="上传图片" :footer="null" @cancel="uploadVisible = false">
+              <a-upload
+                :action="uploadUrl"
+                list-type="picture-card"
+                :file-list="defaultApplicationFileList"
+                @change="handleApplicationFileChange"
+                accept="image/*"
+                :headers="headers"
+              >
+                <div>
+                  <a-icon type="plus" />
+                  <div class="ant-upload-text">
+                    Upload
+                  </div>
+                </div>
+              </a-upload>
+            </a-modal>
+          </a-form-item>
         </row-item>
       </row-list>
     </a-form>
-    <a-tabs v-show='isTransfer' type="card" default-active-key="1">
+    <a-tabs v-show="isTransfer" type="card" default-active-key="1">
       <a-tab-pane key="1" tab="设备列表">
         <div class="table-operator" style="margin-bottom: 8px;">
           <a-button size="small" type="primary" @click="handleStandardSelect">
             <a-icon type="plus"/>
             添加
           </a-button>
-          <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
+          <!-- <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
             <a-icon type="delete"/>
             删除
-          </a-button>
+          </a-button> -->
         </div>
         <a-table
           bordered
@@ -93,7 +136,6 @@
           tableLayout="auto"
           rowKey="id"
           :scroll="{ x: 1600, y: BaseTool.Constant.scrollY }"
-          :row-selection="rowSelection"
         >
           <span slot="action" slot-scope="record">
             <template>
@@ -116,7 +158,9 @@ import SbInfoSelectModal from '@/views/sb/info/modules/SbInfoSelectModal'
 import SbInfoSelectModalByUser from '@/views/sb/info/modules/SbInfoSelectModalByFilter'
 import { updateCustomFieldTemplate } from '@/api/customize/fieldTemplate'
 import { addCustomFieldTemplateDataForm } from '@/api/customize/fieldTemplateData'
-
+import { uploadUrl } from '@/api/upms/file'
+import Vue from 'vue'
+import { ACCESS_TOKEN } from '@/store/mutation-types'
 export default {
   name: 'SbCustomFormView',
   components: {
@@ -125,10 +169,24 @@ export default {
   },
   data () {
     return {
+      uploadUrl: uploadUrl,
       confirmLoading: false,
       modalTitle: null,
       model: null,
       data: [],
+      defaultApplicationFileList: [],
+      defaultCheckFileList: [],
+      checkFileList: [], // 文档
+      applicationFileList: [],
+      fileName: null,
+      imgName: null,
+      imgId: null,
+      fileId: null,
+      uploadVisible: false,
+      uploadFiledVisible: false,
+      headers: {
+        Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
+      },
       form: this.$form.createForm(this),
       visible: false,
       // 下拉框map
@@ -221,7 +279,18 @@ export default {
       if (this.remark === this.DictCache.VALUE.CUSTOM_TEMPLATE_SB_REMARK.SB_ALLOCATE_FORM) {
         this.isTransfer = true
       }
+      console.log(JSON.parse(data.content))
       this.data = JSON.parse(data.content)
+      this.data.forEach(item => {
+        if (item.type === 6) {
+          this.fileName = item.fieldName
+        }
+        if (item.type === 7) {
+          this.imgName = item.fieldName
+        }
+      })
+      console.log(JSON.parse(data.content))
+
       // 调拨单处理
       if (this.data.sbInfos !== null && this.data.sbInfos !== undefined) {
         this.dataSource = JSON.parse(this.data.sbInfos)
@@ -229,6 +298,47 @@ export default {
         this.dataSource = []
       }
     },
+    uploadFile (val, i) {
+      this.uploadFiledVisible = true
+      console.log(val)
+      this.fileId = i
+      this.defaultCheckFileList = this.BaseTool.UPLOAD.transImg(val[this.fieldName])
+      this.defaultCheckFileList.forEach((item, i) => {
+        item.uid = item.uid ? item.uid : i
+      })
+    },
+    uploadImg (val, i) {
+      this.uploadVisible = true
+      this.imgId = i
+      console.log(val)
+      this.defaultApplicationFileList = this.BaseTool.UPLOAD.transImg(val[this.imgName])
+      this.defaultApplicationFileList.forEach((item, i) => {
+        item.uid = item.uid ? item.uid : i
+      })
+      console.log(this.defaultApplicationFileList)
+    },
+    handleApplicationFileChange (info) {
+      this.defaultApplicationFileList = info.fileList
+      this.applicationFileList = this.setFileList(info, 11)
+      this.data[this.imgId][this.imgName] = this.applicationFileList
+    },
+    handleCheckFileChange (info) {
+      this.defaultCheckFileList = info.fileList
+      this.checkFileList = this.setFileList(info, 32)
+      this.data[this.fileId][this.fieldName] = this.checkFileList
+    },
+    setFileList (info, type) {
+      const file = info.file
+      const fileList = info.fileList
+      if (file.status === 'done') {
+        return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
+      } else if (file.status === 'removed') {
+        return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
+      } else if (file.status === 'error') {
+        this.$message.error('上传失败')
+        return []
+      }
+    },
     handleCancel (values) {
       this.visible = false
       this.confirmLoading = false
@@ -274,12 +384,38 @@ export default {
           this.confirmLoading = false
           return
         }
+        if (this.imgName && (this.data.find(item => item.type === 7).required === 1) && (this.defaultApplicationFileList.length === 0)) {
+          console.log(11)
+          this.confirmLoading = false
+          this.$message.error('请上传图片!')
+          return
+        }
+        if (this.fileName && (this.data.find(item => item.type === 6).required === 1) && (this.defaultCheckFileList.length === 0)) {
+          console.log(11)
+
+          this.confirmLoading = false
+          this.$message.error('请上传文件!')
+          return
+        }
         if (values.stopDate !== null && values.stopDate !== undefined) {
           values.stopDate = this.BaseTool.Date.formatter(values.stopDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
         }
         if (this.dataSource.length > 0) { // 调拨单
           values.sbInfos = JSON.stringify(this.dataSource)
         }
+        if (this.fileName) {
+          values[this.fileName] = this.checkFileList.map(item => {
+            item.uid = null
+            return item
+          })
+        }
+
+        if (this.imgName) {
+          values[this.fileName] = this.applicationFileList.map(item => {
+            item.uid = null
+            return item
+          })
+        }
         const content = JSON.stringify(values)
         const obj = {}
         obj.type = this.DictCache.VALUE.CUSTOM_TEMPLATE_SB_REMARK_NUMBER.ACTIVITY_FORM