Browse Source

模板管理

chris 3 years ago
parent
commit
eb2d4c17d0

+ 31 - 0
src/api/warehouse.js

@@ -74,3 +74,34 @@ export function revokeInOutBound (data) {
     data
   })
 }
+// 模板出库查询
+export function getTemplateList (params) {
+  return request({
+    url: request.adornUrl(`/biz-service/TemplateMgCtl/list`),
+    method: 'get',
+    params
+  })
+}
+// 新增模板
+export function addTemplate (data) {
+  return request({
+    url: request.adornUrl(`/biz-service/TemplateMgCtl/save`),
+    method: 'post',
+    data
+  })
+}
+// 模板详情
+export function getTemplateInfo (id) {
+  return request({
+    url: request.adornUrl(`/biz-service/TemplateMgCtl/info/${id}`),
+    method: 'get'
+  })
+}
+// 停用或启用模板
+export function updateTemplate (data) {
+  return request({
+    url: request.adornUrl(`/biz-service/TemplateMgCtl/updateEnableOrDisable`),
+    method: 'post',
+    data
+  })
+}

+ 54 - 49
src/views/modules/warehouse/template-add.vue

@@ -8,12 +8,12 @@
       <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
         <el-row class="my-row">
           <el-form-item label="名称">
-            <el-input v-model="dataForm.code"  placeholder="名称"></el-input>
+            <el-input v-model="dataForm.templateName" :disabled="display"  placeholder="请填写模板名称"></el-input>
           </el-form-item>
         </el-row>
         <el-row class="my-row">
           <el-form-item label="备注">
-              <el-input v-model="dataForm.code"  placeholder="备注"></el-input>
+              <el-input v-model="dataForm.notes"  :disabled="display" placeholder="备注"></el-input>
             </el-form-item>
         </el-row>
         <el-row>
@@ -28,48 +28,49 @@
               align="center">
             </el-table-column>
             <el-table-column
-              prop="-"
+              prop="materialName"
               header-align="center"
               align="center"
               label="物品名称">
             </el-table-column>
             <el-table-column
-              prop="recordType"
+              prop="specifications"
               header-align="center"
               align="center"
               label="规格">
             </el-table-column>
             <el-table-column
-              prop="state"
+              prop="count"
               header-align="center"
               align="center"
               label="数量">
             </el-table-column>
             <el-table-column
-              prop="approver"
+              prop="unitName"
               header-align="center"
               align="center"
               label="单位">
             </el-table-column>
             <el-table-column
-              prop="-"
+              prop="notes"
               header-align="center"
               align="center"
               label="备注">
             </el-table-column>
             <el-table-column
+              v-if="!display"
               fixed="right"
               header-align="center"
               align="center"
               width="100"
               label="操作">
               <template slot-scope="scope">
-                <el-button type="text" size="small" @click="exportItem(scope.row.id)">删除</el-button>
+                <el-button style="color: red" type="text" size="small" @click="removeItem(scope.row.materialId)">删除</el-button>
               </template>
             </el-table-column>
           </el-table>
           <el-row style="text-align: center; margin-top: 10px;">
-            <el-button type="primary" icon="el-icon-plus" @click="inBound"></el-button>
+            <el-button v-if="!display" type="primary" icon="el-icon-plus" @click="inBound"></el-button>
           </el-row>
         </el-row>
       </el-form>
@@ -78,24 +79,26 @@
         <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
       </span>
     </el-dialog>
-    <template-chose v-if="inboundVisible" ref="inbound" />
+    <template-chose v-if="inboundVisible" ref="inbound" @addItem="addMaterial"/>
   </div>
 </template>
 
 <script>
   import UserComponent from '../common/user-component'
   import DictSelect from '../sys/dict-select'
-  import {getUUID} from '../../../utils'
   import templateChose from './template-chose'
