408249787 4 months ago
parent
commit
f540a40d0c
1 changed files with 143 additions and 129 deletions
  1. 143 129
      src/views/purchase/purchase-order-page/modules/BaseForm.vue

+ 143 - 129
src/views/purchase/purchase-order-page/modules/BaseForm.vue

@@ -1,109 +1,108 @@
 <template>
-  <a-modal
-    :title="title"
-    :width="1400"
-    :visible="visible"
-    :confirmLoading="confirmLoading"
-    @cancel="handleCancel"
-  >
-    <a-card >
+  <a-modal :title="title" :width="1400" :visible="visible" :confirmLoading="confirmLoading" @cancel="handleCancel">
+    <a-card>
       <a-form :form="form">
         <row-list :col="1" v-show="false">
           <row-item>
             <a-form-item>
-              <a-input v-decorator="['id']" type="hidden"/>
-              <a-input v-decorator="['sbId']" type="hidden"/>
+              <a-input v-decorator="['id']" type="hidden" />
+              <a-input v-decorator="['sbId']" type="hidden" />
             </a-form-item>
           </row-item>
         </row-list>
         <row-list :col="2">
-          <row-item >
+          <row-item>
             <a-form-item
               label="计划类型"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-select v-decorator="['type', { rules: [{required: true, message: '采购计划类型不能为空'}]}]" placeholder="请选择">
-                <a-select-option
-                  v-for="(label,value) in typeMap"
-                  :key="value"
-                  :label="label"
-                  :value="parseInt(value)">{{ label }}
+              <a-select
+                v-decorator="['type', { rules: [{ required: true, message: '采购计划类型不能为空' }] }]"
+                placeholder="请选择"
+              >
+                <a-select-option v-for="(label, value) in typeMap" :key="value" :label="label" :value="parseInt(value)"
+                  >{{ label }}
                 </a-select-option>
               </a-select>
             </a-form-item>
           </row-item>
 
-          <row-item >
+          <row-item>
             <a-form-item
               label="请购原因"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-input
-                v-decorator="['remark']"/>
+              <a-input v-decorator="['remark']" />
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="采购类型"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-select v-decorator="['cptcode', { rules: [{required: true, message: '采购类型不能为空'}]}]" placeholder="请选择">
-                <a-select-option
-                  v-for="(label,value) in cptcodeMap"
-                  :key="value"
-                  :label="label"
-                  :value="value">{{ label }}
+              <a-select
+                v-decorator="['cptcode', { rules: [{ required: true, message: '采购类型不能为空' }] }]"
+                placeholder="请选择"
+              >
+                <a-select-option v-for="(label, value) in cptcodeMap" :key="value" :label="label" :value="value"
+                  >{{ label }}
                 </a-select-option>
               </a-select>
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="业务类型"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-select v-decorator="['cbustype', {rules: [{required: true, message: '业务类型不能为空'}]}]" placeholder="请选择">
-                <a-select-option
-                  v-for="(label,value) in cbustypeMap"
-                  :key="value"
-                  :label="label"
-                  :value="value">{{ label }}
+              <a-select
+                v-decorator="['cbustype', { rules: [{ required: true, message: '业务类型不能为空' }] }]"
+                placeholder="请选择"
+              >
+                <a-select-option v-for="(label, value) in cbustypeMap" :key="value" :label="label" :value="value"
+                  >{{ label }}
                 </a-select-option>
               </a-select>
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="采购厂区"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-select :disabled="title==='编辑'" v-decorator="['oldOrNew', {rules: [{required: true, message: '采购厂区不能为空'}]}]" @change="setTree">
-                <a-select-option
-                  v-for="(label,value) in flagMap"
-                  :key="value"
-                  :label="label"
-                  :value="parseInt(value)">{{ label }}
+              <a-select
+                :disabled="title === '编辑'"
+                v-decorator="['oldOrNew', { rules: [{ required: true, message: '采购厂区不能为空' }] }]"
+                @change="setTree"
+              >
+                <a-select-option v-for="(label, value) in flagMap" :key="value" :label="label" :value="parseInt(value)"
+                  >{{ label }}
                 </a-select-option>
               </a-select>
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="申请部门"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-select :disabled="!oldOrNew" v-decorator="['cdepcode', {rules: [{required: true, message: '申请部门不能为空'}]}]" placeholder="请选择">
+              <a-select
+                :disabled="!oldOrNew"
+                v-decorator="['cdepcode', { rules: [{ required: true, message: '申请部门不能为空' }] }]"
+                placeholder="请选择"
+              >
                 <a-select-option
