You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
5.2 KiB

  1. const Http = require('../../utils/HttpBasics.js')
  2. const config = require('../../config/config.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. tihuoWay: '微信商户号',
  9. accountData: "",
  10. accountTypeValue: 0,
  11. isFlag: false,
  12. accountCode: false,
  13. cOpendId: ''
  14. },
  15. /**
  16. * 查询收款账户状态
  17. */
  18. findAccountById(merchant_id) {
  19. Http.get({
  20. url: config.api.findAccountById,
  21. data: {
  22. id: merchant_id
  23. }
  24. }).then(res => {
  25. /**
  26. * receiverAccount
  27. * 如有:已设置收款账户
  28. * 没有;未设置收款账户
  29. */
  30. if (res && res.data && res.data.receiver) {
  31. this.setData({
  32. isSet: true,
  33. receiverAccount: res.data.receiver.receiverAccount,
  34. accountData: res.data.receiver
  35. })
  36. } else {
  37. this.setData({
  38. isSet: false
  39. })
  40. }
  41. }).catch(error => {
  42. wx.showToast({
  43. title: error.message,
  44. icon: "none"
  45. })
  46. })
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. let that = this;
  53. if (options && options.merchant_id) {
  54. that.findAccountById(options.merchant_id)
  55. that.setData({
  56. merchant_id: options.merchant_id,
  57. phone: options.phone
  58. })
  59. }
  60. if (options && options.merchant_name) {
  61. that.setData({
  62. merchant_name: options.merchant_name,
  63. phone: options.phone
  64. })
  65. }
  66. this.getAccount(options.phone);
  67. },
  68. //查询商户C端授权状态
  69. getAccount(phone) {
  70. let that = this;
  71. Http.get({
  72. url: `${config.api.getOpenIdByPhone}?phone=${phone}`,
  73. data: {
  74. phone
  75. }
  76. }).then(res => {
  77. console.log(res, 111)//
  78. this.setData({
  79. haveAccount: res.message,
  80. cOpendId: res.data
  81. })
  82. }).catch(error => {
  83. console.log(error, 222)
  84. this.setData({
  85. haveAccount: error.message
  86. })
  87. })
  88. },
  89. // 提交
  90. formSubmit: function (e) {
  91. let that = this;
  92. let accountTypeValue = that.data.accountTypeValue;
  93. let accountId = e.detail.value.id;
  94. let accountName = e.detail.value.name;
  95. let id = that.data.merchant_id;
  96. let name = that.data.merchant_name;
  97. that.setData({
  98. select: false
  99. })
  100. if (!accountId) {
  101. if (accountTypeValue == 0) {
  102. wx.showToast({
  103. title: '商户号不能为空',
  104. icon: "none"
  105. })
  106. }
  107. if (accountTypeValue == 1) {
  108. wx.showToast({
  109. title: '微信号不能为空',
  110. icon: "none"
  111. })
  112. }
  113. }
  114. if (!accountName) {
  115. if (accountTypeValue == 0) {
  116. wx.showToast({
  117. title: '商户名不能为空',
  118. icon: "none"
  119. })
  120. }
  121. if (accountTypeValue == 1) {
  122. wx.showToast({
  123. title: '姓名不能为空',
  124. icon: "none"
  125. })
  126. }
  127. }
  128. let data = {
  129. accountTypeValue: that.data.accountTypeValue == 1 ? 3 : that.data.accountTypeValue,
  130. accountId: (that.data.accountTypeValue == 0 ? e.detail.value.id : this.data.cOpendId).replace(/\s+/g, ""),
  131. accountName: (e.detail.value.name).replace(/\s+/g, ""),
  132. id: that.data.merchant_id,
  133. name: that.data.merchant_name
  134. }
  135. console.log(data)
  136. if (!data.accountId) {
  137. wx.showToast({
  138. title: '当前状态不能提交',
  139. icon: "none"
  140. })
  141. return;
  142. }
  143. if (accountId && accountName && id && name) {
  144. Http.post({
  145. url: config.api.updateAccount,
  146. data: data
  147. }).then(res => {
  148. wx.navigateTo({
  149. url: '/pages/accountManagement/result/success',
  150. })
  151. }).catch(error => {
  152. wx.showToast({
  153. title: error.message,
  154. icon: "none"
  155. })
  156. })
  157. }
  158. },
  159. submitAccount() {
  160. let that = this;
  161. let data = {
  162. accountTypeValue: 3,
  163. accountId: (this.data.cOpendId).replace(/\s+/g, ""),
  164. accountName: (this.data.accountData.trueName).replace(/\s+/g, ""),
  165. id: this.data.accountData.merchantId,
  166. name: that.data.merchant_name
  167. }
  168. console.log(data)
  169. if (data.accountId && data.accountName && data.id && data.name) {
  170. Http.post({
  171. url: config.api.updateAccount,
  172. data: data
  173. }).then(res => {
  174. wx.navigateTo({
  175. url: '/pages/accountManagement/result/success',
  176. })
  177. }).catch(error => {
  178. wx.showToast({
  179. title: error.message,
  180. icon: "none"
  181. })
  182. })
  183. }
  184. },
  185. bindShowMsg(e) {
  186. this.setData({
  187. select: !this.data.select
  188. })
  189. },
  190. mySelect(e) {
  191. var name = e.currentTarget.dataset.name
  192. this.setData({
  193. tihuoWay: name,
  194. accountTypeValue: e.currentTarget.dataset.accounttypevalue,
  195. select: false
  196. })
  197. },
  198. //申请变更
  199. reset() {
  200. let that = this;
  201. that.setData({
  202. isFlag: true
  203. })
  204. },
  205. //删除账号得信息
  206. deleteByReceiverId(e) {
  207. Http.get({
  208. url: config.api.deleteByReceiverId,
  209. data: {
  210. id: e.currentTarget.dataset.id
  211. }
  212. }).then(res => {
  213. wx.navigateTo({
  214. url: '/pages/accountManagement/result/success?type=delete',
  215. })
  216. }).catch(error => {
  217. wx.showToast({
  218. title: `${error.message}`,
  219. icon: "none"
  220. })
  221. })
  222. }
  223. })