刘浩男 1 tahun lalu
induk
melakukan
81bed527db

+ 28 - 12
api/quotations/quotations.js

@@ -1,20 +1,36 @@
 import request from '@/utils/request'
 
 // 查询行情列表
-export  function listQuotations(query) {
-  return request({
-    url: '/quotations/list',
-    method: 'get',
-    params: query
-  })
+export function listQuotations(query) {
+    return request({
+        url: '/quotations/list',
+        method: 'get',
+        params: query
+    })
 }
+
 // 查询行情配置列表
 export function listConfig(query) {
-  return request({
-    url: '/quotationsConfig/all',
-    method: 'get',
-    params: query
-  })
-
+    return request({
+        url: '/quotationsConfig/all',
+        method: 'get',
+        params: query
+    })
+}
+//新增列表
+export function addQuotations(data) {
+    return request({
+        url: '/quotations',
+        method: 'post',
+        data: data
+    })
+}
 
+//查询行情配置子级
+export function QuotationsList(data) {
+    return request({
+        url: '/quotationsConfig/list',
+        method: 'get',
+        data: data
+    })
 }

+ 20 - 3
pages.json

@@ -168,10 +168,27 @@
 				"navigationBarBackgroundColor": "#07c160",
 				"navigationBarTextStyle": "white",
 				"navigationBarTitleText": "行情"
-
-
 			}
