addOrder.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. const _Http = getApp().globalData.http,
  2. {
  3. formatTime
  4. } = require("../../utils/getTime");
  5. let pageNumber = 1,
  6. pageTotal = 1,
  7. sys_payorderid = null,
  8. currency = require("../../utils/currency"),
  9. CNY = value => currency(value, {
  10. symbol: "¥",
  11. precision: 2
  12. }).format();
  13. Page({
  14. data: {
  15. users: [],
  16. remarks: "",
  17. showAmount: "¥0.00",
  18. isDelete: true,
  19. useDiscount: 0
  20. },
  21. onLoad(options) {
  22. this.setData({
  23. sys_payinstructions: wx.getStorageSync('siteP').sys_payinstructions,
  24. sys_payincidence: 1,
  25. opUsers: options.users ? JSON.parse(options.users) : []
  26. })
  27. sys_payorderid = options.sys_payorderid;
  28. this.getVersions(options.vid || "");
  29. this.getDiscounts();
  30. },
  31. /* 获取优惠卷 */
  32. getDiscounts() {
  33. _Http.basic({
  34. "id": 20230801162402,
  35. "content": {
  36. nocache: true
  37. }
  38. }).then(res => {
  39. console.log("获取优惠卷", res)
  40. this.setData({
  41. discounts: res.data
  42. })
  43. })
  44. },
  45. /* 保存订单进度 */
  46. changeOrder() {
  47. _Http.basic({
  48. "classname": "system.payorder.payorder",
  49. "method": "insertUsers",
  50. "content": {
  51. "sys_site_systempartitionid": this.data.sys_site_systempartitionid,
  52. sys_payorderid,
  53. "remarks": this.data.remarks,
  54. "users": this.data.users.map(v => {
  55. let item = this.data.userList.find(s => {
  56. let id = this.data.sys_payincidence == 1 ? s.userid : s.sa_agentsid;
  57. return id == v
  58. })
  59. return {
  60. "isleader": item.isleader,
  61. "userid": item.userid,
  62. "sa_agentsid": item.sa_agentsid,
  63. "enddate": item.enddate[this.data.sys_site_systempartitionid] || ''
  64. }
  65. })
  66. }
  67. }).then(res => {
  68. console.log("修改订单信息", res)
  69. if (res.msg != '成功') return wx.showToast({
  70. title: res.msg,
  71. icon: "none",
  72. mask: true
  73. });
  74. this.setData({
  75. showAmount: CNY(res.data.amount),
  76. orderno: res.data.orderno
  77. })
  78. })
  79. },
  80. /* 更改备注 */
  81. onblur(e) {
  82. console.log(e)
  83. if (e.detail.value == this.data.remarks) return;
  84. this.setData({
  85. remarks: e.detail.value
  86. });
  87. this.changeOrder();
  88. },
  89. /* 获取版本 */
  90. getVersions(vid) {
  91. _Http.basic({
  92. "classname": "system.payorder.payorder",
  93. "method": "chooseSystemPartition",
  94. "content": {
  95. "pageNumber": 1,
  96. "pageSize": 9999,
  97. "where": {
  98. "condition": ""
  99. }
  100. }
  101. }).then(res => {
  102. console.log("版本列表", res)
  103. if (res.msg != '成功') {
  104. wx.showToast({
  105. title: res.msg,
  106. icon: "none",
  107. mask: true
  108. })
  109. setTimeout(() => {
  110. wx.navigateBack();
  111. }, 1000)
  112. return;
  113. };
  114. let sys_site_systempartitionid = res.data[0].sys_site_systempartitionid || '';
  115. if (vid && res.data.some(v => v.sys_site_systempartitionid == vid)) sys_site_systempartitionid = vid - 0;
  116. this.setData({
  117. versionsList: res.data,
  118. sys_site_systempartitionid
  119. })
  120. this.getUsers(true);
  121. })
  122. },
  123. /* 切换版本 */
  124. changeVer(e) {
  125. const {
  126. sys_site_systempartitionid
  127. } = e.currentTarget.dataset.item;
  128. if (this.data.sys_site_systempartitionid == sys_site_systempartitionid) return;
  129. this.setData({
  130. sys_site_systempartitionid
  131. });
  132. this.setUsers();
  133. },
  134. checkVer(e) {
  135. const {
  136. item
  137. } = e.currentTarget.dataset;
  138. this.selectComponent("#inventory").show(item.systemapp)
  139. },
  140. /* 获取可添加账号/主体 */
  141. getUsers(init = false) {
  142. if (init) {
  143. pageNumber = 1;
  144. pageTotal = 1;
  145. };
  146. if (pageNumber > pageTotal) return;
  147. _Http.basic({
  148. "classname": "system.payorder.payorder",
  149. "method": "chooseUsers",
  150. "content": {
  151. pageNumber,
  152. "pageSize": 99999,
  153. "where": {
  154. "condition": ""
  155. }
  156. }
  157. }).then(res => {
  158. console.log("用户列表", res)
  159. if (res.msg != '成功') {
  160. wx.showToast({
  161. title: res.msg,
  162. icon: "none",
  163. mask: true
  164. })
  165. setTimeout(() => {
  166. wx.navigateBack();
  167. }, 1000)
  168. return;
  169. };
  170. pageTotal = res.pageTotal;
  171. this.setData({
  172. userList: res.pageNumber == 1 ? res.data : this.data.userList.concat(res.data)
  173. })
  174. pageNumber = res.pageNumber + 1;
  175. this.setUsers(this.data.opUsers.filter(id => this.data.userList.some(v => id == v.userid)));
  176. // this.changeOrder();
  177. })
  178. },
  179. setUsers(users = []) {
  180. let list = this.data.userList,
  181. idname = this.data.sys_payincidence == 1 ? 'userid' : 'sa_agentsid'
  182. list.forEach(v => {
  183. let date = v.enddate[this.data.sys_site_systempartitionid];
  184. if (v.userid == wx.getStorageSync('userMsg').userid || v.isleader == 1) {
  185. if (date) {
  186. // if (formatTime(new Date(), '-').split(" ")[0] >= date) users.push(v[idname] + '');
  187. } else {
  188. if (!users.some(v => v == v[idname])) users.push(v[idname] + '');
  189. if (v.isleader == 0) this.setData({
  190. useDiscount: this.data.useDiscount += 1
  191. })
  192. }
  193. }
  194. });
  195. this.setData({
  196. users
  197. });
  198. this.changeOrder();
  199. },
  200. onReachBottom() {
  201. // this.getUsers();
  202. },
  203. onChange(e) {
  204. const {
  205. id,
  206. isleader
  207. } = e.currentTarget.dataset;
  208. let users = this.data.users,
  209. useDiscount = this.data.useDiscount;
  210. if (users.some(v => v == id)) {
  211. users = users.filter(s => s != id)
  212. if (isleader == 0) useDiscount -= 1;
  213. } else {
  214. users.push(id + "")
  215. if (isleader == 0) useDiscount += 1;
  216. }
  217. this.setData({
  218. users,
  219. useDiscount
  220. });
  221. this.changeOrder();
  222. },
  223. examine() {
  224. return new Promise((resolve, reject) => {
  225. if (currency(this.data.showAmount).value == 0) {
  226. wx.showModal({
  227. title: '提示',
  228. content: '优惠后金额为0,是否确认',
  229. complete: (res) => {
  230. if (res.cancel) resolve(false)
  231. if (res.confirm) resolve(true)
  232. }
  233. })
  234. } else {
  235. resolve(true)
  236. }
  237. })
  238. },
  239. /* 支付 */
  240. async payment() {
  241. let isPayment = await this.examine();
  242. if (!isPayment) return;
  243. let that = this;
  244. that.data.isDelete = false;
  245. wx.login({
  246. success: (s) => {
  247. _Http.basic({
  248. "classname": "system.payment.wechatpay",
  249. "method": "createWechatOrder",
  250. "content": {
  251. "orderno": that.data.orderno,
  252. "wechat_code": s.code,
  253. "trade_type": "JSAPI"
  254. }
  255. }).then(res => {
  256. wx.requestPayment({
  257. timeStamp: res.data.timeStamp,
  258. nonceStr: res.data.nonceStr,
  259. package: res.data.package,
  260. signType: res.data.signType,
  261. paySign: res.data.paySign,
  262. success() {
  263. wx.showToast({
  264. title: '支付成功',
  265. mask: true
  266. })
  267. },
  268. fail(err) {
  269. if (res.msg == '成功' && currency(that.data.showAmount).value == 0) {
  270. wx.showToast({
  271. title: '支付成功',
  272. mask: true
  273. })
  274. } else {
  275. wx.showToast({
  276. title: '支付失败',
  277. icon: "error",
  278. mask: true
  279. })
  280. console.error(err)
  281. }
  282. },
  283. complete(e) {
  284. console.log(e)
  285. setTimeout(() => {
  286. wx.redirectTo({
  287. url: '/pages/teams/order?id=' + sys_payorderid,
  288. })
  289. }, 1000)
  290. }
  291. })
  292. })
  293. },
  294. })
  295. },
  296. onUnload() {
  297. if (this.data.isDelete) _Http.basic({
  298. "classname": "system.payorder.payorder",
  299. "method": "delete",
  300. "content": {
  301. sys_payorderid
  302. }
  303. }).then(res => {
  304. console.log("删除订单", res)
  305. })
  306. }
  307. })