applyFor.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. requestList: [], //请求列表
  11. showBtn: -1, //选中下标
  12. addvalue: "",
  13. scrolltolowerThrottle: true, //下拉触底截流
  14. pageNumber: 1, //请求分页
  15. pageTotal: 1, //总页数
  16. tabsList: ['建立新合作', '合作请求'], //tabs
  17. tabsIndex: 0, //tabs 选中下标
  18. show: false, //弹出层控制
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. /* 判断主副账号 */
  25. if (wx.getStorageSync('userData').fisadministrator == 0) {
  26. this.setData({
  27. tabsList: ['建立新合作']
  28. })
  29. }
  30. this.getList();
  31. },
  32. /* tabs切换页面 */
  33. setIndex({
  34. detail
  35. }) {
  36. this.setData({
  37. tabsIndex: detail
  38. })
  39. },
  40. /* 下拉触底 */
  41. scrolltolower() {
  42. if (!this.data.scrolltolowerThrottle) return;
  43. if (this.data.pageTotal < this.data.pageNumber) return;
  44. this.setData({
  45. scrolltolowerThrottle: false
  46. })
  47. this.getList();
  48. },
  49. /* 获得列表 */
  50. getList() {
  51. _Http.basic({
  52. "accesstoken": wx.getStorageSync('userData').token,
  53. "classname": "customer.tagents.tagents",
  54. "method": "query_cooperation",
  55. "content": {
  56. "getdatafromdbanyway": true,
  57. "pageNumber": this.data.pageNumber,
  58. "pageSize": 20,
  59. "where": {
  60. "condition": "",
  61. "ftype": "",
  62. "fstatus": "申请"
  63. }
  64. }
  65. }).then(res => {
  66. console.log(res)
  67. if (res.msg != "成功") return wx.showToast({
  68. title: res.data,
  69. icon: 'none'
  70. })
  71. let requestList = [];
  72. if (res.pageNumber == 1) {
  73. requestList = res.data
  74. } else {
  75. requestList = this.data.requestList.concat(res.data)
  76. }
  77. this.setData({
  78. requestList,
  79. scrolltolowerThrottle: true,
  80. pageTotal: res.pageTotal,
  81. pageNumber: this.data.pageNumber + 1
  82. })
  83. })
  84. },
  85. onChange({
  86. detail
  87. }) {
  88. this.setData({
  89. addvalue: detail
  90. })
  91. },
  92. onClick() {
  93. _Http.basic({
  94. "accesstoken": wx.getStorageSync('userData').token,
  95. "classname": "customer.tagents.tagents",
  96. "method": "apply_cooperation",
  97. "content": {
  98. "tcooperationagentsid": "27303",
  99. "ftype": "1"
  100. }
  101. }).then(res => {
  102. console.log(res)
  103. })
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady: function () {
  109. },
  110. /* 回调 */
  111. optionChange({
  112. detail
  113. }) {
  114. console.log(detail)
  115. let ftype = Number;
  116. const i = this.data.showBtn,
  117. content = (detail == '双向合作') ? '是否确定将“' + this.data.requestList[i].fbrand + '”作为您的“' + detail + '”伙伴' : '是否确定将“' + this.data.requestList[i].fbrand + '”作为您的“' + detail + '合作”伙伴',
  118. that = this;
  119. switch (detail) {
  120. case "上游":
  121. ftype = 1;
  122. break;
  123. case "下游":
  124. ftype = 2;
  125. break;
  126. case "双向合作":
  127. ftype = 3;
  128. break;
  129. };
  130. wx.showModal({
  131. title: '提示',
  132. content: content,
  133. success: function (res) {
  134. if (res.confirm) {
  135. _Http.basic({
  136. "accesstoken": wx.getStorageSync('userData').token,
  137. "classname": "customer.tagents.tagents",
  138. "method": "cooperation",
  139. "content": {
  140. "tcooperationagentsid": that.data.requestList[i].tcooperationagentsid,
  141. "ftype": ftype
  142. }
  143. }).then(res => {
  144. if (res.msg != '成功') return wx.showToast({
  145. title: res.data,
  146. icon: "none"
  147. });
  148. wx.showToast({
  149. title: '合作成功!',
  150. })
  151. let requestList = that.data.requestList;
  152. requestList.splice(i, 1);
  153. that.setData({
  154. requestList,
  155. showBtn: -1,
  156. show: false
  157. })
  158. })
  159. } else {
  160. that.setData({
  161. show: false
  162. })
  163. }
  164. }
  165. })
  166. },
  167. /* 选择 */
  168. showBtnIndex(e) {
  169. let {
  170. index
  171. } = e.currentTarget.dataset;
  172. if (index == this.data.showBtn) index = -1;
  173. this.setData({
  174. showBtn: index,
  175. })
  176. },
  177. /* 同意 */
  178. ratify() {
  179. this.setData({
  180. show: !this.data.show
  181. })
  182. },
  183. /* 拒绝 */
  184. refuse(e) {
  185. const {
  186. index
  187. } = e.currentTarget.dataset,
  188. that = this;
  189. wx.showModal({
  190. title: "提示",
  191. content: '是否确定拒绝“' + this.data.requestList[index].fbrand + '”的合作请求',
  192. success(res) {
  193. if (res.confirm) {
  194. _Http.basic({
  195. "accesstoken": wx.getStorageSync('userData').token,
  196. "classname": "customer.tagents.tagents",
  197. "method": "delete_cooperation",
  198. "content": {
  199. "tcooperationagentsid": that.data.requestList[index].tcooperationagentsid
  200. }
  201. }).then(res => {
  202. console.log(res)
  203. if (res.msg != '成功') return wx.showToast({
  204. title: res.data,
  205. icon: "none"
  206. });
  207. let requestList = that.data.requestList;
  208. requestList.splice(index, 1)
  209. that.setData({
  210. requestList
  211. })
  212. })
  213. }
  214. }
  215. })
  216. },
  217. /**
  218. * 生命周期函数--监听页面显示
  219. */
  220. onShow: function () {
  221. },
  222. /**
  223. * 生命周期函数--监听页面隐藏
  224. */
  225. onHide: function () {
  226. },
  227. /**
  228. * 生命周期函数--监听页面卸载
  229. */
  230. onUnload: function () {
  231. },
  232. /**
  233. * 页面相关事件处理函数--监听用户下拉动作
  234. */
  235. onPullDownRefresh: function () {
  236. },
  237. /**
  238. * 页面上拉触底事件的处理函数
  239. */
  240. onReachBottom: function () {
  241. },
  242. /**
  243. * 用户点击右上角分享
  244. */
  245. onShareAppMessage: function () {
  246. }
  247. })