123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- const utilMd5 = require('../../../utils/md5.js')
- const app = getApp()
- Page({
- data: {
- xa_consignee: '',
- xa_city: '',
- et_type: '',
- xa_county: '',
- xa_address: '',
- xa_phone: '',
- startdate: '',
- enddate: '',
- et_url: '',
- et_rent: '',
- et_mortagage: '',
- et_name: '',
- rent: '',
- discount: 0,
- num: 30,
- total: '',
- minusStatus: 'disabled' ,
- userInfo: {},
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo')
- },
- hrefAddress: function(e) {
- if (this.data.xa_consignee == null || this.data.xa_consignee == ''){
- wx.navigateTo({
- url: '/pages/mine/myaddress/createaddress/createaddress?type=bill'
- })
- } else {
- wx.navigateTo({
- url: '/pages/mine/myaddress/myaddress?type=bill'
- })
- }
- },
- //事件处理函数
- bindViewTap: function() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
- onLoad: function (options) {
- var that = this
- wx.request({
- url: app.globalData.url + '/getEqUserAddress',
- method: 'get',
- data: {
- xu_openid: app.globalData.openid
- },
- success: function (res) {
- if (res.data.length != 0) {
- that.setData({
- xa_consignee: res.data.xa_consignee,
- xa_city: res.data.xa_city,
- xa_county: res.data.xa_county,
- xa_address: res.data.xa_address,
- xa_phone: res.data.xa_phone
- })
- }
- },
- fail() {
- app.timeOut()
- }
- })
- this.setData ({
- et_type: options.para
- })
- var date = new Date();
- var date2 = new Date(date);
- date2 = +date2 + 1000 * 60 * 60 * 24 * 30;
- date2 = new Date(date2);
- var seperator1 = "-";
- var year = date.getFullYear();
- var month = ("0" + (date.getMonth() + 1)).slice(-2);
- var strDate = ("0" + (date.getDate())).slice(-2);
- var year2 = date2.getFullYear();
- var month2 = ("0" + (date2.getMonth() + 1)).slice(-2);
- var strDate2 = ("0" + (date2.getDate())).slice(-2);
- this.setData({
- startdate: year + seperator1 + month + seperator1 + strDate,
- enddate: year2 + seperator1 + month2 + seperator1 + strDate2
- })
-
- var that = this
- wx.request({
- url: app.globalData.url +'/getEquipmentAmount',
- data: {
- et_type: this.data.et_type
- },
- method: 'get',
- success: function (res) {
- that.setData({
- et_url: res.data.et_url,
- et_rent: res.data.et_rent.toFixed(2),
- et_mortagage: res.data.et_mortagage.toFixed(2),
- et_name: res.data.et_name,
- rent: (res.data.et_rent * 30).toFixed(2),
- total: (res.data.et_rent * 30 + res.data.et_mortagage).toFixed(2)
- })
- },
- fail() {
- app.timeOut()
- }
- });
- let _this = this;
- _this.setData({
- navH: app.globalData.navHeight
- })
- },
- getUserInfo: function(e) {
- app.globalData.userInfo = e.detail.userInfo
- this.setData({
- userInfo: e.detail.userInfo,
- hasUserInfo: true
- })
- },
- bindDateChange: function (e) {
- var endDate = new Date(e.detail.value);
- endDate = +endDate + 1000 * 60 * 60 * 24 * 30;
- endDate = new Date(endDate);
- this.setData({
- startdate: e.detail.value,
- enddate: endDate.getFullYear() + "-" + ("0" + ((endDate.getMonth() + 1))).slice(-2) + "-" + ("0" + (endDate.getDate())).slice(-2)
- })
- this.compute();
- },
- bindMinus: function () {
- var num = this.data.num;
- // 如果大于1时,才可以减
- if (num > 30) {
- num--;
- }
- // 只有大于一件的时候,才能normal状态,否则disable状态
- var minusStatus = num <= 30 ? 'disabled' : 'normal';
- // 将数值与状态写回
- this.setData({
- num: num,
- minusStatus: minusStatus
- });
- this.compute();
- },
- /* 点击加号 */
- bindPlus: function () {
- var num = this.data.num;
- // 不作过多考虑自增1
- num++;
- // 只有大于一件的时候,才能normal状态,否则disable状态
- var minusStatus = num < 30 ? 'disabled' : 'normal';
- // 将数值与状态写回
- this.setData({
- num: num,
- minusStatus: minusStatus
- });
- this.compute();
- },
- /* 输入框事件 */
- bindManual: function (e) {
- var num = e.detail.value;
- // 将数值与状态写回
- this.setData({
- num: num
- });
- this.compute();
- },
- compute: function() {
- if(this.data.num <= 30) {
- var startDate = new Date(this.data.startdate);
- startDate = +startDate + 1000 * 60 * 60 * 24 * 30;
- startDate = new Date(startDate);
- var temp_rent = Number(30 * this.data.et_rent)
- var temp_total = Number(temp_rent) + Number(this.data.et_mortagage)
- this.setData({
- enddate: startDate.getFullYear() + "-" + ("0" + (startDate.getMonth() + 1)).slice(-2) + "-" + ("0" + (startDate.getDate())).slice(-2),
- num: 30,
- rent: temp_rent.toFixed(2),
- total: temp_total.toFixed(2)
- })
- } else {
- var startDate = new Date(this.data.startdate);
- startDate = +startDate + 1000 * 60 * 60 * 24 * this.data.num;
- startDate = new Date(startDate);
- var temp_rent = Number(this.data.num * this.data.et_rent)
- var temp_total = Number(temp_rent) + Number(this.data.et_mortagage)
- this.setData({
- enddate: startDate.getFullYear() + "-" + ("0" + (startDate.getMonth() + 1)).slice(-2) + "-" + ("0" + (startDate.getDate())).slice(-2),
- rent: temp_rent.toFixed(2),
- total: temp_total.toFixed(2)
- })
- }
- },
- orderSign: function(e){
- //验证输入
- if (this.data.xa_consignee == null || this.data.xa_consignee == '') {
- wx.showToast({
- title: '请选择您的收货地址!',
- icon: 'none',
- duration: 1500
- })
- return false;
- }
- if (this.data.total == null || this.data.total == '') {
- wx.showToast({
- title: '没有合计金额!',
- icon: 'none',
- duration: 1500
- })
- return false;
- }
- //生成订单号
- var date = new Date();
- var year = date.getFullYear();
- var month = ("0" + (date.getMonth() + 1)).slice(-2);;
- var strDate = ("0" + (date.getDate())).slice(-2);
- var hours = ("0" + (date.getHours())).slice(-2);
- var minutes = ("0" + (date.getMinutes())).slice(-2);
- var seconds = ("0" + (date.getSeconds())).slice(-2);
- var rnd = "";
- for (var i = 0; i < 4; i++){
- rnd += Math.floor(Math.random() * 10);
- }
- //head
- var orderno = 'YS' + year + month + strDate + this.data.xa_phone.substring(this.data.xa_phone.length - 4, this.data.xa_phone.length) + rnd;
- var eh_mortagage = Number(this.data.et_mortagage)
- var eh_rental = Number(this.data.rent)
- var eh_cmname = app.globalData.nickName
- var eh_cmphone = app.globalData.userphone
- var eh_cmidcard = app.globalData.openid
- var eh_cmaddress = this.data.xa_consignee + ',' + this.data.xa_phone + ',' + this.data.xa_city + this.data.xa_county + this.data.xa_address
- var eh_usercode = 'onLine'
- var eh_date = year + '-' + month + '-' + strDate
- var eh_time = year + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds;
- var eh_status = '1'
- var eh_source = '1'
- var total = Number(this.data.total)
- var cp_discount = Number(this.data.discount)
- //detail
- var et_type = this.data.et_type
- var ed_startdate = this.data.startdate
- var ed_enddate = this.data.enddate
- // 支付test
- // this.setData({
- // total: 0.01
- // })
- //获取支付参数
- var that = this
- wx.request({
- url: app.globalData.payurl,
- method: 'post',
- data: {
- orderNo: orderno,
- channel: "wx_mini_ys",
- price: this.data.total,
- originPrice: (Number(this.data.et_mortagage) + Number(this.data.rent)).toFixed(2),
- openId: app.globalData.openid,
- title: this.data.et_name +"*1",
- productName: this.data.et_name,
- productId: this.data.et_type
- },
- success: function (res) {
- that.addEquipmenteHireHeadOnline(orderno, eh_mortagage, eh_rental, eh_cmname, eh_cmphone, eh_cmidcard, eh_cmaddress, eh_usercode, eh_date, eh_status, eh_source, that.data.total, cp_discount)
- that.addEquipmenteHireDetail(orderno, et_type, ed_startdate, ed_enddate)
- // 调用支付接口
- var timeStamp = String(parseInt(new Date().getTime() / 1000));
- var nonceStr = that.randomString();
- var newpaySign = "appId=" + res.data.body.appId + "&nonceStr=" + nonceStr + "&package=" + res.data.body.package + "&signType=MD5" + "&timeStamp=" + timeStamp + "&key=" + app.globalData.key;
- var paySign = utilMd5.hexMD5(newpaySign).toUpperCase();
- wx.requestPayment(
- {
- 'timeStamp': timeStamp,
- 'nonceStr': nonceStr,
- 'package': res.data.body.package,
- 'signType': 'MD5',
- 'paySign': paySign,
- 'success': function (res) {
- //发送消息
- wx.showToast({
- title: '付款成功!',
- icon: 'none',
- duration: 1500
- })
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1];
- var prevPage = pages[pages.length - 2];
- wx.navigateBack({
- delta: 1
- })
- wx.request({
- url: app.globalData.url + '/updateEquipmenteHireHeadOnline',
- method: 'post',
- header: { "Content-Type": "application/x-www-form-urlencoded" },
- data: {
- eh_code: orderno,
- eh_mortagage: eh_mortagage,
- eh_rental: eh_rental,
- eh_cmname: eh_cmname,
- eh_cmphone: eh_cmphone,
- eh_cmidcard: eh_cmidcard,
- eh_cmaddress: eh_cmaddress,
- eh_usercode: eh_usercode,
- eh_date: eh_date,
- eh_status: eh_status,
- eh_source: eh_source,
- total: that.data.total,
- cp_discount: cp_discount
- },
- success: function (res) {
- wx.hideLoading()
- wx.showToast({
- title: '租赁成功!',
- icon: 'success',
- duration: 1500
- })
- wx.request({
- url: app.globalData.url + '/insertEqCustomerBooking',
- method: 'post',
- header: { "Content-Type": "application/x-www-form-urlencoded" },
- data: {
- bk_phone: app.globalData.userphone,
- bk_date: year + '-' + month + '-' + strDate,
- bk_type: 3,
- bk_desc: orderno
- }
- })
- that.sendMessage(orderno, that.data.total, eh_time)
- },
- fail() {
- app.timeOut()
- }
- })
- },
- 'fail': function (res) {
- //删除订单 deleteEquipmenteHireHead
- wx.request({
- url: app.globalData.url + '/deleteEquipmenteHireHead',
- method: 'get',
- data: {
- eh_code: orderno
- },
- success: function (resbill) {
- wx.showToast({
- title: '付款失败!',
- icon: 'none',
- duration: 1500
- })
- },
- fail() {
- app.timeOut()
- }
- })
- },
- 'complete': function (res) {
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- },
- addEquipmenteHireHeadOnline: function (orderno, eh_mortagage, eh_rental, eh_cmname, eh_cmphone, eh_cmidcard, eh_cmaddress, eh_usercode, eh_date, eh_status, eh_source, total, cp_discount) {
- wx.request({
- url: app.globalData.url + '/addEquipmenteHireHeadOnline',
- method: 'post',
- header: { "Content-Type": "application/x-www-form-urlencoded" },
- data: {
- eh_code: orderno,
- eh_mortagage: eh_mortagage,
- eh_rental: eh_rental,
- eh_cmname: eh_cmname,
- eh_cmphone: eh_cmphone,
- eh_cmidcard: eh_cmidcard,
- eh_cmaddress: eh_cmaddress,
- eh_usercode: eh_usercode,
- eh_date: eh_date,
- eh_status: eh_status,
- eh_source: eh_source,
- total: total,
- cp_discount: cp_discount
- }
- })
- },
- sendMessage: function (orderno, total, eh_time){
- wx.request({
- url: app.globalData.url + '/WXSendOrderMessage',
- method: 'get',
- data: {
- orderno: orderno,
- total: total,
- date: eh_time
- }
- })
- },
- addEquipmenteHireDetail: function (orderno, et_type, ed_startdate, ed_enddate) {
- var date = new Date();
- var year = date.getFullYear();
- var month = ("0" + (date.getMonth() + 1)).slice(-2);;
- var strDate = ("0" + (date.getDate())).slice(-2);
- var seperator1 = "-";
- wx.request({
- url: app.globalData.url + '/addEquipmenteHireDetail',
- method: 'post',
- header: { "Content-Type": "application/x-www-form-urlencoded" },
- data: {
- eh_code: orderno,
- et_type: et_type,
- ed_startdate: ed_startdate,
- ed_enddate: ed_enddate
- },
- success: function (res) {
-
- },
- fail() {
- app.timeOut()
- }
- })
- },
- randomString: function () {
- var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
- var maxPos = chars.length;
- var pwd = '';
- for(var i = 0; i< 32; i++) {
- pwd += chars.charAt(Math.floor(Math.random() * maxPos));
- }
- return pwd;
- },
- onShareAppMessage: function () {
- return {
- title: '悦所-设备租赁(' + this.data.et_name+')',
- path: '/pages/index/index?skip=1&path=/pages/equipment/leasing/leasing¶=' + this.data.et_type
- }
- }
- })
|