spec_back.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <el-card shadow="never" style="border: 0;">
  3. <el-form ref="form" :model="form" label-width="80px" border stripe>
  4. <el-form-item label="客户名称">
  5. <el-select v-model="value" placeholder="请选择" @change="changeCustomer">
  6. <el-option
  7. v-for="item in customerList"
  8. :key="item.value"
  9. :label="item.label"
  10. :value="item.value">
  11. </el-option>
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="品种">
  15. <el-checkbox-group v-model="form.nameValue">
  16. <el-checkbox :label="item.label" :value="JSON.stringify(item)" v-for="(item, index) in options"
  17. :key="index" @change="changeType">
  18. </el-checkbox>
  19. </el-checkbox-group>
  20. </el-form-item>
  21. <el-form-item label="规格">
  22. <el-table :data="tableData" style="border: 1px solid rgb(235, 235, 235); border-radius: 6px">
  23. <el-table-column prop="name" label="规格" width="200">
  24. </el-table-column>
  25. <el-table-column prop="price" label="发货价格" align="center">
  26. <template #default="{row}">
  27. <el-input v-model="row.price" placeholder="发货价格"></el-input>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="操作" width="120" header-align="right">
  31. <template #default="scope">
  32. <el-button @click.native.prevent="deleteRow(scope.$index, tableData)" type="text"
  33. size="small">
  34. 移除
  35. </el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" @click="onSubmit">立即创建</el-button>
  42. <el-button>取消</el-button>
  43. </el-form-item>
  44. </el-form>
  45. </el-card>
  46. </template>
  47. <script>
  48. import form from "@components/Form.js";
  49. var typeList = [], boxList = [], customerList = [], customer = 0;
  50. export default {
  51. components: { 'YunForm': form },
  52. data() {
  53. return {
  54. row: Yunqi.data.row,
  55. tableData: [],
  56. value: "",
  57. form: {
  58. nameValue: [],
  59. },
  60. options: typeList,
  61. customerList: customerList,
  62. }
  63. },
  64. methods: {
  65. //获取客户
  66. changeCustomer: function (data) {
  67. customer =data
  68. },
  69. //获取规格
  70. changeType: function (data, row) {
  71. let obj = JSON.parse(row.target.value);
  72. //品种去重
  73. let idx = boxList.findIndex(item => item.value == obj.value);
  74. if (idx != -1) {
  75. boxList.splice(idx, 1)
  76. }else{
  77. boxList.push({ label: obj.label, value: obj.value });
  78. }
  79. Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: obj.value }, false, false, true).then(res => {
  80. //编辑数据
  81. if (res.length > 0) {
  82. for (var key in Object(res)) {
  83. let index = this.tableData.findIndex(item => item.value == res[key]['id']);
  84. if (index != -1) {
  85. this.tableData.splice(index, 1)
  86. } else {
  87. this.tableData.push({ name: res[key]['title'], value: res[key]['id'], price: res[key]['price'], type_id:obj.value, type_name: obj.label });
  88. }
  89. }
  90. }
  91. });
  92. },
  93. onSubmit() {
  94. //获取规格
  95. if (this.tableData == "" || boxList.length == 0 || customer=="") return;
  96. Yunqi.ajax.post('shop/customer_spec/add', {customer_id: customer, type_list: boxList, type_box: this.tableData }, false, false, true).then(res => {
  97. if (res.code == 200) {
  98. this.$message.success(__('设置成功'));
  99. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  100. } else {
  101. this.$message.error(res.msg);
  102. return false;
  103. }
  104. });
  105. },
  106. deleteRow(index, rows) {
  107. rows.splice(index, 1);
  108. }
  109. },
  110. onLoad: function () {
  111. let type = Yunqi.data.fieldList;
  112. //全部品种
  113. for (var key in Object(type)) {
  114. typeList.push({ label: type[key], value: key });
  115. }
  116. //全部客户
  117. let customer = Yunqi.data.customerList;
  118. for (var key in Object(customer)) {
  119. customerList.push({ label: customer[key], value: key });
  120. }
  121. },
  122. }
  123. </script>
  124. <style>
  125. </style>