addOrder.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. },
  20. onLoad(options) {
  21. this.setData({
  22. sys_payinstructions: wx.getStorageSync('siteP').sys_payinstructions,
  23. sys_payincidence: 1
  24. })
  25. sys_payorderid = options.sys_payorderid;
  26. this.getVersions();
  27. },
  28. /* 保存订单进度 */
  29. changeOrder() {
  30. _Http.basic({
  31. "classname": "system.payorder.payorder",
  32. "method": "insertUsers",
  33. "content": {
  34. "sys_site_systempartitionid": this.data.sys_site_systempartitionid,
  35. sys_payorderid,
  36. "remarks": this.data.remarks,
  37. "users": this.data.users.map(v => {
  38. let item = this.data.userList.find(s => {
  39. let id = this.data.sys_payincidence == 1 ? s.userid : s.sa_agentsid;
  40. return id == v
  41. })
  42. return {
  43. "isleader": item.isleader,
  44. "userid": item.userid,
  45. "sa_agentsid": item.sa_agentsid,
  46. "enddate": item.enddate[this.data.sys_site_systempartitionid] || ''
  47. }
  48. })
  49. }
  50. }).then(res => {
  51. console.log("修改订单信息", res)
  52. if (res.msg != '成功') return wx.showToast({
  53. title: res.msg,
  54. icon: "none",
  55. mask: true
  56. });
  57. this.setData({
  58. showAmount: CNY(res.data.amount),
  59. orderno: res.data.orderno
  60. })
  61. })
  62. },
  63. /* 更改备注 */
  64. onblur(e) {
  65. console.log(e)
  66. if (e.detail.value == this.data.remarks) return;
  67. this.setData({
  68. remarks: e.detail.value
  69. });
  70. this.changeOrder();
  71. },
  72. /* 获取版本 */
  73. getVersions() {
  74. _Http.basic({
  75. "classname": "system.payorder.payorder",
  76. "method": "chooseSystemPartition",
  77. "content": {
  78. "pageNumber": 1,
  79. "pageSize": 9999,
  80. "where": {
  81. "condition": ""
  82. }
  83. }
  84. }).then(res => {
  85. console.log("版本列表", res)
  86. if (res.msg != '成功') {
  87. wx.showToast({
  88. title: res.msg,
  89. icon: "none",
  90. mask: true
  91. })
  92. setTimeout(() => {
  93. wx.navigateBack();
  94. }, 1000)
  95. return;
  96. };
  97. this.setData({
  98. versionsList: res.data,
  99. sys_site_systempartitionid: res.data[0].sys_site_systempartitionid || ''
  100. })
  101. this.getUsers(true);
  102. })
  103. },
  104. /* 切换版本 */
  105. changeVer(e) {
  106. const {
  107. sys_site_systempartitionid
  108. } = e.currentTarget.dataset.item;
  109. if (this.data.sys_site_systempartitionid == sys_site_systempartitionid) return;
  110. this.setData({
  111. sys_site_systempartitionid
  112. });
  113. this.setUsers();
  114. },
  115. checkVer(e) {
  116. const {
  117. item
  118. } = e.currentTarget.dataset;
  119. this.selectComponent("#inventory").show(item.systemapp)
  120. },
  121. /* 获取可添加账号/主体 */
  122. getUsers(init = false) {
  123. if (init) {
  124. pageNumber = 1;
  125. pageTotal = 1;
  126. };
  127. if (pageNumber > pageTotal) return;
  128. _Http.basic({
  129. "classname": "system.payorder.payorder",
  130. "method": "chooseUsers",
  131. "content": {
  132. pageNumber,
  133. "pageSize": 99999,
  134. "where": {
  135. "condition": ""
  136. }
  137. }
  138. }).then(res => {
  139. console.log("用户列表", res)
  140. if (res.msg != '成功') {
  141. wx.showToast({
  142. title: res.msg,
  143. icon: "none",
  144. mask: true
  145. })
  146. setTimeout(() => {
  147. wx.navigateBack();
  148. }, 1000)
  149. return;
  150. };
  151. pageTotal = res.pageTotal;
  152. this.setData({
  153. userList: res.pageNumber == 1 ? res.data : this.data.userList.concat(res.data)
  154. })
  155. pageNumber = res.pageNumber + 1;
  156. this.setUsers();
  157. this.changeOrder();
  158. })
  159. },
  160. setUsers() {
  161. let users = [],
  162. list = this.data.userList,
  163. idname = this.data.sys_payincidence == 1 ? 'userid' : 'sa_agentsid'
  164. list.forEach(v => {
  165. if (v.userid == wx.getStorageSync('userMsg').userid) {
  166. users.push(v[idname] + '');
  167. } else if (v.isleader == 1) {
  168. let date = v.enddate[this.data.sys_site_systempartitionid];
  169. if (date) {
  170. if (formatTime(new Date(), '-').split(" ")[0] >= date) users.push(v[idname] + '');
  171. } else {
  172. users.push(v[idname] + '');
  173. }
  174. }
  175. });
  176. this.setData({
  177. users
  178. });
  179. this.changeOrder();
  180. },
  181. onReachBottom() {
  182. // this.getUsers();
  183. },
  184. onChange(e) {
  185. const {
  186. id
  187. } = e.currentTarget.dataset;
  188. let users = this.data.users;
  189. if (users.some(v => v == id)) {
  190. users = users.filter(s => s != id)
  191. } else {
  192. users.push(id + "")
  193. }
  194. this.setData({
  195. users
  196. });
  197. this.changeOrder();
  198. },
  199. /* 支付 */
  200. payment() {
  201. let that = this;
  202. that.data.isDelete = false;
  203. wx.login({
  204. success: (s) => {
  205. _Http.basic({
  206. "classname": "system.payment.wechatpay",
  207. "method": "createWechatOrder",
  208. "content": {
  209. "orderno": that.data.orderno,
  210. "wechat_code": s.code,
  211. "trade_type": "JSAPI"
  212. }
  213. }).then(res => {
  214. console.log(res)
  215. wx.requestPayment({
  216. timeStamp: res.data.timeStamp,
  217. nonceStr: res.data.nonceStr,
  218. package: res.data.package,
  219. signType: res.data.signType,
  220. paySign: res.data.paySign,
  221. success() {
  222. wx.showToast({
  223. title: '支付成功',
  224. mask: true
  225. })
  226. },
  227. fail(err) {
  228. wx.showToast({
  229. title: '支付失败',
  230. icon: "error",
  231. mask: true
  232. })
  233. console.error(err)
  234. },
  235. complete(e) {
  236. console.log(e)
  237. setTimeout(() => {
  238. wx.redirectTo({
  239. url: '/pages/teams/order?id=' + sys_payorderid,
  240. })
  241. }, 1000)
  242. }
  243. })
  244. })
  245. },
  246. })
  247. },
  248. onUnload() {
  249. if (this.data.isDelete) _Http.basic({
  250. "classname": "system.payorder.payorder",
  251. "method": "delete",
  252. "content": {
  253. sys_payorderid
  254. }
  255. }).then(res => {
  256. console.log("删除订单", res)
  257. })
  258. }
  259. })