-                  v-for="(label,value) in oldOrNew===2?deptMap:deptNewMap"
+                  v-for="(label, value) in oldOrNew === 2 ? deptMap : deptNewMap"
                   :key="value"
                   :label="label"
-                  :value="value">{{ label }}
+                  :value="value"
+                  >{{ label }}
                 </a-select-option>
               </a-select>
             </a-form-item>
@@ -124,7 +123,7 @@
           <!--              </a-select>-->
           <!--            </a-form-item>-->
           <!--          </row-item>-->
-          <row-item >
+          <row-item>
             <a-form-item
               label="计划到货日期"
               :labelCol="BaseTool.Constant.labelCol"
@@ -135,10 +134,11 @@
                 :disabled-date="disabledDate"
                 @change="dateChange"
                 :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
-                v-decorator="['planGetDate', {rules: [{required: true, message: '计划到货日期不能为空'}]}]" />
+                v-decorator="['planGetDate', { rules: [{ required: true, message: '计划到货日期不能为空' }] }]"
+              />
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="需求日期"
               :labelCol="BaseTool.Constant.labelCol"
@@ -149,23 +149,23 @@
                 style="width: 100%"
                 :disabled-date="disabledDate2"
                 :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
-                v-decorator="['needDate', {rules: [{required: true, message: '需求日期不能为空'}]}]" />
+                v-decorator="['needDate', { rules: [{ required: true, message: '需求日期不能为空' }] }]"
+              />
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="设备位号"
               :labelCol="BaseTool.Constant.labelCol"
               :wrapperCol="BaseTool.Constant.wrapperCol"
             >
-              <a-input
-                style="width: 70%"
-                disabled
-                v-decorator="['positionNo']" />
-              <a-button :disabled="title==='编辑'" style="width: 30%" type="primary" @click="handleSbSelect">选择</a-button>
+              <a-input style="width: 70%" disabled v-decorator="['positionNo']" />
+              <a-button :disabled="title === '编辑'" style="width: 30%" type="primary" @click="handleSbSelect"
+                >选择</a-button
+              >
             </a-form-item>
           </row-item>
-          <row-item >
+          <row-item>
             <a-form-item
               label="关联项目"
               :labelCol="BaseTool.Constant.labelCol"
@@ -209,7 +209,7 @@
     <a-card>
       <div class="table-operator" style="margin-bottom: 8px;">
         <a-button size="small" :disabled="!oldOrNew" type="primary" @click="handleSpareStoreSelect">
-          <a-icon type="plus"/>
+          <a-icon type="plus" />
           物料库添加
         </a-button>
         <!-- <a-button size="small" :disabled="!(oldOrNew&&sbId)" style="margin-left:20px;" type="primary" @click="handleBomSpareStoreSelect">
@@ -217,37 +217,32 @@
           BOM添加
         </a-button> -->
       </div>
-      <a-table
-        bordered
-        :data-source="data"
-        :columns="columns"
-        tableLayout="auto"
-        rowKey="id"
-        :scroll="{ x: 1500 }"
-      >
+      <a-table bordered :data-source="data" :columns="columns" tableLayout="auto" rowKey="id" :scroll="{ x: 1500 }">
         <template slot="iexchrate" slot-scope="text, record">
           <a-input-number v-model="record.iexchrate" :step="0.01" />
         </template>
-        <template slot="funitprice" slot-scope="text, record" >
-          <a-input-number v-model="record.funitprice" :step="0.0001" @blur="computeTax(record,1)" />
+        <template slot="funitprice" slot-scope="text, record">
+          <a-input-number v-model="record.funitprice" :step="0.0001" @blur="computeTax(record, 1)" />
         </template>
         <template slot="fmoney" slot-scope="text, record">
-          <a-input-number v-model="record.fmoney" :step="0.01" @blur="computeTax(record,2)" />
+          <a-input-number v-model="record.fmoney" :step="0.01" @blur="computeTax(record, 2)" />
         </template>
         <template slot="num" slot-scope="text, record">
-          <a-input-number
+          <!-- <a-input-number
             v-model="record.num"
             :min="1"
             :formatter="value => `${value+record.unit}`"
             :parser="value => value.replace(`${record.unit}`, '')"
