index.js 8.4 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. fisadministrator: (wx.getStorageSync('userData').fisadministrator == 1) ? true : 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. _Http.basic({
  47. "accesstoken": wx.getStorageSync('userData').token,
  48. "classname": "customer.tagents.tagents",
  49. "method": "query_enterpriseAgentsMain",
  50. "content": {}
  51. }).then(res => {
  52. const data = res.data[0];
  53. if (data.ftype == '个人' && data.fisauthenticating == 1) {
  54. wx.showToast({
  55. title: '商户信息审核中',
  56. icon: "none",
  57. duration: 5000,
  58. })
  59. this.setData({
  60. butText: "审核中",
  61. fisadministrator: false
  62. })
  63. this.returnData(data)
  64. } else if (data.ftype == '个人' && data.fisauthenticating == 0) {
  65. this.setData({
  66. requestType: "商户认证",
  67. butText: "立即认证"
  68. })
  69. } else {
  70. this.returnData(data)
  71. };
  72. })
  73. },
  74. /* 添加图片 */
  75. imageChange(data) {
  76. this.setData({
  77. attinfos: data.detail.fileList
  78. })
  79. },
  80. /* 选择类目回调 */
  81. saleprodChange(arr) {
  82. let {
  83. detail
  84. } = arr, showSaleprodclass = "";
  85. for (let i = 0; i < detail.length; i++) {
  86. showSaleprodclass += (detail[i] + ',');
  87. };
  88. this.setData({
  89. popups: false,
  90. saleprodclass: detail,
  91. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  92. })
  93. },
  94. /* 返回数据 */
  95. returnData(data) {
  96. let attinfos = [];
  97. for (let i = 0; i < data.attinfos.length; i++) {
  98. let arr = {
  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. attinfos.push(arr)
  106. };
  107. //格式化经营类目
  108. if (data.saleprodclass.length >= 1) {
  109. this.saleprodChange({
  110. detali: data.saleprodclass
  111. })
  112. }
  113. this.setData({
  114. fbrand: data.fbrand,
  115. saleprodclass: data.saleprodclass,
  116. fcontact: data.fcontact,
  117. fphonenumber: data.fphonenumber,
  118. fintroduction: data.fintroduction,
  119. fagentname: data.fagentname,
  120. faddress: data.faddress,
  121. fdutyparagraph: data.fdutyparagraph,
  122. attinfos,
  123. isLogo: imageData
  124. })
  125. },
  126. /* 提交数据 */
  127. submit() {
  128. if (!this.data.fisadministrator) return wx.showToast({
  129. title: '当前无权限修改',
  130. icon: "none"
  131. });
  132. if (!this.formVerify()) return wx.showToast({
  133. title: '请检查表单内容',
  134. icon: "error"
  135. });
  136. /* 验证附件列表 */
  137. if (!_Verify.required(this.data.isLogo, "请上传品牌logo")) return;
  138. /* 发送请求 */
  139. _Http.basic({
  140. "accesstoken": wx.getStorageSync('userData').token,
  141. "classname": "customer.tagents.tagents",
  142. "method": "modify_enterpriseAgent",
  143. "content": {
  144. "ftype": this.data.requestType,
  145. "data": [{
  146. "fbrand": this.data.fbrand,
  147. "saleprodclass": this.data.saleprodclass,
  148. "fcontact": this.data.fcontact,
  149. "fphonenumber": this.data.fphonenumber,
  150. "fagentname": this.data.fagentname,
  151. "fintroduction": this.data.fintroduction,
  152. "faddress": this.data.faddress,
  153. "fdutyparagraph": this.data.fdutyparagraph,
  154. }]
  155. }
  156. }).then(res => {
  157. if (res.data == '成功') {
  158. wx.showToast({
  159. title: '提交成功',
  160. });
  161. wx.navigateBack({
  162. delta: 1,
  163. })
  164. }
  165. })
  166. },
  167. /* 表单验证 */
  168. formVerify() {
  169. let errTips = this.data.errTips,
  170. verify = true;
  171. /* 验证品牌名 */
  172. if (!_Verify.required(this.data.fbrand)) {
  173. errTips.fbrand = true;
  174. verify = false;
  175. }
  176. /* 验证经营类目 */
  177. if (!_Verify.required(this.data.saleprodclass)) {
  178. errTips.saleprodclass = true;
  179. verify = false;
  180. }
  181. /* 验证联系人 */
  182. if (!_Verify.required(this.data.fcontact)) {
  183. errTips.fcontact = true;
  184. verify = false;
  185. }
  186. /* 验证联系方式 */
  187. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  188. errTips.fphonenumber = true;
  189. verify = false;
  190. }
  191. /* 验证商户名称 */
  192. if (!_Verify.required(this.data.fagentname)) {
  193. errTips.fagentname = true;
  194. verify = false;
  195. }
  196. /* 验证商户介绍 */
  197. if (!_Verify.required(this.data.fintroduction)) {
  198. errTips.fintroduction = true;
  199. verify = false;
  200. }
  201. /* 验证地址 */
  202. if (!_Verify.required(this.data.faddress)) {
  203. errTips.faddress = true;
  204. verify = false;
  205. }
  206. this.setData({
  207. errTips
  208. })
  209. return verify;
  210. },
  211. /* 弹出层 */
  212. showPop() {
  213. if (!this.data.fisadministrator) return;
  214. this.setData({
  215. popups: !this.data.popups
  216. })
  217. },
  218. /* 获取焦点 */
  219. inputFocus(e) {
  220. const {
  221. name
  222. } = e.currentTarget.dataset;
  223. let errTips = this.data.errTips;
  224. errTips[name] = false;
  225. this.setData({
  226. errTips
  227. })
  228. },
  229. /* 失去焦点 */
  230. inputBlur(e) {
  231. const {
  232. name
  233. } = e.currentTarget.dataset;
  234. const {
  235. value
  236. } = e.detail;
  237. /* 联系方式验证 */
  238. if (name == 'fphonenumber') {
  239. _Verify.phoneNumber(this.data.fphonenumber, true)
  240. }
  241. if (value.trim() == "") {
  242. let errTips = this.data.errTips;
  243. errTips[name] = true;
  244. this.setData({
  245. errTips
  246. })
  247. }
  248. },
  249. /* 更改logo */
  250. logoChange(data) {
  251. this.setData({
  252. isLogo: data.detail.fileList
  253. })
  254. },
  255. /**
  256. * 生命周期函数--监听页面初次渲染完成
  257. */
  258. onReady: function () {
  259. },
  260. /**
  261. * 生命周期函数--监听页面显示
  262. */
  263. onShow: function () {
  264. },
  265. /**
  266. * 生命周期函数--监听页面隐藏
  267. */
  268. onHide: function () {
  269. },
  270. /**
  271. * 生命周期函数--监听页面卸载
  272. */
  273. onUnload: function () {
  274. },
  275. /**
  276. * 页面相关事件处理函数--监听用户下拉动作
  277. */
  278. onPullDownRefresh: function () {
  279. },
  280. /**
  281. * 页面上拉触底事件的处理函数
  282. */
  283. onReachBottom: function () {
  284. },
  285. /**
  286. * 用户点击右上角分享
  287. */
  288. onShareAppMessage: function () {
  289. }
  290. })