buyerAdd.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // pages/buyerAdd/buyerAdd.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. type: 0, //0是新增,1是编辑
  9. list: [{
  10. selected: true,
  11. customerType: 2,
  12. text: '企业'
  13. }, {
  14. selected: false,
  15. customerType: 1,
  16. text: '个人及政府事业单位'
  17. }],
  18. currentIndex: 0,
  19. customerName: '',
  20. entTaxId: '',
  21. customerMobile: '',
  22. email: '',
  23. address: '',
  24. contactPhone: '',
  25. bankName: '',
  26. bankAccountNumber:""
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. this.setData({
  33. type: Number(options.type)
  34. })
  35. if (this.data.type === 1) {
  36. this.getDetail()
  37. wx.setNavigationBarTitle({
  38. title: '编辑购方'
  39. })
  40. }
  41. },
  42. //如果是编辑操作,就获取回显信息
  43. getDetail() {
  44. let detail = wx.getStorageSync('configBuyer')
  45. this.setData({
  46. customerName: detail.customerName,
  47. entTaxId: detail.customerEntTaxId,
  48. address: detail.address,
  49. contactPhone: detail.contactPhone,
  50. bankName: detail.bankName,
  51. bankAccountNumber: detail.bankAccountNumber,
  52. customerMobile: detail.customerMobile,
  53. email: detail.email,
  54. customerId: detail.customerId
  55. })
  56. },
  57. //提交
  58. submitData() {
  59. let params = {
  60. mobile: utils.getInfo().mobile,
  61. entTaxId: wx.getStorageSync('entTaxId'),
  62. reqChannel: 5,
  63. customerType: this.data.list[this.data.currentIndex].customerType,
  64. customerName: utils.trimAll(this.data.customerName),
  65. customerMobile: utils.trimAll(this.data.customerMobile),
  66. email: utils.trimAll(this.data.email)
  67. }
  68. if (this.data.type === 1) {
  69. params.customerId = this.data.customerId
  70. }
  71. if (params.customerName === '') {
  72. utils.toast('购方名称不能为空')
  73. return
  74. }
  75. if (this.data.currentIndex === 0) {
  76. if (utils.trimAll(this.data.entTaxId) === '') {
  77. utils.toast('税号不能为空')
  78. return
  79. } else {
  80. params.customerEntTaxId = utils.trimAll(this.data.entTaxId)
  81. }
  82. if (utils.trimAll(this.data.address) !== '') {
  83. params.address = utils.trimAll(this.data.address)
  84. }
  85. if (utils.trimAll(this.data.contactPhone) !== '') {
  86. params.contactPhone = utils.trimAll(this.data.contactPhone)
  87. }
  88. if (utils.trimAll(this.data.bankName) !== '') {
  89. params.bankName = utils.trimAll(this.data.bankName)
  90. }
  91. if (utils.trimAll(this.data.bankAccountNumber) !== '') {
  92. params.bankAccountNumber = utils.trimAll(this.data.bankAccountNumber)
  93. }
  94. }
  95. /* if (params.customerMobile === '') {
  96. utils.toast('您的个人手机号不能为空')
  97. return
  98. }
  99. if (params.email === '') {
  100. utils.toast('您的个人邮箱不能为空')
  101. return
  102. } */
  103. if (params.customerMobile !== '') {
  104. if (!utils.testMobile(params.customerMobile)) {
  105. utils.toast('请填写正确的手机号')
  106. return
  107. }
  108. }
  109. if (params.email !== '') {
  110. if (!utils.testEmail(params.email)) {
  111. utils.toast('请填写正确的邮箱')
  112. return
  113. }
  114. }
  115. utils.axios({
  116. method: 'post',
  117. url: '/sys/customer/saveOrUpdate',
  118. data: params,
  119. sendBefore() {
  120. wx.showLoading({
  121. title: '购方保存中...',
  122. mask: true
  123. })
  124. },
  125. complete() {
  126. wx.hideLoading()
  127. },
  128. success: res => {
  129. utils.funPrev(prev => {
  130. prev.toFresh()
  131. utils.toast('购方保存成功')
  132. wx.navigateBack()
  133. })
  134. }
  135. })
  136. },
  137. //选择
  138. choose(e) {
  139. let index = Number(e.currentTarget.dataset.index)
  140. let list = this.data.list
  141. for (let i = 0; i < list.length; i++) {
  142. list[i].selected = false
  143. }
  144. list[index].selected = true
  145. this.setData({
  146. list,
  147. currentIndex: index
  148. })
  149. },
  150. //购方名
  151. getcustomerName(e) {
  152. let value = e.detail.value
  153. this.setData({
  154. customerName: value
  155. })
  156. },
  157. getentTaxId(e) {
  158. let value = e.detail.value
  159. this.setData({
  160. entTaxId: value
  161. })
  162. },
  163. getcustomerMobile(e) {
  164. let value = e.detail.value
  165. this.setData({
  166. customerMobile: value
  167. })
  168. },
  169. getemail(e) {
  170. let value = e.detail.value
  171. this.setData({
  172. email: value
  173. })
  174. },
  175. getaddress(e) {
  176. let value = e.detail.value
  177. this.setData({
  178. address: value
  179. })
  180. },
  181. getcontactPhone(e) {
  182. let value = e.detail.value
  183. this.setData({
  184. contactPhone: value
  185. })
  186. },
  187. getbankName(e) {
  188. let value = e.detail.value
  189. this.setData({
  190. bankName: value
  191. })
  192. },
  193. getbankAccountNumber(e) {
  194. let value = e.detail.value
  195. this.setData({
  196. bankAccountNumber: value
  197. })
  198. },
  199. /**
  200. * 生命周期函数--监听页面初次渲染完成
  201. */
  202. onReady: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload: function () {
  218. },
  219. /**
  220. * 页面相关事件处理函数--监听用户下拉动作
  221. */
  222. onPullDownRefresh: function () {
  223. },
  224. /**
  225. * 页面上拉触底事件的处理函数
  226. */
  227. onReachBottom: function () {
  228. },
  229. /**
  230. * 用户点击右上角分享
  231. */
  232. onShareAppMessage: function () {
  233. }
  234. })