-            @blur="computeTax(record,1)" />
+            @blur="computeTax(record,1)" /> -->
+          <a-input-number v-model="record.num" :min="1" @blur="computeTax(record, 1)" />
         </template>
         <template slot="ipertaxrate" slot-scope="text, record">
           <a-input-number
             v-model="record.ipertaxrate"
             :step="0.01"
             :formatter="value => `${value}%`"
-            :parser="value => value.replace('%', '')" />
+            :parser="value => value.replace('%', '')"
+          />
         </template>
         <template slot="cbmemo" slot-scope="text, record">
           <a-input v-model="record.cbmemo" />
@@ -273,10 +268,9 @@
     <template slot="footer">
       <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
     </template>
-    <sb-info-select-modal ref="sbInfoSelectModal" @selected="handleSbSelectd"/>
-    <spare-store-select-modal ref="spareStoreSelectModal" @selected="handleSpareStoreSelected"/>
-    <BomSpareStoreSelectModal ref="bomSpareStoreSelectModal" @selected="handleSpareStoreSelected"/>
-
+    <sb-info-select-modal ref="sbInfoSelectModal" @selected="handleSbSelectd" />
+    <spare-store-select-modal ref="spareStoreSelectModal" @selected="handleSpareStoreSelected" />
+    <BomSpareStoreSelectModal ref="bomSpareStoreSelectModal" @selected="handleSpareStoreSelected" />
   </a-modal>
 </template>
 
@@ -295,9 +289,8 @@ export default {
     SpareStoreSelectModal,
     SbInfoSelectModal,
     BomSpareStoreSelectModal
-
   },
