index.js 8.2 KB

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