confirmOreder.js 7.2 KB

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