index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. const _Http = getApp().globalData.http;
  2. import currency from "../../utils/currency";
  3. Page({
  4. data: {
  5. loading: true,
  6. active: "新建",
  7. "content": {
  8. nocache: true,
  9. "pageNumber": 1,
  10. "pageTotal": 1,
  11. "pageSize": 20,
  12. "isManage": 0, //默认是1,表示管理端,0表示非管理端,根据用户类型自动区分业务员还是经销商
  13. "isExport": 0,
  14. total: 0,
  15. "where": {
  16. "condition": "",
  17. },
  18. sort: []
  19. },
  20. createShow: false,
  21. types: [{
  22. name: "按借用合同借用"
  23. }, {
  24. name: "单个借用"
  25. }]
  26. },
  27. onLoad(options) {
  28. this.getList(true)
  29. this.setData({
  30. userrole: wx.getStorageSync('userrole')
  31. })
  32. },
  33. getList(init = false) {
  34. if (init.detail != undefined) init = init.detail;
  35. let content = this.data.content;
  36. if (init) content.pageNumber = 1;
  37. if (content.pageNumber > content.pageTotal) return;
  38. content.where.status = this.data.active;
  39. _Http.basic({
  40. "id": 20230114105002,
  41. "version": 1,
  42. content
  43. }).then(res => {
  44. console.log("工具借用列表", res)
  45. this.selectComponent('#ListBox').RefreshToComplete();
  46. res.data = res.data.map(v => {
  47. v.amount = currency(v.amount, {
  48. symbol: "¥",
  49. precision: 2
  50. }).format()
  51. return v
  52. })
  53. this.setData({
  54. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  55. "content.pageNumber": res.pageNumber + 1,
  56. "content.pageTotal": res.pageTotal,
  57. "content.sort": res.sort,
  58. "content.total": res.total,
  59. loading: false
  60. })
  61. })
  62. },
  63. /* 去新增 */
  64. openAction() {
  65. this.setData({
  66. createShow: true
  67. })
  68. },
  69. createBor({
  70. detail
  71. }) {
  72. this.onCancel();
  73. if (detail.name == '按借用合同借用') {
  74. let usertype = wx.getStorageSync('userMsg').usertype,
  75. that = this;
  76. if (usertype == 1) {
  77. wx.navigateTo({
  78. url: `/select/agent/index?params=${JSON.stringify({
  79. "id": 20220920083901,
  80. "content": {
  81. nocache:true,
  82. "where": {
  83. "condition": "",
  84. "type":9,
  85. }
  86. }
  87. })}&radio=true`,
  88. })
  89. getApp().globalData.handleSelect = function ({
  90. item
  91. }) {
  92. wx.redirectTo({
  93. url: `/select/contract/index?params=${JSON.stringify({
  94. "id": 20230114092502,
  95. "content": {
  96. nocache: true,
  97. "pageNumber": 1,
  98. "sys_enterpriseid":item.sys_enterpriseid,
  99. "pageTotal": 1,
  100. "total": null,
  101. "pageSize": 20,
  102. "where": {
  103. "condition": ""
  104. }
  105. }
  106. })}&radio=false`,
  107. success() {
  108. getApp().globalData.handleSelect = that.handleCreated.bind(this);
  109. }
  110. })
  111. }
  112. } else {
  113. wx.navigateTo({
  114. url: `/select/contract/index?params=${JSON.stringify({
  115. "id": 20230114092502,
  116. "content": {
  117. nocache: true,
  118. "pageNumber": 1,
  119. "pageTotal": 1,
  120. "total": null,
  121. "pageSize": 20,
  122. typemx:"合同借用",
  123. "where": {
  124. "condition": ""
  125. }
  126. }
  127. })}&radio=false`
  128. })
  129. getApp().globalData.handleSelect = this.handleCreated.bind(this);
  130. }
  131. } else {
  132. if (this.data.userrole == '业务员') {
  133. wx.navigateTo({
  134. url: `/select/agent/index?params=${JSON.stringify({
  135. "id": 20220920083901,
  136. "content": {
  137. nocache:true,
  138. "where": {
  139. "condition": "",
  140. "type":9,
  141. }
  142. }
  143. })}&radio=true`,
  144. })
  145. getApp().globalData.handleSelect = this.handleSingle.bind(this);
  146. } else {
  147. _Http.basic({
  148. "id": 20230116092702,
  149. "content": {
  150. "sa_orderid": 0
  151. }
  152. }).then(res => {
  153. console.log("按个", res)
  154. if (res.msg != '成功') return wx.showToast({
  155. title: res.msg,
  156. icon: "none"
  157. });
  158. wx.navigateTo({
  159. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  160. })
  161. })
  162. }
  163. }
  164. },
  165. handleSingle({
  166. item
  167. }) {
  168. wx.showModal({
  169. title: '提示',
  170. content: `是否确定选择"${item.enterprisename}"创建工具借用单?`,
  171. complete: (res) => {
  172. if (res.confirm) _Http.basic({
  173. "id": 20230116092702,
  174. "content": {
  175. "sa_orderid": 0,
  176. sys_enterpriseid: item.sys_enterpriseid
  177. }
  178. }).then(res => {
  179. console.log("按个", res)
  180. if (res.msg != '成功') return wx.showToast({
  181. title: res.msg,
  182. icon: "none"
  183. });
  184. wx.redirectTo({
  185. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  186. })
  187. })
  188. }
  189. })
  190. },
  191. handleCreated(e) {
  192. wx.showModal({
  193. title: '提示',
  194. content: `是否确认选择“${e.item.title}”创建借用单`,
  195. complete: ({
  196. confirm
  197. }) => {
  198. if (confirm) _Http.basic({
  199. "id": 20230116092702,
  200. "content": {
  201. "sa_contractid": e.id[0],
  202. "sa_orderid": 0
  203. }
  204. }).then(res => {
  205. console.log("按套", res)
  206. if (res.msg != '成功') return wx.showToast({
  207. title: res.msg,
  208. icon: "none"
  209. });
  210. _Http.basic({
  211. "id": 20230116142602,
  212. "content": {
  213. "sa_orderid": res.data.sa_orderid,
  214. "sys_enterpriseid": res.data.sys_enterpriseid,
  215. "sa_contractid": e.id[0]
  216. }
  217. }, false).then(s => {
  218. console.log("复制合同商品", s)
  219. wx.redirectTo({
  220. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  221. })
  222. })
  223. })
  224. }
  225. })
  226. },
  227. onCancel() {
  228. this.setData({
  229. createShow: false
  230. })
  231. },
  232. /* 搜索 */
  233. onSearch({
  234. detail
  235. }) {
  236. this.setData({
  237. "content.where.condition": detail
  238. });
  239. this.getList(true)
  240. },
  241. /* 切换tabs */
  242. tabsChange(e) {
  243. let status = "";
  244. switch (e.detail.title) {
  245. case '全部':
  246. status = "";
  247. break;
  248. case '待确认':
  249. status = "交期待确认";
  250. break;
  251. default:
  252. status = e.detail.title
  253. break;
  254. }
  255. this.setData({
  256. active: status
  257. });
  258. this.getList(true);
  259. },
  260. onReady() {
  261. this.setListHeight()
  262. },
  263. /* 设置页面高度 */
  264. setListHeight() {
  265. this.selectComponent("#ListBox").setHeight(".total", this);
  266. },
  267. })