index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. const that = this;
  135. if (this.data.requestType == '普通修改') {
  136. wx.showModal({
  137. title: '提示',
  138. content: "是否确认修改商户信息",
  139. success: (res => {
  140. if (res.confirm) {
  141. that.requestToSend();
  142. };
  143. })
  144. })
  145. } else {
  146. that.requestToSend();
  147. }
  148. },
  149. /* 发送请求 */
  150. requestToSend() {
  151. _Http.basic({
  152. "accesstoken": wx.getStorageSync('userData').token,
  153. "classname": "customer.tagents.tagents",
  154. "method": "modify_enterpriseAgent",
  155. "content": {
  156. "ftype": this.data.requestType,
  157. "data": [{
  158. "fbrand": this.data.fbrand,
  159. "saleprodclass": this.data.saleprodclass,
  160. "fcontact": this.data.fcontact,
  161. "fphonenumber": this.data.fphonenumber,
  162. "fagentname": this.data.fagentname,
  163. "fintroduction": this.data.fintroduction,
  164. "faddress": this.data.faddress,
  165. "fdutyparagraph": this.data.fdutyparagraph,
  166. }]
  167. }
  168. }).then(res => {
  169. if (res.msg != '成功') return wx.showToast({
  170. title: res.data,
  171. })
  172. wx.showToast({
  173. title: '提交成功',
  174. });
  175. setTimeout(() => {
  176. wx.navigateBack({
  177. delta: 1,
  178. })
  179. }, 500)
  180. })
  181. },
  182. /* 表单验证 */
  183. formVerify() {
  184. let errTips = this.data.errTips,
  185. verify = true;
  186. /* 验证品牌名 */
  187. if (!_Verify.required(this.data.fbrand)) {
  188. errTips.fbrand = true;
  189. verify = false;
  190. }
  191. /* 验证经营类目 */
  192. if (!_Verify.required(this.data.showSaleprodclass)) {
  193. errTips.saleprodclass = true;
  194. verify = false;
  195. }
  196. /* 验证联系人 */
  197. if (!_Verify.required(this.data.fcontact)) {
  198. errTips.fcontact = true;
  199. verify = false;
  200. }
  201. /* 验证联系方式 */
  202. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  203. errTips.fphonenumber = true;
  204. verify = false;
  205. }
  206. /* 验证商户名称 */
  207. if (!_Verify.required(this.data.fagentname)) {
  208. errTips.fagentname = true;
  209. verify = false;
  210. }
  211. /* 验证商户介绍 */
  212. if (!_Verify.required(this.data.fintroduction)) {
  213. errTips.fintroduction = true;
  214. verify = false;
  215. }
  216. /* 验证地址 */
  217. if (!_Verify.required(this.data.faddress)) {
  218. errTips.faddress = true;
  219. verify = false;
  220. }
  221. this.setData({
  222. errTips
  223. })
  224. return verify;
  225. },
  226. /* 弹出层 */
  227. showPop() {
  228. if (this.data.isDisabled) return;
  229. this.setData({
  230. popups: !this.data.popups
  231. })
  232. },
  233. /* 获取焦点 */
  234. inputFocus(e) {
  235. const {
  236. name
  237. } = e.currentTarget.dataset;
  238. let errTips = this.data.errTips;
  239. errTips[name] = false;
  240. this.setData({
  241. errTips
  242. })
  243. },
  244. /* 失去焦点 */
  245. inputBlur(e) {
  246. const {
  247. name
  248. } = e.currentTarget.dataset;
  249. const {
  250. value
  251. } = e.detail;
  252. let errTips = this.data.errTips;
  253. /* 联系方式验证 */
  254. if (name == 'fphonenumber') {
  255. if (!_Verify.phoneNumber(this.data.fphonenumber, true)) errTips[name] = true;
  256. }
  257. if (value.trim() == "") {
  258. errTips[name] = true;
  259. }
  260. this.setData({
  261. errTips
  262. })
  263. },
  264. /* 更改logo */
  265. logoChange(data) {
  266. this.setData({
  267. isLogo: data.detail.fileList
  268. })
  269. },
  270. /**
  271. * 生命周期函数--监听页面初次渲染完成
  272. */
  273. onReady: function () {
  274. },
  275. /**
  276. * 生命周期函数--监听页面显示
  277. */
  278. onShow: function () {
  279. },
  280. /**
  281. * 生命周期函数--监听页面隐藏
  282. */
  283. onHide: function () {
  284. },
  285. /**
  286. * 生命周期函数--监听页面卸载
  287. */
  288. onUnload: function () {
  289. },
  290. /**
  291. * 页面相关事件处理函数--监听用户下拉动作
  292. */
  293. onPullDownRefresh: function () {
  294. },
  295. /**
  296. * 页面上拉触底事件的处理函数
  297. */
  298. onReachBottom: function () {
  299. },
  300. /**
  301. * 用户点击右上角分享
  302. */
  303. onShareAppMessage: function () {
  304. }
  305. })