+  import { addTemplate, getTemplateInfo } from '@/api/warehouse'
   export default {
     name: 'stock-order-inbound',
     components: {DictSelect, UserComponent, templateChose},
     data () {
       return {
         visible: false,
+        display: false,
         inboundVisible: false,
         dictType: 'material_type',
         dataList: [],
+        id: 0,
         dataForm: {
           id: '',
           amount: 0,
@@ -106,37 +109,34 @@
       }
     },
     methods: {
-      init () {
+      async init (id, display) {
+        console.log('id = ', id)
+        console.log('display = ', display)
         this.visible = true
-        this.dataForm.code = getUUID()
+        this.id = id || 0
+        this.display = display
+        this.dataForm = {}
+        this.dataList = []
+        if (!id) return
+        await getTemplateInfo(id).then(({data}) => {
+          if (data && data.code === '200') {
+            this.dataForm = data.data
+            this.dataList = data.data.whrTemplateMaterialList
+          }
+        })
       },
       // 表单提交
       dataFormSubmit () {
         this.$refs['dataForm'].validate((valid) => {
           if (valid) {
-            this.$http({
-              url: this.$http.adornUrl(`/biz-service/in-out-bound-ctl/inbound`),
-              method: 'post',
-              data: this.$http.adornData({
-                'amount': this.dataForm.amount,
-                'applicant': this.dataForm.applicant,
-                'approver': this.dataForm.approver,
-                'batchNumber': this.dataForm.batchNumber,
-                'cnt': this.dataForm.cnt,
-                'materialId': this.dataForm.materialId,
-                'materialName': this.dataForm.materialName,
-                'notes': this.dataForm.notes,
-                'price': this.dataForm.price,
-                'orgId': this.dataForm.orgId,
-                'recordType': this.dataForm.recordType,
-                'source': this.dataForm.source,
-                'state': this.dataForm.state,
-                'templateItemPlanId': this.dataForm.templateItemPlanId,
-                'usage': this.dataForm.usage,
-                'userId': this.dataForm.userId,
-                'creatorId': this.$store.state.user.id
-              })
-            }).then(({data}) => {
+            let postData = {
+              templateName: this.dataForm.templateName,
+              notes: this.dataForm.notes,
+              whrTemplateMaterialList: this.dataList,
+              orgId: this.$store.state.user.orgId
+            }
+            // console.log('postData = ' + JSON.stringify(postData))
+            addTemplate(postData).then(({data}) => {
               if (data && data.code === '200') {
                 this.$message({
                   message: '操作成功',
@@ -157,24 +157,29 @@
       validateField (type) {
         this.$refs.dataForm.validateField(type)
       },
-      userChanged (userId) {
-        this.$http({
-          url: this.$http.adornUrl('/user-service/user/info/' + userId),
-          method: 'get'
-        }).then(({data}) => {
-          if (data && data.code === '200') {
-            this.dataForm.orgId = data.data.orgId
-            this.dataForm.orgName = data.data.orgName
-          } else {
-            this.$message.error(data.msg)
-          }
-        })
-      },
       inBound () {
         this.inboundVisible = true
         this.$nextTick(() => {
           this.$refs.inbound.init()
         })
+      },
+      // 添加物品
+      addMaterial (item) {
+        if (item) {
+          this.dataList.push({
+            count: item.cnt,
+            materialId: item.materialId,
+            materialName: item.materialName,
+            notes: item.notes,
+            orgId: this.$store.state.user.orgId,
+            unitName: item.unitName
+          })
+        }
+      },
+      // 删除物品
+      removeItem (id) {
+        let index = this.dataList.findIndex((item) => { return item.materialId === id })
+        this.dataList.splice(index, 1)
       }
     }
   }

+ 71 - 50
src/views/modules/warehouse/template.vue

@@ -1,22 +1,22 @@
 <template>
   <div class="stock-order">
-    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
+    <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryData()">
       <el-form-item label="模板名称">
         <el-input v-model="dataForm.name" placeholder="模板名称" clearable></el-input>
       </el-form-item>
-      <el-form-item label="申请日期">
+      <el-form-item label="创建日期">
         <el-date-picker
           v-model="dataForm.date"
-          value-format="yyyy-MM-dd"
-          type="daterange"
+          value-format="yyyy-MM-dd HH:mm:ss"
+          type="datetimerange"
           range-separator="至"
           start-placeholder="开始日期"
           end-placeholder="结束日期">
         </el-date-picker>
       </el-form-item>
       <el-form-item>
-        <el-button @click="getDataList()">查询</el-button>
-        <el-button @click="inBound()"  type="primary">新增</el-button>
+        <el-button @click="queryData()">查询</el-button>
+        <el-button type="primary" @click="addOrUpdateHandle(0, false)">新增</el-button>
       </el-form-item>
     </el-form>
     <el-table
@@ -32,43 +32,53 @@
         align="center">
       </el-table-column>
       <el-table-column
-        prop="-"
+        prop="templateId"
+        v-if="false"
         header-align="center"
         align="center"
+        label="ID">
+      </el-table-column>
+      <el-table-column
+        prop="templateCode"
+        header-align="center"
+        align="center"
+        min-width="120"
         label="编码">
       </el-table-column>
       <el-table-column
-        prop="recordType"
+        prop="templateName"
         header-align="center"
         align="center"
+        min-width="120"
         label="模板名称">
       </el-table-column>
       <el-table-column
-        prop="state"
+        prop="usedNumber"
         header-align="center"
         align="center"
         label="使用次数">
       </el-table-column>
       <el-table-column
-        prop="approver"
+        prop="createTime"
         header-align="center"
         align="center"
         label="创建时间">
       </el-table-column>
       <el-table-column
-        prop="-"
+        prop="productId"
         header-align="center"
         align="center"
-        label="是否产品模版">
+        :formatter="formatProduct"
+        label="是否产品模板">
       </el-table-column>
       <el-table-column
-        prop="-"
+        prop="creatorName"
         header-align="center"
         align="center"
         label="创建人">
       </el-table-column>
       <el-table-column
-        prop="-"
+        prop="notes"
         header-align="center"
         align="center"
         label="备注">
@@ -80,8 +90,9 @@
         width="150"
         label="操作">
         <template slot-scope="scope">
-          <el-button v-if="isAuth('wh:inbound-record-ctl:info')" type="text" size="small" @click="details(scope.row.id)">查看</el-button>
-          <el-button type="text" size="small" @click="exportItem(scope.row.id)">停用</el-button>
+          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.templateId, true)">查看</el-button>
+          <el-button v-if="scope.row.state === '0'" style="color: red" type="text" size="small" @click="update(scope.row.templateId, 1)">停用</el-button>
+          <el-button v-else type="text" size="small" @click="update(scope.row.templateId, 0)">启用</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -94,39 +105,25 @@
       :total="totalPage"
       layout="total, sizes, prev, pager, next, jumper">
     </el-pagination>
-    <!--    入库-->
-    <template-add v-if="inboundVisible" ref="inbound" @refreshDataList="getDataList"></template-add>
-    <!-- <stock-order-outbound v-if="outboundVisible" ref="outbound" @refreshDataList="getDataList"></stock-order-outbound> -->
+    <!--    模板出库-->
+    <template-add v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></template-add>
   </div>
 </template>
 
 <script>
   import templateAdd from './template-add'
+  import { getTemplateList, updateTemplate } from '@/api/warehouse'
   export default {
     name: 'stock-order',
     components: {templateAdd},
     data () {
       return {
-        inboundVisible: false,
+        addOrUpdateVisible: false,
         outboundVisible: false,
         dataForm: {
           name: '',
           date: ''
         },
-        recordTypeOptions: [
-          {
-            value: null,
-            label: '请选择'
-          },
-          {
-            value: '0',
-            label: '入库'
-          },
-          {
-            value: '1',
-            label: '出库'
-          }
-        ],
         dataList: [],
         pageIndex: 1,
         pageSize: 10,
@@ -135,21 +132,26 @@
         dataListSelections: []
       }
     },
+    created () {
+      this.queryData()
+    },
     methods: {
+      // 查询
+      queryData () {
+        this.pageIndex = 1
+        this.getDataList()
+      },
       // 获取数据列表
-      getDataList () {
+      async getDataList () {
         this.dataListLoading = true
-        this.$http({
-          url: this.$http.adornUrl('/biz-service/TemplateMgCtl/list'),
-          method: 'get',
-          params: this.$http.adornParams({
-            'current': this.pageIndex,
-            'size': this.pageSize,
-            'beginTime': this.dataForm.date[0],
-            'endTime': this.dataForm.date[1],
-            'templateName': this.dataForm.name
-          })
-        }).then(({data}) => {
+        let params = {
+          current: this.pageIndex,
+          size: this.pageSize,
+          beginTime: this.dataForm.date[0],
+          endTime: this.dataForm.date[1],
+          templateName: this.dataForm.name
+        }
+        await getTemplateList(params).then(({data}) => {
           if (data && data.code === '200') {
             this.dataList = data.data.records
             this.totalPage = Number(data.data.total)
@@ -175,11 +177,30 @@
       selectionChangeHandle (val) {
         this.dataListSelections = val
       },
-      // 入库申请
-      inBound () {
-        this.inboundVisible = true
+      // 添加模板
+      addOrUpdateHandle (id, disable) {
+        this.addOrUpdateVisible = true
         this.$nextTick(() => {
-          this.$refs.inbound.init()
+          this.$refs.addOrUpdate.init(id, disable)
+        })
+      },
+      // 是否产品模板
+      formatProduct (row) {
+        return row.productId ? '是' : '否'
+      },
+      // 停用
+      async update (templateId, state) {
+        let postData = {
+          state: state,
+          templateId: templateId,
+          updaterId: this.$store.state.user.id
+        }
+        await updateTemplate(postData).then(({data}) => {
+          if (data && data.code === '200') {
+            this.getDataList()
+          } else {
+            this.$message.error(data.msg)
+          }
         })
       }
     }