detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div>
  3. <Toptitle
  4. :title="
  5. type == 1
  6. ? '超标价格方案新增'
  7. : type == 2
  8. ? '超标价格方案编辑'
  9. : '超标价格方案详情'
  10. "
  11. >
  12. <slot name="titleButton">
  13. <Button @click="goBack" type="primary" ghost style="margin-right:10px;"
  14. >返回</Button
  15. >
  16. <Button
  17. @click="postData"
  18. type="primary"
  19. v-show="!isChecked"
  20. style="margin-right:10px;"
  21. >保存</Button
  22. >
  23. </slot>
  24. </Toptitle>
  25. <div class="top_search">
  26. <Form :model="formData" :label-width="100" class="top_search_form">
  27. <FormItem label="ID:">
  28. <Input
  29. type="text"
  30. size="small"
  31. disabled
  32. v-if="type != 3"
  33. v-model="formData.id"
  34. placeholder="自动生成"
  35. style="width: 200px"
  36. />
  37. <span v-else>{{ formData.id }}</span>
  38. </FormItem>
  39. <FormItem label="方案名称:">
  40. <Input
  41. type="text"
  42. size="small"
  43. v-if="type != 3"
  44. v-model="formData.title"
  45. placeholder="请输入方案名称"
  46. style="width: 200px"
  47. />
  48. <span v-else>{{ formData.title }}</span>
  49. </FormItem>
  50. </Form>
  51. </div>
  52. <div class="addBtn">
  53. <Button @click="handleRuleAdd()" v-show="!isChecked" type="primary"
  54. >新增规则</Button
  55. >
  56. </div>
  57. <Table :columns="tableColumns" max-height="600" :data="tableData" border>
  58. <template slot="productSet" slot-scope="{ index }">
  59. <!-- <Select v-model="tableData[index].basic_product_id"
  60. :disabled="isChecked"
  61. @on-change="changeProduct(tableData[index],index)">
  62. <Option v-for="item of cascader_list"
  63. :key="item.id"
  64. :value="item.id"
  65. :label="item.title"></Option>
  66. </Select> -->
  67. <el-cascader
  68. v-if="type != 3"
  69. v-model="tableData[index].basic_product_id"
  70. size="small"
  71. :show-all-levels="false"
  72. :options="cascader_list"
  73. :props="{
  74. expandTrigger: 'hover',
  75. children: 'child',
  76. value: 'id',
  77. label: 'title',
  78. emitPath: false,
  79. }"
  80. @change="changeProduct(tableData[index], index)"
  81. ></el-cascader>
  82. <span v-else>{{ tableData[index].product_type_title }}</span>
  83. </template>
  84. <template slot="partsSet" slot-scope="{ index }">
  85. <Select v-model="tableData[index].part_id" v-if="type != 3">
  86. <!-- @on-change="changeProduct(tableData[index],index)" -->
  87. <Option
  88. v-for="item of tableData[index].partsList"
  89. :key="item.id"
  90. :value="item.id"
  91. :label="item.title"
  92. ></Option>
  93. </Select>
  94. <span v-else>{{ tableData[index].part_title }}</span>
  95. </template>
  96. <template slot="typeSet" slot-scope="{ index }">
  97. <Select v-model="tableData[index].type" v-if="type != 3">
  98. <!-- @on-change="changeProduct(tableData[index],index)" -->
  99. <Option label="高" :value="1"></Option>
  100. <Option label="宽" :value="2"></Option>
  101. <Option label="厚" :value="3"></Option>
  102. </Select>
  103. <span v-else>{{
  104. tableData[index].type == 1
  105. ? "高"
  106. : tableData[index].type == 2
  107. ? "宽"
  108. : "厚"
  109. }}</span>
  110. </template>
  111. <template slot="priceSet" slot-scope="{ index }">
  112. <Input
  113. @on-focus="openKey(index)"
  114. v-if="type != 3"
  115. clearable
  116. placeholder="请输入公式"
  117. v-model="tableData[index].formula"
  118. />
  119. <span v-else>{{ tableData[index].formula }}</span>
  120. </template>
  121. <template slot="set" slot-scope="{ index }">
  122. <a
  123. style="margin:0 5px"
  124. :disabled="isChecked"
  125. @click="handleSet(tableData[index], index, 5)"
  126. >复制</a
  127. >
  128. <a
  129. style="margin:0 5px"
  130. v-show="!isChecked"
  131. @click="handleSet(tableData[index], index, 4)"
  132. >删除</a
  133. >
  134. </template>
  135. </Table>
  136. <Modal
  137. v-model="keyModal"
  138. :width="1250"
  139. :mask-closable="false"
  140. :closable="false"
  141. >
  142. <div>
  143. <KeyBoard
  144. :rightData="measureList"
  145. @cancel="cancelKey"
  146. @success="successKey"
  147. class="key-co"
  148. />
  149. </div>
  150. <div slot="footer"></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,
  169. loading: false,
  170. tableData: [],
  171. page_index: 1,
  172. total: 0,
  173. page_size: 10,
  174. formData: {},
  175. keyModal: false,
  176. tableColumns: [
  177. {
  178. title: "产品分类",
  179. key: "basic_product_id",
  180. align: "center",
  181. minWidth: 140,
  182. slot: "productSet",
  183. },
  184. {
  185. title: "部件",
  186. key: "part_id",
  187. align: "center",
  188. minWidth: 140,
  189. slot: "partsSet",
  190. },
  191. {
  192. title: "测量字段",
  193. key: "type",
  194. align: "center",
  195. minWidth: 140,
  196. slot: "typeSet",
  197. },
  198. {
  199. title: "最小数值",
  200. key: "min",
  201. align: "center",
  202. minWidth: 160,
  203. render: (h, params) => {
  204. const { row, index } = params;
  205. const currencyRow = this.tableData[index];
  206. return this.type != 3
  207. ? h("Input", {
  208. props: {
  209. placeholder: "默认为0",
  210. value: currencyRow.min,
  211. disabled: this.isChecked,
  212. },
  213. on: {
  214. "on-change": (e) => {
  215. const val = e.target.value * 1;
  216. currencyRow.min = val;
  217. // this.tableData.splice(index, 1, currencyRow);
  218. },
  219. },
  220. })
  221. : h("span", {}, currencyRow.min);
  222. },
  223. },
  224. {
  225. title: "最大数值",
  226. key: "max",
  227. align: "center",
  228. minWidth: 160,
  229. render: (h, params) => {
  230. const { row, index } = params;
  231. const currencyRow = this.tableData[index];
  232. return this.type != 3
  233. ? h("Input", {
  234. props: {
  235. placeholder: "默认为99999",
  236. value: currencyRow.max,
  237. disabled: this.isChecked,
  238. },
  239. on: {
  240. "on-change": (e) => {
  241. const val = e.target.value * 1;
  242. currencyRow.max = val;
  243. // this.tableData.splice(index, 1, currencyRow);
  244. },
  245. },
  246. })
  247. : h("span", {}, currencyRow.max);
  248. },
  249. },
  250. {
  251. title: "超标价格",
  252. key: "formula",
  253. align: "center",
  254. slot: "priceSet",
  255. minWidth: 140,
  256. },
  257. { title: "操作", key: "", align: "center", slot: "set", width: 120 },
  258. ],
  259. partsList: [],
  260. measureList: [],
  261. attrindex: null,
  262. cascader_list: [],
  263. };
  264. },
  265. // 生命周期 - 创建完成(可以访问当前this实例)
  266. created() {
  267. // 获取产品分类
  268. this.axios
  269. .get("/api/basics_product_index")
  270. .then((res) => {
  271. this.cascader_list = res.data.data;
  272. })
  273. .catch((err) => {
  274. console.error(err);
  275. });
  276. },
  277. // 生命周期 - 挂载完成(可以访问DOM元素)
  278. mounted() {
  279. this.init();
  280. },
  281. methods: {
  282. init() {
  283. this.id &&
  284. this.axios
  285. .get("/api/overdraft_detail", { params: { id: this.id } })
  286. .then((res) => {
  287. this.tableData = res.data.list;
  288. this.formData = res.data.detail;
  289. if (this.type != 3) {
  290. this.tableData.forEach((element, index) => {
  291. element.partsList = [];
  292. this.axios
  293. .get("/api/get_part_by_basic_product", {
  294. params: { basic_product_id: element.basic_product_id },
  295. })
  296. .then((res) => {
  297. element.partsList = res.data;
  298. this.tableData.splice(index, 1, element);
  299. // this.$forceUpdate()
  300. })
  301. .catch((err) => {
  302. console.error(err);
  303. });
  304. element.basic_product_id &&
  305. this.axios("/api/basics_product_list", {
  306. params: { id: element.basic_product_id },
  307. }).then((res) => {
  308. if (res.code == 200) {
  309. const { data } = res;
  310. const result = data.filter(
  311. (rows) => rows.id == element.basic_product_id
  312. );
  313. // this.productFiled = data;
  314. this.measureList = result[0].measure;
  315. }
  316. });
  317. });
  318. }
  319. })
  320. .catch((err) => {
  321. console.error(err);
  322. });
  323. },
  324. goBack() {
  325. this.$router.go(-1);
  326. },
  327. handleSet(row, index, type) {
  328. let obj;
  329. // 4删除5复制
  330. switch (type) {
  331. case 4:
  332. this.tableData.splice(index, 1);
  333. break;
  334. case 5:
  335. obj = JSON.parse(JSON.stringify(row));
  336. this.tableData.splice(index, 0, obj);
  337. break;
  338. }
  339. },
  340. postData() {
  341. this.axios({
  342. method: "post",
  343. url: "/api/overdraft_edit",
  344. data: {
  345. ...this.formData,
  346. detail: this.tableData,
  347. },
  348. }).then((res) => {
  349. if (res.code == 200) {
  350. this.$Message.success(res.msg);
  351. this.goBack();
  352. }
  353. });
  354. },
  355. handleRuleAdd() {
  356. const obj = { min: null, max: null, formula: null };
  357. this.tableData.push(obj);
  358. },
  359. changeProduct(row, index) {
  360. row.basic_product_id &&
  361. this.axios
  362. .get("/api/get_part_by_basic_product", {
  363. params: { basic_product_id: row.basic_product_id },
  364. })
  365. .then((res) => {
  366. row.partsList = res.data;
  367. row.part_id = "";
  368. this.tableData.splice(index, 1, row);
  369. })
  370. .catch((err) => {
  371. console.error(err);
  372. });
  373. row.basic_product_id &&
  374. this.axios("/api/basics_product_list", {
  375. params: { id: row.basic_product_id },
  376. }).then((res) => {
  377. if (res.code == 200) {
  378. const { data } = res;
  379. const result = data.filter(
  380. (rows) => rows.id == row.basic_product_id
  381. );
  382. // this.productFiled = data;
  383. this.measureList = result[0].measure;
  384. }
  385. });
  386. },
  387. openKey(row) {
  388. this.keyModal = true;
  389. this.attrindex = row;
  390. },
  391. successKey(str) {
  392. this.tableData[this.attrindex].formula = str;
  393. this.keyModal = false;
  394. this.tableData.splice(this.attrindex, 1, this.tableData[this.attrindex]);
  395. },
  396. cancelKey() {
  397. this.keyModal = false;
  398. },
  399. },
  400. // 监听属性 类似于data概念
  401. computed: {},
  402. // 监控data中的数据变化
  403. watch: {},
  404. beforeCreate() {}, // 生命周期 - 创建之前
  405. beforeMount() {}, // 生命周期 - 挂载之前
  406. beforeUpdate() {}, // 生命周期 - 更新之前
  407. updated() {}, // 生命周期 - 更新之后
  408. beforeDestroy() {}, // 生命周期 - 销毁之前
  409. destroyed() {}, // 生命周期 - 销毁完成
  410. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  411. };
  412. </script>
  413. <style lang="scss" scoped>
  414. .top_search {
  415. padding: 20px 0;
  416. width: 100%;
  417. .top_search_form {
  418. // width: 800px;
  419. // display: flex;
  420. // justify-content: space-around;
  421. /deep/ .ivu-form-item {
  422. display: inline-block;
  423. width: 300px;
  424. }
  425. }
  426. }
  427. .addBtn {
  428. display: flex;
  429. justify-content: flex-end;
  430. padding: 10px 0;
  431. }
  432. /deep/ .ivu-table-wrapper {
  433. overflow: visible;
  434. }
  435. /deep/.ivu-form-item-content {
  436. span {
  437. vertical-align: middle;
  438. }
  439. }
  440. </style>