confirmOreder.js 7.3 KB

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