detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <div class="borderless" v-loading="pageLoading">
  3. <div class="customer-head">
  4. <div class="customer-back">
  5. <el-button
  6. type="danger"
  7. style="border: none;background: none;color: red"
  8. icon="el-icon-arrow-left"
  9. @click="backToList"
  10. :loading="btnLoading"
  11. >返回列表</el-button>
  12. </div>
  13. <div class="add-customer-btn">
  14. <el-button
  15. type="primary"
  16. size="small"
  17. class="el-button--small-yh"
  18. @click.stop="openEdit"
  19. v-if="disabled"
  20. >编 辑</el-button>
  21. <el-button
  22. type="success"
  23. :disabled="!form.id"
  24. size="small"
  25. @click="copyDoc"
  26. :loading="btnLoading"
  27. v-if="false"
  28. >复制单据</el-button>
  29. <el-button
  30. type="primary"
  31. @click="editCustomer"
  32. size="small"
  33. :loading="btnLoading"
  34. >保存数据</el-button>
  35. </div>
  36. </div>
  37. <div class="customer-main">
  38. <containerTitle title="基础信息"/>
  39. <basic-container :showBtn="true">
  40. <avue-form
  41. ref="form"
  42. class="trading-form"
  43. v-model="form"
  44. :option="option"
  45. >
  46. <template slot="corpId">
  47. <crop-select
  48. v-model="form.corpId"
  49. @getCorpData="getKHData"
  50. corpType="KH"
  51. />
  52. </template>
  53. <template slot="fromUser">
  54. <el-select
  55. v-model="form.fromUser"
  56. filterable
  57. clearable
  58. size="small"
  59. :disabled="disabled"
  60. >
  61. <el-option
  62. v-for="(item,index) in userList"
  63. :key="index"
  64. :label="item.realName"
  65. :value="item.id"
  66. ></el-option>
  67. </el-select>
  68. </template>
  69. <template slot="toUser">
  70. <el-select
  71. v-model="form.toUser"
  72. filterable
  73. clearable
  74. size="small"
  75. :disabled="disabled"
  76. >
  77. <el-option
  78. v-for="(item,index) in userList"
  79. :key="index"
  80. :label="item.realName"
  81. :value="item.id"
  82. ></el-option>
  83. </el-select>
  84. </template>
  85. </avue-form>
  86. </basic-container>
  87. <containerTitle title="沟通记录"/>
  88. <basic-container>
  89. <avue-crud
  90. ref="crud"
  91. :data="dataList"
  92. :option="tableOption"
  93. :cell-style="cellStyle"
  94. @saveColumn="saveColumn"
  95. @resetColumn="resetColumn"
  96. >
  97. <template slot="menuLeft">
  98. <el-button
  99. type="primary"
  100. icon="el-icon-plus"
  101. size="small"
  102. @click.stop="newDetails"
  103. :disabled="disabled"
  104. >录入明细</el-button>
  105. <el-button
  106. type="info"
  107. icon="el-icon-printer"
  108. size="small"
  109. v-if="false"
  110. >报表打印</el-button>
  111. </template>
  112. <template slot="menu" slot-scope="{ row, index }">
  113. <el-button
  114. size="small"
  115. icon="el-icon-edit"
  116. type="text"
  117. @click="rowCell(row, index)"
  118. :disabled="disabled"
  119. >{{ row.$cellEdit ? "保存" : "修改" }}</el-button>
  120. <el-button
  121. size="small"
  122. icon="el-icon-delete"
  123. type="text"
  124. @click="rowDel(row, index)"
  125. :disabled="disabled"
  126. >删除</el-button>
  127. </template>
  128. <template slot="bizDate" slot-scope="{ row, index }">
  129. <el-date-picker
  130. v-if="row.$cellEdit"
  131. v-model="row.bizDate"
  132. type="date"
  133. placeholder="选择日期"
  134. size="small"
  135. style="width: 100%"
  136. format="yyyy-MM-dd"
  137. valueFormat="yyyy-MM-dd"
  138. ></el-date-picker>
  139. <span v-else>{{row.bizDate}}</span>
  140. </template>
  141. <template slot="bizContent" slot-scope="{ row, index }">
  142. <el-input
  143. v-if="row.$cellEdit"
  144. v-model="row.bizContent"
  145. size="small"
  146. placeholder="输入内容"
  147. />
  148. <span v-else>{{row.bizContent}}</span>
  149. </template>
  150. <template slot="contacts" slot-scope="{ row, index }">
  151. <el-input
  152. v-if="row.$cellEdit"
  153. v-model="row.contacts"
  154. size="small"
  155. placeholder="输入客户联系人"
  156. />
  157. <span v-else>{{row.contacts}}</span>
  158. </template>
  159. <template slot="tel" slot-scope="{ row, index }">
  160. <el-input
  161. v-if="row.$cellEdit"
  162. v-model="row.tel"
  163. size="small"
  164. placeholder="输入联系方式"
  165. />
  166. <span v-else>{{row.tel}}</span>
  167. </template>
  168. <template slot="approval" slot-scope="{ row, index }">
  169. <el-switch
  170. v-model="row.approval"
  171. :disabled="!row.$cellEdit"
  172. :inactive-value="0"
  173. :active-value="1"
  174. ></el-switch>
  175. </template>
  176. </avue-crud>
  177. </basic-container>
  178. </div>
  179. </div>
  180. </template>
  181. <script>
  182. import tableOption from "./config/customerContact.json";
  183. import {
  184. isDiscount,
  185. isPercentage,
  186. micrometerFormat,
  187. IntegerFormat
  188. } from "@/util/validate";
  189. import { gainUser } from "@/api/basicData/customerInquiry";
  190. import {getUserInfo} from "@/api/system/user";
  191. import {getDeptTree} from "@/api/system/dept";
  192. import { getCurrentDate } from "@/util/date";
  193. import {dataDetail, typeSave, removeGoods, pleaseCheck} from "@/api/standAlone/saleLeads";
  194. import { contrastObj, contrastList } from "@/util/contrastData";
  195. export default {
  196. name: "detail",
  197. props: {
  198. detailData: {
  199. type: Object
  200. }
  201. },
  202. data() {
  203. const validateRemark = (rule, value, callback) => {
  204. if (this.form.status == 2 && !this.form.remarks) {
  205. callback(new Error('备注不能为空'))
  206. } else {
  207. callback()
  208. }
  209. }
  210. return {
  211. disabled: false,
  212. checkDisabled: false,
  213. pageLoading: false,
  214. btnLoading: false,
  215. form: {},
  216. option: {
  217. menuBtn: false,
  218. labelWidth: 100,
  219. column: [
  220. {
  221. label: "客户名称",
  222. prop: "corpName",
  223. rules: [
  224. {
  225. required: true,
  226. message: " ",
  227. trigger: "blur"
  228. }
  229. ],
  230. span: 8,
  231. slot: true,
  232. },
  233. {
  234. label: "客户联系人",
  235. prop: "contacts",
  236. rules: [
  237. {
  238. required: true,
  239. message: " ",
  240. trigger: "blur"
  241. }
  242. ],
  243. span: 8,
  244. slot: true,
  245. },
  246. {
  247. label: "客户电话",
  248. prop: "tel",
  249. rules: [
  250. {
  251. required: true,
  252. message: " ",
  253. trigger: "blur"
  254. }
  255. ],
  256. span: 8,
  257. slot: true,
  258. type: 'number',
  259. controls: false,
  260. mock: {
  261. type: 'number',
  262. precision: 0,
  263. },
  264. },
  265. {
  266. label: "业务内容",
  267. prop: "bizContent",
  268. rules: [
  269. {
  270. required: true,
  271. message: " ",
  272. trigger: "blur"
  273. }
  274. ],
  275. span: 8,
  276. slot: true,
  277. },
  278. {
  279. label: "业务日期",
  280. prop: "bizDate",
  281. span: 8,
  282. type: "date",
  283. format: "yyyy-MM-dd",
  284. valueFormat: "yyyy-MM-dd 00:00:00",
  285. rules: [
  286. {
  287. required: true,
  288. message: " ",
  289. trigger: "blur"
  290. }
  291. ]
  292. },
  293. {
  294. label: "承揽人",
  295. prop: "fromUser",
  296. rules: [
  297. {
  298. required: true,
  299. message: " ",
  300. trigger: "change"
  301. }
  302. ],
  303. span: 8,
  304. slot: true,
  305. },
  306. {
  307. label: "对接人",
  308. prop: "toUser",
  309. rules: [
  310. {
  311. required: true,
  312. message: " ",
  313. trigger: "change"
  314. }
  315. ],
  316. span: 8,
  317. slot: true,
  318. },
  319. {
  320. label: "状态",
  321. prop: "status",
  322. span: 8,
  323. type: 'select',
  324. dicData: [
  325. {label: '沟通中', value: 0},
  326. {label: '成交', value: 1},
  327. {label: '未成交', value: 2},
  328. ],
  329. rules: [
  330. {
  331. required: true,
  332. message: " ",
  333. trigger: "change"
  334. }
  335. ],
  336. },
  337. {
  338. label: "备注",
  339. prop: "remarks",
  340. type: "textarea",
  341. minRows: 2,
  342. span: 24,
  343. rules: [
  344. {validator: validateRemark, trigger: 'blur'}
  345. ]
  346. },
  347. ],
  348. },
  349. dataList: [],
  350. tableOption: {},
  351. goodsoptions: [],
  352. unitOption: [],
  353. selectionList: [],
  354. search: {},
  355. treeStyle: "height:" + (window.innerHeight - 315) + "px",
  356. goodsOption: {},
  357. loading: false,
  358. switchDialog: false, // 报表弹窗控制
  359. userList: [],
  360. dic: [],
  361. loginUser: '', // 登录人
  362. loginUserId: null,
  363. oldForm: {},
  364. oldDataList: [],
  365. }
  366. },
  367. async created() {
  368. this.$set(this.form, 'bizDate', getCurrentDate()); // 默认当前日期
  369. this.tableOption = await this.getColumnData(
  370. this.getColumnName(102),
  371. tableOption
  372. );
  373. gainUser().then(res => {
  374. this.userList = res.data.data;
  375. });
  376. getUserInfo().then(res => {
  377. this.$set(this.form, 'fromUser', res.data.data.id);
  378. this.$set(this.form, 'toUser', res.data.data.id);
  379. this.loginUser = res.data.data.realName;
  380. this.loginUserId = res.data.data.id;
  381. })
  382. getDeptTree().then(res => {
  383. this.dic = res.data.data
  384. })
  385. this.getWorkDicts('unit').then(res => {
  386. this.unitOption = res.data.data;
  387. })
  388. if (this.detailData.query) {
  389. this.disabled = true;
  390. this.option.column.map(e => {
  391. this.$set(e, 'disabled', true)
  392. })
  393. this.queryData(this.detailData.id);
  394. } else if (this.detailData.auditId) {
  395. this.checker = true;
  396. this.batchNo = this.detailData.check.batchNo
  397. this.queryData(this.detailData.id);
  398. }
  399. },
  400. filters: {
  401. IntegerFormat(num) {
  402. return IntegerFormat(num);
  403. },
  404. decimalFormat(num) {
  405. return num ? Number(num).toFixed(2) : "0.00";
  406. }
  407. },
  408. methods: {
  409. // 查询
  410. queryData(id) {
  411. this.pageLoading = true;
  412. dataDetail({id: id}).then(res => {
  413. this.form = res.data.data;
  414. this.dataList = this.form.itemList? this.form.itemList: [];
  415. this.oldForm = {...this.form};
  416. this.oldDataList = [...this.dataList];
  417. delete this.form.itemList;
  418. this.checkDisabled = this.form.status > 0? true: false;
  419. if (this.form.status > 0) {
  420. this.option.column.map(e => {
  421. this.$set(e, 'disabled', true)
  422. })
  423. }
  424. }).finally(() => {
  425. this.pageLoading = false;
  426. })
  427. },
  428. //返回列表
  429. backToList() {
  430. this.$emit("goBack");
  431. },
  432. // 编辑按钮触发
  433. openEdit() {
  434. this.disabled = false;
  435. this.option.column.map(e => {
  436. if (this.checkDisabled) {
  437. this.$set(e, 'disabled', true)
  438. } else {
  439. this.$set(e, 'disabled', false)
  440. }
  441. })
  442. },
  443. // 复制
  444. copyDoc() {
  445. this.$emit("copyOrder", this.form.id);
  446. },
  447. //修改提交触发
  448. editCustomer(status) {
  449. this.$refs["form"].validate((valid, done) => {
  450. done();
  451. if (valid) {
  452. this.btnLoading = true;
  453. this.$set(this.form, 'itemList', this.dataList)
  454. typeSave(this.form).then(res => {
  455. this.$message({type: "success", message: this.form.id ? "修改成功!" : "新增成功!"});
  456. this.queryData(res.data.data);
  457. }).finally(() => {
  458. this.btnLoading = false;
  459. })
  460. } else {
  461. return false
  462. }
  463. })
  464. },
  465. cellStyle() {
  466. return "padding:0;height:40px;";
  467. },
  468. async saveColumn() {
  469. const inSave = await this.saveColumnData(
  470. this.getColumnName(102),
  471. this.tableOption
  472. );
  473. if (inSave) {
  474. this.$message.success("保存成功");
  475. //关闭窗口
  476. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  477. this.$nextTick(() => {
  478. this.$refs.crud.doLayout()
  479. })
  480. }
  481. },
  482. async resetColumn() {
  483. this.tableOption = tableOption;
  484. const inSave = await this.delColumnData(
  485. this.getColumnName(102),
  486. tableOption
  487. );
  488. if (inSave) {
  489. this.$nextTick(() => {
  490. this.$refs.crud.doLayout()
  491. })
  492. this.$message.success("重置成功");
  493. //关闭窗口
  494. setTimeout(() => {
  495. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  496. }, 1000);
  497. }
  498. },
  499. //录入明细
  500. newDetails() {
  501. this.$refs["form"].validate((valid, done) => {
  502. done()
  503. if (valid) {
  504. this.dataList.push({
  505. bizDate: getCurrentDate(),
  506. bizTime: getCurrentDate(),
  507. bizUserName: this.loginUser,
  508. bizUser: this.loginUserId,
  509. $cellEdit: true,
  510. })
  511. }
  512. })
  513. },
  514. rowCell(row, index) {
  515. if (row.$cellEdit == true) {
  516. this.$set(row, "$cellEdit", false);
  517. } else {
  518. this.$set(row, "$cellEdit", true);
  519. }
  520. },
  521. rowDel(row, index) {
  522. this.$confirm("确定删除数据?", {
  523. confirmButtonText: "确定",
  524. cancelButtonText: "取消",
  525. type: "warning"
  526. }).then(() => {
  527. if (row.id) {
  528. removeGoods(row.id).then(res => {
  529. this.$message({
  530. type: 'success',
  531. message: '删除成功!'
  532. })
  533. this.dataList.splice(row.$index, 1);
  534. })
  535. } else {
  536. this.$message({
  537. type: "success",
  538. message: "删除成功!"
  539. });
  540. this.dataList.splice(row.$index, 1);
  541. }
  542. });
  543. },
  544. getKHData(row) {},
  545. // 验证新旧值对比
  546. verification() {
  547. if (contrastObj(this.form, this.oldForm) ||
  548. contrastList(this.dataList, this.oldDataList)) {
  549. this.$confirm("数据发生变化未有提交记录, 是否提交?", "提示", {
  550. confirmButtonText: "确定",
  551. cancelButtonText: "取消",
  552. type: "warning"
  553. }).then(() => {
  554. this.editCustomer();
  555. }).catch(() => {
  556. return false; //取消改动数据
  557. })
  558. } else {
  559. return true;
  560. }
  561. },
  562. },
  563. }
  564. </script>
  565. <style scoped>
  566. </style>