index.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. if (usertype == 1) {
  76. wx.navigateTo({
  77. url: `/select/agent/index?params=${JSON.stringify({
  78. "id": 20220920083901,
  79. "content": {
  80. nocache:true,
  81. "where": {
  82. "condition": "",
  83. "type":9,
  84. }
  85. }
  86. })}&radio=true`,
  87. })
  88. getApp().globalData.handleSelect = function ({
  89. item
  90. }) {
  91. console.log(item)
  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. })
  108. getApp().globalData.handleSelect = this.handleCreated.bind(this);
  109. }
  110. } else {
  111. wx.navigateTo({
  112. url: `/select/contract/index?params=${JSON.stringify({
  113. "id": 20230114092502,
  114. "content": {
  115. nocache: true,
  116. "pageNumber": 1,
  117. "pageTotal": 1,
  118. "total": null,
  119. "pageSize": 20,
  120. typemx:"合同借用",
  121. "where": {
  122. "condition": ""
  123. }
  124. }
  125. })}&radio=false`
  126. })
  127. getApp().globalData.handleSelect = this.handleCreated.bind(this);
  128. }
  129. } else {
  130. if (this.data.userrole == '业务员') {
  131. wx.navigateTo({
  132. url: `/select/agent/index?params=${JSON.stringify({
  133. "id": 20220920083901,
  134. "content": {
  135. nocache:true,
  136. "where": {
  137. "condition": "",
  138. "type":9,
  139. }
  140. }
  141. })}&radio=true`,
  142. })
  143. getApp().globalData.handleSelect = this.handleSingle.bind(this);
  144. } else {
  145. _Http.basic({
  146. "id": 20230116092702,
  147. "content": {
  148. "sa_orderid": 0
  149. }
  150. }).then(res => {
  151. console.log("按个", res)
  152. if (res.msg != '成功') return wx.showToast({
  153. title: res.msg,
  154. icon: "none"
  155. });
  156. wx.navigateTo({
  157. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  158. })
  159. })
  160. }
  161. }
  162. },
  163. handleSingle({
  164. item
  165. }) {
  166. wx.showModal({
  167. title: '提示',
  168. content: `是否确定选择"${item.enterprisename}"创建工具借用单?`,
  169. complete: (res) => {
  170. if (res.confirm) _Http.basic({
  171. "id": 20230116092702,
  172. "content": {
  173. "sa_orderid": 0,
  174. sys_enterpriseid: item.sys_enterpriseid
  175. }
  176. }).then(res => {
  177. console.log("按个", res)
  178. if (res.msg != '成功') return wx.showToast({
  179. title: res.msg,
  180. icon: "none"
  181. });
  182. wx.redirectTo({
  183. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  184. })
  185. })
  186. }
  187. })
  188. },
  189. handleCreated(e) {
  190. wx.showModal({
  191. title: '提示',
  192. content: `是否确认选择“${e.item.title}”创建借用单`,
  193. complete: ({
  194. confirm
  195. }) => {
  196. if (confirm) _Http.basic({
  197. "id": 20230116092702,
  198. "content": {
  199. "sa_contractid": e.id[0],
  200. "sa_orderid": 0
  201. }
  202. }).then(res => {
  203. console.log("按套", res)
  204. if (res.msg != '成功') return wx.showToast({
  205. title: res.msg,
  206. icon: "none"
  207. });
  208. _Http.basic({
  209. "id": 20230116142602,
  210. "content": {
  211. "sa_orderid": res.data.sa_orderid,
  212. "sys_enterpriseid": res.data.sys_enterpriseid,
  213. "sa_contractid": e.id[0]
  214. }
  215. }, false).then(s => {
  216. console.log("复制合同商品", s)
  217. wx.redirectTo({
  218. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  219. })
  220. })
  221. })
  222. }
  223. })
  224. },
  225. onCancel() {
  226. this.setData({
  227. createShow: false
  228. })
  229. },
  230. /* 搜索 */
  231. onSearch({
  232. detail
  233. }) {
  234. this.setData({
  235. "content.where.condition": detail
  236. });
  237. this.getList(true)
  238. },
  239. /* 切换tabs */
  240. tabsChange(e) {
  241. let status = "";
  242. switch (e.detail.title) {
  243. case '全部':
  244. status = "";
  245. break;
  246. case '待确认':
  247. status = "交期待确认";
  248. break;
  249. default:
  250. status = e.detail.title
  251. break;
  252. }
  253. this.setData({
  254. active: status
  255. });
  256. this.getList(true);
  257. },
  258. onReady() {
  259. this.setListHeight()
  260. },
  261. /* 设置页面高度 */
  262. setListHeight() {
  263. this.selectComponent("#ListBox").setHeight(".total", this);
  264. },
  265. })