index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. isDisabled: false, //是否禁用
  15. butText: "保存", //按钮文字
  16. popups: false, //弹出层控制
  17. /* */
  18. fbrand: "", //品牌名称
  19. attinfos: [], // 图片列表
  20. isLogo: [], //用于判断是否上传logo
  21. saleprodclass: [], //经营类目
  22. showSaleprodclass: "", //显示经营类目
  23. fcontact: "", //联系人
  24. fphonenumber: "", //联系方式
  25. fagentname: "", //商户名称
  26. fintroduction: "", //商户介绍
  27. faddress: "", //地址
  28. fdutyparagraph: "", //统一社会代码
  29. requestType: "普通修改", //请求类型
  30. /* */
  31. errTips: {
  32. fbrand: false,
  33. attinfos: false,
  34. saleprodclass: false,
  35. fcontact: false,
  36. fphonenumber: false,
  37. fagentname: false,
  38. fintroduction: false,
  39. faddress: false,
  40. }
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. // 判断主子账号 是否禁用
  47. this.setData({
  48. isDisabled: (wx.getStorageSync('userData').fisadministrator == 1) ? false : true
  49. });
  50. //判断进入方式
  51. if (options.data == null) {
  52. console.log("注册进入")
  53. this.setData({
  54. requestType: "商户认证"
  55. })
  56. } else if (options.data == 1) {
  57. wx.showToast({
  58. title: '商户信息审核中',
  59. icon: 'none',
  60. duration: 5000
  61. });
  62. this.setData({
  63. requestType: "商户认证",
  64. isDisabled: true
  65. })
  66. } else {
  67. console.log("商户进入");
  68. const data = JSON.parse(options.data);
  69. console.log(data)
  70. this.returnData(data)
  71. }
  72. },
  73. /* 添加图片 */
  74. imageChange(data) {
  75. this.setData({
  76. attinfos: data.detail.fileList
  77. })
  78. },
  79. /* 选择类目回调 */
  80. saleprodChange(arr) {
  81. let detail = arr.detail,
  82. showSaleprodclass = "";
  83. for (let i = 0; i < detail.length; i++) {
  84. showSaleprodclass += (detail[i] + ',');
  85. };
  86. this.setData({
  87. popups: false,
  88. saleprodclass: detail,
  89. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  90. })
  91. },
  92. /* 返回数据 */
  93. returnData(data) {
  94. let attinfos = [];
  95. // 格式化图片
  96. if (data.attinfos.length >= 1) {
  97. const i = data.attinfos.length - 1;
  98. attinfos = [{
  99. url: data.attinfos[i].fobsurl,
  100. ownerid: data.attinfos[i].ownerid,
  101. tattachmentid: data.attinfos[i].tattachmentid,
  102. ownertable: data.attinfos[i].ownertable,
  103. fdocument: data.attinfos[i].fdocument
  104. }]
  105. }
  106. //格式化经营类目
  107. if (data.saleprodclass.length >= 1) {
  108. this.saleprodChange({
  109. detail: data.saleprodclass
  110. })
  111. }
  112. this.setData({
  113. fbrand: data.fbrand,
  114. saleprodclass: data.saleprodclass,
  115. fcontact: data.fcontact,
  116. fphonenumber: data.fphonenumber,
  117. fintroduction: data.fintroduction,
  118. fagentname: data.fagentname,
  119. faddress: data.faddress,
  120. fdutyparagraph: data.fdutyparagraph,
  121. attinfos,
  122. })
  123. },
  124. /* 提交数据 */
  125. submit() {
  126. if (!this.formVerify()) return wx.showToast({
  127. title: '请检查表单内容',
  128. icon: "error"
  129. });
  130. if (this.data.attinfos.length < 1) return wx.showToast({
  131. title: '请上传品牌LOGO!',
  132. icon: "none"
  133. });
  134. /* 发送请求 */
  135. _Http.basic({
  136. "accesstoken": wx.getStorageSync('userData').token,
  137. "classname": "customer.tagents.tagents",
  138. "method": "modify_enterpriseAgent",
  139. "content": {
  140. "ftype": this.data.requestType,
  141. "data": [{
  142. "fbrand": this.data.fbrand,
  143. "saleprodclass": this.data.saleprodclass,
  144. "fcontact": this.data.fcontact,
  145. "fphonenumber": this.data.fphonenumber,
  146. "fagentname": this.data.fagentname,
  147. "fintroduction": this.data.fintroduction,
  148. "faddress": this.data.faddress,
  149. "fdutyparagraph": this.data.fdutyparagraph,
  150. }]
  151. }
  152. }).then(res => {
  153. if (res.msg != '成功') return wx.showToast({
  154. title: res.data,
  155. })
  156. wx.showToast({
  157. title: '提交成功',
  158. });
  159. setTimeout(() => {
  160. wx.navigateBack({
  161. delta: 1,
  162. })
  163. }, 500)
  164. })
  165. },
  166. /* 表单验证 */
  167. formVerify() {
  168. let errTips = this.data.errTips,
  169. verify = true;
  170. /* 验证品牌名 */
  171. if (!_Verify.required(this.data.fbrand)) {
  172. errTips.fbrand = true;
  173. verify = false;
  174. }
  175. /* 验证经营类目 */
  176. if (!_Verify.required(this.data.showSaleprodclass)) {
  177. errTips.saleprodclass = true;
  178. verify = false;
  179. }
  180. /* 验证联系人 */
  181. if (!_Verify.required(this.data.fcontact)) {
  182. errTips.fcontact = true;
  183. verify = false;
  184. }
  185. /* 验证联系方式 */
  186. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  187. errTips.fphonenumber = true;
  188. verify = false;
  189. }
  190. /* 验证商户名称 */
  191. if (!_Verify.required(this.data.fagentname)) {
  192. errTips.fagentname = true;
  193. verify = false;
  194. }
  195. /* 验证商户介绍 */
  196. if (!_Verify.required(this.data.fintroduction)) {
  197. errTips.fintroduction = true;
  198. verify = false;
  199. }
  200. /* 验证地址 */
  201. if (!_Verify.required(this.data.faddress)) {
  202. errTips.faddress = true;
  203. verify = false;
  204. }
  205. this.setData({
  206. errTips
  207. })
  208. return verify;
  209. },
  210. /* 弹出层 */
  211. showPop() {
  212. if (this.data.isDisabled) return;
  213. this.setData({
  214. popups: !this.data.popups
  215. })
  216. },
  217. /* 获取焦点 */
  218. inputFocus(e) {
  219. const {
  220. name
  221. } = e.currentTarget.dataset;
  222. let errTips = this.data.errTips;
  223. errTips[name] = false;
  224. this.setData({
  225. errTips
  226. })
  227. },
  228. /* 失去焦点 */
  229. inputBlur(e) {
  230. const {
  231. name
  232. } = e.currentTarget.dataset;
  233. const {
  234. value
  235. } = e.detail;
  236. let errTips = this.data.errTips;
  237. /* 联系方式验证 */
  238. if (name == 'fphonenumber') {
  239. if(!_Verify.phoneNumber(this.data.fphonenumber, true)) errTips[name] = true;
  240. }
  241. if (value.trim() == "") {
  242. errTips[name] = true;
  243. }
  244. this.setData({
  245. errTips
  246. })
  247. },
  248. /* 更改logo */
  249. logoChange(data) {
  250. this.setData({
  251. isLogo: data.detail.fileList
  252. })
  253. },
  254. /**
  255. * 生命周期函数--监听页面初次渲染完成
  256. */
  257. onReady: function () {
  258. },
  259. /**
  260. * 生命周期函数--监听页面显示
  261. */
  262. onShow: function () {
  263. },
  264. /**
  265. * 生命周期函数--监听页面隐藏
  266. */
  267. onHide: function () {
  268. },
  269. /**
  270. * 生命周期函数--监听页面卸载
  271. */
  272. onUnload: function () {
  273. },
  274. /**
  275. * 页面相关事件处理函数--监听用户下拉动作
  276. */
  277. onPullDownRefresh: function () {
  278. },
  279. /**
  280. * 页面上拉触底事件的处理函数
  281. */
  282. onReachBottom: function () {
  283. },
  284. /**
  285. * 用户点击右上角分享
  286. */
  287. onShareAppMessage: function () {
  288. }
  289. })