123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- var app = getApp() //实例化小程序,从而获取全局数据或者使用全局函数
- var MD5Util = require('../../utils/md5.js');
- // let URLINDEX=util.prefix();
- var addressList = [];
- var addressAll = [];
- Page({
- data: {
- hidden: 'hidden',
- addressAll: addressAll,
- addressList: addressList,
- addressBg: "../../images/address_line.png",
- addressVal: "../../images/address_logo.png",
- addressAddImg: "../../images/add_address.png",
- addressEditImg: "../../images/gray_back.png",
- checkState: true,
- carts: [],
- gotJson2: {},
- total: 0,
- value: 0,
- checked: false,//发票默认不选中
- servalue: 1,
- serchecked: true,//服务协议默认选中
- isShow: false,
- address: '',
- total1: 0,
- total2: 0,
- province: '',
- city: '',
- area: '',
- adress: '',
- consignee: '',
- phone: '',
- hiddenmodal: true,
- minNum: 0,//优惠金额
- coupon_id: '',
- couponName: '', //优惠劵名称
- invoice: false,
- invCont: '我要开发票',
- //发票信息
- invoice_send_flag: 3,
- invoice_flag: 3, //发票标志位,如果为3,则为不开发票
- invoice_type_name: '',//发票类型名称
- invoice_company_name: '',//发票公司名字(纸质单位和增值单位的公司名称相同)
- invoice_number: '', //纳税人识别号
- invoice_address: '',//注册地址
- invoice_telphone: '',//注册电话
- invoice_brandName: '',//开户银行
- invoice_brandNum: '',//银行账户
- invoice_company_content: '',//增值发票内容
- invoice_price: '',//发票金额
- invoice_title: '',//纸质个人发票抬头
- invoice_company_title: '',//纸质单位和增值发票抬头
- invoice_takeName: '',//收货姓名
- invoice_takeTelphone: '',//收货人联系方式
- invoice_takeAddress: '',//收货人地址
- invoiceTypeFlag: 0,
- orderState: 0,
- orderState1: 0,
- stateNum: 0,
- maskBg: false,//支付提示蒙层
- agrService: true,//同意服务协议
- upViewShow : false
- },
- onLoad: function (options) {
- wx.showNavigationBarLoading();
- var that = this;
- var carts = JSON.parse(options.carts);
- for (var i = 0; i < carts.length; i++) {
- var name = carts[i].name;
- name = name.replace(/zss/g, "&");
- carts[i].name = name;
- }
- that.setData({
- carts: carts
- })
- var carts = that.data.carts;
- var total = 0;
- var total2 = 0;
- for (var i = 0; i < that.data.carts.length; i++) {
- var boxPrice = that.data.carts[i].box_price;
- var goodsPrice = that.data.carts[i].cost;
- if (boxPrice == '' && boxPrice == null) {
- boxPrice = 0;
- }
- total += (parseFloat(goodsPrice) + parseFloat(boxPrice)) * (that.data.carts[i].num);
- }
- total2 = total - that.data.minNum;
- if (total == 0) {
- total = 0.01;
- }
- if (total2 == 0) {
- total2 = 0.01;
- }
- that.setData({
- carts: carts,
- total1: total,
- total2: total2
- })
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- if (un_id != undefined && un_id != '' && un_id != null) {
- wx.request({
- url: host + "/adressapi/adressview",//收货地址
- data: {
- user_id: un_id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- addressAll: res.data.rows
- });
- var len = that.data.addressAll.length;
- for (var i = 0; i < len; i++) {
- if (that.data.addressAll[i].adress_flag == 1) {
- that.setData({
- consignee: that.data.addressAll[i].consignee,
- phone: that.data.addressAll[i].phone,
- province: that.data.addressAll[i].province,
- city: that.data.addressAll[i].city,
- area: that.data.addressAll[i].area,
- adress: that.data.addressAll[i].adress
- })
- }
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- wx.hideNavigationBarLoading(//加载完成后显示页面
- that.setData({
- hidden: ''
- })
- )
- }
- });
- //查询是否有默认地址,如有则直接返回默认地址所有信息
- //查询是否有发票信息
- wx.request({
- url: host + "invoiceapi/adressview",//发票
- data: {
- user_id: un_id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- var flag = res.data.rows;
- if (res.data.total > 0) {
- if (res.data.rows[0].invoice_flag == 0) {
- that.setData({
- invoice_flag: 0,
- invoice_send_flag: 0,
- invCont: '纸质普通发票',
- invoice: true,
- invoice_type_name: '纸质普通发票',
- invoice_title: '个人',
- invoice_name: res.data.rows[0].invoice_name,//个人姓名
- invoice_content: res.data.rows[0].invoice_content,//发票内容
- invoice_price: res.data.rows[0].invoice_price//金额
- })
- } else if (res.data.rows[0].invoice_flag == 1) {
- that.setData({
- invoice_flag: 1,
- invoice_send_flag: 1,
- invCont: '纸质普通发票',
- invoice: true,
- invoice_type_name: '纸质普通发票',
- invoice_company_title: '单位',
- invoice_company_name: res.data.rows[0].invoice_company_name,//单位名称
- invoice_number: res.data.rows[0].invoice_number,//纳税人识别号
- invoice_content: res.data.rows[0].invoice_content,//发票内容
- invoice_price: res.data.rows[0].invoice_price //金额
- })
- } else {
- that.setData({
- invoice_flag: 2,
- invoice_send_flag: 2,
- invCont: '增值税专用发票',
- invoice: true,
- invoice_type_name: '增值税专用发票',
- invoice_company_title: '单位',
- invoice_company_name: res.data.rows[0].invoice_company_name,//单位名称
- invoice_number: res.data.rows[0].invoice_number,//纳税人识别号
- invoice_address: res.data.rows[0].invoice_address,//注册地址
- invoice_telphone: res.data.rows[0].invoice_telphone,//注册电话
- invoice_brandName: res.data.rows[0].invoice_brandName,//开户银行
- invoice_brandNum: res.data.rows[0].invoice_brandNum,//银行账户
- invoice_company_content: '明细',//发票内容
- invoice_price: res.data.rows[0].invoice_price, //金额
- invoice_takeName: res.data.rows[0].invoice_takeName,
- invoice_takeTelphone: res.data.rows[0].invoice_takeTelphone,
- invoice_takeAddress: res.data.rows[0].invoice_takeAddress
- })
- }
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- }
- },
- coupon: function () {//选择优惠劵
- wx.navigateTo({//把总价带过去,直接返回优惠之后的总价
- url: '/pages/mineCoupon/coupon?total2=' + this.data.total1
- })
- },
- invoice: function () {//我要开发票,把商品价钱带过来
- wx.navigateTo({
- url: '/pages/invoiceInfor/invoiceInfor?total1=' + this.data.total1
- })
- },
- checkboxChange: function (e) {
- var that = this;
- var datavalue = e.currentTarget.dataset.value;
- var invoice = this.data.invoice;
- if (invoice) {
- if (datavalue == 0) {
- that.setData({
- 'value': 1,
- 'checked': true,
- 'isShow': true,
- invCont: that.data.invoice_type_name
- })
- } else {
- that.setData({
- 'value': 0,
- 'checked': false,
- 'isShow': true,
- invCont: that.data.invoice_type_name
- })
- }
- }
- },
- agrService: function (e) {
- var that = this;
- var datavalue = e.currentTarget.dataset.value;
- if (datavalue == 0) {
- that.setData({
- servalue: 1,
- 'serchecked': true
- })
- } else {
- that.setData({
- servalue: 0,
- 'serchecked': false
- })
- }
- },
- save: function (e) {
- var that = this;
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1]; //当前页面
- var prevPage = pages[pages.length - 2]; //上一个页面
- var prevPageUrl = prevPage.route;
- that.setData({
- upViewShow : true
- })
-
- var province = that.data.province;
- if (province == '') {
- that.setData({
- hiddenmodal: false,
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- if (that.data.value == 0) {
- that.setData({
- invoice_flag: 3,
- invoice_send_flag: 3,
- invoice_type_name: '',//发票类型名称
- invoice_name: '',//个人名字
- invoice_content: '',//纸质发票内容
- invoice_company_name: '',//发票公司名字(纸质单位和增值单位的公司名称相同)
- invoice_number: '', //纳税人识别号
- invoice_address: '',//注册地址
- invoice_telphone: '',//注册电话
- invoice_brandName: '',//开户银行
- invoice_brandNum: '',//银行账户
- invoice_company_content: '',//增值发票内容
- invoice_price: '',//发票金额
- invoice_title: '',//纸质个人发票抬头
- invoice_company_title: '',//纸质单位和增值发票抬头
- invoice_takeName: '',//收货姓名
- invoice_takeTelphone: '',//收货人联系方式
- invoice_takeAddress: ''//收货人地址
- })
- }
- var timestamp = Date.parse(new Date());
- timestamp = timestamp / 1000;
- var timestamp1 = timestamp;
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- var user_num = parseInt(that.data.carts[0].user_num) - parseInt(that.data.carts[0].num);//上线数量
- if (user_num <= -1){
- that.setData({
- hiddenmodal: false,
- modalCont: '数量已达上限'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }else{
- if (un_id != undefined && un_id != '' && un_id != null){
- //获取该用户下的该商品限购数量
- wx.request({
- url: host + "userapi/user_fake_split_view",
- data: {
- user_id: that.data.user_id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- user_allow_num: res.data.rows[0].user_num
- })
- if (res.data.rows[0].user_num <= 0) {
- that.setData({
- hiddenmodal: false,
- modalCont: '数量已达上限'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- } else {
- }
- }
- })
- wx.request({
- url: host + "orderapi/insertorder",
- data: {
- order_userid: un_id,
- order_sta: '1',
- order_number: timestamp,
- order_type: '0',
- order_Consignee: that.data.consignee,
- order_phone: that.data.phone,
- order_address: that.data.province +
- that.data.city + that.data.area + that.data.adress,
- order_commodityid: that.data.carts[0].id,
- order_num: that.data.carts[0].num,
- order_Price: 0,//////
- orderr_Coupon: that.data.minNum,
- coupon_id: that.data.coupon_id,
- order_Specifications: '',
- order_gixbox: '',
- invoice_send_flag: that.data.invoice_send_flag,
- invoice_flag: that.data.invoice_flag, //发票标志位
- invoice_type_name: that.data.invoice_type_name,//发票类型名称
- invoice_name: that.data.invoice_name,//个人名字
- invoice_content: that.data.invoice_content,//纸质发票内容
- invoice_company_name: that.data.invoice_company_name,//发票公司名字(纸质单位和增值单位的公司名称相同)
- invoice_number: that.data.invoice_number, //纳税人识别号
- invoice_address: that.data.invoice_address,//注册地址
- invoice_telphone: that.data.invoice_telphone,//注册电话
- invoice_brandName: that.data.invoice_brandName,//开户银行
- invoice_brandNum: that.data.invoice_brandNum,//银行账户
- invoice_company_content: that.data.invoice_company_content,//增值发票内容
- invoice_price: that.data.invoice_price,//发票金额
- invoice_title: that.data.invoice_title,//纸质个人发票抬头
- invoice_company_title: that.data.invoice_company_title,//纸质单位和增值发票抬头
- invoice_takeName: that.data.invoice_takeName,//收货姓名
- invoice_takeTelphone: that.data.invoice_takeTelphone,//收货人联系方式
- invoice_takeAddress: that.data.invoice_takeAddress//收货人地址
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- for (var i = 0; i < that.data.carts.length; i++) {
- wx.request({
- url: host + "orderaffapi/insertOrderAff",
- data: {
- order_number: timestamp,
- cost: that.data.carts[i].cost,
- com_id: that.data.carts[i].com_id,
- logo: that.data.carts[i].logo,
- name: that.data.carts[i].name,
- num: that.data.carts[i].num,
- process: that.data.carts[i].process,
- giftbox_name: that.data.carts[i].giftbox_name,
- giftbox_id: that.data.carts[i].giftbox,
- box_price: that.data.carts[i].box_price,
- process_name: that.data.carts[i].process_name,
- process_id: that.data.carts[i].process,
- logo: that.data.carts[i].logo,
- style1: that.data.carts[i].style1,
- style1_name: that.data.carts[i].style1_name,
- style2: that.data.carts[i].style2,
- style2_name: that.data.carts[i].style2_name,
- style3: that.data.carts[i].style3,
- style3_name: that.data.carts[i].style3_name,
- style4: that.data.carts[i].style4,
- style4_name: that.data.carts[i].style4_name,
- style5: that.data.carts[i].style5,
- style5_name: that.data.carts[i].style5_name,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- var stateNum = 0;
- for (var i = 0; i < that.data.carts.length; i++) {
- if ((that.data.carts[i].process_name != '') && (that.data.carts[i].process != -1)) {
- stateNum++;
- }
- }
- if (stateNum > 0) {
- that.setData({
- orderState1: 2
- })
- } else {
- that.setData({
- orderState1: 3
- })
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- }
- //获取用户登录状态
- wx.login({
- success: function (res) {
- //发起网络请求,发起的是HTTPS请求,向服务端请求预支付
- var code = res.code;
- var title = that.data.carts[0].name;
- var price = that.data.total2 * 100;
- price = 1;
- var timestamp = String(Date.parse(new Date())) //时间戳
- wx.request({
- url: host + 'prepay',
- data: {
- code: code,
- price: price,
- title: title,
- order_number: timestamp1
- },
- success: function (res) {
- wx.hideLoading()
- that.setData({
- maskBg: false
- })
- if (res.data.result == true) {
- var nonceStr = res.data.nonceStr;
- var prepayId = res.data.prepayId;
- console.log("1:" + nonceStr);
- // 按照字段首字母排序组成新字符串
- var payDataA = "appId=wx9e3f68fa2172f1c7&nonceStr=" + res.data.nonceStr + "&package=prepay_id=" + res.data.prepayId + "&signType=MD5&timeStamp=" + timestamp;
- var payDataB = payDataA + "&key=MlxMZWpZidKxCPPaOOztMP84XvQzqSOh";
- // 使用MD5加密算法计算加密字符串
- paySign = MD5Util.MD5(payDataB).toUpperCase();
- // 使用MD5加密算法计算加密字符串
- var paySign = MD5Util.MD5(payDataB).toUpperCase();
- wx.request({
- url: host + "orderapi/update",
- data: {
- order_sta: that.data.orderState1,
- order_number: timestamp1,
- orderState: that.data.orderState1
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- //获取该用户下的该商品限购数量
- wx.request({
- url: host + "userapi/user_fake_split_update",
- data: {
- user_id: un_id,
- user_num: user_num,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- // that.setData({
- // user_allow_num: res.data.result
- // })
- }
- })
- wx.redirectTo({
- url: '/pages/orderList/orderList?isSelect=0'
- })
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- } else {
- console.log('请求失败' + res.data.info)
- }
- }
- })
- }
- });
- }
- }
-
- }
- })
- var that;
- var Util = require('../../utils/util.js');
|