123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- const {
- default: api
- } = require("../../js/api");
- const utils = require('../../utils/util');
- Page({
-
- data: {
- nozzleId: '',
- nozzleInfo: null,
- quantify: '元',
- fastInputs: [10, 20, 50, 100, 200, 500],
- type: [{
- name: '金额',
- checked: true
- },
- {
- name: '升数',
- checked: false
- }
- ],
- inputValue: '',
- inputTip: '请输入金额',
- amount: '',
- latitude: 0,
- longitude: 0,
- stationLatitude: 0,
- stationLongitude: 0,
- },
-
- onLoad(options) {
- const link = decodeURIComponent(options.q)
- var id = link.split('yuwxapp?id=')[1];
- if (id == undefined) {
- id = options.id;
- }
- this.setData({
- nozzleId: id
- })
- wx.showToast({
- title: id,
- })
- },
-
- getStationData() {
- console.log("获取站点")
- api.request_GetSiteInfo().then(res => {
- if (res.data.statusCode == 203) {
-
- setTimeout(() => {
- wx.navigateTo({
- url: '../login/login'
- })
- }, 500)
- return
- }
- console.log("站点信息", res)
- const stationLocation = res.data.data.site.gpsCoordinates.split(",");
- if (stationLocation.length == 2) {
- this.setData({
- stationLatitude: stationLocation[0],
- stationLongitude: stationLocation[1]
- })
- }
- this.getLocation();
- })
- },
-
- getLocation() {
- const that = this;
- wx.getLocation({
- type: 'wgs84',
- success(res) {
- console.log("获取经纬度结果", res)
- that.setData({
- latitude: res.latitude,
- longitude: res.longitude
- })
- }
- })
- this.getNozzleInfo();
- },
-
- getNozzleInfo() {
- const that = this;
- api.request_GetNozzleInfo(this.data.nozzleId).then(res => {
- console.log("获取油枪信息", res)
- if (res.data.content.length != 0) {
- var nozzle = res.data.content[0];
- nozzle.productPrice = utils.formatDiNumber(nozzle.productPrice);
- that.setData({
- nozzleInfo: nozzle
- })
- }
- })
- },
-
- onInputChange(event) {
- console.log("输入框变化", event)
- this.setData({
- inputValue: event.detail.value
- })
- },
-
- onFastInputClick(event) {
- console.log("点击", event)
- const amount = event.currentTarget.dataset.id;
- this.setData({
- inputValue: amount
- });
- },
-
- toAuthorization() {
- console.log(this.data)
-
-
-
-
-
-
-
- this.createOrder()
- },
-
- createOrder() {
- const nozzle = this.data.nozzleInfo;
- const value = this.data.inputValue;
- console.log("要授权的油枪信息", nozzle, value)
- if(value <= 0){
- wx.showToast({
- title: '定量值非法',
- })
- return
- }
- var requestData = null
- if (this.data.quantify == '元') {
- requestData = {
- externalGunNumber: nozzle.externalGunNumber,
- originalAmount: value,
- product: nozzle.productName,
- price: parseFloat(nozzle.productPrice),
- transactionNumber: ''
- };
- } else {
- requestData = {
- externalGunNumber: nozzle.externalGunNumber,
- qty: value,
- product: nozzle.productName,
- price: nozzle.productPrice,
- transactionNumber: ''
- };
- }
- api.request_createOrder(requestData).then(res => {
- console.log("创建订单", res)
- if (res.data.statusCode != 200) {
- wx.showToast({
- icon: "none",
- title: res.data.message == undefined ? res.data.notification : res.data.message,
- })
- return
- }
- utils.subAndsendMessage(res.data.data.id, "下单").then(response => {
- this.toPayPage(res)
- }).catch(err => {
- this.toPayPage(res)
- });
- })
- },
- toPayPage(res) {
- const order = res.data.data;
- const time = utils.formatDateNotSecond(order.createTime)
- setTimeout(() => {
- wx.navigateTo({
- url: '../AuthorizationTransactionPage/AuthorizationTransactionPage?nozzleId=' + this.data.nozzleId,
- success: function (res) {
- res.eventChannel.emit('acceptDataFromQuantify', {
- oilName: order.productName,
- nozzle: order.nozzleId,
- volume: order.qty,
- amount: order.originalAmount,
- payAmount: order.actualPaymentAmount,
- discount: order.originalAmount - order.actualPaymentAmount,
- orderId: order.id,
- time: time
- })
- }
- })
- }, 500)
- },
-
- onReady() {
- },
-
- onShow() {
- console.log("页面显示")
- this.getStationData();
- },
-
- onHide() {
- },
-
- onUnload() {
- },
-
- onPullDownRefresh() {
- },
-
- onReachBottom() {
- },
-
- onShareAppMessage() {
- },
-
- onTypeChange(event) {
- var type = event.detail.value;
- if (type == '升数') {
- this.setData({
- quantify: '升',
- inputTip: '请输入升数'
- });
- } else {
- this.setData({
- quantify: '元',
- inputTip: '请输入金额'
- });
- }
- }
- })
|