confirmOreder.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. // pages/order/confirmOreder/confirmOreder.js
  2. const app = getApp();
  3. const addr = require('../../my/address/addSite/addSite.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isonline: 1,
  10. currentList: [{
  11. tit: '塑封包膜',
  12. num: "30",
  13. id: 1
  14. }, {
  15. tit: '绒面鞋补色',
  16. num: "20",
  17. id: 2
  18. }, {
  19. tit: '防水处理',
  20. num: "20",
  21. id: 3
  22. }, {
  23. tit: '防水处理',
  24. num: "10",
  25. id: 4
  26. }],
  27. mode: 1,
  28. checked: true,
  29. show1: false,
  30. show2: false,
  31. code: "",
  32. order_no: "",
  33. orderinfo: "",
  34. address: "",
  35. useraddr: "",
  36. remark: "",
  37. address_id:0,
  38. freight:0,
  39. total_price:0,
  40. isphone: false,
  41. isphonenum: false,
  42. phonenum: '',
  43. couponinfo: ''
  44. },
  45. onLoad(opticon) {
  46. let order_no = opticon.order_no;
  47. let currentList = this.data.currentList
  48. currentList.map(item => {
  49. item.active = false
  50. })
  51. this.detail(order_no);
  52. this.setData({
  53. currentList,
  54. order_no
  55. })
  56. },
  57. onShow(){
  58. this.setData({couponinfo: this.data.citem})
  59. if(this.data.couponinfo){
  60. if(this.data.couponinfo.type==1){
  61. if((parseFloat(this.data.freight)-parseFloat(this.data.couponinfo.money))>0){
  62. this.setData({total_price: (parseFloat(this.data.total_price) - parseFloat(this.data.couponinfo.money)).toFixed(2)})
  63. }else{
  64. this.setData({total_price: (parseFloat(this.data.total_price) - parseFloat(this.data.freight)).toFixed(2)})
  65. }
  66. }else if(this.data.couponinfo.type==2){
  67. if((parseFloat(this.data.total_price) - parseFloat(this.data.couponinfo.money))>0){
  68. this.setData({total_price: (parseFloat(this.data.total_price) - parseFloat(this.data.couponinfo.money)).toFixed(2)})
  69. }else{
  70. this.setData({total_price: 0})
  71. }
  72. }
  73. }
  74. },
  75. goyhq(){
  76. wx.navigateTo({
  77. url: '../coupon/coupon?totalprice='+this.data.total_price+'&freight='+this.data.freight,
  78. })
  79. },
  80. changeisphone(){
  81. this.setData({isphone: !this.data.isphone})
  82. },
  83. //详情
  84. detail(order) {
  85. var that = this;
  86. app.api.useApi(app.globalData.baseAppUrl + "api/order_detail", {
  87. order_no: order,
  88. }, "get").then(function (res) {
  89. if (res.code != 200) {
  90. wx.showLoading({
  91. title: res.message.msg,
  92. })
  93. setTimeout(function () {
  94. wx.hideLoading({
  95. success: (res) => { },
  96. })
  97. }, 2000);
  98. } else {
  99. that.setData({isonline: res.is_online})
  100. if(res.message.address!=' '&&res.message.address!=''){
  101. console.log('不为空')
  102. that.setData({isphone: false})
  103. }else{
  104. that.setData({isphonenum: true,isphone:true})
  105. }
  106. var unit=res.message.data.network.unit[res.message.data.network.unit.length-1];
  107. var total_price=parseFloat(res.message.data.total_price);
  108. var price=parseFloat(unit.price);
  109. that.setData({
  110. orderinfo: res.message.data,
  111. address: res.message.address.address,
  112. code: res.message.address.phone,
  113. name: res.message.address.username,
  114. address_id:res.message.address.id,
  115. useraddr: res.message.address,
  116. mode:unit.type,
  117. order_type:unit.type,
  118. freight:unit.price,
  119. total_price:(total_price+price).toFixed(2)
  120. })
  121. }
  122. }).catch(function (err) {
  123. console.log(err);
  124. })
  125. },
  126. changeClose1(e) {
  127. this.setData({
  128. show1: !this.data.show1
  129. })
  130. },
  131. changeClose2(e) {
  132. // console.log(e)
  133. this.setData({
  134. show2: !this.data.show2,
  135. remark: this.data.remark
  136. })
  137. },
  138. onChange(event) {
  139. console.log(event);
  140. this.setData({
  141. checked: event.detail,
  142. });
  143. },
  144. chios(e) {
  145. let { item } = e.currentTarget.dataset
  146. let currentList = this.data.currentList
  147. currentList.map((it, index) => {
  148. if (item.id == it.id) {
  149. it.active = !it.active
  150. }
  151. })
  152. this.setData({
  153. currentList
  154. })
  155. },
  156. changeMode(e) {
  157. var id = e.currentTarget.dataset.id
  158. var key=e.currentTarget.dataset.indx;
  159. var unit=this.data.orderinfo.network.unit[key];
  160. var total_price=parseFloat(this.data.orderinfo.total_price);
  161. var price=parseFloat(unit.price)
  162. this.setData({
  163. mode: id,
  164. freight:unit.price,
  165. total_price:total_price+price
  166. })
  167. },
  168. goto() {
  169. let that = this
  170. if(!that.data.checked){
  171. wx.showLoading({
  172. title: '请阅读并同意洗护协议',
  173. })
  174. setTimeout(function () {
  175. wx.hideLoading({
  176. success: (res) => { },
  177. })
  178. }, 1000);
  179. }else{
  180. wx.requestSubscribeMessage({
  181. tmplIds: ['VGlAo-fOukIVSjdmOS5_-9IldrNplzrbKzZzWI2rFuc'],
  182. success (res) {
  183. console.log('成功-'+res);
  184. console.log(res)
  185. that.orderConfirm();
  186. }
  187. })
  188. }
  189. },
  190. getPhoneNumber(e) {
  191. app.login();
  192. console.log(e)
  193. let that = this
  194. var data = {
  195. 'mds': wx.getStorageSync('seisson_key'),
  196. 'encryptedData': e.detail.encryptedData,
  197. 'errMsg': e.detail.errMsg,
  198. 'iv': e.detail.iv,
  199. 'appid':wx.getAccountInfoSync().miniProgram.appId,
  200. }
  201. app.api.useApi(app.globalData.baseAppUrl+"api/user/getPhoneNumber",data,"post").then((res)=>{
  202. if (res.code == 200) {
  203. var phone = res.message.data.phone
  204. console.log(phone);
  205. if (phone) {
  206. if(that.data.isphonenum){
  207. that.setData({
  208. code: phone,
  209. })
  210. }
  211. that.changeisphone()
  212. }
  213. }
  214. }).catch((err)=>{
  215. console.log(err)
  216. })
  217. // console.log("fetch cloudfunction success", cloudResult.result)
  218. },
  219. input1(e) {
  220. console.log(e.detail);
  221. this.setData({
  222. name: e.detail.value
  223. })
  224. },
  225. input2(e) {
  226. this.setData({
  227. code: e.detail.value
  228. })
  229. },
  230. input3(e) {
  231. this.setData({
  232. address: e.detail.value
  233. })
  234. },
  235. input4(e) {
  236. this.setData({
  237. remark: e.detail.value
  238. })
  239. },
  240. addAddress() {
  241. var that = this;
  242. app.api.useApi(app.globalData.baseAppUrl + "api/address/create", {
  243. username: that.data.name,
  244. phone: that.data.code,
  245. address: that.data.address,
  246. }, "post").then(function (res) {
  247. if (res.code != 200) {
  248. wx.showLoading({
  249. title: res.original.message.msg,
  250. })
  251. setTimeout(function () {
  252. wx.hideLoading({
  253. success: (res) => { },
  254. })
  255. }, 1000);
  256. } else {
  257. that.changeClose1();
  258. that.setData({
  259. address_id: res.message.data.address.id,
  260. })
  261. }
  262. }).catch(function (err) {
  263. console.log(err);
  264. })
  265. },
  266. updateaddr(e) {
  267. var that = this;
  268. app.api.useApi(app.globalData.baseAppUrl + "api/address/update", {
  269. username: that.data.name,
  270. phone: that.data.code,
  271. address: that.data.address,
  272. id: e.target.dataset.id,
  273. }, "post").then(function (res) {
  274. if (res.code != 200) {
  275. wx.showLoading({
  276. title: res.message.msg,
  277. })
  278. } else {
  279. that.changeClose1();
  280. // wx.navigateTo({
  281. // url: '/pages/my/address/address',
  282. // })
  283. }
  284. setTimeout(function () {
  285. wx.hideLoading({
  286. success: (res) => { },
  287. })
  288. }, 2000);
  289. }).catch(function (err) {
  290. console.log(err.message);
  291. })
  292. },
  293. orderConfirm() {
  294. var that=this;
  295. let cid = 0
  296. if(that.data.couponinfo!=''&&that.data.couponinfo!=undefined){
  297. cid = that.data.couponinfo.pivot.id
  298. }
  299. app.api.useApi(app.globalData.baseAppUrl + "api/orders", {
  300. order_no: that.data.order_no,
  301. order_type: that.data.mode,
  302. user_remark: that.data.remark,
  303. address_id:that.data.address_id,
  304. coupon_id: cid
  305. }, "post").then(function (res) {
  306. console.log(res)
  307. if (res.code != 200) {
  308. wx.showLoading({
  309. title: res.message.msg,
  310. })
  311. if(res.code == 1020){
  312. // that.changeisphone()
  313. that.changeClose1()
  314. }
  315. setTimeout(function () {
  316. wx.hideLoading({
  317. success: (res) => { },
  318. })
  319. }, 1000);
  320. } else {
  321. wx.navigateTo({
  322. url: '/pages/my/cashier/cashier?order_no='+that.data.order_no
  323. })
  324. }
  325. }).catch(function (err) {
  326. // console.log(222);
  327. console.log(err)
  328. })
  329. },
  330. })