-		},{
+		},
+		{
+			"path": "pages/quotations/quotationsForm",
+			"style": {
+				"usingComponents": {},
+				"navigationBarBackgroundColor": "#07c160",
+				"navigationBarTextStyle": "white",
+				"navigationBarTitleText": "新增行情列表"
+			}
+		},
+		{
+			"path": "pages/quotations/quotationsSecond",
+			"style": {
+				"usingComponents": {},
+				"navigationBarBackgroundColor": "#07c160",
+				"navigationBarTextStyle": "white",
+				"navigationBarTitleText": "行情"
+			}
+		},
+		{
 			"path": "pages/toGovernmentList/toGovernmentList",
 			"style": {
 				"usingComponents": {},

+ 20 - 44
pages/quotations/quotations.vue

@@ -32,49 +32,28 @@
           </uni-td>
         </uni-tr>
       </uni-table>
-      <uni-fab ref="fab"  :horizontal="right" :vertical="bottom"
-                 @fabClick="fabClick('bottom')"/>
+      <uni-fab ref="fab" :horizontal="right" :vertical="bottom"
+               @fabClick="fabClick()"/>
     </view>
-    <uni-popup ref="popup" background-color="#fff" @change="popup">
-    <view class="example">
-      <!-- 基础用法,不包含校验规则 -->
-      <uni-forms ref="baseForm" :modelValue="form" >
-        <uni-forms-item label="产品名称" required>
-          <uni-easyinput v-model="form.productName" placeholder="请输入产品名称" />
-        </uni-forms-item>
-        <uni-forms-item label="地区" required>
-          <uni-easyinput v-model="form.area" placeholder="请输入地区" />
-        </uni-forms-item>
-        <uni-forms-item label="价格" required>
-          <uni-easyinput v-model="form.price" placeholder="请输入价格" />
-        </uni-forms-item>
-        <uni-forms-item label="地址" required>
-          <uni-easyinput v-model="form.address" placeholder="请输入地址" />
-        </uni-forms-item>
-        <uni-forms-item label="手机号" required>
-          <uni-easyinput v-model="form.phone" placeholder="请输入手机号" />
-        </uni-forms-item>
-        <uni-forms-item label="图片" required>
-        <upload :imgArr="imageList" :fileSize="1" :limit="3" @updateImg="updateImg"></upload>
-        </uni-forms-item>
-      </uni-forms>
-    </view>
-    </uni-popup>
   </view>
 </template>
 
 <script>
 import {listConfig, listQuotations} from "@/api/quotations/quotations";
+import upload from '../../components/upload/index.vue'
 
 export default {
+  components: {
+    upload
+  },
   data() {
     return {
       //是否显示弹出层
       open: false,
       //悬浮按钮右对齐
-      right:'right',
+      right: 'right',
       //悬浮按钮下对齐
-      bottom:'bottom',
+      bottom: 'bottom',
       //分类列表
       categories: [
         // 这里是一级分类的数据
@@ -90,8 +69,8 @@ export default {
         id: null,
       },
       //表单数据
-      form:{},
-      imageList:[]
+      form: {},
+      imageList: []
     }
   },
   created() {
@@ -114,23 +93,20 @@ export default {
     },
     //根据分类id查询列表
     change(e) {
-      this.queryParams.type = e.detail.index;
-      listQuotations(this.queryParams).then(response => {
-        this.quotationsList = response.rows.map(item => {
-          let date = new Date(item.createTime);
-          item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
-          return item;
-        });
+      console.log(e)
+      const type = e.detail.index;
+      uni.navigateTo({
+        url: `../quotations/quotationsSecond?type=${type}`
       });
     },
     //悬浮按钮点击事件
-    fabClick(type){
-      this.type = type
-      // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
-      this.$refs.popup.open(type)
+    fabClick() {
+      uni.navigateTo({
+        url: '../quotations/quotationsForm'
+      });
     },
-    popup(){
-
+    updateImg(imgList) {
+      this.imageList = imgList;
     }
 
   }

+ 189 - 0
pages/quotations/quotationsForm.vue

@@ -0,0 +1,189 @@
+<template>
+  <uni-section title="自定义校验规则" type="line">
+    <view class="example">
+      <!-- 自定义表单校验 -->
+      <uni-forms ref="customForm" :rules="rules" :modelValue="customFormData" label-align="center">
+        <uni-forms-item label="产品名称" required name="productName" label-width="85" label-align="center">
+          <uni-easyinput v-model="customFormData.productName" placeholder="请输入产品名称" />
+        </uni-forms-item>
+        <uni-forms-item label="地区" required name="area" >
+          <uni-easyinput v-model="customFormData.area" placeholder="请输入地区" />
+        </uni-forms-item>
+        <uni-forms-item label="价格" required name="price" >
+          <uni-easyinput v-model="customFormData.price" placeholder="请输入价格" />
+        </uni-forms-item>
+        <uni-forms-item label="手机号" required name="phone" >
+          <uni-easyinput v-model="customFormData.phone" placeholder="请输入手机号" />
+        </uni-forms-item>
+        <uni-forms-item label="地址" required name="address">
+          <uni-easyinput v-model="customFormData.address" placeholder="请输入地址" />
+        </uni-forms-item>
+        <uni-forms-item label="类型" required name="type" >
+          <uni-data-picker placeholder="请选择分类" popup-title="请选择所属分类" :localdata="TreeData" v-model="customFormData.type"/>
+        </uni-forms-item>
+        <uni-forms-item label="图片" required name="url" label-width="85">
+          <upload :imgArr="imageList" :fileSize="1" :limit="3" @updateImg="updateImg"/>
+        </uni-forms-item>
+      </uni-forms>
+      <button type="primary" @click="submit('customForm')">提交</button>
+    </view>
+  </uni-section>
+</template>
+
+<script>
+import {listConfig,addQuotations} from "@/api/quotations/quotations";
+import upload from '../../components/upload/index.vue'
+export default {
+  components: {
+    upload
+  },
+  data() {
+    return {
+      // 基础表单数据
+      baseFormData: {
+        productName: '',
+        area:'',
+        price:'',
+        phone:'',
+        address:'',
+        type:'',
+        url:[]
+      },
+      //树数据
+      TreeData:[],
+      // 校验规则
+      rules: {
+        productName: {
+          rules: [{
+            required: true,
+            errorMessage: '产品名称不能为空'
+          }]
+        },
+        area: {
+          rules: [{
+            required: true,
+            errorMessage: '地区不能为空'
+          }]
+        },
+        phone: {
+          rules: [{
+            required: true,
+            errorMessage: '年龄不能为空'
+          }, {
+            validateFunction: function(rule, value, data, callback) {
+              const reg = /^1[3-9]\.\d{9}$/;
+              if (!reg.test(value)) {
+                callback('请输入正确的手机号码');
+              }
+              return true;
+            }
+          }]
+        },
+        address: {
+          rules: [{
+            required: true,
+            errorMessage: '地址不能为空'
+          }]
+        },
+        type: {
+          rules: [{
+            required: true,
+            errorMessage: '分类不能为空'
+          }]
+        },
+        imgUrlList: {
+          rules: [{
+            required: true,
+            errorMessage: '图片不能为空'
+          }]
+        },
+        price: {
+          rules: [{
+            required: true,
+            errorMessage: '年龄不能为空'
+          }, {
+            format: 'number',
+            errorMessage: '年龄只能输入数字'
+          }]
+        }
+      },
+      imageList: [],
+      customFormData:{}
+    }
+  },
+  onLoad() {},
+  onReady() {
+    // 设置自定义表单校验规则,必须在节点渲染完毕后执行
+    this.$refs.customForm.setRules(this.rules)
+  },
+  created() {
+    this.getType();
+  },
+  methods: {
+    getType(){
+      listConfig().then(response => {
+        this.TreeData = this.formatOptions(response.data.quotations);
+      });
+    },
+    //转换为下拉选列表
+    formatOptions(data) {
+      return data.map(item => ({
+        value: item.id,
+        text: item.productName,
+        children: item.children ? this.formatOptions(item.children) : null,
+      }));
+    },
+    submit(ref) {
+      this.$refs[ref].validate().then(res => {
+        if (res) {
+          this.customFormData.url = this.imageList.join(',')
+          addQuotations(this.customFormData).then(response => {
+            this.$modal.msgSuccess('提交成功');
+            this.customFormData = {...this.baseFormData};
+            this.imageList = [];
+            uni.navigateTo({
+              url: '../quotations/quotations'
+            });
+          }).catch(err => {
+            console.log('err', err);
+          })
+        }
+      })
+    },
+    updateImg(imgList) {
+      this.imageList = imgList;
+    }
+  }
+}
+</script>
+
+<style lang="scss">
+
+.example {
+  padding: 15px;
+  background-color: #fff;
+}
+
+.segmented-control {
+  margin-bottom: 15px;
+}
+
+.button-group {
+  margin-top: 15px;
+  display: flex;
+  justify-content: space-around;
+}
+
+.form-item {
+  display: flex;
+  align-items: center;
+}
+
+.button {
+  display: flex;
+  align-items: center;
+  height: 35px;
+  margin-left: 10px;
+}
+</style>
+

+ 148 - 0
pages/quotations/quotationsSecond.vue

@@ -0,0 +1,148 @@
+<template>
+  <view>
+    <view>
+      <scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120">
+        <uni-grid :column="5" @change="change" showBorder="false" square="false">
+          <uni-grid-item v-for="item in categories" :index="item.id">
+            <view class="grid-item-box">
+              <image class="image" :src="loadImgSrc(item.icon)" mode="aspectFit"></image>
+              <text class="text">{{ item.productName }}</text>
+            </view>
+          </uni-grid-item>
+        </uni-grid>
+      </scroll-view>
+    </view>
+    <view class="uni-container">
+      <uni-table>
+        <uni-tr>
+          <uni-th width="80" align="center">名称</uni-th>
+          <uni-th width="80" align="center">类型</uni-th>
+          <uni-th width="80" align="center">价格</uni-th>
+          <uni-th width="100" align="center">时间</uni-th>
+        </uni-tr>
+        <uni-tr v-for="(item, index) in quotationsList" :key="index">
+          <uni-td align="center">{{ item.productName }}
+          </uni-td>
+          <uni-td align="center">
+            <view class="name">{{ item.type }}</view>
+          </uni-td>
+          <uni-td align="center">{{ item.price }}
+          </uni-td>
+          <uni-td align="center">{{ item.createTime }}
+          </uni-td>
+        </uni-tr>
+      </uni-table>
+      <uni-fab ref="fab" :horizontal="right" :vertical="bottom"
+               @fabClick="fabClick()"/>
+    </view>
+  </view>
+</template>
+
+<script>
+import {listConfig,QuotationsList, listQuotations} from "@/api/quotations/quotations";
+import upload from '../../components/upload/index.vue'
+
+export default {
+  components: {
+    upload
+  },
+  data() {
+    return {
+      //父组件传值
+      FatherType: '',
+      //是否显示弹出层
+      open: false,
+      //悬浮按钮右对齐
+      right: 'right',
+      //悬浮按钮下对齐
+      bottom: 'bottom',
+      //分类列表
+      categories: [
+        // 这里是一级分类的数据
+      ],
+      // 行情列表
+      quotationsList: [
+        // 这里是列表的数据
+      ],
+      //查询参数
+      queryParams: {
+        // pageNum: 1,
+        // pageSize: 10,
+        id: null,
+      },
+      //表单数据
+      form: {},
+      //分类树列表
+      forms:{},
+      imageList: []
+    }
+  },
+  onLoad(e) {
+    this.FatherType = e.type;
+    this.getList();
+  },
+  methods: {
+    getList(row) {
+      // 这里是获取列表的方法
+      this.form.type = this.FatherType
+      listQuotations(this.form).then(response => {
+        this.quotationsList = response.rows.map(item => {
+          let date = new Date(item.createTime);
+          item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
+          return item;
+        });
+      });
+      this.forms.parentId = this.FatherType
+      //获取分类树的方法
+      QuotationsList(this.forms).then(response => {
+        //取出response.rows中所有homeDisplay为1的数据
+        this.categories = response.rows.filter(item => item.homeDisplay === 1);
+      });
+    },
+    //递归查询分类的父级
+
+    //根据分类id查询列表
+    change(e) {
+      this.queryParams.type = e.detail.index;
+      listQuotations(this.queryParams).then(response => {
+        this.quotationsList = response.rows.map(item => {
+          let date = new Date(item.createTime);
+          item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
+          return item;
+        });
+      });
+    },
+    //悬浮按钮点击事件
+    fabClick() {
+      uni.navigateTo({
+        url: '../quotations/quotationsForm'
+      });
+    },
+    updateImg(imgList) {
+      this.imageList = imgList;
+    }
+
+  }
+}
+</script>
+
+<style>
+.grid-item-box {
+  flex: 1;
+// position: relative;
+  /* #ifndef APP-NVUE */
+  display: flex;
+  /* #endif */
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  padding: 0px 0;
+}
+
+.image {
+  height: 100%;
+  width: 100%;
+}
+
+
+</style>