-  data () {
+  data() {
     return {
       form: this.$form.createForm(this),
       visible: false,
@@ -425,7 +418,7 @@ export default {
     }
   },
 
-  created () {
+  created() {
     this.flagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PROJECT_NEW_AND_OLD)
     this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.LONG_YAN_PURCHASE_TYPE)
     this.cptcodeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.LONG_YAN_PURCHASE_ORDER_PLAN_TYPE)
@@ -435,7 +428,7 @@ export default {
     this.soMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SO_TYPE)
   },
   methods: {
-    computeTax (record, type) {
+    computeTax(record, type) {
       if (type === 1) {
         console.log(record)
         const data = (record.funitprice * record.num * (1 + record.ipertaxrate / 100)).toFixed(2)
@@ -446,19 +439,19 @@ export default {
       }
       this.$forceUpdate()
     },
-    disabledDate (current) {
+    disabledDate(current) {
       // Can not select days before today and today
       return current && current < moment().endOf('day')
     },
-    disabledDate2 (current) {
+    disabledDate2(current) {
       // Can not select days before today and today
       return current && current <= this.date
     },
-    dateChange (data) {
+    dateChange(data) {
       console.log(data)
       this.date = data
     },
-    base (record) {
+    base(record) {
       this.visible = true
       if (this.BaseTool.Object.isBlank(record)) {
         this.title = '新增'
@@ -467,57 +460,69 @@ export default {
       this.title = '编辑'
       this.data = record.detailVOS
       this.setTree(record.oldOrNew)
-      const { form: { setFieldsValue } } = this
+      const {
+        form: { setFieldsValue }
+      } = this
       this.$nextTick(() => {
-        setFieldsValue(Object.assign(pick(record, [
-          'id',
-          'sbId',
-          'type',
-          'oldOrNew',
-          'projectId',
-          'positionNo',
-          'cdefine11',
-          'cdefine12',
-          'cptcode',
-          'remark',
-          'cdepcode',
-          'cbustype',
-          'planGetDate',
-          'needDate',
-          'cdefine22',
-          'cdefine28'
-        ])))
+        setFieldsValue(
+          Object.assign(
+            pick(record, [
+              'id',
+              'sbId',
+              'type',
+              'oldOrNew',
+              'projectId',
+              'positionNo',
+              'cdefine11',
+              'cdefine12',
+              'cptcode',
+              'remark',
+              'cdepcode',
+              'cbustype',
+              'planGetDate',
+              'needDate',
+              'cdefine22',
+              'cdefine28'
+            ])
+          )
+        )
       })
     },
     // 获取巡检人与巡检主管信息
 
-    handleSbSelect () {
+    handleSbSelect() {
       this.$refs.sbInfoSelectModal.base({})
     },
-    handleSbSelectd (keys, rows) {
-      const [ key ] = keys
-      const [ row ] = rows
-      const { form: { setFieldsValue } } = this
+    handleSbSelectd(keys, rows) {
+      const [key] = keys
+      const [row] = rows
+      const {
+        form: { setFieldsValue }
+      } = this
       this.sbId = key
       // 日期处理
       this.$nextTick(() => {
-        setFieldsValue(Object.assign({
-          'sbId': key,
-          'positionNo': row.positionNo
-        }))
+        setFieldsValue(
+          Object.assign({
+            sbId: key,
+            positionNo: row.positionNo
+          })
+        )
       })
     },
-    setTree (val) {
+    setTree(val) {
       console.log(val)
       this.oldOrNew = val
       fetchProjectTree({
         flag: val
-      }).then((res) => {
+      }).then(res => {
         this.treeData = res.data
       })
     },
-    save () {
-      const { form: { validateFieldsAndScroll } } = this
+    save() {
+      const {
+        form: { validateFieldsAndScroll }
+      } = this
       // this.confirmLoading = true
       validateFieldsAndScroll((errors, values) => {
         if (errors) {
@@ -528,12 +533,18 @@ export default {
           return
         }
         let status = 0
-        values.needDate = values.needDate ? this.BaseTool.Date.formatter(values.needDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN) : null
-        values.planGetDate = values.planGetDate ? this.BaseTool.Date.formatter(values.planGetDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN) : null
+        values.needDate = values.needDate
+          ? this.BaseTool.Date.formatter(values.needDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
+          : null
+        values.planGetDate = values.planGetDate
+          ? this.BaseTool.Date.formatter(values.planGetDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
+          : null
         values.detailDTOS = this.data.map(item => {
-          if (!item.funitprice) {
+          if (!parseFloat(item.funitprice) > 0) {
             status++
+            console.log(item.funitprice)
             this.$message.error('请填写' + item.spareName + '单价')
+            return
           }
           item.funitprice = (+item.funitprice).toFixed(4)
           item.ipertaxrate = (+item.ipertaxrate).toFixed(2)
@@ -557,14 +568,14 @@ export default {
         }
       })
     },
-    handleSpareStoreSelect () {
+    handleSpareStoreSelect() {
       console.log(this.oldOrNew)
       this.$refs.spareStoreSelectModal.base({ tokenType: this.oldOrNew })
     },
-    handleBomSpareStoreSelect () {
+    handleBomSpareStoreSelect() {
       this.$refs.bomSpareStoreSelectModal.base({ tokenType: this.oldOrNew, sbId: this.sbId })
     },
-    handleSpareStoreSelected (record, keys, rows) {
+    handleSpareStoreSelected(record, keys, rows) {
       console.log(rows)
       const codes = []
       const { data } = this
@@ -591,18 +602,22 @@ export default {
         isNew: this.oldOrNew
       }).then(res => {
         data.forEach(item => {
-          item.funitprice = !item.funitprice ? res.data.find(price => item.no === price.cinvCode) ? res.data.find(price => item.no === price.cinvCode).iunitPrice : 0 : item.funitprice
+          item.funitprice = !item.funitprice
+            ? res.data.find(price => item.no === price.cinvCode)
+              ? res.data.find(price => item.no === price.cinvCode).iunitPrice
+              : 0
+            : item.funitprice
           const data = (item.funitprice * item.num * (1 + item.ipertaxrate / 100)).toFixed(2)
           item.fmoney = isNaN(data) ? 0 : data
         })
         this.$forceUpdate()
       })
     },
-    handleDelOne (record) {
+    handleDelOne(record) {
       const data = [...this.data]
       this.data = data.filter(item => record.spareId !== item.spareId)
     },
-    handleCancel (values) {
+    handleCancel(values) {
       this.visible = false
       this.data = []
       this.date = null
@@ -612,16 +627,15 @@ export default {
       this.oldOrNew = null
       this.$emit('ok', values)
     }
-
   }
 }
 </script>
 <style lang="less" scoped>
-.tooltip{
-  font-size:20px;
-  color:#ccc;
+.tooltip {
+  font-size: 20px;
+  color: #ccc;
   &:hover {
-  color:#2f54eb;
+    color: #2f54eb;
   }
 }
 </style>