index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <view>
  3. <z-navbar :title="(type==0?'新建':'编辑')+'咨询'" back>
  4. <view slot="right" @click="submit">保存</view>
  5. </z-navbar>
  6. <w-picker mode="date" startYear="2000" endYear="2100" v-model="info.alertDate" :current="true" fields="day" @confirm="onConfirm($event)"
  7. @cancel="onCancel" :disabled-after="false" ref="date"></w-picker>
  8. <w-picker mode="date" startYear="2000" endYear="2100" v-model="info.wantDate" :current="true" fields="day" @confirm="onConfirmWantDate($event)"
  9. @cancel="onCancel" :disabled-after="false" ref="wantdate"></w-picker>
  10. <z-form :model="info" :rules="rules" ref="info">
  11. <z-form-item label="客户姓名" prop="customName">
  12. <image slot="icon" class="common_icon" src="../../../static/icon_person.png"></image>
  13. <z-input v-model="info.customName" placeholder="点击填写"></z-input>
  14. </z-form-item>
  15. <z-divider></z-divider>
  16. <z-form-item label="客户电话" prop="phone" showline>
  17. <image slot="icon" class="common_icon" src="../../../static/icon_tel.png"></image>
  18. <z-input type="number" v-model="info.phone" placeholder="点击填写"></z-input>
  19. </z-form-item>
  20. <z-form-item label="微信号" prop="wechatNo" showline>
  21. <image slot="icon" class="common_icon" src="../../../static/icon_weixin.png"></image>
  22. <z-input type="number" v-model="info.wechatNo" placeholder="点击填写"></z-input>
  23. </z-form-item>
  24. <z-form-item label="意向日期" prop="wantDate" arrow showline>
  25. <image slot="icon" class="common_icon" src="../../../static/icon_date.png"></image>
  26. <z-text v-model="info.wantDate" placeholder="选择意向日期" @click="choosewantDate"></z-text>
  27. </z-form-item>
  28. <z-form-item label="时间段" prop="wantBeginTime" showline>
  29. <image slot="icon" class="common_icon" src="../../../static/icon_time.png"></image>
  30. <view class="flex-n fac fje">
  31. <z-text v-model="info.wantBeginTime" placeholder="开始时间" @click.native="showTime1=true"></z-text>
  32. <view class="mlr-20">-</view>
  33. <z-text v-model="info.wantEndTime" placeholder="结束时间" @click.native="showTime2=true"></z-text>
  34. </view>
  35. </z-form-item>
  36. <z-time-select :visible.sync="showTime1" :step="30" v-model="info.wantBeginTime" start="07:00" :maxTime="info.wantEndTime"></z-time-select>
  37. <z-time-select :visible.sync="showTime2" :step="30" start="07:00" :minTime="info.wantBeginTime||'7:00'" v-model="info.wantEndTime"></z-time-select>
  38. <z-form-item label="意向数量" prop="userCount" showline>
  39. <image slot="icon" class="common_icon" src="../../../static/icon_num.png"></image>
  40. <z-input type="number" v-model="info.userCount" placeholder="点击填写"></z-input>
  41. </z-form-item>
  42. <z-form-item label="意向场地" prop="wantHouse" showline>
  43. <image slot="icon" class="common_icon" src="../../../static/icon_local.png"></image>
  44. <want-house multiple @checkedDetail="checkedWantHouseDetail" v-model="info.wantHouse" placeholder="选择意向场地"></want-house>
  45. </z-form-item>
  46. <z-form-item label="预算金额" prop="budgetStart" showline>
  47. <image slot="icon" class="common_icon" src="../../../static/icon_price.png"></image>
  48. <view class="flex-n fac">
  49. <z-input style="text-align: left;" type="number" v-model="info.budgetStart" placeholder="¥"></z-input>
  50. <view class="mlr-20">~</view>
  51. <z-input style="text-align: right;" type="number" v-model="info.budgetEnd" placeholder="¥"></z-input>
  52. </view>
  53. </z-form-item>
  54. <z-form-item label="意向度" prop="wantLevel" showline>
  55. <image slot="icon" class="common_icon" src="../../../static/icon_star.png"></image>
  56. <want-level v-model="info.wantLevel" placeholder="请选择意向度"></want-level>
  57. </z-form-item>
  58. <z-form-item label="顾客来源" prop="userFrom" showline>
  59. <image slot="icon" class="common_icon" src="../../../static/icon_phone.png"></image>
  60. <user-from v-model="info.userFrom" placeholder="选择客户来源" @changeDetail="changeUserFormDetail"></user-from>
  61. </z-form-item>
  62. <template v-if="info.wantDate&&new Date(info.wantDate).getTime()>=new Date($Date.getDayDate().date).getTime()">
  63. <z-divider></z-divider>
  64. <z-form-item height="100rpx" label="关闭提醒" showline>
  65. <switch :checked="switchAlert" @change="changeSwitchAlert" />
  66. </z-form-item>
  67. <z-form-item label="提醒时间" prop="alertDate" v-show="!switchAlert" arrow :required="!switchAlert" dynamic>
  68. <image slot="icon" class="common_icon" src="../../../static/icon_date.png"></image>
  69. <z-text v-model="info.alertDate" placeholder="选择提醒时间" @click="chooseDate"></z-text>
  70. </z-form-item>
  71. </template>
  72. <z-divider></z-divider>
  73. <z-form-item label="备注信息" prop="remark" labelPos="top">
  74. <textarea class="textarea" :value="info.remark" placeholder="请输入备注信息" maxlength="512" auto-height></textarea>
  75. </z-form-item>
  76. </z-form>
  77. <u-toast ref="uToast"></u-toast>
  78. </view>
  79. </template>
  80. <script>
  81. const app = getApp({
  82. allowDefault: true
  83. });
  84. import wantHouse from '../../component/wantHouse/wantHouse.vue';
  85. import wantLevel from '../../component/wantLevel/wantLevel.vue';
  86. import userFrom from '../../component/userFrom/userFrom.vue'
  87. export default {
  88. components: {
  89. wantLevel,
  90. wantHouse,
  91. userFrom
  92. },
  93. data() {
  94. var validatePhone = (rule, value, callback) => {
  95. if (this.info.phone && this.info.phone.length < 11 && this.info.phone.length > 0)
  96. return {
  97. state: false,
  98. message: '请输入11位有效的电话号'
  99. };
  100. else
  101. return true;
  102. };
  103. var validateAlertDate = (rule, value, callback) => {
  104. // time.getTime() > new Date(wantDate).getTime()
  105. if(!this.switchAlert){
  106. if (new Date(this.info.alertDate).getTime() > new Date(this.info.wantDate).getTime())
  107. return {
  108. state: false,
  109. message: '提醒日期不能大于意向日期'
  110. };
  111. else if (new Date(this.info.alertDate).getTime() < new Date(this.$Date.getDayDate().date).getTime()) {
  112. return {
  113. state: false,
  114. message: '设置的提醒日期不能小于当前日期'
  115. }
  116. }else{
  117. console.log('ok')
  118. return true;
  119. }
  120. }
  121. else{
  122. console.log('ok')
  123. return true;
  124. }
  125. };
  126. var validateBudget = (rule, value, callback) => {
  127. if (this.info.budgetStart == '' && this.info.budgetEnd != '') {
  128. return {
  129. state: false,
  130. message: '请输入预算金额最小值'
  131. };
  132. } else if (this.info.budgetStart != '' && this.info.budgetEnd == '') {
  133. return {
  134. state: false,
  135. message: '请输入预算金额最大值'
  136. };
  137. } else {
  138. if (Number(this.info.budgetStart) > Number(this.info.budgetEnd)) {
  139. return {
  140. state: false,
  141. message: '预算金额最大值应大于最小值'
  142. };
  143. }
  144. return true;
  145. }
  146. };
  147. var validateWantTime = (rule, value, callback) => {
  148. if ((this.info.wantBeginTime == '' || !this.info.wantBeginTime) && this.info.wantEndTime) {
  149. return {
  150. state: false,
  151. message: '请选择开始时间'
  152. };
  153. } else if ((this.info.wantEndTime == '' || !this.info.wantEndTime) && this.info.wantBeginTime) {
  154. return {
  155. state: false,
  156. message: '请选择结束时间'
  157. };
  158. }
  159. return true;
  160. };
  161. return {
  162. id: '',
  163. type: 0,
  164. wantHouseDetail: [],
  165. userFromDetail: {},
  166. switchAlert: true,
  167. showTime1: false,
  168. showTime2: false,
  169. info: {
  170. customName: '',
  171. phone: '',
  172. wechatNo: '',
  173. wantDate: '',
  174. userCount: '',
  175. wantHouse: '',
  176. budgetStart: '',
  177. budgetEnd: '',
  178. wantLevel: '',
  179. userFrom: '',
  180. alertDate: '',
  181. wantBeginTime: '',
  182. wantEndTime: '',
  183. remark: ''
  184. },
  185. rules: {
  186. customName: [{
  187. required: true,
  188. message: ''
  189. }],
  190. phone: [{
  191. validator: validatePhone
  192. }],
  193. wantDate: [{
  194. required: true,
  195. message: ''
  196. }],
  197. userCount: [{
  198. required: true,
  199. message: ''
  200. }],
  201. wantHouse: [{
  202. required: true,
  203. message: ''
  204. }],
  205. budgetStart: [{
  206. validator: validateBudget
  207. }],
  208. wantBeginTime: [{
  209. validator: validateWantTime
  210. }],
  211. wantLevel: [{
  212. required: true,
  213. message: ''
  214. }],
  215. userFrom: [{
  216. required: true,
  217. message: ''
  218. }],
  219. alertDate: [{
  220. validator: validateAlertDate
  221. }]
  222. },
  223. askAlertDaysAfter: 0,
  224. alertDate: ''
  225. };
  226. },
  227. watch: {
  228. // 'info.wantDate'(newval, oldval) {
  229. // console.log(newval)
  230. // var wantDate = newval;
  231. // //默认提醒日期
  232. // var time = new Date(new Date(this.$Date.getDayDate().date).getTime() + this.askAlertDaysAfter * 24 * 60 * 60 * 1000)
  233. // console.log(time)
  234. // var month = time.getMonth() + 1,
  235. // day = time.getDate();
  236. // if (!this.switchAlert)
  237. // //默认提醒日期大于wantDate
  238. // if (time.getTime() > new Date(wantDate).getTime()) {
  239. // this.$set(this.info, 'alertDate', null);
  240. // } else {
  241. // this.$set(this.info, 'alertDate', time.getFullYear() + '-' + (month < 10 ? ('0' + month) : month) + '-' + (
  242. // day < 10 ? ('0' + day) : day))
  243. // }
  244. // this.alertDate = this.info.alertDate;
  245. // }
  246. },
  247. onLoad(option) {
  248. this.type = option.type;
  249. this.id = option.id;
  250. if (this.type == 1)
  251. this.getData(option.id);
  252. },
  253. mounted() {
  254. this.getaskalertTime();
  255. },
  256. methods: {
  257. selectError() {
  258. uni.showToast({
  259. title: '需大于开始时间' + this.info.wantBeginTime,
  260. icon: 'none'
  261. });
  262. },
  263. bindBeginTimeChange(e) {
  264. this.$set(this.info, 'wantBeginTime', e.target.value)
  265. },
  266. bindEndTimeChange(e) {
  267. this.$set(this.info, 'wantEndTime', e.target.value)
  268. },
  269. getaskalertTime() {
  270. console.log('storeId', uni.getStorageSync('storeId'))
  271. this.$axios.get('config/baseByStoreId/' + uni.getStorageSync('storeId')).then(res => {
  272. console.log('咨询后', res.data.askAlertDaysAfter, '天')
  273. console.log(res.data, res.data.orderAlertDaysBefore)
  274. this.askAlertDaysAfter = Number(res.data.askAlertDaysAfter) || 0;
  275. }).catch(err => {
  276. this.$refs.uToast.error(err.msg);
  277. })
  278. },
  279. getData(askId) {
  280. this.$axios.get('app/preUserAsk/findById/' + askId).then(res => {
  281. console.log(res)
  282. var info = res.data
  283. var wantHouse = [],
  284. wantHouse2 = [];
  285. for (var i = 0, len = info.wantHouse.length; i < len; i++) {
  286. if (info.wantHouse[i]) {
  287. wantHouse.push(info.wantHouse[i].houseId)
  288. wantHouse2.push({
  289. houseId: info.wantHouse[i].houseId,
  290. houseName: info.wantHouse[i].houseName
  291. })
  292. }
  293. }
  294. info.userFrom = info.customFromId;
  295. info.wantHouse = wantHouse;
  296. this.wantHouseDetail = wantHouse2;
  297. this.info = info;
  298. this.alertDate = info.alertDate;
  299. }).catch(err => {
  300. console.log(err)
  301. this.$refs.uToast.error(err.msg);
  302. })
  303. },
  304. changeSwitchAlert(e) {
  305. this.switchAlert = e.detail.value;
  306. if (this.switchAlert) {
  307. this.$set(this.info, 'alertDate', null)
  308. } else {
  309. this.$set(this.info, 'alertDate', this.alertDate)
  310. }
  311. },
  312. checkedWantHouseDetail(data) {
  313. var wantHouse = [];
  314. for (var i = 0, len = data.length; i < len; i++) {
  315. wantHouse.push({
  316. houseId: data[i].id,
  317. houseName: data[i].houseName
  318. })
  319. }
  320. console.log(wantHouse)
  321. this.wantHouseDetail = wantHouse;
  322. },
  323. changeUserFormDetail(data) {
  324. console.log(data)
  325. this.userFromDetail = data;
  326. },
  327. choosewantDate() {
  328. this.$refs.wantdate.show();
  329. },
  330. chooseDate() {
  331. this.$refs.date.show();
  332. },
  333. onConfirm(e) {
  334. this.$set(this.info, 'alertDate', e.value);
  335. this.alertDate = e.value;
  336. },
  337. onConfirmWantDate(e) {
  338. var wantDate = e.value;
  339. this.$set(this.info, 'wantDate', e.value)
  340. //默认提醒日期
  341. var time = new Date(new Date(this.$Date.getDayDate().date).getTime() + this.askAlertDaysAfter * 24 * 60 * 60 * 1000)
  342. console.log(time)
  343. var month = time.getMonth() + 1,
  344. day = time.getDate();
  345. if (!this.switchAlert) {
  346. //默认提醒日期大于wantDate
  347. if (time.getTime() > new Date(wantDate).getTime()) {
  348. this.$set(this.info, 'alertDate', null);
  349. } else {
  350. this.$set(this.info, 'alertDate', time.getFullYear() + '-' + (month < 10 ? ('0' + month) : month) + '-' + (
  351. day < 10 ? ('0' + day) : day))
  352. }
  353. }
  354. if (new Date(wantDate).getTime() < new Date(this.$Date.getDayDate().date).getTime()) {
  355. this.switchAlert = true;
  356. this.$set(this.info, 'alertDate', null);
  357. }
  358. this.alertDate = this.info.alertDate;
  359. },
  360. onCancel() {
  361. console.log(this.$refs.date.value, this.$refs.date.pickVal)
  362. },
  363. submit() {
  364. this.$refs.info.validate(val => {
  365. console.log(val)
  366. if (val) {
  367. if (this.type == 0) {
  368. this.addSubmit();
  369. } else {
  370. this.editSubmit();
  371. }
  372. } else {
  373. this.$refs.uToast.error('表单填写有误');
  374. }
  375. })
  376. },
  377. addSubmit() {
  378. var info = this.info;
  379. this.$axios.post('app/preUserAsk/saveAsk', {
  380. storeId: uni.getStorageSync('storeId'), //this.$root.getStorage('storeId')
  381. customName: info.customName, //客户名称
  382. phone: info.phone, //手机号
  383. wechatNo: info.wechatNo, //微信号
  384. userCount: info.userCount, //意向人数
  385. wantDate: info.wantDate, //意向日期
  386. wantBeginTime: info.wantBeginTime,
  387. wantEndTime: info.wantEndTime,
  388. alertDate: info.alertDate, //提醒日期
  389. customFromId: this.userFromDetail.id, //用户来源
  390. customFromName: this.userFromDetail.customFrom,
  391. budgetStart: info.budgetStart, //预期起
  392. budgetEnd: info.budgetEnd, //预期止
  393. wantLevel: info.wantLevel, //意向程度
  394. wantHouse: this.wantHouseDetail, //意向场地
  395. remark: info.remark, //备注
  396. }).then(res => {
  397. this.$refs.uToast.success('新增咨询成功!');
  398. uni.navigateBack({
  399. delta: 1
  400. });
  401. }).catch(err => {
  402. this.$refs.uToast.error(err.msg);
  403. })
  404. },
  405. editSubmit() {
  406. var info = this.info;
  407. this.$axios.post('app/preUserAsk/updateAsk', {
  408. storeId: '2', //this.$root.getStorage('storeId')
  409. id: this.id,
  410. customName: info.customName, //客户名称
  411. phone: info.phone, //手机号
  412. wechatNo: info.wechatNo, //微信号
  413. userCount: info.userCount, //意向人数
  414. wantDate: info.wantDate, //意向日期
  415. wantBeginTime: info.wantBeginTime,
  416. wantEndTime: info.wantEndTime,
  417. alertDate: info.alertDate, //提醒日期
  418. customFromId: this.userFromDetail.dicCode, //用户来源
  419. customFromName: this.userFromDetail.dicName,
  420. budgetStart: info.budgetStart, //预期起
  421. budgetEnd: info.budgetEnd, //预期止
  422. wantLevel: info.wantLevel, //意向程度
  423. wantHouse: this.wantHouseDetail, //意向场地
  424. remark: info.remark, //备注
  425. }).then(res => {
  426. this.$refs.uToast.success('新增咨询成功!');
  427. uni.navigateBack({
  428. delta: 1
  429. });
  430. }).catch(err => {
  431. this.$refs.uToast.error(err.msg);
  432. })
  433. }
  434. }
  435. }
  436. </script>
  437. <style lang="scss" scoped>
  438. .order_package_manage {
  439. background: #0075FF;
  440. color: #0075FF;
  441. width: 34rpx;
  442. height: 34rpx;
  443. }
  444. .textarea {
  445. font-size: 28rpx;
  446. min-height: 80rpx;
  447. padding-bottom: 20rpx;
  448. width: 100%;
  449. }
  450. .common_icon {
  451. width: 58rpx;
  452. height: 58rpx;
  453. min-width: 58rpx;
  454. margin-right: 30rpx;
  455. }
  456. </style>