Browse Source

记录规则页面基本完成

lucw 9 months ago
parent
commit
f05fac8d06

+ 91 - 0
src/api/recordrules/index.js

@@ -0,0 +1,91 @@
+import request from '@/utils/request';
+
+// 规则记录分页查询
+export async function recordrulesPage(body) {
+  const res = await request.post(`/main/recordrules/page`, body);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 规则记录批量删除
+export async function recordrulesDeletes(ids) {
+  const res = await request.delete(`/main/recordrules/delete`, { data: ids });
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 规则记录清空
+export async function recordrulesClear() {
+  const res = await request.delete(`/main/recordrules/clear`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 保存 /main/recordrules/save
+export async function recordrulesSave(data) {
+  const res = await request.post(`/main/recordrules/save`, data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 保存并发布
+export async function recordrulesSaveAndPublish(data) {
+  const res = await request.post(`/main/recordrules/saveAndPublish`, data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 发布 /main/recordrules/publish/{id}
+export async function recordrulesPublish(id) {
+  const res = await request.post(`/main/recordrules/publish/${id}`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 撤销  /main/recordrules/revokePublish/{id}
+export async function recordrulesRevokePublish(id) {
+  const res = await request.post(`/main/recordrules/revokePublish/${id}`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 规则记录明细分页查询 /main/recordrulesdetail/page
+export async function recordrulesDetailPage(body) {
+  const res = await request.post(`/main/recordrulesdetail/page`, body);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 修改 /main/recordrules/update
+export async function recordrulesUpdate(data) {
+  const res = await request.put(`/main/recordrules/update`, data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 更新版本 /main/recordrules/updateVersion
+export async function recordrulesUpdateVersion(body) {
+  const res = await request.post(`/main/recordrules/updateVersion`, body);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 4 - 3
src/enum/dict.js

@@ -73,7 +73,9 @@ export default {
   文档类型: 'doc_type',
   文档类型: 'doc_type',
   存货类型: 'inventory_type',
   存货类型: 'inventory_type',
   物品机型: 'product_model_key',
   物品机型: 'product_model_key',
-  物品颜色: 'product_color_key'
+  物品颜色: 'product_color_key',
+  记录规则类型: 'record_sheet',
+  记录规则频率: 'record_rules_frequency'
 };
 };
 
 
 export const numberList = [
 export const numberList = [
@@ -212,8 +214,7 @@ export const fineRule = [
     label: '文本',
     label: '文本',
     value: '1',
     value: '1',
     pid: '6',
     pid: '6',
-    reg: '文本',
-    reg: ''
+    reg: '文本'
   }
   }
   // {
   // {
   //   label: 'A-Z0-9',
   //   label: 'A-Z0-9',

+ 588 - 187
src/views/rulesManagement/releaseRules/components/permitAdd.vue

@@ -8,21 +8,18 @@
     width="80%"
     width="80%"
     :maxable="true"
     :maxable="true"
   >
   >
-    <el-form label-width="115px" :model="formData" ref="formRef">
+    <el-form
+      label-width="115px"
+      :model="formData"
+      :rules="formRules"
+      ref="formRef"
+    >
       <el-row>
       <el-row>
         <el-col :span="8">
         <el-col :span="8">
-          <el-form-item
-            label="记录规则分类"
-            prop="classifyId"
-            :rules="{
-              required: true,
-              message: '请选择记录表分类',
-              trigger: 'change'
-            }"
-          >
+          <el-form-item label="记录规则类型" prop="classify" required>
             <el-select
             <el-select
               style="width: 100%"
               style="width: 100%"
-              v-model="formData.classifyId"
+              v-model="formData.classify"
               placeholder="请选择"
               placeholder="请选择"
             >
             >
               <el-option
               <el-option
@@ -35,25 +32,28 @@
             </el-select>
             </el-select>
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
-        <el-col :span="7">
-          <el-form-item label="规则编码" prop="name">
+        <el-col :span="8">
+          <el-form-item label="记录规则编码" prop="code">
             <el-input
             <el-input
               v-model="formData.code"
               v-model="formData.code"
               size="small"
               size="small"
               :disabled="true"
               :disabled="true"
+              placeholder="系统自动生成"
             ></el-input>
             ></el-input>
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
-        <el-col :span="6">
-          <el-form-item
-            label="规则名称"
-            prop="name"
-            :rules="{
-              required: true,
-              message: '请输入规则名称',
-              trigger: 'change'
-            }"
-          >
+        <el-col :span="8">
+          <el-form-item label="记录规则版本" prop="version">
+            <el-input
+              :value="versionText"
+              size="small"
+              disabled
+              placeholder="系统自动生成"
+            ></el-input>
+          </el-form-item>
+        </el-col>
+        <el-col :span="8">
+          <el-form-item label="记录规则名称" prop="name">
             <el-input
             <el-input
               v-model="formData.name"
               v-model="formData.name"
               placeholder="请输入"
               placeholder="请输入"
@@ -62,35 +62,78 @@
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
 
 
-        <el-col :span="5">
-          <el-form-item label="状态" label-width="70px" required>
-            <el-switch
-              v-model="formData.enable"
-              active-text="生效"
-              inactive-text="失效"
-              :active-value="true"
-              :inactive-value="false"
-            >
-            </el-switch>
+        <el-col :span="8">
+          <el-form-item label="启用时间" required prop="startDate">
+            <el-date-picker
+              v-model="formData.startDate"
+              type="date"
+              placeholder="请选择启用时间"
+              size="small"
+              style="width: 100%"
+            ></el-date-picker>
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
-        <el-col :span="24">
-          <el-form-item label="周期" required>
-            <RuleCycle
-              ref="cycleMultipleRef"
-              :isOnce="true"
-              :formData="formData"
-              pageType="1"
-              :isBindPlan="false"
+
+        <el-col :span="8">
+          <el-form-item label="停止时间" required prop="stopDate">
+            <el-date-picker
+              v-model="formData.stopDate"
+              type="date"
+              placeholder="请选择停止时间"
+              size="small"
+              style="width: 100%"
             />
             />
           </el-form-item>
           </el-form-item>
         </el-col>
         </el-col>
+        <el-col :span="8">
+          <el-col :span="12">
+            <el-form-item label="周期" required prop="frequencyValue">
+              <el-input
+                class="cycle_value"
+                size="small"
+                v-model.number="formData.frequencyValue"
+                placeholder="请输入频率数值"
+              ></el-input>
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item required prop="frequencyUnit" label-width="0">
+              <el-select
+                v-model="formData.frequencyUnit"
+                size="small"
+                placeholder="请选择频率单位"
+              >
+                <el-option
+                  v-for="item in recordRulesFrequency"
+                  :key="item.value"
+                  :label="item.label"
+                  :value="item.value"
+                ></el-option>
+              </el-select>
+            </el-form-item>
+          </el-col>
+        </el-col>
+        <el-col v-if="formData.classify == 3" :span="8">
+          <el-form-item label="关联设备" prop="deviceName" required>
+            <el-input
+              v-model="formData.deviceName"
+              placeholder="请选择设备"
+              size="small"
+              :readonly="true"
+            >
+              <template #append>
+                <el-button size="small" @click="selectDeviceId"
+                  >选择设备</el-button
+                >
+              </template>
+            </el-input>
+          </el-form-item>
+        </el-col>
       </el-row>
       </el-row>
       <ele-pro-table
       <ele-pro-table
         ref="table"
         ref="table"
         :columns="bankColumns"
         :columns="bankColumns"
-        :datasource="formData.ruleItems"
-        :toolkit="[]"
+        :datasource="formData.recordRulesDetailList"
         :need-page="false"
         :need-page="false"
         row-key="id"
         row-key="id"
         class="table_list"
         class="table_list"
@@ -101,77 +144,174 @@
             type="primary"
             type="primary"
             icon="el-icon-plus"
             icon="el-icon-plus"
             class="ele-btn-icon"
             class="ele-btn-icon"
-            @click="add({})"
+            @click="addRow"
           >
           >
             新建
             新建
           </el-button>
           </el-button>
         </template>
         </template>
-        <template v-slot:tools="{ row }">
-          <div
-            style="display: inline-block"
-            v-for="(item, idx) in row.tools"
-            :key="idx"
-            >{{ item.name }}
-            <span v-if="row.tools && idx != row.tools.length - 1">, </span>
-          </div>
+
+        <template v-slot:paramType="{ row }">
+          <el-select
+            v-model="row.paramType"
+            placeholder="请选择参数类型"
+            size="mini"
+            required
+          >
+            <el-option label="数值" :value="1" />
+            <el-option label="选择" :value="2" />
+            <el-option label="上下限" :value="3" />
+            <el-option label="规格" :value="4" />
+            <el-option label="时间" :value="5" />
+            <el-option label="范围" :value="6" />
+            <el-option label="文本" :value="7" />
+            <!-- <el-option label="枚举" :value="8" /> -->
+          </el-select>
+        </template>
+
+        <template v-slot:paramValue="{ row }">
+          <!-- 根据参数类型渲染不同的输入组件 -->
+          <el-input
+            v-model="row.paramValue"
+            placeholder="请输入参数内容"
+            size="mini"
+          ></el-input>
+        </template>
+        <template v-slot:defaultValue="{ row }">
+          <el-row>
+            <el-col :span="12">
+              <!-- <el-select
+                v-if="row.paramType != 7"
+                v-model="row.symbol"
+                placeholder="请选择"
+                size="mini"
+              >
+                <el-option label=">" value=">"> </el-option>
+                <el-option label="<" value="<"> </el-option>
+                <el-option label="!=" value="!="> </el-option>
+                <el-option label=">=" value=">="> </el-option>
+                <el-option label="<=" value="<="> </el-option>
+                <el-option label="~~" value="~~"> </el-option>
+                <el-option label="+-" value="+-"> </el-option>
+                <el-option label="......" value="......"> </el-option>
+              </el-select> -->
+              <DictSelection
+                v-if="row.paramType != 7"
+                clearable
+                dictName="数学字符"
+                v-model="row.numberOperator"
+                placeholder="请选择逻辑"
+                size="mini"
+              ></DictSelection>
+            </el-col>
+            <el-col :span="row.paramType != 7 ? 12 : 24">
+              <el-input
+                v-model="row.defaultValue"
+                placeholder="请输入默认值"
+                size="mini"
+              ></el-input>
+            </el-col>
+          </el-row>
+        </template>
+        <template v-slot:maxValue="{ row }">
+          <el-input
+            v-if="row.paramType == 3 || row.paramType == 6"
+            v-model="row.maxValue"
+            placeholder="请输入参数上限"
+            size="mini"
+          ></el-input>
+        </template>
+        <template v-slot:minValue="{ row }">
+          <el-input
+            v-if="row.paramType == 3 || row.paramType == 6"
+            v-model="row.minValue"
+            placeholder="请输入参数下限"
+            size="mini"
+          ></el-input>
+        </template>
+        <template v-slot:unitName="{ row }">
+          <!-- <el-input
+            v-model="row.unitName"
+            placeholder="请输入参数单位"
+            size="mini"
+          ></el-input> -->
+          <DictSelection
+            v-if="row.paramType != 7"
+            dictName="工艺参数单位"
+            clearable
+            filterable
+            v-model="row.unitName"
+            size="mini"
+          >
+          </DictSelection>
+        </template>
+        <template v-slot:toolName="{ row }">
+          <el-link :underline="false" style="cursor: pointer">
+            <div class="ele-cell">
+              <!-- class="ele-elip" style="width: 90px" -->
+              <div @click="handleAdd(row)">
+                {{
+                  row.tools && row.tools.length > 0
+                    ? row.tools.map((i) => i.toolName).join(',')
+                    : '请选择'
+                }}
+              </div>
+              <i
+                v-if="row.tools.length == 0"
+                class="el-icon-arrow-down"
+                @click="handleAdd(row)"
+              ></i>
+              <i v-else class="el-icon-close" @click="clearTool(row)"></i>
+            </div>
+          </el-link>
+        </template>
+        <template v-slot:toolCodes="{ row }">
+          <el-input
+            :value="
+              row.tools && row.tools.length > 0
+                ? row.tools.map((i) => i.toolCode).join(',')
+                : ''
+            "
+            placeholder="工具自动带出"
+            disabled
+            size="mini"
+          ></el-input>
         </template>
         </template>
-        <template v-slot:textType="{ row }">
-          {{
-            row.textType == 1
-              ? '数值'
-              : row.textType == 2
-              ? '选择'
-              : row.textType == 3
-              ? '上下限'
-              : row.textType == 4
-              ? '规格'
-              : row.textType == 5
-              ? '时间'
-              : row.textType == 6
-              ? '范围'
-              : row.textType == 7
-              ? '文本'
-              : row.textType == 8
-              ? '枚举'
-              : ''
-          }}
+        <template v-slot:remark="{ row }">
+          <el-input
+            v-model="row.remark"
+            placeholder="请输入"
+            size="mini"
+          ></el-input>
         </template>
         </template>
-        <template v-slot:action="{ row, $index }">
+        <template v-slot:action="{ row }">
           <el-link
           <el-link
-            type="primary"
-            @click="edit(row, $index)"
+            type="danger"
             :underline="false"
             :underline="false"
-            icon="el-icon-edit"
-            >编辑</el-link
+            icon="el-icon-delete"
+            @click="deleteRow(row)"
           >
           >
-          <el-popconfirm
-            class="ele-action"
-            title="确定要删除当前数据吗?"
-            @confirm="itemDel($index)"
-          >
-            <template v-slot:reference>
-              <el-link type="danger" :underline="false" icon="el-icon-delete"
-                >删除</el-link
-              >
-            </template>
-          </el-popconfirm>
+            删除
+          </el-link>
         </template>
         </template>
       </ele-pro-table>
       </ele-pro-table>
     </el-form>
     </el-form>
-    <operation-guideDialog ref="operationGuideDialog" @save="saveEdit" />
-    <Details
-      ref="userEdit"
-      :visible.sync="showEdit"
-      :data="current"
-      :dataIndex="dataIndex"
-      @done="save"
-    />
     <template v-slot:footer>
     <template v-slot:footer>
-      <el-button :loading="btnLoading" @click="handleClose">取消</el-button>
+      <el-button :loading="btnLoading" type="primary" @click="saveAndPublish">
+        保存并发布
+      </el-button>
       <el-button :loading="btnLoading" type="primary" @click="confirm">
       <el-button :loading="btnLoading" type="primary" @click="confirm">
         保存
         保存
       </el-button>
       </el-button>
+      <el-button :loading="btnLoading" @click="handleClose">取消</el-button>
     </template>
     </template>
+
+    <ProductModal ref="productRefs" @chooseModal="chooseModal" />
+
+    <MaterialAdd
+      ref="deviceSelectDialog"
+      selectType="single"
+      @chooseEquipment="chooseEquipment"
+    />
   </ele-modal>
   </ele-modal>
 </template>
 </template>
 
 
@@ -181,26 +321,36 @@
   import RuleCycle from './rule-cycle.vue';
   import RuleCycle from './rule-cycle.vue';
   import OperationGuideDialog from '@/views/rulesManagement/matterRules/components/operationGuideDialog.vue';
   import OperationGuideDialog from '@/views/rulesManagement/matterRules/components/operationGuideDialog.vue';
   import Details from './details.vue';
   import Details from './details.vue';
+  import dictMixins from '@/mixins/dictMixins';
+  import ProductModal from './ProductModal.vue';
+  import MaterialAdd from '../../components/MaterialAdd.vue';
   import {
   import {
-    releasePermitRules,
-    updatePermitRules
-  } from '@/api/releasePermitRules/index';
+    recordrulesSave,
+    recordrulesDetailPage,
+    recordrulesUpdate,
+    recordrulesPublish,
+    recordrulesSaveAndPublish,
+    recordrulesUpdateVersion
+  } from '@/api/recordrules/index';
+
   export default {
   export default {
-    components: { OperationGuideDialog, RuleCycle, Details },
+    components: {
+      OperationGuideDialog,
+      RuleCycle,
+      Details,
+      ProductModal,
+      MaterialAdd
+    },
+    mixins: [dictMixins],
     computed: {
     computed: {
       bankColumns() {
       bankColumns() {
         return [
         return [
           {
           {
-            prop: 'name',
-            label: '参数名称',
+            width: 110,
+            type: 'index',
+            columnKey: 'index',
             align: 'center',
             align: 'center',
-            minWidth: 130
-          },
-          {
-            prop: 'code',
-            label: '参数编码',
-            align: 'center',
-            minWidth: 130
+            label: '序号'
           },
           },
           {
           {
             prop: 'paramType',
             prop: 'paramType',
@@ -210,56 +360,75 @@
             minWidth: 110
             minWidth: 110
           },
           },
           {
           {
-            prop: 'defaultVal',
+            prop: 'paramValue',
+            label: '参数内容',
+            align: 'center',
+            slot: 'paramValue',
+            minWidth: 180
+          },
+          {
+            prop: 'defaultValue',
             label: '默认值',
             label: '默认值',
             align: 'center',
             align: 'center',
-            showOverflowTooltip: true
+            slot: 'defaultValue',
+            minWidth: 150
           },
           },
-
           {
           {
-            prop: 'upperLimit',
+            prop: 'maxValue',
             label: '参数上限',
             label: '参数上限',
             align: 'center',
             align: 'center',
-            showOverflowTooltip: true
+            slot: 'maxValue',
+            minWidth: 110
           },
           },
           {
           {
-            slot: 'lowerLimit',
+            prop: 'minValue',
             label: '参数下限',
             label: '参数下限',
             align: 'center',
             align: 'center',
-            showOverflowTooltip: true
+            slot: 'minValue',
+            minWidth: 110
           },
           },
           {
           {
-            prop: 'paramUnit',
+            prop: 'unitName',
             label: '参数单位',
             label: '参数单位',
-            align: 'center'
+            align: 'center',
+            slot: 'unitName',
+            minWidth: 110
           },
           },
           {
           {
-            prop: 'tools',
-            slot: 'tools',
+            prop: 'toolName',
             label: '工具名称',
             label: '工具名称',
             align: 'center',
             align: 'center',
-            minWidth: 150
+            slot: 'toolName',
+            minWidth: 110
           },
           },
           {
           {
-            label: '状态',
-            prop: 'enable',
-            formatter: (row, column, cellValue) => {
-              return cellValue == 1 ? '启用' : cellValue === 0 ? '停用' : '';
-            }
+            prop: 'toolCodes',
+            label: '工具编码',
+            align: 'center',
+            slot: 'toolCodes',
+            minWidth: 110
           },
           },
           {
           {
+            prop: 'remark',
             label: '备注',
             label: '备注',
-            prop: 'remarks'
+            align: 'center',
+            slot: 'remark',
+            minWidth: 110
           },
           },
           {
           {
             columnKey: 'action',
             columnKey: 'action',
             label: '操作',
             label: '操作',
-            width: 140,
+            width: 110,
             align: 'center',
             align: 'center',
             resizable: false,
             resizable: false,
             slot: 'action'
             slot: 'action'
           }
           }
         ];
         ];
+      },
+      versionText() {
+        return this.formData.version
+          ? `V${this.formData.version.toFixed(1)}`
+          : 'V1.0';
       }
       }
     },
     },
     data() {
     data() {
@@ -267,21 +436,81 @@
         dialogTitle: '',
         dialogTitle: '',
         visible: false,
         visible: false,
         formData: {
         formData: {
-          ruleItems: [],
-          classifyId: '',
-          code: '',
+          id: null,
+          classify: null,
+          deviceId: null,
+          deviceName: '',
+          frequencyUnit: null,
+          frequencyValue: null,
           name: '',
           name: '',
-          enable: true
+          recordRulesDetailList: [
+            {
+              id: 0,
+              defaultValue: '',
+              maxValue: null,
+              minValue: null,
+              paramType: null,
+              paramValue: null,
+              remark: '',
+              symbol: null,
+              tools: [],
+              unitName: null
+            }
+          ],
+          startDate: null,
+          stopDate: null,
+          version: 1,
+          code: '',
+          fromId: null
+        },
+        formRules: {
+          name: [
+            { required: true, message: '请输入规则名称', trigger: 'blur' }
+          ],
+          frequencyValue: [
+            { required: true, message: '请输入频率数值', trigger: 'blur' }
+          ],
+          frequencyUnit: [
+            { required: true, message: '请选择频率单位', trigger: 'change' }
+          ],
+          classify: [
+            { required: true, message: '请选择规则类型', trigger: 'change' }
+          ],
+          // startDate 启用时间要大于当前时间
+          // stopDate 停用时间要大于当前时间并且大于启用时间
+          startDate: [
+            { required: true, message: '请选择启用时间', trigger: 'change' },
+            { validator: this.validateStartDate, trigger: 'change' }
+          ],
+          stopDate: [
+            { required: true, message: '请选择停用时间', trigger: 'change' },
+            { validator: this.validateStopDate, trigger: 'change' }
+          ],
+          deviceName: [
+            { required: true, message: '请输入选择设备', trigger: 'blur' }
+          ]
         },
         },
         recordSheet: [], // 记录表
         recordSheet: [], // 记录表
         current: {},
         current: {},
         dataIndex: null,
         dataIndex: null,
         showEdit: false,
         showEdit: false,
-        btnLoading: false
+        btnLoading: false,
+        recordRulesFrequency: [],
+        currentRow: null
       };
       };
     },
     },
     mounted() {
     mounted() {
       this.getByCodeData();
       this.getByCodeData();
+
+      this.requestDict('记录规则频率').then(() => {
+        if (this.$store.state.dict['record_rules_frequency']) {
+          this.recordRulesFrequency = this.$store.state.dict[
+            'record_rules_frequency'
+          ].map((i) => {
+            return { label: i.dictValue, value: Number(i.dictCode) };
+          });
+        }
+      });
     },
     },
     methods: {
     methods: {
       open(row, type, title) {
       open(row, type, title) {
@@ -289,11 +518,37 @@
         this.dialogTitle = title;
         this.dialogTitle = title;
         this.type = type;
         this.type = type;
         console.log('type', type, row);
         console.log('type', type, row);
+
         if (type == 'edit') {
         if (type == 'edit') {
-          this.$util.assignObject(this.formData, this.$util.deepClone(row));
-          // string 转换 number
-          this.formData.classifyId = Number(row.classifyId);
-          console.log('this.formData', this.formData);
+          this.$util.assignObject(this.formData, row);
+
+          this.formData.startDate = new Date(row.startDate);
+          this.formData.stopDate = new Date(row.stopDate);
+
+          this.recordrulesDetailPage(row);
+
+          console.log('this.formData', this.formData, this.formData.version);
+        }
+
+        if (type == 'clone') {
+          this.$util.assignObject(this.formData, row);
+
+          this.formData.name = this.formData.name + '-副本';
+          this.formData.version += 1;
+
+          this.formData.fromId = row.id;
+          this.formData.id = null;
+          this.formData.startDate = new Date(row.stopDate);
+          this.formData.stopDate = new Date('2099-12-31 00:00:00');
+
+          this.recordrulesDetailPage(row);
+        }
+
+        if (type == 'add') {
+          this.formData.version = 1;
+
+          // 停用日期 默认为 2099-12-31
+          this.formData.stopDate = new Date('2099-12-31 00:00:00');
         }
         }
       },
       },
       async getByCodeData() {
       async getByCodeData() {
@@ -301,26 +556,23 @@
         let list = res.data.map((item) => {
         let list = res.data.map((item) => {
           let values = Object.keys(item);
           let values = Object.keys(item);
           return {
           return {
-            value: Number(values[0]),
+            value: values[0],
             label: item[values[0]]
             label: item[values[0]]
           };
           };
         });
         });
         this.recordSheet = list;
         this.recordSheet = list;
-        console.log('this.recordSheet', this.recordSheet);
-      },
-      add(row) {
-        this.current = row;
-        this.showEdit = true;
-        this.$refs.userEdit.$refs.form &&
-          this.$refs.userEdit.$refs.form.clearValidate();
       },
       },
       // 保存数据
       // 保存数据
       save(data, idx) {
       save(data, idx) {
         if (idx || idx === 0) {
         if (idx || idx === 0) {
-          this.$set(this.formData.ruleItems, idx, data);
+          this.$set(this.formData.recordRulesDetailList, idx, data);
         } else {
         } else {
-          this.formData.ruleItems.push(data);
+          this.formData.recordRulesDetailList.push(data);
         }
         }
+        console.log(
+          'this.formData.recordRulesDetailList',
+          this.formData.recordRulesDetailList
+        );
       },
       },
       edit(row, index) {
       edit(row, index) {
         this.current = row;
         this.current = row;
@@ -330,65 +582,214 @@
           this.$refs.userEdit.$refs.form.clearValidate();
           this.$refs.userEdit.$refs.form.clearValidate();
       },
       },
       itemDel(index) {
       itemDel(index) {
-        this.formData.ruleItems.splice(index, 1);
+        this.formData.recordRulesDetailList.splice(index, 1);
       },
       },
       /* 打开操作手册编辑款 */
       /* 打开操作手册编辑款 */
       openOperationGuideDialogDialog(row, index) {
       openOperationGuideDialogDialog(row, index) {
         this.$refs.operationGuideDialog.open(row, index);
         this.$refs.operationGuideDialog.open(row, index);
       },
       },
-      saveEdit(data, index) {
-        this.$set(this.formData.ruleItems[index], 'operationGuide', data);
-      },
       handleClose() {
       handleClose() {
         this.visible = false;
         this.visible = false;
         this.$refs['formRef'].resetFields();
         this.$refs['formRef'].resetFields();
         // 清空表单数据
         // 清空表单数据
         this.formData = {
         this.formData = {
-          ruleItems: [],
-          classifyId: '',
-          code: '',
+          id: null,
+          classify: null,
+          deviceId: null,
+          deviceName: '',
+          frequencyUnit: null,
+          frequencyValue: null,
           name: '',
           name: '',
-          enable: true
+          recordRulesDetailList: [
+            {
+              id: 0,
+              defaultValue: '',
+              maxValue: null,
+              minValue: null,
+              paramType: null,
+              paramValue: null,
+              remark: '',
+              symbol: null,
+              toolCodes: null,
+              tools: []
+            }
+          ],
+          startDate: null,
+          stopDate: null,
+          version: 1,
+          code: '',
+          fromId: null
         };
         };
       },
       },
+      // 保存
       confirm() {
       confirm() {
-        if (!this.formData.cycleValue || !this.formData.cycleType) {
-          return this.$message.warning('请填写周期参数');
-        }
-        if (this.formData.ruleItems.length == 0) {
-          return this.$message.warning('至少条件一条规则项');
-        }
+        console.log('this.formData', this.formData);
 
 
-        this.$refs.formRef.validate((valid) => {
+        // 验证表单规则
+        this.$refs.formRef.validate(async (valid) => {
           if (!valid) {
           if (!valid) {
             return false;
             return false;
           }
           }
-          let data = {
-            name: this.formData.name,
-            classifyId: this.formData.classifyId,
-            enable: this.formData.enable,
-            frequencyUnit: this.formData.cycleType,
-            frequencyValue: this.formData.cycleValue,
-            items: this.formData.ruleItems
-          };
-          let cycle = this.$refs.cycleMultipleRef.ruleCycleList;
-          if (cycle.length > 0) {
-            data.frequencyTimes = cycle;
+          if (this.formData.recordRulesDetailList.length == 0) {
+            return this.$message.warning('至少条件一条规则项');
+          }
+
+          try {
+            this.btnLoading = true;
+
+            const body = { ...this.formData };
+
+            body.startDate = this.$util.toDateString(
+              body.startDate,
+              'yyyy-MM-dd HH:mm:ss'
+            );
+
+            body.stopDate = this.$util.toDateString(
+              body.stopDate,
+              'yyyy-MM-dd HH:mm:ss'
+            );
+
+            if (this.type == 'add') {
+              await recordrulesSave(body);
+            } else if (this.type == 'clone') {
+              await recordrulesUpdateVersion(body);
+            } else {
+              // 编辑
+              body.fromId = null;
+              await recordrulesUpdate(body);
+            }
+
+            this.btnLoading = false;
+            this.$message.success('操作成功');
+
+            this.handleClose();
+            this.$emit('reload');
+          } catch (error) {
+            this.btnLoading = false;
+          }
+        });
+      },
+      // 保存并发布
+      saveAndPublish() {
+        // 验证表单规则
+        this.$refs.formRef.validate(async (valid) => {
+          if (!valid) {
+            return false;
+          }
+          if (this.formData.recordRulesDetailList.length == 0) {
+            return this.$message.warning('至少条件一条规则项');
+          }
+
+          try {
+            this.btnLoading = true;
+
+            const body = { ...this.formData };
+
+            body.startDate = this.$util.toDateString(
+              body.startDate,
+              'yyyy-MM-dd HH:mm:ss'
+            );
+
+            body.stopDate = this.$util.toDateString(
+              body.stopDate,
+              'yyyy-MM-dd HH:mm:ss'
+            );
+
+            await recordrulesSaveAndPublish(body);
+
+            this.btnLoading = false;
+            this.$message.success('操作成功');
+
+            this.handleClose();
+            this.$emit('reload');
+          } catch (error) {
+            this.btnLoading = false;
           }
           }
-          this.btnLoading = true;
-          releasePermitRules(data)
-            .then((res) => {
-              this.btnLoading = false;
-              if (res) {
-                this.$message.success('操作成功');
-                this.handleClose();
-                this.$emit('reload');
-              }
-            })
-            .catch((err) => {
-              this.btnLoading = false;
-            });
         });
         });
+      },
+      // startDate 启用时间要大于当前时间
+      validateStartDate(rule, value, callback) {
+        const startDate = this.formData.startDate;
+        if (!startDate) {
+          return callback(new Error('启用时间不能为空'));
+        }
+
+        callback();
+      },
+      // stopDate 停用时间要大于当前时间并且大于启用时间
+      validateStopDate(rule, value, callback) {
+        const startDate = this.formData.startDate;
+        const stopDate = this.formData.stopDate;
+        if (
+          stopDate &&
+          startDate &&
+          new Date(stopDate) <= new Date(startDate)
+        ) {
+          return callback(new Error('停用时间必须大于启用时间'));
+        }
+
+        callback();
+      },
+      // 去选择设备
+      selectDeviceId() {
+        this.$refs.deviceSelectDialog.open([]);
+      },
+      // 选择设备回调
+      chooseEquipment(data, index, categoryId) {
+        console.log('data', data, index, categoryId);
+        this.formData.deviceId = data[0]?.id || null;
+        this.formData.deviceName = data[0]?.name || '';
+      },
+      // 添加
+      addRow() {
+        this.formData.recordRulesDetailList.push({
+          id: new Date().getTime(),
+          defaultValue: '',
+          maxValue: null,
+          minValue: null,
+          paramType: null,
+          paramValue: null,
+          remark: '',
+          symbol: null,
+          tools: [],
+          unitName: null
+        });
+      },
+      deleteRow(row) {
+        const index = this.formData.recordRulesDetailList.indexOf(row);
+        if (index !== -1) {
+          this.formData.recordRulesDetailList.splice(index, 1);
+        }
+      },
+      handleAdd(row) {
+        this.currentRow = row;
+        this.$refs.productRefs.open(row.toolCodes);
+      },
+      chooseModal(data) {
+        console.log('data', data);
+        this.currentRow.tools = data.map((i) => {
+          return {
+            toolCode: i.code,
+            toolName: i.name
+            // rulesDetailId: this.currentRow.id,
+            // rulesId: this.formData.id
+          };
+        });
+      },
+      // 规则明细表
+      async recordrulesDetailPage(row) {
+        const { list } = await recordrulesDetailPage({
+          // deptId: row.deptId,
+          pageNum: 1,
+          rulesId: row.id,
+          size: 9999
+        });
+        console.log('list 数据', list);
+        this.formData.recordRulesDetailList = list;
+      },
+      // 清空工具
+      clearTool(row) {
+        row.tools = [];
       }
       }
     }
     }
   };
   };

+ 37 - 7
src/views/rulesManagement/releaseRules/components/search.vue

@@ -4,10 +4,15 @@
 </template>
 </template>
 
 
 <script>
 <script>
+  import dictMixins from '@/mixins/dictMixins';
+
   export default {
   export default {
     props: {},
     props: {},
+    mixins: [dictMixins],
     data() {
     data() {
-      return {};
+      return {
+        typeList: []
+      };
     },
     },
     computed: {
     computed: {
       // 表格列配置
       // 表格列配置
@@ -27,19 +32,44 @@
           },
           },
           {
           {
             label: '记录表分类:',
             label: '记录表分类:',
-            value: 'fl',
-            type: 'input',
-            placeholder: '记录表分类'
+            value: 'classify',
+            type: 'select',
+            placeholder: '记录表分类',
+            planList: this.typeList
           },
           },
           {
           {
             label: '状态:',
             label: '状态:',
-            value: 'status',
-            type: 'input',
-            placeholder: '状态'
+            value: 'publishStatus',
+            type: 'select',
+            placeholder: '状态',
+            // 0-草稿,1-已发布,2-已撤销
+            planList: [
+              {
+                label: '草稿',
+                value: '0'
+              },
+              {
+                label: '已发布',
+                value: '1'
+              },
+              {
+                label: '已撤销',
+                value: '2'
+              }
+            ]
           }
           }
         ];
         ];
       }
       }
     },
     },
+    mounted() {
+      this.requestDict('记录规则类型').then(() => {
+        if (this.$store.state.dict['record_sheet']) {
+          this.typeList = this.$store.state.dict['record_sheet'].map((i) => {
+            return { label: i.dictValue, value: i.dictCode };
+          });
+        }
+      });
+    },
     methods: {
     methods: {
       /* 搜索 */
       /* 搜索 */
       search(e) {
       search(e) {

+ 127 - 22
src/views/rulesManagement/releaseRules/index.vue

@@ -9,7 +9,7 @@
             type="primary"
             type="primary"
             icon="el-icon-plus"
             icon="el-icon-plus"
             class="ele-btn-icon"
             class="ele-btn-icon"
-            @click="addPermit('', 'add', '新增记录规则')"
+            @click="addPermit(null, 'add', '新增记录规则')"
           >
           >
             新建
             新建
           </el-button>
           </el-button>
@@ -17,14 +17,29 @@
         <!-- <template v-slot:status="{ row }"> </template> -->
         <!-- <template v-slot:status="{ row }"> </template> -->
         <template v-slot:action="{ row }">
         <template v-slot:action="{ row }">
           <el-link
           <el-link
-            type="primary"
+            v-if="row.publishStatus === 1"
+            type="success"
             :underline="false"
             :underline="false"
             icon="el-icon-finished"
             icon="el-icon-finished"
-            @click="addPermit('clone', row)"
+            @click="addPermit(row, 'clone', '变更记录规则')"
           >
           >
-            克隆
+            变更
           </el-link>
           </el-link>
+          <el-popconfirm
+            v-if="row.publishStatus == 1"
+            class="ele-action"
+            title="确定要撤销此条数据吗?"
+            @confirm="recordrulesRevokePublish(row)"
+          >
+            <template v-slot:reference>
+              <el-link type="warning" :underline="false" icon="el-icon-delete">
+                撤销
+              </el-link>
+            </template>
+          </el-popconfirm>
+
           <el-link
           <el-link
+            v-if="row.publishStatus != 1"
             type="primary"
             type="primary"
             :underline="false"
             :underline="false"
             icon="el-icon-edit"
             icon="el-icon-edit"
@@ -32,7 +47,26 @@
           >
           >
             修改
             修改
           </el-link>
           </el-link>
+
           <el-popconfirm
           <el-popconfirm
+            v-if="row.publishStatus != 1"
+            class="ele-action"
+            title="确定要发布此条数据吗?"
+            @confirm="publish(row)"
+          >
+            <template v-slot:reference>
+              <el-link
+                type="primary"
+                :underline="false"
+                icon="el-icon-position"
+              >
+                发布
+              </el-link>
+            </template>
+          </el-popconfirm>
+
+          <el-popconfirm
+            v-if="row.publishStatus != 1"
             class="ele-action"
             class="ele-action"
             title="确定要删除此条数据吗?"
             title="确定要删除此条数据吗?"
             @confirm="remove(row)"
             @confirm="remove(row)"
@@ -41,8 +75,6 @@
               <el-link type="danger" :underline="false" icon="el-icon-delete">
               <el-link type="danger" :underline="false" icon="el-icon-delete">
                 删除
                 删除
               </el-link>
               </el-link>
-
-
             </template>
             </template>
           </el-popconfirm>
           </el-popconfirm>
         </template>
         </template>
@@ -56,9 +88,18 @@
   // import { getList } from '@/api/ruleManagement/matter';
   // import { getList } from '@/api/ruleManagement/matter';
   import search from './components/search.vue';
   import search from './components/search.vue';
   import permitAdd from './components/permitAdd.vue';
   import permitAdd from './components/permitAdd.vue';
-  import { getRulesList } from '@/api/releasePermitRules/index';
+  import {
+    recordrulesPage,
+    recordrulesDeletes,
+    recordrulesPublish,
+    recordrulesRevokePublish
+  } from '@/api/recordrules/index';
+  import tabMixins from '@/mixins/tableColumnsMixin';
+  import dictMixins from '@/mixins/dictMixins';
+
   export default {
   export default {
     components: { search, permitAdd },
     components: { search, permitAdd },
+    mixins: [tabMixins, dictMixins],
     computed: {
     computed: {
       columns() {
       columns() {
         return [
         return [
@@ -86,35 +127,41 @@
             minWidth: 110
             minWidth: 110
           },
           },
           {
           {
-            prop: 'classifyName',
+            prop: 'classify',
             label: '记录规则分类',
             label: '记录规则分类',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
-            minWidth: 110
+            minWidth: 110,
+            formatter: (row) => {
+              return this.getDictValue('记录规则类型', row.classify);
+            }
           },
           },
           {
           {
-            prop: 'createName',
+            prop: 'version',
             label: '版本号',
             label: '版本号',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
-            minWidth: 110
+            minWidth: 110,
+            formatter: (row) => {
+              return row.version ? `V${row.version.toFixed(1)}` : '';
+            }
           },
           },
           {
           {
-            prop: '',
+            prop: 'fromName',
             label: '来源版本',
             label: '来源版本',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
             minWidth: 150
             minWidth: 150
           },
           },
           {
           {
-            prop: '',
+            prop: 'startDate',
             label: '启用日期',
             label: '启用日期',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
             minWidth: 110
             minWidth: 110
           },
           },
           {
           {
-            prop: '',
+            prop: 'stopDate',
             label: '停用日期',
             label: '停用日期',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
@@ -125,10 +172,15 @@
             label: '周期',
             label: '周期',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
-            minWidth: 110
+            formatter: (row) => {
+              return (
+                row.frequencyValue +
+                this.getDictValue('记录规则频率', row.frequencyUnit)
+              );
+            }
           },
           },
           {
           {
-            prop: '',
+            prop: 'createUserName',
             label: '创建人',
             label: '创建人',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
@@ -142,20 +194,32 @@
             minWidth: 110
             minWidth: 110
           },
           },
           {
           {
-            prop: '',
+            prop: 'enable',
             label: '是否启用',
             label: '是否启用',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
-            minWidth: 110
+            minWidth: 110,
+            formatter: (row) => {
+              return row.enable ? '启用' : '停用';
+            }
           },
           },
           {
           {
-            prop: 'enable',
+            prop: 'publishStatus',
             label: '状态',
             label: '状态',
             align: 'center',
             align: 'center',
             showOverflowTooltip: true,
             showOverflowTooltip: true,
             minWidth: 110,
             minWidth: 110,
             formatter: (row) => {
             formatter: (row) => {
-              return row.enable ? '生效' : '失效';
+              switch (row.publishStatus) {
+                case 0:
+                  return '草稿';
+                case 1:
+                  return '已发布';
+                case 2:
+                  return '已撤销';
+                default:
+                  return '';
+              }
             }
             }
           },
           },
           {
           {
@@ -174,18 +238,59 @@
         loading: false
         loading: false
       };
       };
     },
     },
+    created() {
+      this.requestDict('记录规则类型');
+      this.requestDict('记录规则频率');
+    },
     methods: {
     methods: {
       addPermit(row, type, title) {
       addPermit(row, type, title) {
         this.$refs.permitAddRef.open(row, type, title);
         this.$refs.permitAddRef.open(row, type, title);
       },
       },
-      remove(row) {},
+      async remove(row) {
+        try {
+          console.log('row', row);
+          await recordrulesDeletes([row.id]);
+          this.$message.success('删除成功');
+          this.reload();
+        } catch (error) {
+          this.$message.error('删除失败');
+        }
+      },
       /* 表格数据源 */
       /* 表格数据源 */
       datasource({ page, limit, where, order }) {
       datasource({ page, limit, where, order }) {
-        return getRulesList({ pageNum: page, size: limit, ...where });
+        return recordrulesPage({ pageNum: page, size: limit, ...where });
       },
       },
       /* 刷新表格 */
       /* 刷新表格 */
       reload(where) {
       reload(where) {
         this.$refs.table.reload({ page: 1, where });
         this.$refs.table.reload({ page: 1, where });
+      },
+      // 发布
+      async publish(row) {
+        // 判断时间
+        const startDate = new Date(row.startDate);
+        const stopDate = new Date(row.stopDate);
+
+        if (startDate >= stopDate) {
+          return this.$message.warning('请先修改规则停用时间!');
+        }
+
+        try {
+          await recordrulesPublish(row.id);
+          this.$message.success('发布成功');
+          this.reload();
+        } catch (error) {
+          this.$message.error('发布失败');
+        }
+      },
+      // 撤销
+      async recordrulesRevokePublish(row) {
+        try {
+          await recordrulesRevokePublish(row.id);
+          this.$message.success('撤销成功');
+          this.reload();
+        } catch (error) {
+          this.$message.error('撤销失败');
+        }
       }
       }
     }
     }
   };
   };

+ 4 - 1
vue.config.js

@@ -37,11 +37,14 @@ module.exports = {
         // target: 'http://192.168.1.176:18086',
         // target: 'http://192.168.1.176:18086',
 
 
         // target: 'http://192.168.1.251:18086',
         // target: 'http://192.168.1.251:18086',
-        target: 'http://192.168.1.125:18086',
+        // target: 'http://192.168.1.125:18086',
 
 
         // target: 'http://192.168.1.251:18186',
         // target: 'http://192.168.1.251:18186',
 
 
         // target: 'http://192.168.1.251:18087',
         // target: 'http://192.168.1.251:18087',
+
+        target: 'http://192.168.1.116:18086',
+
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
         pathRewrite: {
         pathRewrite: {
           '^/api': ''
           '^/api': ''