Bläddra i källkod

经销商设置价格

Jeffry Yu 7 år sedan
förälder
incheckning
a4200f4dfc
5 ändrade filer med 121 tillägg och 105 borttagningar
  1. 3 1
      Album/js/conf/data.js
  2. 14 2
      Album/js/draw/PriceModal.js
  3. 2 1
      Album/js/draw/base.js
  4. 88 96
      Album/js/main.js
  5. 14 5
      Album/js/util/drawText.js

+ 3 - 1
Album/js/conf/data.js

xqd
@@ -3,4 +3,6 @@ export const FLDbtnArea = []
 export const SLDArea = []
 export const DetailbtnArea = []
 export const ContentbtnArea = []
-export const setpriceArea = []
+export const setpriceArea = []
+export const SetPriceBtnArea = []
+export const SearchButtonArea = []

+ 14 - 2
Album/js/draw/PriceModal.js

xqd xqd
@@ -1,6 +1,7 @@
 import drawText from '../util/drawText.js'
 import drawImage from '../util/drawImage.js'
 import Modal from './Modal'
+import { SetPriceBtnArea } from '../conf/data.js'
 
 export default class PriceModal extends Modal {
   constructor(context, data) {
@@ -15,7 +16,18 @@ export default class PriceModal extends Modal {
     let startX = this.win_dimension.startX + 13;
     let startY = 160 + 76;
     drawText(this.data.name, startX + this.win_dimension.width / 2, startY + font_size * 3, 'center')
-    drawText((this.data.price || '0') + ' ¥', startX + this.win_dimension.width / 2, startY + font_size * 5, 'center')
-    drawImage('images/agent/btn_save@2x.png', startX + this.win_dimension.width / 2, 590 - font_size, 'center,bottom')
+    drawText((this.data.price || '0') + ' ¥', startX + this.win_dimension.width / 2, startY + font_size * 5, 'center').then((dimension) => {
+      this.price_dimension = SetPriceBtnArea[0] = {...dimension}
+    })
+    drawImage('images/agent/btn_save@2x.png', startX + this.win_dimension.width / 2, 590 - font_size * 2, 'center,bottom').then((dimension) => {
+      SetPriceBtnArea[1] = {...dimension}
+    })
+  }
+  updatePrice(price) {
+    this.context.fillStyle = '#fdedac'
+    this.context.fillRect(this.price_dimension.startX, this.price_dimension.startY, this.price_dimension.width, this.price_dimension.height)
+    drawText((price || '0') + ' ¥', this.price_dimension.startX, this.price_dimension.startY).then((dimension) => {
+      this.price_dimension = SetPriceBtnArea[0] = { ...dimension }
+    })
   }
 }

+ 2 - 1
Album/js/draw/base.js

xqd xqd
@@ -1,5 +1,5 @@
 import drawImage from '../util/drawImage.js'
-import { FLDsource, FLDbtnArea, SLDArea } from '../conf/data.js'
+import { FLDsource, FLDbtnArea, SLDArea, SearchButtonArea } from '../conf/data.js'
 import drawText from '../util/drawText.js';
 
 let header_height
@@ -24,6 +24,7 @@ function header(context) {
   }).then((dimension) => {
     return drawImage('images/homepage/bg_search@2x.png', dimension.endX + 100, header_height / 2, 'middle')
   }).then((dimension) => {
+    SearchButtonArea[0] = {...dimension}
     return drawImage('images/homepage/icon_search@2x.png', dimension.startX + 20, header_height / 2, 'middle')
   }).then((dimension) => {
     return drawImage('images/homepage/text_placeholder@2x.png', dimension.endX + 15, header_height / 2, 'middle')

+ 88 - 96
Album/js/main.js

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -44,8 +44,11 @@ import {
   DetailbtnArea,
   ContentbtnArea,
   SLDArea,
-  setpriceArea
+  setpriceArea,
+  SearchButtonArea,
+  SetPriceBtnArea
 } from './conf/data.js'
+import drawImage from './util/drawImage.js';
 //二级目录按钮区域
 let SLDbtnArea = []
 
@@ -55,13 +58,13 @@ let SA = []
 
 
 //搜索按钮
-let SearchButton = []
-//翻页按钮
 let pageArea = []
 //尺寸安装图片转换界面
 let attrArea = []
 
 let sp = []
+let priceModal
+
 
 GameGlobal.isiPhoneX = false
 let res = wx.getSystemInfoSync()
@@ -106,8 +109,6 @@ function init() {
   //详情界面按钮区域
   var DA = [{ startX: 0, startY: screenHeight - 50, endX: 50, endY: screenHeight }, { startX: screenWidth / 2 - 200, startY: screenHeight - 35, endX: screenWidth / 2 - 110, endY: screenHeight - 12 }, { startX: screenWidth / 2 - 100, startY: screenHeight - 35, endX: screenWidth / 2 - 10, endY: screenHeight - 12 }, { startX: screenWidth / 2, startY: screenHeight - 35, endX: screenWidth / 2 + 90, endY: screenHeight - 12 }, { startX: screenWidth / 2 + 100, startY: screenHeight - 35, endX: screenWidth / 2 + 190, endY: screenHeight - 12 }, { startX: 10, startY: screenHeight / 2 - 15, endX: 40, endY: screenHeight / 2 + 15 }, { startX: screenWidth - 40, startY: screenHeight / 2 - 15, endX: screenWidth - 10, endY: screenHeight / 2 + 15 }]
   //搜索按钮
-  SearchButton = [{ startX: 38, startY: 10, endX: 140, endY: 30 }, { startX: 150, startY: 10, endX: 200, endY: 30 }]
-  //翻页按钮
   pageArea = [{ startX: screenWidth - 50, startY: screenHeight - 30, endX: screenWidth, endY: screenHeight }, { startX: screenWidth - 50, startY: screenHeight - 65, endX: screenWidth, endY: screenHeight - 35 }]
   //尺寸安装图片转换界面
   attrArea = [{ startX: (screenWidth - (screenHeight - 100) * 1.778) / 2, startY: 30, endX: screenWidth / 2, endY: 60 }, { startX: screenWidth / 2, startY: 30, endX: (screenWidth + (screenHeight - 100) * 1.778) / 2 - 30, endY: 60 }, { startX: (screenWidth + (screenHeight - 100) * 1.778) / 2 - 30, startY: 30, endX: (screenWidth + (screenHeight - 100) * 1.778) / 2, endY: 60 }]
@@ -234,11 +235,7 @@ function reStart() {
         dt.showDetails(context, GoodsDetail.detail_pic, GoodsDetail.name, GoodsDetail.price)
       }
       else {
-        if (isiPhoneX) {
-          context.drawImage(img, 70, 0, screenWidth * 2, screenHeight * 2)
-        } else {
-          context.drawImage(img, 0, 0, screenWidth * 2, screenHeight * 2)
-        }
+        drawImage(GoodsDetail.detail_pic, 0, 0, screenWidth, screenHeight)
       }
 
     } catch (e) {
@@ -364,38 +361,38 @@ wx.onTouchStart(((e) => {
       getGoodsSource(callback3, SLDsource)
     }
     //翻页控制
-    if (x >= pageArea[0].startX
-      && x <= pageArea[0].endX
-      && y >= pageArea[0].startY
-      && y <= pageArea[0].endY) {
-      if (page == parseInt(GoodsSource.length / 9)) {
+    // if (x >= pageArea[0].startX
+    //   && x <= pageArea[0].endX
+    //   && y >= pageArea[0].startY
+    //   && y <= pageArea[0].endY) {
+    //   if (page == parseInt(GoodsSource.length / 9)) {
 
-      } else {
-        if (page < parseInt(GoodsSource.length / 9))//只有在当前页数小于实际页数的时候才能再往上+
-          page++//点击翻页时页数+1
-        console.log(page)
-        //getFLDsource(callback1, url)//重绘
-        reStart()
-      }
-    }
-    if (x >= pageArea[1].startX
-      && x <= pageArea[1].endX
-      && y >= pageArea[1].startY
-      && y <= pageArea[1].endY) {
-      if (page == 0) {
+    //   } else {
+    //     if (page < parseInt(GoodsSource.length / 9))//只有在当前页数小于实际页数的时候才能再往上+
+    //       page++//点击翻页时页数+1
+    //     console.log(page)
+    //     //getFLDsource(callback1, url)//重绘
+    //     reStart()
+    //   }
+    // }
+    // if (x >= pageArea[1].startX
+    //   && x <= pageArea[1].endX
+    //   && y >= pageArea[1].startY
+    //   && y <= pageArea[1].endY) {
+    //   if (page == 0) {
 
-      } else {
-        if (page > 0)
-          page--//点击翻页时页数-1
-        console.log(page)
-        reStart()
-      }
-    }
+    //   } else {
+    //     if (page > 0)
+    //       page--//点击翻页时页数-1
+    //     console.log(page)
+    //     reStart()
+    //   }
+    // }
     //搜索
-    if (x >= SearchButton[0].startX
-      && x <= SearchButton[0].endX
-      && y >= SearchButton[0].startY
-      && y <= SearchButton[0].endY) {
+    if (x >= SearchButtonArea[0].startX
+      && x <= SearchButtonArea[0].endX
+      && y >= SearchButtonArea[0].startY
+      && y <= SearchButtonArea[0].endY) {
       //清除目录控制状态 
       flag5 = -1
       for (let i in FLDbtnArea) {
@@ -412,55 +409,21 @@ wx.onTouchStart(((e) => {
           wx.onKeyboardConfirm(((res) => {
             KeyWord = res.value
             context.fillStyle = '#fff'
-            context.fillRect(76, 20, 220, 40)
+            context.fillRect(
+              SearchButtonArea[0].startX + font_size * 2,
+              SearchButtonArea[0].startY + 2,
+              SearchButtonArea[0].width - SearchButtonArea[0].startX - font_size * 2 - 10,
+              SearchButtonArea[0].height - 4)
             context.font = "26px Arial"
             context.fillStyle = '#696969'
             context.fillText(KeyWord, 90, 50)
             wx.hideKeyboard({})
-            wx.showToast({
-              title: '输入完成',
-              icon: 'success',
-              duration: 500
-            })
+            search(KeyWord)
           }))
         }
       })
       reStart()
     }
-    if (x >= SearchButton[1].startX
-      && x <= SearchButton[1].endX
-      && y >= SearchButton[1].startY
-      && y <= SearchButton[1].endY) {
-      if (KeyWord == '') {
-        //do nothing
-      } else {
-        wx.request({
-          url: 'https://t6.9026.com/api/album/search_goods',
-          data: {
-            store_id: 1,
-            keywords: KeyWord
-          },
-          method: 'GET',
-          success: function (res) {
-            try {
-              let test = JSON.stringify(res.data)
-              let tet = JSON.parse(test)
-              GoodsSource.splice(0, GoodsSource.length)//每次调用重新填充数据的时候清空之前数据
-              for (let i in tet.data.goods) {
-                GoodsSource.push(tet.data.goods[i])
-              }
-            } catch (e) {
-              wx.showToast({
-                title: '请求异常',
-                icon: 'none',
-                duration: 800
-              })
-            }
-            callback3(GoodsSource)//导出商品列表
-          }
-        })
-      }
-    }
     if (isAgent == true) {
       // if (x >= SLDArea[3].startX
       //   && x <= SLDArea[3].endX
@@ -481,6 +444,7 @@ wx.onTouchStart(((e) => {
       //   context.fillStyle = '#fff'
       //   context.fillText('确定', screenWidth - 30, screenHeight + 110)
       // }
+      // 首页报价按钮
       if (x >= SLDArea[4].startX
         && x <= SLDArea[4].endX
         && y >= SLDArea[4].startY
@@ -511,7 +475,7 @@ wx.onTouchStart(((e) => {
     }
     if (setprice == false) {
       if (setMobile == false) {
-        //内容点击进入详情控制
+        //内容点击进入产品详情控制
         for (let con in ContentbtnArea) {
           if (x >= ContentbtnArea[con].startX
             && x <= ContentbtnArea[con].endX
@@ -533,6 +497,7 @@ wx.onTouchStart(((e) => {
     } else {
       if (setMobile == false) {
         if (setClick == false) {
+          // 经销商报价按钮
           for (let con in setpriceArea) {
             if (x >= setpriceArea[con].startX
               && x <= setpriceArea[con].endX
@@ -542,15 +507,18 @@ wx.onTouchStart(((e) => {
               console.log('报价' + con)
               con = parseInt(con)
               flag4 = (page * 9) + con
-              new PriceModal(context, GoodsSource[flag4]).draw()
+              priceModal = new PriceModal(context, GoodsSource[flag4])
+              priceModal.draw()
             }
           }
         }
+        // 报价弹窗
         if (setClick == true) {
-          if (x >= sp[0].startX
-            && x <= sp[0].endX
-            && y >= sp[0].startY
-            && y <= sp[0].endY) {
+          // 点击价格,弹出键盘
+          if (x >= SetPriceBtnArea[0].startX
+            && x <= SetPriceBtnArea[0].endX
+            && y >= SetPriceBtnArea[0].startY
+            && y <= SetPriceBtnArea[0].endY) {
             wx.showKeyboard({
               defaultValue: '',
               maxLength: 8,
@@ -560,21 +528,17 @@ wx.onTouchStart(((e) => {
               success: function () {
                 wx.onKeyboardConfirm(((res) => {
                   pricein = res.value
-                  context.fillStyle = '#f8f8f8'
-                  context.fillRect((screenWidth / 2 - 150) * 2, screenHeight - 70, 600, 70)
-                  context.font = '32px Arial'
-                  context.fillStyle = '#DCDCDC'
-                  console.log('设置价格执行')
-                  context.fillText(pricein, (screenWidth / 2 - 130) * 2, screenHeight)
+                  priceModal.updatePrice(pricein)
                   wx.hideKeyboard({})
                 }))
               }
             })
           }
-          if (x >= sp[1].startX
-            && x <= sp[1].endX
-            && y >= sp[1].startY
-            && y <= sp[1].endY) {
+          // 保存价格
+          if (x >= SetPriceBtnArea[1].startX
+            && x <= SetPriceBtnArea[1].endX
+            && y >= SetPriceBtnArea[1].startY
+            && y <= SetPriceBtnArea[1].endY) {
             setClick = false
             console.log('setSuccess')
             let turl = 'https://t6.9026.com/api/album/set-price'
@@ -601,6 +565,7 @@ wx.onTouchStart(((e) => {
         }
       }
     }
+    // 设置电话弹窗
     if (setMobile == false) {
     } else {
       if (x >= sp[0].startX
@@ -1097,7 +1062,7 @@ function UserLogin() {
                 getFLDsource(callback1, url)
               }
               else {
-                isAgent = false
+                isAgent = true
                 var test = wx.getLaunchOptionsSync()
                 console.log(test)
                 agent_id = test.query.agent_id
@@ -1114,6 +1079,33 @@ function UserLogin() {
     }
   })
 }
+function search(KeyWord) {
+  wx.request({
+    url: 'https://t6.9026.com/api/album/search_goods',
+    data: {
+      store_id: 1,
+      keywords: KeyWord
+    },
+    method: 'GET',
+    success: function (res) {
+      try {
+        let test = JSON.stringify(res.data)
+        let tet = JSON.parse(test)
+        GoodsSource.splice(0, GoodsSource.length)//每次调用重新填充数据的时候清空之前数据
+        for (let i in tet.data.goods) {
+          GoodsSource.push(tet.data.goods[i])
+        }
+      } catch (e) {
+        wx.showToast({
+          title: '请求异常',
+          icon: 'none',
+          duration: 800
+        })
+      }
+      callback3(GoodsSource)//导出商品列表
+    }
+  })
+}
 function sleep(time) {
   return new Promise((resolve) => setTimeout(resolve, time));
 }

+ 14 - 5
Album/js/util/drawText.js

xqd
@@ -2,29 +2,38 @@ let ctx = canvas.getContext('2d')
 
 export default function drawText(text, x, y, align='left top', font_size = 28, color = '#000') {
     return new Promise(function(resolve, reject) {
+        let r_x
+        let r_y
+        let { width } = ctx.measureText(text)
+
         if (align.indexOf('center') > -1) {
             ctx.textAlign = 'center';
+            r_x = x - width / 2
         } else if (align.indexOf('right') > -1) {
             ctx.textAlign = 'end';
+            r_x = x - width
         } else {
             ctx.textAlign = 'start';
+            r_x = x
         }
         if (align.indexOf('middle') > -1) {
             ctx.textBaseline = 'middle';
+            r_y = y - font_size / 2
         } else if (align.indexOf('bottom') > -1) {
             ctx.textBaseline = 'bottom';
+            r_y = y - font_size
         } else {
             ctx.textBaseline = 'top';
+            r_y = y
         } 
         ctx.font = font_size + "px Arial"
         ctx.fillStyle = color
         ctx.fillText(text, x, y)
-        let {width} = ctx.measureText(text)
         resolve({
-            startX: x,
-            startY: y,
-            endX: x + width,
-            endY: y + font_size,
+            startX: r_x,
+            startY: r_y,
+            endX: r_x + width,
+            endY: r_y + font_size,
             width: width,
             height: font_size
         })