123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- // pages/order/confirmOreder/confirmOreder.js
- const app = getApp();
- const addr = require('../../my/address/addSite/addSite.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- currentList: [{
- tit: '塑封包膜',
- num: "30",
- id: 1
- }, {
- tit: '绒面鞋补色',
- num: "20",
- id: 2
- }, {
- tit: '防水处理',
- num: "20",
- id: 3
- }, {
- tit: '防水处理',
- num: "10",
- id: 4
- }],
- mode: 1,
- checked: true,
- show1: false,
- show2: false,
- code: "",
- order_no: "",
- orderinfo: "",
- address: "",
- useraddr: "",
- remark: "",
- address_id:0,
- freight:0,
- total_price:0,
- },
- onLoad(opticon) {
- let order_no = opticon.order_no;
- let currentList = this.data.currentList
- currentList.map(item => {
- item.active = false
- })
- this.detail(order_no);
- this.setData({
- currentList,
- order_no
- })
- },
- //详情
- detail(order) {
- var that = this;
- app.api.useApi(app.globalData.baseAppUrl + "api/order_detail", {
- order_no: order,
- }, "get").then(function (res) {
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 2000);
- } else {
-
- var unit=res.message.data.network.unit[res.message.data.network.unit.length-1];
- var total_price=parseFloat(res.message.data.total_price);
- var price=parseFloat(unit.price);
- that.setData({
- orderinfo: res.message.data,
- address: res.message.address.address,
- code: res.message.address.phone,
- name: res.message.address.username,
- address_id:res.message.address.id,
- useraddr: res.message.address,
- mode:unit.type,
- order_type:unit.type,
- freight:unit.price,
- total_price:(total_price+price).toFixed(2)
- })
- }
- }).catch(function (err) {
- console.log(err);
- })
- },
- changeClose1(e) {
- this.setData({
- show1: !this.data.show1
- })
- },
- changeClose2(e) {
- // console.log(e)
- this.setData({
- show2: !this.data.show2,
- remark: this.data.remark
- })
- },
- onChange(event) {
- console.log(event);
- this.setData({
- checked: event.detail,
- });
- },
- chios(e) {
- let { item } = e.currentTarget.dataset
- let currentList = this.data.currentList
- currentList.map((it, index) => {
- if (item.id == it.id) {
- it.active = !it.active
- }
- })
- this.setData({
- currentList
- })
- },
- changeMode(e) {
- var id = e.currentTarget.dataset.id
- var key=e.currentTarget.dataset.indx;
- var unit=this.data.orderinfo.network.unit[key];
-
- var total_price=parseFloat(this.data.orderinfo.total_price);
- var price=parseFloat(unit.price)
-
- this.setData({
- mode: id,
- freight:unit.price,
- total_price:total_price+price
-
- })
- },
- goto() {
- if(!this.data.checked){
- wx.showLoading({
- title: '请阅读并同意洗护协议',
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- }else{this.orderConfirm();}
-
- },
- getPhoneNumber(e) {
- app.login();
- console.log(e)
- var data = {
- 'mds': wx.getStorageSync('seisson_key'),
- 'encryptedData': e.detail.encryptedData,
- 'errMsg': e.detail.errMsg,
- 'iv': e.detail.iv,
- 'appid': wx.getAppBaseInfo().host.appId,
- }
- app.api.useApi(app.globalData.baseAppUrl+"api/user/getPhoneNumber",data,"post").then((res)=>{
- if (res.code == 200) {
- var phone = res.message.data.phone
- console.log(phone);
- if (phone) {
- this.setData({
- code: phone,
- })
- }
- }
- }).catch((err)=>{
- console.log(err)
- })
- // console.log("fetch cloudfunction success", cloudResult.result)
- },
- input1(e) {
- console.log(e.detail);
- this.setData({
- name: e.detail.value
- })
- },
- input2(e) {
- this.setData({
- code: e.detail.value
- })
- },
- input3(e) {
- this.setData({
- address: e.detail.value
- })
- },
- input4(e) {
- this.setData({
- remark: e.detail.value
- })
- },
- addAddress() {
- var that = this;
- app.api.useApi(app.globalData.baseAppUrl + "api/address/create", {
- username: that.data.name,
- phone: that.data.code,
- address: that.data.address,
- }, "post").then(function (res) {
-
- if (res.code != 200) {
- wx.showLoading({
- title: res.original.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- } else {
- that.changeClose1();
- that.setData({
- address_id: res.message.data.address.id,
- })
- }
-
- }).catch(function (err) {
- console.log(err);
- })
- },
- updateaddr(e) {
- var that = this;
- app.api.useApi(app.globalData.baseAppUrl + "api/address/update", {
- username: that.data.name,
- phone: that.data.code,
- address: that.data.address,
- id: e.target.dataset.id,
- }, "post").then(function (res) {
-
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- } else {
- that.changeClose1();
- // wx.navigateTo({
- // url: '/pages/my/address/address',
- // })
- }
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 2000);
- }).catch(function (err) {
- console.log(err.message);
- })
- },
- orderConfirm() {
- var that=this;
- app.api.useApi(app.globalData.baseAppUrl + "api/orders", {
- order_no: that.data.order_no,
- order_type: that.data.mode,
- user_remark: that.data.remark,
- address_id:that.data.address_id
- }, "post").then(function (res) {
- console.log(res)
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- } else {
- wx.navigateTo({
- url: '/pages/my/cashier/cashier?order_no='+that.data.order_no
- })
- }
- }).catch(function (err) {
- // console.log(222);
- console.log(err)
- })
- },
- })
|