goodImg.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="clearfix">
  3. <a-row>
  4. <a-col>商品大图</a-col>
  5. <a-col>
  6. <a-upload
  7. action="/rooms/cesGoods/modify"
  8. list-type="picture-card"
  9. :file-list="fileList"
  10. @preview="handlePreview"
  11. @change="handleChange"
  12. >
  13. <div v-if="fileList.length < 1">
  14. <a-icon type="plus" />
  15. <!-- <div class="ant-upload-text">Upload</div> -->
  16. </div>
  17. </a-upload>
  18. </a-col>
  19. </a-row>
  20. <a-row>
  21. <a-col>图片</a-col>
  22. <a-col>
  23. <a-upload
  24. action="#"
  25. list-type="picture-card"
  26. :file-list="fileListImgs"
  27. @preview="handlePreview"
  28. @change="handleChangeImgs"
  29. >
  30. <div v-if="fileList.length < 8">
  31. <a-icon type="plus" />
  32. <!-- <div class="ant-upload-text">Upload</div> -->
  33. </div>
  34. </a-upload>
  35. </a-col>
  36. </a-row>
  37. <a-button @click="submitImg">确认</a-button>
  38. <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
  39. <img alt="example" style="width: 100%" :src="previewImage" />
  40. </a-modal>
  41. </div>
  42. </template>
  43. <script>
  44. function getBase64(file) {
  45. return new Promise((resolve, reject) => {
  46. const reader = new FileReader();
  47. reader.readAsDataURL(file);
  48. reader.onload = () => resolve(reader.result);
  49. reader.onerror = (error) => reject(error);
  50. });
  51. }
  52. import { httpAction, getAction } from "@/api/manage";
  53. export default {
  54. inject:['modelData'],
  55. data() {
  56. return {
  57. previewVisible: false,
  58. previewImage: "",
  59. fileList: [],
  60. fileListImgs: [],
  61. model: {
  62. id: "",
  63. hotelId: 0,
  64. goodType: "",
  65. goodUnit: "",
  66. barCode: "",
  67. bid: null,
  68. name: "",
  69. sellingPrice: "",
  70. purchases: null,
  71. salesVolume: null,
  72. inventory: null,
  73. appState: false,
  74. canStoreCard: false,
  75. canIntegralPay: false,
  76. },
  77. url: {
  78. edit: "/rooms/cesGoods/modify",
  79. },
  80. };
  81. },
  82. created(){
  83. console.log(this.model);
  84. },
  85. methods: {
  86. getStartData(){
  87. this.model = this.modelData
  88. if (this.model.cover) {
  89. this.fileList.push(this.model.cover);
  90. }
  91. if (this.model.images) {
  92. this.fileListImgs = this.model.images.split(",");
  93. }
  94. },
  95. handleCancel() {
  96. this.previewVisible = false;
  97. },
  98. async handlePreview(file) {
  99. if (!file.url && !file.preview) {
  100. file.preview = await getBase64(file.originFileObj);
  101. }
  102. this.previewImage = file.url || file.preview;
  103. this.previewVisible = true;
  104. },
  105. handleChange({ fileList }) {
  106. console.log(fileList);
  107. this.fileList = fileList;
  108. },
  109. handleChangeImgs({ fileList }) {
  110. console.log(fileList);
  111. this.fileListImgs = fileList;
  112. },
  113. edit(record) {
  114. console.log(22222222, record);
  115. this.model = JSON.parse(JSON.stringify(record));
  116. if (this.model.cover) {
  117. this.fileList.push(this.model.cover);
  118. }
  119. if (this.model.images) {
  120. this.fileListImgs = this.model.images.split(",");
  121. }
  122. // console.log(this.filterType(this.treeData, record.goodType));
  123. // console.log(this.arr);
  124. this.visible = true;
  125. // getSelectList({
  126. // id: this.model.id,
  127. // }).then((res) => {
  128. // if (res.success) {
  129. // this.members = res.result;
  130. // }
  131. // });
  132. },
  133. //修改图片
  134. submitImg() {
  135. const that = this;
  136. that.confirmLoading = true;
  137. let httpurl = "";
  138. let method = "";
  139. httpurl += this.url.edit;
  140. method = "put";
  141. if (this.model.payFlag == 0) {
  142. this.model.payAmount = 0;
  143. }
  144. this.model.cover = this.fileList[0].thumbUrl;
  145. let arr=[]
  146. this.fileListImgs.forEach(ele=>{
  147. arr.push(ele.thumbUrl)
  148. })
  149. this.model.images = arr.toString()
  150. httpAction(httpurl, this.model, method)
  151. .then((res) => {
  152. if (res.success) {
  153. that.$message.success(res.message);
  154. that.$emit("ok");
  155. } else {
  156. that.$message.warning(res.message);
  157. }
  158. })
  159. .finally(() => {
  160. that.confirmLoading = false;
  161. });
  162. },
  163. submitForm() {
  164. const that = this;
  165. // 触发表单验证
  166. debugger;
  167. this.$refs.form.validate((valid) => {
  168. if (valid) {
  169. that.confirmLoading = true;
  170. let httpurl = "";
  171. let method = "";
  172. if (!this.model.id) {
  173. httpurl += this.url.add;
  174. method = "post";
  175. } else {
  176. httpurl += this.url.edit;
  177. method = "put";
  178. }
  179. if (this.model.payFlag == 0) {
  180. this.model.payAmount = 0;
  181. }
  182. httpAction(httpurl, this.model, method)
  183. .then((res) => {
  184. if (res.success) {
  185. that.$message.success(res.message);
  186. that.$emit("ok");
  187. } else {
  188. that.$message.warning(res.message);
  189. }
  190. })
  191. .finally(() => {
  192. that.confirmLoading = false;
  193. });
  194. }
  195. });
  196. },
  197. },
  198. };
  199. </script>
  200. <style>
  201. /* you can make up upload button and sample style by using stylesheets */
  202. .ant-upload-select-picture-card i {
  203. font-size: 32px;
  204. color: #999;
  205. }
  206. .ant-upload-select-picture-card .ant-upload-text {
  207. margin-top: 8px;
  208. color: #666;
  209. }
  210. </style>