index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. //引入网络请求
  2. import {
  3. ApiModel
  4. } from "../../utils/api.js"
  5. //引入文本校验
  6. import {
  7. TestVerify
  8. } from "../../utils/verify"
  9. const _Verify = new TestVerify()
  10. const _Http = new ApiModel()
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. disabled: false, //是否禁用
  17. brandName: "", //品牌名称
  18. classify: "", //经营类目
  19. contact: "", //联系人
  20. telephone: "", //电话号
  21. companyName: "", //公司名称
  22. companyIntroduce: "", //公司介绍
  23. companyAddress: "", //公司地址
  24. userCode: "", //统一社会编码
  25. fileList: "", //logo
  26. //必填项状态 是否红色字体
  27. ErrRed: {
  28. brandNameErrRed: false, //品牌名
  29. logoErrRed: false, //logo
  30. classifyErrRed: false, //经营类目
  31. contactErrRed: false, //联系人
  32. telephoneErrRed: false, //联系方式
  33. },
  34. logoErrTips: "", //logo格式/大小错误提示
  35. telephoneErrTitle: "", //手机号错误提示
  36. tagentsid: "", //上传图片使用
  37. butText: "立即创建", //按钮显示文本
  38. httpType:"商户认证",//请求方式
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. //判断个人中心进入
  45. if (options.type == "edit") {
  46. //查看是否为主账号
  47. const main = getApp().globalData.accountList[wx.getStorageSync('userIndex')];
  48. //更改按钮显示文本并隐藏跳过按钮
  49. this.setData({
  50. butText: "提交修改",
  51. httpType:"普通修改"
  52. })
  53. //非主账号禁用表单
  54. if (main != 1) {
  55. this.setData({
  56. disabled: true,
  57. })
  58. }
  59. }
  60. /* 查询商户信息 */
  61. _Http.basic({
  62. "accesstoken": wx.getStorageSync('token'),
  63. "classname": "customer.tagents.tagents",
  64. "method": "query_enterpriseAgentsMain",
  65. "content": {}
  66. }).then(s => {
  67. if (s.msg != "成功") return;
  68. let data = s.data[0];
  69. console.log(data)
  70. if (data.ftype == "普通商户") {
  71. this.refreshData(data)
  72. } else if (data.ftype == "个人" && data.fisauthenticating == 1) {
  73. //商户认证中
  74. wx.showToast({
  75. title: '商户认证审核中',
  76. icon: "none",
  77. duration: 5000
  78. })
  79. } else if (data.ftype == "个人" && data.fisauthenticating == 0) {
  80. //商户未认证
  81. this.setData({
  82. disabled: false,
  83. butText: "认证商户"
  84. })
  85. }
  86. })
  87. },
  88. /* 更新数据 */
  89. refreshData(data) {
  90. this.setData({
  91. brandName: data.fbrand, //品牌名称
  92. classify: data.saleprodclass, //经营类目
  93. contact: data.fcontact, //联系人
  94. telephone: data.fphonenumber, //电话号
  95. companyName: data.fagentname, //公司名称
  96. companyIntroduce: data.fintroduction, //公司介绍
  97. companyAddress: data.faddress, //公司地址
  98. userCode: data.fdutyparagraph, //统一社会编码
  99. tagentsid: data.tagentsid,//id
  100. fileList:data.attinfos[0].fobsurl
  101. })
  102. },
  103. /* 必填项获焦 */
  104. isInputFocus(e) {
  105. let data = this.data.ErrRed;
  106. data[e.currentTarget.dataset.name] = false;
  107. this.setData({
  108. ErrRed: data
  109. })
  110. },
  111. /* 必填项失焦 */
  112. isInputBlur(e) {
  113. let data = this.data.ErrRed;
  114. if (e.detail.value) return;
  115. data[e.currentTarget.dataset.name] = true;
  116. this.setData({
  117. ErrRed: data
  118. })
  119. },
  120. //联系方式失去焦点校验
  121. inputTelephoneBlur(e) {
  122. if (!_Verify.phoneNumber(this.data.telephone)) {
  123. let data = this.data.ErrRed;
  124. data[e.currentTarget.dataset.name] = true;
  125. this.setData({
  126. telephoneErrTitle: "手机号格式错误",
  127. ErrRed: data
  128. })
  129. return
  130. }
  131. this.setData({
  132. telephoneErrTitle: "",
  133. })
  134. },
  135. /* 上传图片 */
  136. afterRead(event) {
  137. // 初始化数据
  138. this.setData({
  139. logoErrTips: ""
  140. })
  141. var that = this
  142. const {
  143. file
  144. } = event.detail;
  145. var index = file.url.lastIndexOf(".");
  146. var ext = file.url.substr(index + 1);
  147. const fileName = file.url.split('/'),
  148. name = fileName[fileName.length - 1];
  149. //验证文件格式大小
  150. const Uploader = _Verify.verifyUploader({
  151. file
  152. });
  153. if (Uploader == "发送请求") {
  154. wx.getFileSystemManager().readFile({
  155. filePath: file.url,
  156. // encoding:'utf-8',
  157. success: result => {
  158. //返回临时文件路径
  159. const fileData = result.data
  160. _Http.basic({
  161. "accesstoken": wx.getStorageSync('token'),
  162. "classname": "system.system.docManage",
  163. "method": "getFileName",
  164. "content": {
  165. "filename": name,
  166. "filetype": ext,
  167. "ownertable": "tagents",
  168. "ownerid": that.data.tagentsid,
  169. "ftype": "brandlogo"
  170. }
  171. }).then(res => {
  172. that.uploadFile(res, fileData)
  173. }).catch(err => {
  174. console.log(err)
  175. })
  176. },
  177. fail: console.error
  178. })
  179. } else {
  180. this.setData({
  181. logoErrTips: Uploader
  182. })
  183. }
  184. },
  185. /* 上传成功反馈 */
  186. uploadFile(res, data) {
  187. var that = this
  188. wx.request({
  189. url: res.data.obsuploadurl,
  190. method: "PUT",
  191. data: data,
  192. header: {
  193. 'content-type': 'application/octet-stream' // 默认值
  194. },
  195. success() {
  196. _Http.basic({
  197. "accesstoken": wx.getStorageSync('token'),
  198. "classname": "system.system.docManage",
  199. "method": "uploadSuccess",
  200. "content": {
  201. "obsfilename": res.data.obsfilename
  202. }
  203. }).then(res => {
  204. if (res.msg != "成功") return;
  205. console.log(res)
  206. const fileList = [{
  207. url: res.data[0].fobsurl,
  208. tattachmentid: res.data[0].tattachmentid
  209. }]
  210. that.setData({
  211. fileList
  212. })
  213. }).catch(err => {
  214. console.log(err)
  215. })
  216. }
  217. })
  218. },
  219. /* 删除logo */
  220. logoDelete() {
  221. console.log(1)
  222. _Http.basic({
  223. "accesstoken": wx.getStorageSync('token'),
  224. "classname": "system.system.docManage",
  225. "method": "deleteDoc",
  226. "content": {
  227. "ownertable": "tagents",
  228. "ownerid": this.data.tagentsid,
  229. "tattachmentid": this.data.fileList.tattachmentid
  230. }
  231. }).then(s => {
  232. if (s.msg != "成功") return;
  233. this.setData({
  234. fileList: "",
  235. })
  236. })
  237. },
  238. /* 必填项目检测 */
  239. inputCertain() {
  240. let ErrRed = this.data.ErrRed,
  241. state = true;
  242. /* 品牌名 */
  243. if (!_Verify.required(this.data.brandName)) {
  244. ErrRed.brandNameErrRed = true;
  245. state = false;
  246. };
  247. /* logo */
  248. if (this.data.fileList == '') {
  249. this.setData({
  250. logoErrTips: "品牌Logo还未上传"
  251. })
  252. state = false;
  253. };
  254. /* 经营类目 */
  255. if (!_Verify.required(this.data.classify)) {
  256. ErrRed.classifyErrRed = true;
  257. state = false;
  258. };
  259. /* 联系人 */
  260. if (!_Verify.required(this.data.contact)) {
  261. ErrRed.contactErrRed = true;
  262. state = false;
  263. };
  264. /* 电话号 */
  265. if (!_Verify.phoneNumber(this.data.telephone)) {
  266. ErrRed.telephoneErrRed = true;
  267. state = false;
  268. };
  269. this.setData({
  270. ErrRed
  271. });
  272. return state;
  273. },
  274. /* 立即创建--完善设置商户信息 */
  275. setUserMsg() {
  276. //必填项,校验
  277. if (!this.inputCertain()) return;
  278. _Http.basic({
  279. "accesstoken": wx.getStorageSync('token'),
  280. "classname": "customer.tagents.tagents",
  281. "method": "modify_enterpriseAgent",
  282. "content": {
  283. "ftype": this.data.httpType,
  284. "data": [{
  285. "fagentnum": this.data.companyName,
  286. "fbrand": this.data.brandName,
  287. "fcontact": this.data.contact,
  288. "fphonenumber": this.data.telephone,
  289. "faddress": this.data.companyAddress,
  290. "fdutyparagraph": this.data.userCode,
  291. "fintroduction": this.data.companyIntroduce,
  292. "saleprodclass": this.data.classify
  293. }]
  294. }
  295. }).then(s => {
  296. if (s.msg != "成功") return;
  297. console.log(s)
  298. this.toHomePage();
  299. })
  300. },
  301. /* 跳过 */
  302. toHomePage() {
  303. wx.reLaunch({
  304. url: '/pages/tabbarPage/Home/index'
  305. })
  306. },
  307. /**
  308. * 生命周期函数--监听页面初次渲染完成
  309. */
  310. onReady: function () {
  311. },
  312. /**
  313. * 生命周期函数--监听页面显示
  314. */
  315. onShow: function () {
  316. },
  317. /**
  318. * 生命周期函数--监听页面隐藏
  319. */
  320. onHide: function () {
  321. },
  322. /**
  323. * 生命周期函数--监听页面卸载
  324. */
  325. onUnload: function () {
  326. },
  327. /**
  328. * 页面相关事件处理函数--监听用户下拉动作
  329. */
  330. onPullDownRefresh: function () {
  331. },
  332. /**
  333. * 页面上拉触底事件的处理函数
  334. */
  335. onReachBottom: function () {
  336. },
  337. /**
  338. * 用户点击右上角分享
  339. */
  340. onShareAppMessage: function () {
  341. }
  342. })