detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <div>
  3. <Toptitle
  4. :title="type == 1 ? '新增客户' : type == 2 ? '编辑客户' : '查看客户'"
  5. >
  6. <slot name="titleButton">
  7. <Button @click="goBack" type="primary" ghost style="margin-right:10px;"
  8. >返回</Button
  9. >
  10. <Button
  11. @click="postData"
  12. :disabled="isChecked"
  13. type="primary"
  14. style="margin-right:10px;"
  15. >保存</Button
  16. >
  17. </slot>
  18. </Toptitle>
  19. <div class="top_search">
  20. <Form :model="formData" :label-width="100" class="top_search_form">
  21. <FormItem label="客户编码:">
  22. <Input
  23. type="text"
  24. size="small"
  25. v-model="formData.code"
  26. :disabled="isChecked"
  27. placeholder="请输入客户编码"
  28. style="width: 200px"
  29. />
  30. </FormItem>
  31. <FormItem label="客户分类:">
  32. <el-cascader
  33. v-model="formData.basics_custom_id"
  34. size="small"
  35. :show-all-levels="false"
  36. :disabled="isChecked"
  37. :options="cascader_list"
  38. :props="{
  39. expandTrigger: 'hover',
  40. children: 'sub',
  41. value: 'id',
  42. label: 'title',
  43. checkStrictly: true,
  44. emitPath: false,
  45. }"
  46. @change="handleCascaderChange"
  47. ></el-cascader>
  48. </FormItem>
  49. <FormItem label="客户名称:">
  50. <Input
  51. type="text"
  52. size="small"
  53. v-model="formData.title"
  54. :disabled="isChecked"
  55. placeholder="请输入客户名称"
  56. style="width: 200px"
  57. />
  58. </FormItem>
  59. <FormItem label="折扣率(%):">
  60. <Input
  61. type="text"
  62. size="small"
  63. :disabled="isChecked"
  64. v-model="formData.fax"
  65. placeholder="请输入折扣率"
  66. style="width: 200px"
  67. >
  68. </Input>
  69. </FormItem>
  70. <FormItem label="专营业务员:">
  71. <Select
  72. v-model="formData.service_id"
  73. filterable
  74. clearable
  75. :disabled="isChecked"
  76. >
  77. <Option
  78. v-for="item of userList"
  79. :key="item.id"
  80. :value="item.id"
  81. :label="item.nickname"
  82. ></Option>
  83. </Select>
  84. </FormItem>
  85. <FormItem label="超标方案:">
  86. <Select
  87. v-model="formData.overdraft_plan_id"
  88. filterable
  89. clearable
  90. :disabled="isChecked"
  91. >
  92. <Option
  93. v-for="item of overStandardList"
  94. :key="item.id"
  95. :value="item.id"
  96. :label="item.title"
  97. ></Option>
  98. </Select>
  99. </FormItem>
  100. <FormItem label="是否启用:">
  101. <i-switch v-model="formData.lockState" :disabled="isChecked" />
  102. </FormItem>
  103. </Form>
  104. </div>
  105. <div class="addBtn">
  106. <Button @click="handleRuleAdd()" :disabled="isChecked" type="primary"
  107. >新增</Button
  108. >
  109. </div>
  110. <Table :columns="tableColumns" max-height="550" :data="tableData" border>
  111. <template slot="priceSet" slot-scope="{ index }">
  112. <Input
  113. :disabled="type == 3"
  114. @on-focus="openKey(index)"
  115. clearable
  116. placeholder="请输入公式"
  117. v-model="tableData[index].formula"
  118. ></Input>
  119. </template>
  120. <template slot="set" slot-scope="{ index }">
  121. <a
  122. style="margin:0 5px"
  123. :disabled="isChecked"
  124. @click="handleSet(tableData[index], index, 4)"
  125. >删除</a
  126. >
  127. <a
  128. style="margin:0 5px"
  129. :disabled="isChecked"
  130. @click="handleSet(tableData[index], index, 5)"
  131. >设为默认</a
  132. >
  133. </template>
  134. </Table>
  135. <Modal
  136. v-model="showModal"
  137. title="选择地区"
  138. @on-ok="handleModalOk"
  139. @on-cancel="showModal = false"
  140. >
  141. <div class="modal_content">
  142. <Tree
  143. :data="treeData"
  144. @on-select-change="handleSelectChange"
  145. @on-toggle-expand="handleToggleExpand"
  146. children-key="sub"
  147. style="width:100%;"
  148. class="demo-tree-render"
  149. ></Tree>
  150. </div>
  151. </Modal>
  152. </div>
  153. </template>
  154. <script>
  155. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  156. // 例如:import 《组件名称》 from '《组件路径》';
  157. import KeyBoard from "../../../components/keyboard/index";
  158. export default {
  159. name: "",
  160. components: { KeyBoard },
  161. props: {},
  162. // import引入的组件需要注入到对象中才能使用
  163. data() {
  164. // 这里存放数据
  165. return {
  166. type: this.$route.query.type || null,
  167. id: this.$route.query.id || null,
  168. isChecked: this.$route.query.type == 3 ? true : false,
  169. loading: false,
  170. tableData: [],
  171. page_index: 1,
  172. total: 0,
  173. page_size: 10,
  174. formData: {
  175. lockState: true,
  176. },
  177. keyModal: false,
  178. tableColumns: [
  179. {
  180. title: "负责人",
  181. key: "service_name",
  182. align: "center",
  183. minWidth: 140,
  184. render: (h, params) => {
  185. const { row, index } = params;
  186. const currencyRow = this.tableData[index];
  187. return this.type != 3
  188. ? h(
  189. "Input",
  190. {
  191. props: {
  192. value: currencyRow.service_name,
  193. placeholder: "请输入负责人",
  194. },
  195. on: {
  196. "on-change": (e) => {
  197. currencyRow.service_name = e.target.value;
  198. },
  199. },
  200. },
  201. currencyRow.service_name
  202. )
  203. : h("span", {}, currencyRow.service_name);
  204. },
  205. },
  206. {
  207. title: "手机号",
  208. key: "mobile",
  209. align: "center",
  210. minWidth: 140,
  211. render: (h, params) => {
  212. const { row, index } = params;
  213. const currencyRow = this.tableData[index];
  214. return this.type != 3
  215. ? h(
  216. "Input",
  217. {
  218. props: {
  219. value: currencyRow.mobile,
  220. placeholder: "请输入手机号",
  221. },
  222. on: {
  223. "on-change": (e) => {
  224. currencyRow.mobile = e.target.value;
  225. },
  226. },
  227. },
  228. currencyRow.mobile
  229. )
  230. : h("span", {}, currencyRow.mobile);
  231. },
  232. },
  233. {
  234. title: "地区",
  235. key: "area_title",
  236. align: "center",
  237. minWidth: 120,
  238. render: (h, params) => {
  239. const { row, index } = params;
  240. const currencyRow = this.tableData[index];
  241. return this.isChecked
  242. ? h("span", {}, currencyRow.area_title)
  243. : h(
  244. "a",
  245. {
  246. on: {
  247. click: () => {
  248. this.handleAreaSet(currencyRow, index);
  249. },
  250. },
  251. },
  252. currencyRow.area_title ? currencyRow.area_title : "选择地区"
  253. );
  254. },
  255. },
  256. {
  257. title: "详细地址",
  258. key: "part_id",
  259. align: "center",
  260. minWidth: 200,
  261. render: (h, params) => {
  262. const { row, index } = params;
  263. const currencyRow = this.tableData[index];
  264. return this.type != 3
  265. ? h(
  266. "Input",
  267. {
  268. props: {
  269. value: currencyRow.address,
  270. placeholder: "请输入详细地址",
  271. },
  272. on: {
  273. "on-change": (e) => {
  274. currencyRow.address = e.target.value;
  275. },
  276. },
  277. },
  278. currencyRow.address
  279. )
  280. : h("span", {}, currencyRow.address);
  281. },
  282. },
  283. { title: "操作", key: "", align: "center", slot: "set", width: 200 },
  284. ],
  285. treeData: [
  286. {
  287. title: "地区分类",
  288. expand: 1,
  289. contextmenu: 1,
  290. id: 0,
  291. sub: [],
  292. render: (h, { root, node, data }) => {
  293. return h(
  294. "span",
  295. {
  296. style: {
  297. display: "inline-block",
  298. width: "100%",
  299. },
  300. },
  301. [
  302. h("span", [
  303. h("Icon", {
  304. props: {
  305. type: "ios-folder-outline",
  306. },
  307. style: {
  308. marginRight: "8px",
  309. },
  310. }),
  311. h("span", data.title),
  312. ]),
  313. h(
  314. "span",
  315. {
  316. style: {
  317. display: "inline-block",
  318. float: "right",
  319. marginRight: "32px",
  320. },
  321. },
  322. []
  323. ),
  324. ]
  325. );
  326. },
  327. },
  328. ],
  329. tableData: [],
  330. productTypeList: [],
  331. partsList: [],
  332. attrindex: null,
  333. userList: [],
  334. overStandardList: [],
  335. showModal: false,
  336. selected: null,
  337. currencyIndex: null,
  338. cascader_list: [],
  339. };
  340. },
  341. // 生命周期 - 创建完成(可以访问当前this实例)
  342. created() {
  343. this.axios
  344. .get("/api/basics_product_index")
  345. .then((res) => {
  346. this.productTypeList = res.data.data;
  347. })
  348. .catch((err) => {
  349. console.error(err);
  350. });
  351. // 获取用户列表
  352. this.axios({ method: "get", url: "/api/employee_list" })
  353. .then((res) => {
  354. this.userList = res.data;
  355. })
  356. .catch((err) => {});
  357. // 获取超标方案
  358. this.axios({ method: "get", url: "/api/overdraft_list" })
  359. .then((res) => {
  360. this.overStandardList = res.data.data;
  361. })
  362. .catch((err) => {});
  363. // 获取地区分类列表
  364. this.axios({
  365. method: "get",
  366. url: "/api/basic_area_list",
  367. })
  368. .then((res) => {
  369. this.treeData[0].sub = res.data;
  370. })
  371. .catch((err) => {});
  372. // 获取客户分类列表
  373. this.axios({
  374. method: "post",
  375. url: "/api/basic_custom_list",
  376. })
  377. .then((res) => {
  378. this.cascader_list = res.data;
  379. })
  380. .catch((err) => {});
  381. },
  382. // 生命周期 - 挂载完成(可以访问DOM元素)
  383. mounted() {
  384. this.init();
  385. },
  386. methods: {
  387. init() {
  388. this.id &&
  389. this.axios
  390. .get("/api/custom_detail", { params: { id: this.id } })
  391. .then((res) => {
  392. this.tableData = res.data.list;
  393. this.formData = res.data.detail;
  394. this.formData.lockState = this.formData.lock == 1 ? true : false;
  395. })
  396. .catch((err) => {
  397. console.error(err);
  398. });
  399. },
  400. goBack() {
  401. this.$router.go(-1);
  402. },
  403. handleSet(row, index, type) {
  404. switch (type) {
  405. case 4:
  406. this.tableData.splice(index, 1);
  407. break;
  408. //设为默认 todo
  409. case 5:
  410. break;
  411. }
  412. },
  413. handleAreaSet(row, index) {
  414. this.showModal = true;
  415. this.currencyIndex = index;
  416. },
  417. postData() {
  418. this.axios({
  419. method: "post",
  420. url: "/api/custom_edit",
  421. data: {
  422. ...this.formData,
  423. lock: this.formData.lockState ? 1 : 0,
  424. detail: this.tableData,
  425. },
  426. }).then((res) => {
  427. if (res.code == 200) {
  428. this.$Message.success(res.msg);
  429. this.goBack();
  430. }
  431. });
  432. },
  433. handleRuleAdd() {
  434. const obj = { min: null, max: null, formula: null };
  435. this.tableData.push({});
  436. },
  437. changeProduct(row, index) {
  438. this.axios
  439. .get("/api/get_part_by_basic_product", {
  440. params: { basic_product_id: row.basic_product_id },
  441. })
  442. .then((res) => {
  443. this.partsList = res.data;
  444. })
  445. .catch((err) => {
  446. console.error(err);
  447. });
  448. },
  449. handleToggleExpand(row) {},
  450. handleModalOk() {
  451. this.tableData[this.currencyIndex].area_title = this.selected.title || "";
  452. this.tableData[this.currencyIndex].basic_area_id = this.selected.id || "";
  453. this.tableData.splice(
  454. this.currencyIndex,
  455. 1,
  456. this.tableData[this.currencyIndex]
  457. );
  458. },
  459. handleSelectChange(arr, row) {
  460. if (row.sub.length > 0) {
  461. this.selected = [];
  462. } else {
  463. this.selected = row;
  464. }
  465. },
  466. handleCascaderChange(value) {},
  467. },
  468. // 监听属性 类似于data概念
  469. computed: {},
  470. // 监控data中的数据变化
  471. watch: {},
  472. beforeCreate() {}, // 生命周期 - 创建之前
  473. beforeMount() {}, // 生命周期 - 挂载之前
  474. beforeUpdate() {}, // 生命周期 - 更新之前
  475. updated() {}, // 生命周期 - 更新之后
  476. beforeDestroy() {}, // 生命周期 - 销毁之前
  477. destroyed() {}, // 生命周期 - 销毁完成
  478. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  479. };
  480. </script>
  481. <style lang="scss" scoped>
  482. .top_search {
  483. padding: 20px 0;
  484. width: 100%;
  485. max-height: 150px;
  486. overflow: hidden;
  487. overflow-y: auto;
  488. .top_search_form {
  489. // width: 800px;
  490. // display: flex;
  491. // justify-content: space-around;
  492. /deep/ .ivu-form-item {
  493. display: inline-block;
  494. width: 300px;
  495. }
  496. }
  497. }
  498. .addBtn {
  499. display: flex;
  500. justify-content: flex-end;
  501. padding: 10px 0;
  502. }
  503. /deep/ .ivu-table-wrapper {
  504. overflow: visible;
  505. }
  506. /deep/.el-input {
  507. width: 200px;
  508. height: 26px;
  509. }
  510. /deep/.el-input__inner {
  511. height: 26px;
  512. line-height: 26px;
  513. }
  514. // /deep/.is-disabled {
  515. // background-color: #f3f3f3;
  516. // color: #ccc;
  517. // cursor: not-allowed;
  518. // }
  519. </style>