JPattributeEditor.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <div class="JPattributeEditor">
  3. <van-nav-bar class="navBar" title="金牌店档案编辑" left-arrow @click-left="onClickLeft" />
  4. <div class="content" v-if="detail">
  5. <van-form ref="tabstoreVal">
  6. <van-field
  7. class="sendCode"
  8. v-model="detail.ownerMobile"
  9. label="主经营者电话"
  10. placeholder="请输入主经营者电话"
  11. @blur="sendCodeTelFn(detail.ownerMobile)"
  12. type="tel">
  13. <template #button v-if="!verifyMobile">
  14. <van-button
  15. size="small"
  16. style="color: white; background: rgb(0, 87, 186); border-radius: 6px"
  17. @click="sendCode(detail.ownerMobile)"
  18. :disabled="telConfirm">
  19. <span v-if="telConfirm">已确认</span>
  20. <span v-else>确认真实</span>
  21. </van-button>
  22. </template>
  23. </van-field>
  24. <span style="color: #ee0a24;font-size: 12px;">为了不打扰金牌店老板,不再发送短信验证码,请务必确认手机号正确无误!</span>
  25. <!-- <van-field
  26. v-model="verificationVal"
  27. label="主经营者收到的验证码"
  28. placeholder="请输入验证码"
  29. type="number"
  30. @blur="verification(verificationVal)"
  31. v-if="!verifyMobile" /> -->
  32. <van-field v-model="detail.ownerName" :error-message="ownerNameMsg" label="主经营者姓名" />
  33. <!-- <van-field
  34. v-model="detail.ownerBirthday"
  35. label="主经营者出生日期"
  36. placeholder="请输入主经营者出生日期"
  37. @click="getNyr('ownerBirthday', detail.ownerBirthday)" /> -->
  38. <van-field autosize type="textarea" label="主营/擅长经营品类">
  39. <template #input>
  40. <van-checkbox-group v-model="detail.mainProductCategorys" direction="horizontal">
  41. <van-checkbox
  42. v-for="(item, index) in mainProductCategorys"
  43. :name="item.dictValue"
  44. shape="square"
  45. :key="index">
  46. {{ item.dictValue }}
  47. </van-checkbox>
  48. </van-checkbox-group>
  49. </template>
  50. </van-field>
  51. <van-field
  52. v-model="detail.totalSalesAmount"
  53. type="number"
  54. :error-message="totalSalesAmountMsg"
  55. label="门店24年总进货额(含所有品牌品类,单位:万元)" />
  56. <van-field
  57. v-model="detail.performanceRatio"
  58. type="number"
  59. :error-message="performanceRatioMsg"
  60. label="门店立邦业绩占比(单位:%)" />
  61. <van-field
  62. v-model="detail.mainBrand"
  63. autosize
  64. type="textarea"
  65. :error-message="mainBrandMsg"
  66. label="门店主营TOP3品牌" />
  67. <van-field label="是否有工地资源(支持工地配送,承接工地双包等)">
  68. <template #input>
  69. <van-radio-group
  70. v-model="detail.constructionResource"
  71. direction="horizontal"
  72. @change="changeResource">
  73. <van-radio name="是">是</van-radio>
  74. <van-radio name="否">否</van-radio>
  75. </van-radio-group>
  76. </template>
  77. </van-field>
  78. <van-field
  79. v-if="detail.constructionResource == '是'"
  80. v-model="detail.constructionYearNum"
  81. type="number"
  82. :error-message="constructionYearNumMsg"
  83. label="年工地数量" />
  84. <van-field label="是否有双包能力">
  85. <template #input>
  86. <van-radio-group v-model="detail.doubleContracting" direction="horizontal">
  87. <van-radio name="是">是</van-radio>
  88. <van-radio name="否">否</van-radio>
  89. </van-radio-group>
  90. </template>
  91. </van-field>
  92. <van-field label="紧急联系人身份">
  93. <template #input>
  94. <van-radio-group v-model="detail.emergencyContactRelation" direction="horizontal">
  95. <van-radio
  96. v-for="(item, index) in emergencyContactRelation"
  97. :name="item.dictValue"
  98. :key="index">
  99. {{ item.dictValue }}
  100. </van-radio>
  101. </van-radio-group>
  102. </template>
  103. </van-field>
  104. <van-field v-model="detail.emergencyContact" label="紧急联系人姓名" />
  105. <!-- <van-field
  106. v-model="detail.emergencyContactBirthday"
  107. label="紧急联系人出生日期"
  108. @click="getNyr('emergencyContactBirthday', detail.emergencyContactBirthday)" /> -->
  109. <van-field
  110. v-model="detail.emergencyContactMobile"
  111. type="number"
  112. @blur="emergencyContactBlur(detail.emergencyContactMobile)"
  113. label="紧急联系人电话" />
  114. </van-form>
  115. </div>
  116. <div class="footer-btn">
  117. <van-button
  118. style="color: white; background: rgb(0, 87, 186); border-radius: 6px; width: 90%"
  119. @click="confirmShare">
  120. 保 存
  121. </van-button>
  122. </div>
  123. <!-- 时间选择 -->
  124. <van-popup v-model="datetimeShowPicker" position="bottom">
  125. <van-datetime-picker
  126. v-model="currentDate"
  127. type="date"
  128. title="选择年月日"
  129. :min-date="minDate"
  130. :max-date="maxDate"
  131. @confirm="datetimeOnConfirm"
  132. @cancel="datetimeShowPicker = false" />
  133. </van-popup>
  134. </div>
  135. </template>
  136. <script>
  137. import { sendAndCheckVerCode, getDictOption } from '@/api/index';
  138. import { getStoreArchives, updateArchives } from '@/api/storeManagement';
  139. export default {
  140. name: 'JPattributeEditor',
  141. data() {
  142. return {
  143. ownerNameMsg: '',
  144. totalSalesAmountMsg: '',
  145. performanceRatioMsg: '',
  146. mainBrandMsg: '',
  147. constructionYearNumMsg: '',
  148. detail: null,
  149. time: null, //计时
  150. timeNum: 60,
  151. verificationVal: '',
  152. datetimeShowPicker: false,
  153. activatNyrItem: '',
  154. checkboxGroup: [],
  155. mainProductCategorys: [],
  156. emergencyContactRelation: [],
  157. verificationPassedPhoneNum: '', //验证通过手机号
  158. minDate: new Date(1945, 0, 1),
  159. maxDate: new Date(),
  160. currentDate: new Date(1945, 0, 1),
  161. mobileStatus: '0',
  162. verifyMobile: false, //手机号是否验证透通过
  163. checkRadioFlag: false,
  164. telConfirm: false,
  165. };
  166. },
  167. activated() {
  168. this.telConfirm = false;
  169. this.ownerNameMsg = '';
  170. this.totalSalesAmountMsg = '';
  171. this.performanceRatioMsg = '';
  172. this.mainBrandMsg = '';
  173. this.constructionYearNumMsg = '';
  174. this.detail = null;
  175. this.verificationVal = '';
  176. if (this.time) clearInterval(this.time);
  177. this.time = null; //计时
  178. this.timeNum = 60;
  179. this.toastLoading(0, '加载中...', true);
  180. getDictOption({}, 'archives_main_product_categorys').then((res) => {
  181. let mainProductCategorys = [];
  182. let emergencyContactRelation = [];
  183. res.data.forEach((val) => {
  184. if (val.remark == 'mainProductCategorys') {
  185. mainProductCategorys.push(val);
  186. } else {
  187. emergencyContactRelation.push(val);
  188. }
  189. });
  190. this.mainProductCategorys = mainProductCategorys;
  191. this.emergencyContactRelation = emergencyContactRelation;
  192. this.getDetaild();
  193. });
  194. },
  195. methods: {
  196. getDetaild() {
  197. getStoreArchives({ storeCode: this.$route.query.storeCode }).then((res) => {
  198. this.toastLoading().clear();
  199. if (res.code == 200) {
  200. // let copyData = JSON.parse(JSON.stringify(res.data));
  201. res.data.mainProductCategorys = res.data.mainProductCategorys
  202. ? res.data.mainProductCategorys.split(',')
  203. : [];
  204. this.detail = res.data;
  205. this.mobileStatus = res.data.mobileStatus;
  206. // mobileStatus 是否验证通过 1,2是
  207. if (res.data.mobileStatus == '1' || res.data.mobileStatus == '2') {
  208. this.verificationPassedPhoneNum = this.detail.ownerMobile;
  209. }
  210. // 验证码和发送按钮是否显示
  211. this.verifyMobile = this.mobileStatus == '0' ? false : true;
  212. }
  213. });
  214. },
  215. sendCodeTelFn(tel) {
  216. if (!/^1[123456789]\d{9}$/.test(tel) || tel == '') {
  217. this.$toast('格式错误');
  218. return;
  219. }
  220. if (tel != this.verificationPassedPhoneNum) {
  221. this.telConfirm = false;
  222. this.verifyMobile = false;
  223. } else {
  224. this.telConfirm = false;
  225. this.verifyMobile = true;
  226. }
  227. },
  228. // 发送验证码
  229. sendCode(val) {
  230. if (!/^1[123456789]\d{9}$/.test(val) || val == '') {
  231. this.$toast('格式错误');
  232. return;
  233. }
  234. this.telConfirm = true;
  235. this.verificationPassedPhoneNum = val;
  236. this.$toast('验证成功');
  237. // if (this.time) return;
  238. // clearInterval(this.time);
  239. // this.timeNum = 60;
  240. // this.sendCodeFun(
  241. // {
  242. // type: '1', //String 调用类型:1:发送验证码 2:校验验证码
  243. // phone: val, //String 手机号
  244. // verification: '', //String 手机号验证码
  245. // },
  246. // () => {
  247. // this.time = setInterval(() => {
  248. // this.timeNum--;
  249. // if (this.timeNum <= 0) {
  250. // clearInterval(this.time);
  251. // this.time = null;
  252. // }
  253. // }, 1000);
  254. // this.$toast('发送成功');
  255. // }
  256. // );
  257. },
  258. sendCodeFun(params, callback) {
  259. sendAndCheckVerCode(params).then((res) => {
  260. if (res.code == 200) {
  261. callback && callback(res);
  262. }
  263. });
  264. },
  265. verification(val) {
  266. // 验证码
  267. if (val == '') {
  268. return;
  269. }
  270. // 手机号
  271. if (this.detail.ownerMobile == '') {
  272. return;
  273. }
  274. this.sendCodeFun(
  275. {
  276. type: '2', //String 调用类型:1:发送验证码 2:校验验证码
  277. phone: this.detail.ownerMobile, //String 手机号
  278. verification: val, //String 手机号验证码
  279. },
  280. (res) => {
  281. if (res.data) this.verificationPassedPhoneNum = this.detail.ownerMobile;
  282. this.$toast(res.data ? '验证成功' : '验证码错误');
  283. }
  284. );
  285. },
  286. getNyr(val, date) {
  287. this.activatNyrItem = val;
  288. if (date && date != '') {
  289. let time = date.split('-');
  290. this.currentDate = new Date(time[0], Number(time[1]) - 1, time[2]);
  291. } else {
  292. this.currentDate = new Date(1945, 0, 1);
  293. }
  294. this.datetimeShowPicker = true;
  295. },
  296. datetimeOnConfirm(time) {
  297. this.$set(this.detail, this.activatNyrItem, this.parseTime(time, '{y}-{m}-{d}'));
  298. // this.detail.ownerBirthday = this.parseTime(time, '{y}-{m}-{d}');
  299. this.datetimeShowPicker = false;
  300. },
  301. isValidOwnerName() {
  302. this.ownerNameMsg = '';
  303. let ownerName = this.detail.ownerName;
  304. if (ownerName.length < 2) {
  305. this.ownerNameMsg = '最短字数2';
  306. return true;
  307. }
  308. if (ownerName.length > 20) {
  309. this.ownerNameMsg = '最长字数20';
  310. return true;
  311. }
  312. const chineseChars = ownerName.match(/[\u4e00-\u9fa5]/g) || [];
  313. if (chineseChars.length < 1) {
  314. this.ownerNameMsg = '至少一个汉字';
  315. return true;
  316. }
  317. if (!/^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]*)*·?$/.test(ownerName)) {
  318. this.ownerNameMsg = '只能输入中文';
  319. return true;
  320. }
  321. // if (!/^[\u4e00-\u9fa5a-zA-Z0-9·]+$/.test(ownerName)) {
  322. // this.ownerNameMsg = '不可输入特殊符号';
  323. // return true;
  324. // }
  325. return false;
  326. },
  327. isValidTotalSalesAmount() {
  328. this.totalSalesAmountMsg = '';
  329. let totalSalesAmount = this.detail.totalSalesAmount;
  330. const value = parseFloat(totalSalesAmount);
  331. if (isNaN(value)) {
  332. this.totalSalesAmountMsg = '请输入数字';
  333. return true;
  334. }
  335. if (value < 1) {
  336. this.totalSalesAmountMsg = '最小值1';
  337. return true;
  338. }
  339. if (value > 1000) {
  340. this.totalSalesAmountMsg = '最大值1000';
  341. return true;
  342. }
  343. return false;
  344. },
  345. isConstructionYearNum() {
  346. this.constructionYearNumMsg = '';
  347. let constructionYearNum = this.detail.constructionYearNum;
  348. const value = parseFloat(constructionYearNum);
  349. if (isNaN(value)) {
  350. this.constructionYearNumMsg = '请输入数字';
  351. return true;
  352. }
  353. if (value < 1) {
  354. this.constructionYearNumMsg = '最小值1';
  355. return true;
  356. }
  357. if (value > 10000) {
  358. this.constructionYearNumMsg = '最大值10000';
  359. return true;
  360. }
  361. return false;
  362. },
  363. isPerformanceRatio() {
  364. this.performanceRatioMsg = '';
  365. let performanceRatio = this.detail.performanceRatio;
  366. const value = parseFloat(performanceRatio);
  367. if (isNaN(value)) {
  368. this.performanceRatioMsg = '请输入数字';
  369. return true;
  370. }
  371. if (value < 1) {
  372. this.performanceRatioMsg = '最小值1';
  373. return true;
  374. }
  375. if (value > 100) {
  376. this.performanceRatioMsg = '最大值100';
  377. return true;
  378. }
  379. return false;
  380. },
  381. isValidMainBrand() {
  382. this.mainBrandMsg = '';
  383. let mainBrand = this.detail.mainBrand;
  384. const chineseChars = mainBrand.match(/[\u4e00-\u9fa5]/g) || [];
  385. if (chineseChars.length < 1) {
  386. this.mainBrandMsg = '至少一个汉字';
  387. return true;
  388. }
  389. return false;
  390. },
  391. // 保存
  392. confirmShare() {
  393. this.isValidOwnerName();
  394. this.isValidTotalSalesAmount();
  395. this.isValidMainBrand();
  396. if (
  397. this.verificationPassedPhoneNum == '' ||
  398. this.detail.ownerMobile != this.verificationPassedPhoneNum
  399. ) {
  400. this.$toast('请验证手机号');
  401. return;
  402. }
  403. this.isValidOwnerName();
  404. this.isValidTotalSalesAmount();
  405. this.isPerformanceRatio();
  406. this.isValidMainBrand();
  407. if (this.detail.constructionResource == '是') {
  408. this.isConstructionYearNum();
  409. }
  410. if (this.isValidOwnerName()) return;
  411. if (this.isValidTotalSalesAmount()) return;
  412. if (this.isPerformanceRatio()) return;
  413. if (this.isValidMainBrand()) return;
  414. if (this.detail.constructionResource == '是') {
  415. if (this.isConstructionYearNum()) return;
  416. }
  417. if (this.detail.emergencyContactMobile != '') {
  418. if (!/^1[123456789]\d{9}$/.test(this.detail.emergencyContactMobile)) {
  419. this.$toast('紧急联系人电话格式错误');
  420. return;
  421. }
  422. }
  423. this.toastLoading(0, '加载中...', true);
  424. let params = JSON.parse(JSON.stringify(this.detail));
  425. params.mainProductCategorys = params.mainProductCategorys.join(',');
  426. params.storeCode = this.$route.query.storeCode;
  427. updateArchives(params).then((res) => {
  428. this.toastLoading().clear();
  429. if (res.code == 200) {
  430. this.$toast(res.msg);
  431. this.$router.go(-1);
  432. } else {
  433. this.$toast(res.msg);
  434. }
  435. });
  436. },
  437. emergencyContactBlur(val) {
  438. if (!/^1[123456789]\d{9}$/.test(val)) {
  439. this.$toast('紧急联系人电话格式错误');
  440. }
  441. },
  442. clickFn() {
  443. if (!this.checkRadioFlag) {
  444. this.detail.emergencyContactRelation = '';
  445. }
  446. this.checkRadioFlag = false;
  447. },
  448. changeFn() {
  449. this.checkRadioFlag = true;
  450. },
  451. changeResource(val) {
  452. if (val == '否') {
  453. this.detail.constructionYearNum = '';
  454. }
  455. },
  456. onClickLeft() {
  457. this.$router.go(-1);
  458. },
  459. },
  460. };
  461. </script>
  462. <style lang="scss">
  463. .JPattributeEditor {
  464. width: 100%;
  465. height: 100%;
  466. display: flex;
  467. flex-direction: column;
  468. justify-content: space-between;
  469. overflow: hidden;
  470. .content {
  471. flex: 1;
  472. overflow-y: auto;
  473. background: #fff;
  474. padding: 10px 15px;
  475. margin-top: 10px;
  476. background: #fff;
  477. .van-cell {
  478. padding: 10px 0;
  479. border-bottom: 1px solid #ccc;
  480. }
  481. .van-field__label {
  482. width: 9em;
  483. }
  484. .sendCode {
  485. border: none !important;
  486. input {
  487. border: 1px solid #f1f1f1;
  488. height: 35px;
  489. }
  490. }
  491. .van-checkbox--horizontal {
  492. margin-bottom: 10px;
  493. width: 100%;
  494. }
  495. .van-radio--horizontal {
  496. margin-bottom: 10px;
  497. }
  498. }
  499. .footer-btn {
  500. display: flex;
  501. justify-content: space-around;
  502. padding: 10px 0;
  503. }
  504. }
  505. </style>