confirmOreder.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. currentList: [{
  10. tit: '塑封包膜',
  11. num: "30",
  12. id: 1
  13. }, {
  14. tit: '绒面鞋补色',
  15. num: "20",
  16. id: 2
  17. }, {
  18. tit: '防水处理',
  19. num: "20",
  20. id: 3
  21. }, {
  22. tit: '防水处理',
  23. num: "10",
  24. id: 4
  25. }],
  26. mode: 1,
  27. checked: true,
  28. show1: false,
  29. show2: false,
  30. code: "",
  31. order_no: "",
  32. orderinfo: "",
  33. address: "",
  34. useraddr: "",
  35. remark: "",
  36. address_id:0,
  37. freight:0,
  38. total_price:0,
  39. },
  40. onLoad(opticon) {
  41. let order_no = opticon.order_no;
  42. let currentList = this.data.currentList
  43. currentList.map(item => {
  44. item.active = false
  45. })
  46. this.detail(order_no);
  47. this.setData({
  48. currentList,
  49. order_no
  50. })
  51. },
  52. //详情
  53. detail(order) {
  54. var that = this;
  55. app.api.useApi(app.globalData.baseAppUrl + "api/order_detail", {
  56. order_no: order,
  57. }, "get").then(function (res) {
  58. if (res.code != 200) {
  59. wx.showLoading({
  60. title: res.message.msg,
  61. })
  62. setTimeout(function () {
  63. wx.hideLoading({
  64. success: (res) => { },
  65. })
  66. }, 2000);
  67. } else {
  68. var unit=res.message.data.network.unit[res.message.data.network.unit.length-1];
  69. var total_price=parseFloat(res.message.data.total_price);
  70. var price=parseFloat(unit.price);
  71. that.setData({
  72. orderinfo: res.message.data,
  73. address: res.message.address.address,
  74. code: res.message.address.phone,
  75. name: res.message.address.username,
  76. address_id:res.message.address.id,
  77. useraddr: res.message.address,
  78. mode:unit.type,
  79. order_type:unit.type,
  80. freight:unit.price,
  81. total_price:(total_price+price).toFixed(2)
  82. })
  83. }
  84. }).catch(function (err) {
  85. console.log(err);
  86. })
  87. },
  88. changeClose1(e) {
  89. this.setData({
  90. show1: !this.data.show1
  91. })
  92. },
  93. changeClose2(e) {
  94. // console.log(e)
  95. this.setData({
  96. show2: !this.data.show2,
  97. remark: this.data.remark
  98. })
  99. },
  100. onChange(event) {
  101. console.log(event);
  102. this.setData({
  103. checked: event.detail,
  104. });
  105. },
  106. chios(e) {
  107. let { item } = e.currentTarget.dataset
  108. let currentList = this.data.currentList
  109. currentList.map((it, index) => {
  110. if (item.id == it.id) {
  111. it.active = !it.active
  112. }
  113. })
  114. this.setData({
  115. currentList
  116. })
  117. },
  118. changeMode(e) {
  119. var id = e.currentTarget.dataset.id
  120. var key=e.currentTarget.dataset.indx;
  121. var unit=this.data.orderinfo.network.unit[key];
  122. var total_price=parseFloat(this.data.orderinfo.total_price);
  123. var price=parseFloat(unit.price)
  124. this.setData({
  125. mode: id,
  126. freight:unit.price,
  127. total_price:total_price+price
  128. })
  129. },
  130. goto() {
  131. if(!this.data.checked){
  132. wx.showLoading({
  133. title: '请阅读并同意洗护协议',
  134. })
  135. setTimeout(function () {
  136. wx.hideLoading({
  137. success: (res) => { },
  138. })
  139. }, 1000);
  140. }else{this.orderConfirm();}
  141. },
  142. getPhoneNumber(e) {
  143. app.login();
  144. console.log(e)
  145. var data = {
  146. 'mds': wx.getStorageSync('seisson_key'),
  147. 'encryptedData': e.detail.encryptedData,
  148. 'errMsg': e.detail.errMsg,
  149. 'iv': e.detail.iv,
  150. 'appid': wx.getAppBaseInfo().host.appId,
  151. }
  152. app.api.useApi(app.globalData.baseAppUrl+"api/user/getPhoneNumber",data,"post").then((res)=>{
  153. if (res.code == 200) {
  154. var phone = res.message.data.phone
  155. console.log(phone);
  156. if (phone) {
  157. this.setData({
  158. code: phone,
  159. })
  160. }
  161. }
  162. }).catch((err)=>{
  163. console.log(err)
  164. })
  165. // console.log("fetch cloudfunction success", cloudResult.result)
  166. },
  167. input1(e) {
  168. console.log(e.detail);
  169. this.setData({
  170. name: e.detail.value
  171. })
  172. },
  173. input2(e) {
  174. this.setData({
  175. code: e.detail.value
  176. })
  177. },
  178. input3(e) {
  179. this.setData({
  180. address: e.detail.value
  181. })
  182. },
  183. input4(e) {
  184. this.setData({
  185. remark: e.detail.value
  186. })
  187. },
  188. addAddress() {
  189. var that = this;
  190. app.api.useApi(app.globalData.baseAppUrl + "api/address/create", {
  191. username: that.data.name,
  192. phone: that.data.code,
  193. address: that.data.address,
  194. }, "post").then(function (res) {
  195. if (res.code != 200) {
  196. wx.showLoading({
  197. title: res.original.message.msg,
  198. })
  199. setTimeout(function () {
  200. wx.hideLoading({
  201. success: (res) => { },
  202. })
  203. }, 1000);
  204. } else {
  205. that.changeClose1();
  206. that.setData({
  207. address_id: res.message.data.address.id,
  208. })
  209. }
  210. }).catch(function (err) {
  211. console.log(err);
  212. })
  213. },
  214. updateaddr(e) {
  215. var that = this;
  216. app.api.useApi(app.globalData.baseAppUrl + "api/address/update", {
  217. username: that.data.name,
  218. phone: that.data.code,
  219. address: that.data.address,
  220. id: e.target.dataset.id,
  221. }, "post").then(function (res) {
  222. if (res.code != 200) {
  223. wx.showLoading({
  224. title: res.message.msg,
  225. })
  226. } else {
  227. that.changeClose1();
  228. // wx.navigateTo({
  229. // url: '/pages/my/address/address',
  230. // })
  231. }
  232. setTimeout(function () {
  233. wx.hideLoading({
  234. success: (res) => { },
  235. })
  236. }, 2000);
  237. }).catch(function (err) {
  238. console.log(err.message);
  239. })
  240. },
  241. orderConfirm() {
  242. var that=this;
  243. app.api.useApi(app.globalData.baseAppUrl + "api/orders", {
  244. order_no: that.data.order_no,
  245. order_type: that.data.mode,
  246. user_remark: that.data.remark,
  247. address_id:that.data.address_id
  248. }, "post").then(function (res) {
  249. console.log(res)
  250. if (res.code != 200) {
  251. wx.showLoading({
  252. title: res.message.msg,
  253. })
  254. setTimeout(function () {
  255. wx.hideLoading({
  256. success: (res) => { },
  257. })
  258. }, 1000);
  259. } else {
  260. wx.navigateTo({
  261. url: '/pages/my/cashier/cashier?order_no='+that.data.order_no
  262. })
  263. }
  264. }).catch(function (err) {
  265. // console.log(222);
  266. console.log(err)
  267. })
  268. },
  269. })