detail.vue 15 KB

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